From e0a4c7793bcf901203e9e2eef22293aacfeedc5a Mon Sep 17 00:00:00 2001 From: Okan Kocabalkanli Date: Thu, 5 Oct 2023 17:17:30 -0400 Subject: [PATCH] added windows and macos benchmark --- .github/workflows/test-build.yml | 22 ++++++++++++--- packaging/uniformBuild/aws_utils.go | 5 +--- packaging/uniformBuild/constant.go | 3 +-- packaging/uniformBuild/docs/docs.md | 2 +- packaging/uniformBuild/uniformBuilder.go | 27 ++++++++++--------- packaging/uniformBuild/uniformBuilder_test.go | 5 ++-- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index 73920fec66..0339a93dbd 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -112,11 +112,21 @@ jobs: passphrase: ${{ secrets.PASSPHRASE }} BinaryBenchmarkTest: name: BinaryBenchmarkTest - runs-on: ubuntu-latest - needs: [MakeBinary] + needs: [ MakeBinary ] permissions: id-token: write contents: read + strategy: + matrix: + os: [ubuntu-latest,windows-latest,macos-latest] + include: + - os: ubuntu-latest + installationScript: time sudo dpkg -i -E ./amazon-cloudwatch-agent.deb + - os: windows-latest + installationScript: Measure-Command { Start-Process msiexec "/i ./amazon-cloudwatch-agent.msi /norestart " } + - os: macos-latest + installationScript: time sudo installer -pkg ./amazon-cloudwatch-agent.pkg -target / + runs-on: ${{ matrix.os }} steps: - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v2 @@ -126,10 +136,14 @@ jobs: - name: Download RPM run: | aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/linux/amd64/amazon-cloudwatch-agent.deb . + aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/amd64/amazon-cloudwatch-agent.pkg . + aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/${{ inputs.PackageBucketKey }}/amazon-cloudwatch-agent.msi . + - name: GetRPMSize - run: ls -lh + if: matrix.os == 'ubuntu-latest' + run: ls -lh - name: Measure Installation Time - run : time sudo dpkg -i -E ./amazon-cloudwatch-agent.deb + run : ${{matrix.installationScript}} # #GH actions set up gpg only works on ubuntu as of this commit date GPGSignMacAndWindowsPackage: diff --git a/packaging/uniformBuild/aws_utils.go b/packaging/uniformBuild/aws_utils.go index e45d133953..731bd562d6 100644 --- a/packaging/uniformBuild/aws_utils.go +++ b/packaging/uniformBuild/aws_utils.go @@ -273,8 +273,6 @@ func StopInstance(c context.Context, api EC2StopInstancesAPI, input *ec2.StopIns return resp, err } func StopInstanceCmd(client *ec2.Client, instanceID string) error { - //@TODO:Change to terminate - input := &ec2.StopInstancesInput{ InstanceIds: []string{ instanceID, @@ -292,7 +290,6 @@ func StopInstanceCmd(client *ec2.Client, instanceID string) error { } func TerminateInstanceCmd(client *ec2.Client, instanceID string) error { - //@TODO:Change to terminate input := &ec2.TerminateInstancesInput{ InstanceIds: []string{ @@ -306,7 +303,7 @@ func TerminateInstanceCmd(client *ec2.Client, instanceID string) error { fmt.Println("Got an error terminating the instance") return err } - fmt.Println("Stopped instance with ID " + instanceID) + fmt.Println("Terminated the instance with ID " + instanceID) return nil } diff --git a/packaging/uniformBuild/constant.go b/packaging/uniformBuild/constant.go index 961b43f964..50ea4f1e77 100644 --- a/packaging/uniformBuild/constant.go +++ b/packaging/uniformBuild/constant.go @@ -18,6 +18,7 @@ const BUILD_ARN = "arn:aws:iam::506463145083:instance-profile/Uniform-Build-Env- const COMMAND_TRACKING_TIMEOUT = 20 * time.Minute const COMMAND_TRACKING_INTERVAL = 1 * time.Second const COMMAND_TRACKING_COUNT = int(COMMAND_TRACKING_TIMEOUT / COMMAND_TRACKING_INTERVAL) +const PLATFORM_KEY = "platform" const ( LINUX OS = "linux" @@ -35,5 +36,3 @@ var SUPPORTED_OS = []OS{ WINDOWS, MACOS, } //go doesn't let me create a slice from enum so this is the solution - -const PLATFORM_KEY = "platform" diff --git a/packaging/uniformBuild/docs/docs.md b/packaging/uniformBuild/docs/docs.md index d9692ff070..650d000b9b 100644 --- a/packaging/uniformBuild/docs/docs.md +++ b/packaging/uniformBuild/docs/docs.md @@ -13,7 +13,7 @@ InstanceManager -0aa349f04d9ea7346 + ## FAQ - Q: Why are we running commands as one giant command instead of individual ones? diff --git a/packaging/uniformBuild/uniformBuilder.go b/packaging/uniformBuild/uniformBuilder.go index abefc5cf3d..71e5c1d725 100644 --- a/packaging/uniformBuild/uniformBuilder.go +++ b/packaging/uniformBuild/uniformBuilder.go @@ -97,9 +97,14 @@ func (rbm *RemoteBuildManager) BuildCWAAgent(gitUrl string, branch string, commi // Windows func (rbm *RemoteBuildManager) MakeMsiZip(instanceName string, commitHash string) error { - //rbm.fileExistsInS3(fmt.) - //@TODO add cache - //@TODO add os check + err := rbm.instanceManager.insertOSRequirement(instanceName, LINUX) + if err != nil { + return err + } + if isAlreadyBuilt := rbm.fileExistsInS3(fmt.Sprintf("%s/buildMSI.zip", commitHash)); isAlreadyBuilt { + fmt.Println("\033Found cache skipping build") + return nil + } command := mergeCommands( CloneGitRepo(TEST_REPO, "main"), "cd ccwa", @@ -181,17 +186,14 @@ func initEnvCmd(os OS) string { // CACHE COMMANDS func (rbm *RemoteBuildManager) fileExistsInS3(targetFile string) bool { fmt.Printf("Checking for %s cache \n", targetFile) - input := &s3.ListObjectsV2Input{ + input := &s3.HeadObjectInput{ Bucket: aws.String(S3_INTEGRATION_BUCKET), - Prefix: aws.String(targetFile), + Key: aws.String(targetFile), } - _, err := rbm.s3Client.ListObjectsV2(context.Background(), input) + _, err := rbm.s3Client.HeadObject(context.TODO(), input) if err != nil { - if err.Error() == "NotFound: Not Found" { - fmt.Printf("Object %s does not exist in bucket %s\n", S3_INTEGRATION_BUCKET, targetFile) - } else { - fmt.Println(err) - } + fmt.Printf("Object %s does not exist in bucket %s\n", targetFile, S3_INTEGRATION_BUCKET) + fmt.Println(err) return false } fmt.Printf("Object %s exists in bucket %s\n", S3_INTEGRATION_BUCKET, targetFile) @@ -200,7 +202,6 @@ func (rbm *RemoteBuildManager) fileExistsInS3(targetFile string) bool { } func main() { - //@TODO FIX CACHE var repo string var branch string var comment string @@ -246,7 +247,7 @@ func main() { fmt.Printf("Failed because: %s \n", err) return } - fmt.Printf("\033[32mSuccesfully\033[0m built CWA from %s with %s branch, check \033[32m%s \033[0m bucket with \033[1;32m%s\033[0m hash", + fmt.Printf("\033[32mSuccesfully\033[0m built CWA from %s with %s branch, check \033[32m%s \033[0m bucket with \033[1;32m%s\033[0m hash\n", repo, branch, S3_INTEGRATION_BUCKET, comment) } diff --git a/packaging/uniformBuild/uniformBuilder_test.go b/packaging/uniformBuild/uniformBuilder_test.go index 7ed34f5903..2ce15ee929 100644 --- a/packaging/uniformBuild/uniformBuilder_test.go +++ b/packaging/uniformBuild/uniformBuilder_test.go @@ -29,7 +29,6 @@ func TestMain(m *testing.M) { } func TestAmiLatest(t *testing.T) { cfg, _ := config.LoadDefaultConfig(context.TODO()) - imng := CreateNewInstanceManager(cfg, DEFAULT_INSTANCE_GUIDE) // is it consistent previous := *imng.GetLatestAMIVersion(accountID).ImageId @@ -61,8 +60,8 @@ func TestS3Cache(t *testing.T) { cfg, _ := config.LoadDefaultConfig(context.TODO()) rbm := RemoteBuildManager{} rbm.s3Client = s3.NewFromConfig(cfg) - require.False(t, rbm.CheckS3("FileThatDoestExist"), "Should fail") - rbm.CheckS3("s3Check") + require.False(t, rbm.fileExistsInS3("FileThatDoestExist"), "Should fail") + require.True(t, rbm.fileExistsInS3("checkS3")) } func TestOnSpecificInstance(t *testing.T) {