|
| 1 | +name: Tag Latest container images |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + secrets: |
| 6 | + PUSH_IMAGE_ROLE: |
| 7 | + required: true |
| 8 | + inputs: |
| 9 | + ecr_name: |
| 10 | + type: string |
| 11 | + description: "The name of the ECR repository to push the dev container image to." |
| 12 | + required: true |
| 13 | + container_image_tag: |
| 14 | + type: string |
| 15 | + description: "The tag to use for the dev container image." |
| 16 | + required: true |
| 17 | + version_tag_to_apply: |
| 18 | + type: string |
| 19 | + description: "The version tag to apply to the latest dev container image." |
| 20 | + required: true |
| 21 | +jobs: |
| 22 | + tag_latest_container_images: |
| 23 | + permissions: |
| 24 | + id-token: write |
| 25 | + runs-on: ubuntu-22.04 |
| 26 | + steps: |
| 27 | + - name: Set up Docker Buildx |
| 28 | + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 |
| 29 | + |
| 30 | + - name: Configure AWS Credentials |
| 31 | + uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8 |
| 32 | + with: |
| 33 | + aws-region: eu-west-2 |
| 34 | + role-to-assume: ${{ secrets.PUSH_IMAGE_ROLE }} |
| 35 | + role-session-name: multi-arch-manifest |
| 36 | + output-credentials: true |
| 37 | + |
| 38 | + - name: Retrieve AWS Account ID |
| 39 | + id: retrieve-deploy-account-id |
| 40 | + run: | |
| 41 | + ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) |
| 42 | + echo "account_id=$ACCOUNT_ID" >> "$GITHUB_OUTPUT" |
| 43 | +
|
| 44 | + - name: Login to Amazon ECR |
| 45 | + run: | |
| 46 | + aws ecr get-login-password --region eu-west-2 | docker login --username AWS --password-stdin ${{ steps.retrieve-deploy-account-id.outputs.account_id }}.dkr.ecr.eu-west-2.amazonaws.com |
| 47 | +
|
| 48 | + - name: Create and push multi-architecture manifest for tag |
| 49 | + env: |
| 50 | + ECR_REPOSITORY: ${{ inputs.ecr_name }} |
| 51 | + IMAGE_TAG: ${{ inputs.container_image_tag }} |
| 52 | + ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }} |
| 53 | + VERSION_TAG_TO_APPLY: ${{ inputs.version_tag_to_apply }} |
| 54 | + run: | |
| 55 | + # Create manifest list combining both architectures |
| 56 | + docker buildx imagetools create -t "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:latest" \ |
| 57 | + "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-amd64" \ |
| 58 | + "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-arm64" |
| 59 | + docker buildx imagetools create -t "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${VERSION_TAG_TO_APPLY}" \ |
| 60 | + "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-amd64" \ |
| 61 | + "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-arm64" |
| 62 | +
|
| 63 | + - name: Tag images for individual architectures |
| 64 | + env: |
| 65 | + ECR_REPOSITORY: ${{ inputs.ecr_name }} |
| 66 | + IMAGE_TAG: ${{ inputs.container_image_tag }} |
| 67 | + ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }} |
| 68 | + VERSION_TAG_TO_APPLY: ${{ inputs.version_tag_to_apply }} |
| 69 | + run: | |
| 70 | + # Get the image manifest |
| 71 | + MANIFEST=$(aws ecr batch-get-image \ |
| 72 | + --repository-name "${ECR_REPOSITORY}" \ |
| 73 | + --image-ids imageTag="${IMAGE_TAG}-amd64" \ |
| 74 | + --output text --query 'images[].imageManifest') |
| 75 | +
|
| 76 | + # Put the image with a new tag using the same manifest |
| 77 | + aws ecr put-image --repository-name "${ECR_REPOSITORY}" \ |
| 78 | + --image-manifest "$MANIFEST" \ |
| 79 | + --image-tag "${VERSION_TAG_TO_APPLY}-amd64" |
| 80 | + aws ecr put-image --repository-name "${ECR_REPOSITORY}" \ |
| 81 | + --image-manifest "$MANIFEST" \ |
| 82 | + --image-tag latest-amd64 |
| 83 | +
|
| 84 | + MANIFEST=$(aws ecr batch-get-image \ |
| 85 | + --repository-name "${ECR_REPOSITORY}" \ |
| 86 | + --image-ids imageTag="${IMAGE_TAG}-arm64" \ |
| 87 | + --output text --query 'images[].imageManifest') |
| 88 | +
|
| 89 | + # Put the image with a new tag using the same manifest |
| 90 | + aws ecr put-image --repository-name "${ECR_REPOSITORY}" \ |
| 91 | + --image-manifest "$MANIFEST" \ |
| 92 | + --image-tag "${VERSION_TAG_TO_APPLY}-arm64" |
| 93 | + aws ecr put-image --repository-name "${ECR_REPOSITORY}" \ |
| 94 | + --image-manifest "$MANIFEST" \ |
| 95 | + --image-tag latest-arm64 |
| 96 | +
|
| 97 | + - name: Verify multi-architecture manifest |
| 98 | + env: |
| 99 | + ECR_REPOSITORY: ${{ inputs.ecr_name }} |
| 100 | + IMAGE_TAG: ${{ inputs.container_image_tag }} |
| 101 | + ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }} |
| 102 | + run: | |
| 103 | + echo "=== Verifying multi-architecture manifest ===" |
| 104 | + docker buildx imagetools inspect "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:latest" |
0 commit comments