Skip to content

Commit

Permalink
Integration Test
Browse files Browse the repository at this point in the history
  • Loading branch information
okankoAMZ committed Oct 3, 2023
1 parent c757731 commit cadd0b6
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
with:
ContainerRepositoryNameAndTag: "cwagent-integration-test:${{ github.sha }}"
BucketKey: "integration-test/binary/${{ github.sha }}"
PackageBucketKey: "integration-test/packaging/${{ github.sha }}"
PackageBucketKey: "integration-test/binary/${{ github.sha }}"

GenerateTestMatrix:
name: 'GenerateTestMatrix'
Expand Down
116 changes: 58 additions & 58 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ env:
CWA_GITHUB_REPO_NAME: "aws/amazon-cloudwatch-agent"

on:
push:
branches:
- uniform-build-env
# push:
## branches:
### - uniform-build-env
workflow_dispatch:
inputs:
ContainerRepositoryNameAndTag:
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
if: contains(inputs.BucketKey, 'test') == false || steps.cached_binaries.outputs.cache-hit == false
run: |
cd packaging/uniformBuild
./uniformBuild -r "https://github.com/${{env.CWA_GITHUB_REPO_NAME}}.git" -b "main" -c "${{github.sha}}" -a "${{secrets.AWS_TEST_ACCOUNT_ID}}"
./uniformBuild -r "https://github.com/${{env.CWA_GITHUB_REPO_NAME}}.git" -b "main" -c "${{inputs.BucketKey}}" -a "${{secrets.AWS_TEST_ACCOUNT_ID}}"
# - name: Cache go ^^^ make it not main
# # Only skip for integration builds not release builds.
# if: contains(inputs.BucketKey, 'test') == false || steps.cached_binaries.outputs.cache-hit == false
Expand All @@ -103,13 +103,13 @@ jobs:
# ~/go/pkg/mod
# ~/.cache/go-build
# key: v1-go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
#
# - name: Import GPG Key
# if: contains(inputs.BucketKey, 'test') == false || steps.cached_binaries.outputs.cache-hit == false
# uses: crazy-max/ghaction-import-gpg@v5
# with:
# gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
# passphrase: ${{ secrets.PASSPHRASE }}

- name: Import GPG Key
if: contains(inputs.BucketKey, 'test') == false || steps.cached_binaries.outputs.cache-hit == false
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
#
# - name: Build Binaries
# if: contains(inputs.BucketKey, 'test') == false || steps.cached_binaries.outputs.cache-hit == false
Expand All @@ -118,7 +118,7 @@ jobs:
# - name: Sign Build Files
# if: contains(inputs.BucketKey, 'test') == false || steps.cached_binaries.outputs.cache-hit == false
# run: for f in $(find build/bin/); do if [ ! -d $f ]; then echo "Signing file $f" && gpg --detach-sign $f ; fi ; done
#

#
# - name: Upload to s3
# if: contains(inputs.BucketKey, 'test') == false || steps.cached_binaries.outputs.cache-hit == false
Expand Down Expand Up @@ -333,49 +333,49 @@ jobs:
# .\create_msi.ps1 "nosha" ${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}
#
# #GH actions set up gpg only works on ubuntu as of this commit date
# GPGSignMacAndWindowsPackage:
# name: 'SignMacAndWindowsPackage'
# runs-on: ubuntu-latest
# needs: [BuildMSI, MakeMacPkg]
# permissions:
# id-token: write
# contents: read
# steps:
# - uses: actions/checkout@v3
#
# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v2
# with:
# role-to-assume: ${{ secrets.TERRAFORM_AWS_ASSUME_ROLE }}
# aws-region: us-west-2
#
# - name: Cache sig
# id: cached_sig
# uses: actions/cache@v3
# with:
# key: "cached_sig_${{ github.sha }}"
# path: go.mod
#
# - name: Download from s3
# if: contains(inputs.BucketKey, 'test') == false || steps.cached_sig.outputs.cache-hit == false
# run: |
# mkdir -p packages/amd64
# mkdir packages/arm64
# aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/amazon-cloudwatch-agent.msi ./packages/amazon-cloudwatch-agent.msi
# aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/amd64/amazon-cloudwatch-agent.pkg ./packages/amd64/amazon-cloudwatch-agent.pkg
# aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/arm64/amazon-cloudwatch-agent.pkg ./packages/arm64/amazon-cloudwatch-agent.pkg
# - name: Import GPG Key
# uses: crazy-max/ghaction-import-gpg@v5
# with:
# gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
# passphrase: ${{ secrets.PASSPHRASE }}
#
# - name: Sign Build Files
# run: for f in $(find packages/); do if [ ! -d $f ]; then echo "Signing file $f" && gpg --detach-sign $f ; fi ; done
#
# - name: Upload to s3
# if: contains(inputs.BucketKey, 'test') == false || steps.cached_sig.outputs.cache-hit == false
# run: |
# aws s3 cp packages/amazon-cloudwatch-agent.msi.sig s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/amazon-cloudwatch-agent.msi.sig
# aws s3 cp packages/amd64/amazon-cloudwatch-agent.pkg.sig s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/amd64/amazon-cloudwatch-agent.pkg.sig
# aws s3 cp packages/arm64/amazon-cloudwatch-agent.pkg.sig s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/arm64/amazon-cloudwatch-agent.pkg.sig
GPGSignMacAndWindowsPackage:
name: 'SignMacAndWindowsPackage'
runs-on: ubuntu-latest
needs: [MakeBinary]
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.TERRAFORM_AWS_ASSUME_ROLE }}
aws-region: us-west-2

- name: Cache sig
id: cached_sig
uses: actions/cache@v3
with:
key: "cached_sig_${{ github.sha }}"
path: go.mod

- name: Download from s3
if: contains(inputs.BucketKey, 'test') == false || steps.cached_sig.outputs.cache-hit == false
run: |
mkdir -p packages/amd64
mkdir packages/arm64
aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/amazon-cloudwatch-agent.msi ./packages/amazon-cloudwatch-agent.msi
aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/amd64/amazon-cloudwatch-agent.pkg ./packages/amd64/amazon-cloudwatch-agent.pkg
aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/arm64/amazon-cloudwatch-agent.pkg ./packages/arm64/amazon-cloudwatch-agent.pkg
- name: Import GPG Key
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}

- name: Sign Build Files
run: for f in $(find packages/); do if [ ! -d $f ]; then echo "Signing file $f" && gpg --detach-sign $f ; fi ; done

- name: Upload to s3
if: contains(inputs.BucketKey, 'test') == false || steps.cached_sig.outputs.cache-hit == false
run: |
aws s3 cp packages/amazon-cloudwatch-agent.msi.sig s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/amazon-cloudwatch-agent.msi.sig
aws s3 cp packages/amd64/amazon-cloudwatch-agent.pkg.sig s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/amd64/amazon-cloudwatch-agent.pkg.sig
aws s3 cp packages/arm64/amazon-cloudwatch-agent.pkg.sig s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/arm64/amazon-cloudwatch-agent.pkg.sig
36 changes: 30 additions & 6 deletions packaging/uniformBuild/aws_utils.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package main

import (
"context"
"encoding/json"
"errors"
"fmt"
"sort"
"strconv"
"strings"
"sync"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/aws/aws-sdk-go-v2/service/ssm"
ssmtypes "github.com/aws/aws-sdk-go-v2/service/ssm/types"
"github.com/aws/smithy-go"
"github.com/schollz/progressbar/v3"
"sort"
"strconv"
"strings"
"sync"
"time"
)

var (
Expand Down Expand Up @@ -150,7 +154,7 @@ func (imng *InstanceManager) Close() error {
wg.Add(1)
go func(client *ec2.Client, instanceID string) {
defer wg.Done()
err := StopInstanceCmd(client, instanceID)
err := TerminateInstanceCmd(client, instanceID)
time.Sleep(10 * time.Second)
if err != nil {
return
Expand Down Expand Up @@ -286,6 +290,26 @@ func StopInstanceCmd(client *ec2.Client, instanceID string) error {
fmt.Println("Stopped instance with ID " + instanceID)
return nil
}

func TerminateInstanceCmd(client *ec2.Client, instanceID string) error {
//@TODO:Change to terminate

input := &ec2.TerminateInstancesInput{
InstanceIds: []string{
instanceID,
},
DryRun: aws.Bool(false),
}

_, err := client.TerminateInstances(context.TODO(), input)
if err != nil {
fmt.Println("Got an error terminating the instance")
return err
}
fmt.Println("Stopped instance with ID " + instanceID)
return nil
}

func enforceCommentLimit(s string) string {
const commentCharLimit = 100
if len(s) > commentCharLimit {
Expand Down
33 changes: 16 additions & 17 deletions packaging/uniformBuild/commands.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package main

import (
Expand Down Expand Up @@ -33,35 +36,33 @@ func MakeBuild() string {
)
return command
}
func UploadToS3(commitHash string) string {
BucketKey := commitHash
func UploadToS3(key string) string {
command := mergeCommands(
fmt.Sprintf("echo 'BucketKey: %s %s'",
fmt.Sprintf("echo 'key: %s %s'",
S3_INTEGRATION_BUCKET,
BucketKey,
key,
),
"cd ccwa",
fmt.Sprintf("aws s3 cp build/bin s3://%s/%s --recursive",
S3_INTEGRATION_BUCKET,
BucketKey,
key,
),
fmt.Sprintf("aws s3 cp build/bin/linux/amd64/amazon-cloudwatch-agent.rpm s3://%s/%s/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm",
S3_INTEGRATION_BUCKET,
BucketKey,
key,
),
fmt.Sprintf("aws s3 cp build/bin/linux/arm64/amazon-cloudwatch-agent.rpm s3://%s/%s/amazon_linux/arm64/latest/amazon-cloudwatch-agent.rpm",
S3_INTEGRATION_BUCKET,
BucketKey,
key,
),
)
return command
}
func CopyBinary(commitHash string) string {
BucketKey := commitHash
func CopyBinary(key string) string {
command := mergeCommands(fmt.Sprintf(
"aws s3 cp s3://%s/%s . --recursive",
S3_INTEGRATION_BUCKET,
BucketKey,
key,
),
)
return command
Expand All @@ -79,19 +80,18 @@ func MakeMSI() string {
"go run msi/tools/msiversion/msiversionconverter.go $version msi_dep/manifest.json __VERSION__",
)
}
func CopyMsi(commitHash string) string {
func CopyMsi(key string) string {
return fmt.Sprintf(
"aws s3 cp s3://%s/%s/buildMSI.zip .",
S3_INTEGRATION_BUCKET,
commitHash,
key,
)
}
func UploadMSI(commitHash string) string {
BucketKey := commitHash
func UploadMSI(key string) string {
return fmt.Sprintf(
"aws s3 cp buildMSI.zip s3://%s/%s/buildMSI.zip",
S3_INTEGRATION_BUCKET,
BucketKey,
key,
)
}

Expand Down Expand Up @@ -126,9 +126,8 @@ func CreatePkgCopyDeps() string {
"cd ..",
)
}
func BuildAndUploadMac(commitHash string) string {
func BuildAndUploadMac(key string) string {
bucket := S3_INTEGRATION_BUCKET
key := commitHash
return mergeCommands(
"cd /tmp/",
"chmod +x create_pkg.sh",
Expand Down
8 changes: 6 additions & 2 deletions packaging/uniformBuild/constant.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package main

import (
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
"time"

"github.com/aws/aws-sdk-go-v2/service/ec2/types"
)

type OS string

const TEST_REPO = "https://github.com/aws/amazon-cloudwatch-agent-test"
const MAIN_REPO = "https://github.com/aws/amazon-cloudwatch-agent.git"
const S3_INTEGRATION_BUCKET = "uniform-build-env-test"
const S3_INTEGRATION_BUCKET = "cloudwatch-agent-integration-bucket"
const BUILD_ARN = "arn:aws:iam::506463145083:instance-profile/Uniform-Build-Env-Instance-Profile"
const COMMAND_TRACKING_TIMEOUT = 20 * time.Minute
const COMMAND_TRACKING_INTERVAL = 1 * time.Second
Expand Down
29 changes: 0 additions & 29 deletions packaging/uniformBuild/scripts/actions.py

This file was deleted.

Loading

0 comments on commit cadd0b6

Please sign in to comment.