diff --git a/.github/workflows/build-and-upload.yml b/.github/workflows/build-and-upload.yml index f56fac6ec..ffb30911e 100644 --- a/.github/workflows/build-and-upload.yml +++ b/.github/workflows/build-and-upload.yml @@ -9,7 +9,7 @@ env: ECR_OPERATOR_RELEASE_IMAGE: ${{ vars.ECR_OPERATOR_RELEASE_IMAGE }} ECR_TARGET_ALLOCATOR_STAGING_REPO: ${{ vars.ECR_TARGET_ALLOCATOR_STAGING_REPO }} ECR_TARGET_ALLOCATOR_RELEASE_REPO: ${{ vars.ECR_TARGET_ALLOCATOR_RELEASE_REPO }} - + on: workflow_call: inputs: @@ -41,7 +41,7 @@ on: description: "Run Test on the new container image" default: true type: boolean - region: + region: description: "AWS Region to run the build/test on" default: "us-west-2" type: string @@ -54,6 +54,7 @@ jobs: permissions: id-token: write contents: read + steps: - uses: actions/checkout@v3 with: @@ -87,17 +88,43 @@ jobs: if: steps.cached_binaries.outputs.cache-hit == false uses: docker/setup-qemu-action@v1 - - name: Build Cloudwatch Agent Operator Image and push to ECR + - name: Build Cloudwatch Agent Operator AMD64 Image + uses: docker/build-push-action@v4 + if: steps.cached_binaries.outputs.cache-hit == false + with: + file: ./Dockerfile + context: . + push: true + platforms: linux/amd64 + tags: | + ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-amd64 + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + VERSION_PKG=${{ env.VERSION_PKG }} + VERSION=${{ inputs.tag }} + VERSION_DATE=${{ env.VERSION_DATE }} + AGENT_VERSION=${{ env.AGENT_VERSION }} + AUTO_INSTRUMENTATION_JAVA_VERSION=${{ env.AUTO_INSTRUMENTATION_JAVA_VERSION }} + AUTO_INSTRUMENTATION_PYTHON_VERSION=${{ env.AUTO_INSTRUMENTATION_PYTHON_VERSION }} + AUTO_INSTRUMENTATION_DOTNET_VERSION=${{ env.AUTO_INSTRUMENTATION_DOTNET_VERSION }} + AUTO_INSTRUMENTATION_NODEJS_VERSION=${{ env.AUTO_INSTRUMENTATION_NODEJS_VERSION }} + DCMG_EXPORTER_VERSION=${{ env.DCMG_EXPORTER_VERSION }} + NEURON_MONITOR_VERSION=${{ env.NEURON_MONITOR_VERSION }} + TARGET_ALLOCATOR_VERSION=${{ env.TARGET_ALLOCATOR_VERSION }} + outputs: type=image,push=true + provenance: false + + - name: Build Cloudwatch Agent Operator ARM64 Image uses: docker/build-push-action@v4 if: steps.cached_binaries.outputs.cache-hit == false with: file: ./Dockerfile context: . push: true - platforms: linux/amd64,linux/arm64 + platforms: linux/arm64 tags: | - ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }} - ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.target-sha }} + ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-arm64 cache-from: type=gha cache-to: type=gha,mode=max build-args: | @@ -157,20 +184,38 @@ jobs: run: | go mod download go mod tidy - export GOARCH=arm64 && make targetallocator - export GOARCH=amd64 && make targetallocator + mkdir -p cmd/amazon-cloudwatch-agent-target-allocator/bin + GOARCH=amd64 make targetallocator + GOARCH=arm64 make targetallocator + ls -la cmd/amazon-cloudwatch-agent-target-allocator/bin/ - - name: Build Cloudwatch Agent Target Allocator Image and push to ECR + - name: Build Target Allocator AMD64 Image uses: docker/build-push-action@v4 if: steps.cached_binaries.outputs.cache-hit == false with: file: ./cmd/amazon-cloudwatch-agent-target-allocator/Dockerfile context: ./cmd/amazon-cloudwatch-agent-target-allocator push: true + platforms: linux/amd64 tags: | - ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }} - ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.target-sha }} - platforms: linux/amd64, linux/arm64 + ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-amd64 + cache-from: type=gha + cache-to: type=gha,mode=max + provenance: false + + - name: Build Target Allocator ARM64 Image + if: steps.cached_binaries.outputs.cache-hit == false + uses: docker/build-push-action@v4 + with: + file: ./cmd/amazon-cloudwatch-agent-target-allocator/Dockerfile + context: ./cmd/amazon-cloudwatch-agent-target-allocator + push: true + platforms: linux/arm64 + tags: | + ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-arm64 + cache-from: type=gha + cache-to: type=gha,mode=max + provenance: false bypass-info: if: ${{ inputs.e2e-test-bypass-link != '' || inputs.e2e-test-bypass-approver != '' }} @@ -185,7 +230,7 @@ jobs: e2e-test: if: ${{inputs.test-image-before-upload}} name: "Application Signals E2E Test" - needs: MakeBinary + needs: CreateManifest uses: ./.github/workflows/application-signals-e2e-test.yml secrets: inherit permissions: @@ -196,7 +241,7 @@ jobs: push-release-ecr: if: ${{ inputs.release }} - needs: [ MakeTABinary, e2e-test ] + needs: [ MakeTABinary, e2e-test, CreateManifest ] permissions: id-token: write contents: read @@ -213,12 +258,64 @@ jobs: role-to-assume: ${{ env.AWS_ASSUME_ROLE }} aws-region: ${{inputs.region}} - - name: Login ECR + - name: Login to ECR id: login-ecr + if: steps.cached_binaries.outputs.cache-hit == false uses: aws-actions/amazon-ecr-login@v1 - name: Push image to release ECR run: | docker buildx imagetools create \ -t ${{ env.ECR_OPERATOR_RELEASE_IMAGE }} \ - ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }} \ No newline at end of file + ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }} + + CreateManifest: + needs: [ MakeBinary, MakeTABinary ] + runs-on: ubuntu-latest + permissions: + id-token: write + contents: read + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ inputs.target-sha }} + repository: ${{inputs.repository}} + + - name: Set up Go 1.x + uses: actions/setup-go@v4 + with: + go-version: '>1.22' + cache: true + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ env.AWS_ASSUME_ROLE }} + aws-region: ${{inputs.region}} + + - name: Login ECR + uses: aws-actions/amazon-ecr-login@v2 + + - name: Create manifests + run: | + docker manifest create ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }} \ + --amend ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-amd64 \ + --amend ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-arm64 + docker manifest push ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }} + + docker manifest create ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ github.sha }} \ + --amend ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-amd64 \ + --amend ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-arm64 + docker manifest push ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ github.sha }} + + + docker manifest create ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }} \ + --amend ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-amd64 \ + --amend ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-arm64 + docker manifest push ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }} + + docker manifest create ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ github.sha }} \ + --amend ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-amd64 \ + --amend ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}-linux-arm64 + docker manifest push ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ github.sha }} \ No newline at end of file