Skip to content

Commit

Permalink
Fix merge conflict for log.Panicf
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhntd committed Apr 5, 2022
2 parents 805abd4 + 80f8b30 commit 8e8e8b0
Show file tree
Hide file tree
Showing 31 changed files with 723 additions and 292 deletions.
113 changes: 88 additions & 25 deletions .github/workflows/integrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ env:
PRIVATE_KEY: ${{ secrets.AWS_PRIVATE_KEY }}
TERRAFORM_AWS_ACCESS_KEY_ID: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }}
TERRAFORM_AWS_SECRET_ACCESS_KEY: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }}
S3_INTEGRATION_BUCKET: ${{ secrets.S3_INTEGRATION_BUCKET }}
KEY_NAME: ${{ secrets.KEY_NAME }}
VPC_SECURITY_GROUPS_IDS: ${{ secrets.VPC_SECURITY_GROUPS_IDS }}
IAM_ROLE: ${{ secrets.IAM_ROLE }}

on:
push:
Expand Down Expand Up @@ -64,11 +68,11 @@ jobs:

- name: Build Binaries
if: steps.cached_binaries.outputs.cache-hit != 'true'
run: make build package-rpm package-deb package-win
run: make build package-rpm package-deb package-win package-darwin

- name: Upload to s3
if: steps.cached_binaries.outputs.cache-hit != 'true'
run: aws s3 cp build/bin s3://cloudwatch-agent-integration-bucket/integration-test/binary/${{ github.sha }} --recursive
run: aws s3 cp build/bin s3://${S3_INTEGRATION_BUCKET}/integration-test/binary/${{ github.sha }} --recursive

MakeMSIZip:
name: 'MakeMSIZip'
Expand Down Expand Up @@ -99,7 +103,7 @@ jobs:
- name: Copy binary
if: steps.cached_win_zip.outputs.cache-hit != 'true'
run: |
aws s3 cp s3://cloudwatch-agent-integration-bucket/integration-test/binary/${{ github.sha }} . --recursive
aws s3 cp s3://${S3_INTEGRATION_BUCKET}/integration-test/binary/${{ github.sha }} . --recursive
- uses: montudor/action-zip@v1
if: steps.cached_win_zip.outputs.cache-hit != 'true'
Expand All @@ -125,7 +129,53 @@ jobs:

- name: Upload zip
if: steps.cached_win_zip.outputs.cache-hit != 'true'
run: aws s3 cp buildMSI.zip s3://cloudwatch-agent-integration-bucket/integration-test/packaging/${{ github.sha }}/buildMSI.zip
run: aws s3 cp buildMSI.zip s3://${S3_INTEGRATION_BUCKET}/integration-test/packaging/${{ github.sha }}/buildMSI.zip

MakeMacPkg:
name: 'MakeMacPkg'
runs-on: macos-latest
needs: [MakeBinary]
steps:
- uses: actions/checkout@v2

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ~1.15.15

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-2

- name: Cache pkg
id: cached_pkg
uses: actions/cache@v2
with:
key: "cached_pkg_${{ github.sha }}"
path: RELEASE_NOTES

- name: Copy binary
if: steps.cached_pkg.outputs.cache-hit != 'true'
run: |
aws s3 cp s3://${S3_INTEGRATION_BUCKET}/integration-test/binary/${{ github.sha }} . --recursive
- name: Create pkg dep folder and copy deps
if: steps.cached_pkg.outputs.cache-hit != 'true'
run: |
echo cw agent version $(cat CWAGENT_VERSION)
cp CWAGENT_VERSION /tmp/CWAGENT_VERSION
cp -r integration/pkg/tools/. /tmp/
cp -r darwin/amd64/. /tmp/
- name: Build And Upload PKG
if: steps.cached_pkg.outputs.cache-hit != 'true'
working-directory: /tmp/
run : |
chmod +x create_pkg.sh
./create_pkg.sh ${{ secrets.S3_INTEGRATION_BUCKET }} ${{ github.sha }}
BuildMSI:
name: 'BuildMSI'
Expand All @@ -148,9 +198,10 @@ jobs:
key: "cached_msi_${{ github.sha }}"
path: buildMSI/amazon-cloudwatch-agent.msi

# Using the env variable returns "" for bucket name thus use the secret
- name: Copy msi
if: steps.cached_msi.outputs.cache-hit != 'true'
run: aws s3 cp s3://cloudwatch-agent-integration-bucket/integration-test/packaging/${{ github.sha }}/buildMSI.zip .
run: aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/integration-test/packaging/${{ github.sha }}/buildMSI.zip .

- name: Create msi
if: steps.cached_msi.outputs.cache-hit != 'true'
Expand All @@ -161,7 +212,7 @@ jobs:
$env:PATH = $env:PATH + $wixToolsetBinPath
Expand-Archive buildMSI.zip -Force
cd buildMSI
.\create_msi.ps1 ${{ github.sha }}
.\create_msi.ps1 ${{ github.sha }} ${{ secrets.S3_INTEGRATION_BUCKET }}
StartLocalStack:
name: 'StartLocalStack'
Expand Down Expand Up @@ -194,11 +245,15 @@ jobs:
terraform apply --auto-approve
-var="ssh_key=${PRIVATE_KEY}"
-var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
-var="github_sha=${GITHUB_SHA}" &&
-var="github_sha=${GITHUB_SHA}"
-var="s3_bucket=${S3_INTEGRATION_BUCKET}"
-var="vpc_security_group_ids=${VPC_SECURITY_GROUPS_IDS}"
-var="key_name=${KEY_NAME}"
-var="iam_instance_profile=${IAM_ROLE}" &&
LOCAL_STACK_HOST_NAME=$(terraform output -raw public_dns) &&
echo $LOCAL_STACK_HOST_NAME &&
echo "::set-output name=local_stack_host_name::$LOCAL_STACK_HOST_NAME" &&
aws s3 cp terraform.tfstate s3://cloudwatch-agent-integration-bucket/integration-test/local-stack-terraform-state/${GITHUB_SHA}/terraform.tfstate
aws s3 cp terraform.tfstate s3://${S3_INTEGRATION_BUCKET}/integration-test/local-stack-terraform-state/${GITHUB_SHA}/terraform.tfstate
EC2LinuxIntegrationTest:
needs: [MakeBinary, StartLocalStack]
Expand All @@ -211,47 +266,48 @@ jobs:
fail-fast: false
matrix:
arrays: [
{ os: "ubuntu", package: "package-deb", username: "ubuntu",
installAgentCommand: "dpkg -i -E ./amazon-cloudwatch-agent.deb",
{ os: "ubuntu", username: "ubuntu",
# ubuntu needs to have dpkg lock cleared before installing cw agent
installAgentCommand: "aptdcon --safe-upgrade && sudo dpkg -i -E ./amazon-cloudwatch-agent.deb",
ami: "cloudwatch-agent-integration-test-ubuntu*", caCertPath: "/etc/ssl/certs/ca-certificates.crt",
arc: "amd64", binaryName: "amazon-cloudwatch-agent.deb" },
{ os: "al2", package: "package-rpm", username: "ec2-user",
{ os: "al2", username: "ec2-user",
installAgentCommand: "rpm -U ./amazon-cloudwatch-agent.rpm",
ami: "cloudwatch-agent-integration-test-al2*", caCertPath: "/etc/ssl/certs/ca-bundle.crt",
arc: "amd64", binaryName: "amazon-cloudwatch-agent.rpm" },
{ os: "rhel8", package: "package-rpm", username: "ec2-user",
{ os: "rhel8", username: "ec2-user",
installAgentCommand: "rpm -U ./amazon-cloudwatch-agent.rpm",
ami: "cloudwatch-agent-integration-test-rhel8-base*", caCertPath: "/etc/ssl/certs/ca-bundle.crt",
arc: "amd64", binaryName: "amazon-cloudwatch-agent.rpm" },
{ os: "rhel8-1", package: "package-rpm", username: "ec2-user",
{ os: "rhel8-1", username: "ec2-user",
installAgentCommand: "rpm -U ./amazon-cloudwatch-agent.rpm",
ami: "cloudwatch-agent-integration-test-rhel8-1*", caCertPath: "/etc/ssl/certs/ca-bundle.crt",
arc: "amd64", binaryName: "amazon-cloudwatch-agent.rpm" },
{ os: "rhel8-2", package: "package-rpm", username: "ec2-user",
{ os: "rhel8-2", username: "ec2-user",
installAgentCommand: "rpm -U ./amazon-cloudwatch-agent.rpm",
ami: "cloudwatch-agent-integration-test-rhel8-2*", caCertPath: "/etc/ssl/certs/ca-bundle.crt",
arc: "amd64", binaryName: "amazon-cloudwatch-agent.rpm" },
{ os: "rhel8-3", package: "package-rpm", username: "ec2-user",
{ os: "rhel8-3", username: "ec2-user",
installAgentCommand: "rpm -U ./amazon-cloudwatch-agent.rpm",
ami: "cloudwatch-agent-integration-test-rhel8-3*", caCertPath: "/etc/ssl/certs/ca-bundle.crt",
arc: "amd64", binaryName: "amazon-cloudwatch-agent.rpm" },
{ os: "rhel8-4", package: "package-rpm", username: "ec2-user",
{ os: "rhel8-4", username: "ec2-user",
installAgentCommand: "rpm -U ./amazon-cloudwatch-agent.rpm",
ami: "cloudwatch-agent-integration-test-rhel8-4*", caCertPath: "/etc/ssl/certs/ca-bundle.crt",
arc: "amd64", binaryName: "amazon-cloudwatch-agent.rpm" },
{ os: "ol8-1", package: "package-rpm", username: "ec2-user",
{ os: "ol8-1", username: "ec2-user",
installAgentCommand: "rpm -U ./amazon-cloudwatch-agent.rpm",
ami: "cloudwatch-agent-integration-test-ol8-1*", caCertPath: "/etc/ssl/certs/ca-bundle.crt",
arc: "amd64", binaryName: "amazon-cloudwatch-agent.rpm" },
{ os: "ol8-2", package: "package-rpm", username: "ec2-user",
{ os: "ol8-2", username: "ec2-user",
installAgentCommand: "rpm -U ./amazon-cloudwatch-agent.rpm",
ami: "cloudwatch-agent-integration-test-ol8-2*", caCertPath: "/etc/ssl/certs/ca-bundle.crt",
arc: "amd64", binaryName: "amazon-cloudwatch-agent.rpm" },
{ os: "o8-3", package: "package-rpm", username: "ec2-user",
{ os: "o8-3", username: "ec2-user",
installAgentCommand: "rpm -U ./amazon-cloudwatch-agent.rpm",
ami: "cloudwatch-agent-integration-test-ol8-3*", caCertPath: "/etc/ssl/certs/ca-bundle.crt",
arc: "amd64", binaryName: "amazon-cloudwatch-agent.rpm" },
{ os: "ol8-4", package: "package-rpm", username: "ec2-user",
{ os: "ol8-4", username: "ec2-user",
installAgentCommand: "rpm -U ./amazon-cloudwatch-agent.rpm",
ami: "cloudwatch-agent-integration-test-ol8-4*", caCertPath: "/etc/ssl/certs/ca-bundle.crt",
arc: "amd64", binaryName: "amazon-cloudwatch-agent.rpm" }
Expand Down Expand Up @@ -291,20 +347,22 @@ jobs:
-var="ssh_key=${PRIVATE_KEY}"
-var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
-var="github_sha=${GITHUB_SHA}"
-var="package=${{ matrix.arrays.package }}"
-var="install_agent=${{ matrix.arrays.installAgentCommand }}"
-var="user=${{ matrix.arrays.username }}"
-var="ami=${{ matrix.arrays.ami }}"
-var="ca_cert_path=${{ matrix.arrays.caCertPath }}"
-var="arc=${{ matrix.arrays.arc }}"
-var="binary_name=${{ matrix.arrays.binaryName }}"
-var="local_stack_host_name=${{ needs.StartLocalStack.outputs.local_stack_host_name }}"
-var="s3_bucket=${S3_INTEGRATION_BUCKET}"
-var="vpc_security_group_ids=${VPC_SECURITY_GROUPS_IDS}"
-var="key_name=${KEY_NAME}"
-var="test_name=cw-integ-test-${{ matrix.arrays.os }}"
-var="iam_instance_profile=${IAM_ROLE}"
- name: Terraform destroy
if: ${{ always() && steps.ec2-linux-integration-test.outputs.cache-hit != 'true' }}
run: >
terraform destroy --auto-approve
-var="ami=${{ matrix.arrays.ami }}"
run: terraform destroy --auto-approve

EC2WinIntegrationTest:
needs: [BuildMSI]
Expand Down Expand Up @@ -352,9 +410,14 @@ jobs:
echo run terraform and execute test code &&
terraform apply --auto-approve
-var="ssh_key=${PRIVATE_KEY}"
-var="key_name=${KEY_NAME}"
-var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
-var="github_sha=${GITHUB_SHA}"
-var="ami=${{ matrix.arrays.ami }}"
-var="test_name=cw-integ-test-${{ matrix.arrays.os }}"
-var="iam_instance_profile=${IAM_ROLE}"
-var="vpc_security_group_ids=${VPC_SECURITY_GROUPS_IDS}"
-var="s3_bucket=${S3_INTEGRATION_BUCKET}"
- name: Terraform destroy
if: ${{ always() && steps.ec2-win-integration-test.outputs.cache-hit != 'true' }}
Expand All @@ -381,7 +444,7 @@ jobs:
aws-region: us-west-2

- name: Copy state
run: aws s3 cp s3://cloudwatch-agent-integration-bucket/integration-test/local-stack-terraform-state/${GITHUB_SHA}/terraform.tfstate .
run: aws s3 cp s3://${S3_INTEGRATION_BUCKET}/integration-test/local-stack-terraform-state/${GITHUB_SHA}/terraform.tfstate .

- name: Verify Terraform version
run: terraform --version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15
go-version: ~1.15.15
id: go

#Need to install rpm so ubuntu can make rpm by default ubuntu can make deb
Expand Down
2 changes: 1 addition & 1 deletion cmd/config-downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func main() {

var region, mode, downloadLocation, outputDir, inputConfig, multiConfig string

flag.StringVar(&mode, "mode", "ec2", "The mode value, i.e. ec2 or onPrem")
flag.StringVar(&mode, "mode", "ec2", "Please provide the mode, i.e. ec2, onPremise, auto")
flag.StringVar(&downloadLocation, "download-source", "",
"Download source. Example: \"ssm:my-parameter-store-name\" for an EC2 SSM Parameter Store Name holding your CloudWatch Agent configuration.")
flag.StringVar(&outputDir, "output-dir", "", "Path of output json config directory.")
Expand Down
2 changes: 1 addition & 1 deletion cmd/config-translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func initFlags() {
var inputJsonFile = flag.String("input", "", "Please provide the path of input agent json config file")
var inputJsonDir = flag.String("input-dir", "", "Please provide the path of input agent json config directory.")
var inputTomlFile = flag.String("output", "", "Please provide the path of the output CWAgent config file")
var inputMode = flag.String("mode", "ec2", "Please provide the mode, i.e. ec2, onPrem")
var inputMode = flag.String("mode", "ec2", "Please provide the mode, i.e. ec2, onPremise, auto")
var inputConfig = flag.String("config", "", "Please provide the common-config file")
var multiConfig = flag.String("multi-config", "remove", "valid values: default, append, remove")
flag.Parse()
Expand Down
5 changes: 3 additions & 2 deletions integration/msi/tools/create_msi.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# get the version
$version=$args[0]
$bucket=$args[1]

# create msi
candle.exe -ext WixUtilExtension.dll ./amazon-cloudwatch-agent.wxs
light.exe -ext WixUtilExtension.dll ./amazon-cloudwatch-agent.wixobj

# upload to s3
aws s3 cp ./amazon-cloudwatch-agent.msi "s3://cloudwatch-agent-integration-bucket/integration-test/packaging/$version/amazon-cloudwatch-agent.msi"
Write-Host "s3 for msi is s3://cloudwatch-agent-integration-bucket/integration-test/packaging/$version/amazon-cloudwatch-agent.msi"
aws s3 cp ./amazon-cloudwatch-agent.msi "s3://$bucket/integration-test/packaging/$version/amazon-cloudwatch-agent.msi"
Write-Host "s3 for msi is s3://$bucket/integration-test/packaging/$version/amazon-cloudwatch-agent.msi"
35 changes: 35 additions & 0 deletions integration/pkg/tools/create_pkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

#get the version of the agent
AGENT_VERSION=$(</tmp/CWAGENT_VERSION)

#create a .pkg file
rm -rf /tmp/AmazonCWAgentPackage
mkdir /tmp/AmazonCWAgentPackage
gunzip -c /tmp/amazon-cloudwatch-agent.tar.gz | tar -C /tmp/AmazonCWAgentPackage -xvf -
COMMON_CONFIG_PATH=/tmp/AmazonCWAgentPackage/opt/aws/amazon-cloudwatch-agent/etc/common-config.toml
SAMPLE_SUFFIX=SAMPLE_DO_NOT_MODIFY
mv ${COMMON_CONFIG_PATH} ${COMMON_CONFIG_PATH}.${SAMPLE_SUFFIX}
if [ $? -ne 0 ]; then
echo "Failed to mv common-config.toml"
exit 1
fi

mkdir /tmp/AmazonAgentScripts
mv preinstall.sh /tmp/AmazonAgentScripts/preinstall
mv postinstall.sh /tmp/AmazonAgentScripts/postinstall
chmod +x /tmp/AmazonAgentScripts/preinstall
chmod +x /tmp/AmazonAgentScripts/postinstall

rm -rf artifact
mkdir artifact
sudo pkgbuild --root /tmp/AmazonCWAgentPackage/ --install-location "/" --scripts /tmp/AmazonAgentScripts --identifier com.amazon.cloudwatch.agent --version=$AGENT_VERSION artifact/amazon-cloudwatch-agent.pkg
aws s3 cp ./artifact/amazon-cloudwatch-agent.pkg "s3://$1/integration-test/packaging/$2/amazon-cloudwatch-agent.pkg"

#TODO uncomment when signing is implemented
## create a package.tar.gz for the uploding it to signing bucket
#tar -cvzf artifact.gz -C artifact .
#tar -cvzf package.tar.gz manifest.yaml artifact.gz
#
##upload the .pkg file created
#/usr/local/bin/aws s3 cp /tmp/package.tar.gz "s3://macos-cwagent-binaries/$AGENT_VERSION/pre-signed/package.tar.gz" --acl public-read
11 changes: 11 additions & 0 deletions integration/pkg/tools/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type: :app # MUST indicate the :app type.
os: :osx
name: amazon-cloudwatch-agent.pkg # MUST reference the EXECUTABLES_TO_SIGN path in the output.
outputs:
- label: macos
path: amazon-cloudwatch-agent.pkg
app:
:identifier: com.amazon.cloudwatch.agent # must to be the same with the Bundle Identifier in info.plist
signing_requirements:
certificate_type: :developerIDInstallerDistribution
app_id_prefix: 94KV3E626L
30 changes: 30 additions & 0 deletions integration/pkg/tools/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

echo "Creating a default user cwagent"
COMMON_CONFIG_PATH=/opt/aws/amazon-cloudwatch-agent/etc/common-config.toml
SAMPLE_SUFFIX=SAMPLE_DO_NOT_MODIFY
if [ ! -f ${COMMON_CONFIG_PATH} ]; then
cp ${COMMON_CONFIG_PATH}.${SAMPLE_SUFFIX} ${COMMON_CONFIG_PATH}
fi

if [[ cwagent == `sudo dscl . -list /Users UniqueID | awk '{print $1}' | grep -w cwagent` ]]; then
echo "User already exists!"
exit 0
fi

LastID=`sudo dscl . -list /Users UniqueID | awk '{print $2}' | sort -n | tail -1`
NextID=$((LastID + 1))

. /etc/rc.common
sudo dscl . create /Users/cwagent
sudo dscl . create /Users/cwagent RealName cwagent

sudo dscl . create /Users/cwagent UniqueID $NextID
# PrimaryGroupID of 20 to create a standard user
sudo dscl . create /Users/cwagent PrimaryGroupID 20
sudo dscl . create /Users/cwagent UserShell /usr/bin/false
sudo dscl . create /Users/cwagent NFSHomeDirectory /Users/cwagent
sudo createhomedir -u cwagent -c

echo " "
echo "New user `sudo dscl . -list /Users UniqueID | awk '{print $1}' | grep -w cwagent` has been created with unique ID `sudo dscl . -list /Users UniqueID | grep -w cwagent | awk '{print $2}'`"
18 changes: 18 additions & 0 deletions integration/pkg/tools/preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

COMMON_CONFIG_PATH=/opt/aws/amazon-cloudwatch-agent/etc/common-config.toml
SAMPLE_SUFFIX=SAMPLE_DO_NOT_MODIFY
if [ -e ${COMMON_CONFIG_PATH}.${SAMPLE_SUFFIX} -a -e ${COMMON_CONFIG_PATH} ]; then
diff ${COMMON_CONFIG_PATH}.${SAMPLE_SUFFIX} ${COMMON_CONFIG_PATH} >/dev/null 2>&1
if [ $? -eq 0 ]; then
rm -r ${COMMON_CONFIG_PATH}
fi
fi

launchctl list com.amazon.cloudwatch.agent >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Agent is running in the instance"
echo "Stopping the agent"
launchctl unload /Library/LaunchDaemons/com.amazon.cloudwatch.agent.plist
echo "Agent stopped"
fi
Loading

0 comments on commit 8e8e8b0

Please sign in to comment.