|
46 | 46 | AWS_DEFAULT_REGION: ${{ inputs.aws_region }} |
47 | 47 | AWS_ACCOUNT_ID: ${{ vars.AWS_ACCOUNT_ID }} |
48 | 48 | CI_IAM_ROLE: ${{ inputs.ci_iam_role }} |
| 49 | + IMAGE_TAG: ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/${{ inputs.image_name }}:${{ inputs.image_tag }} |
49 | 50 | permissions: |
50 | 51 | id-token: write |
51 | 52 | contents: read |
@@ -80,26 +81,37 @@ jobs: |
80 | 81 | run: | |
81 | 82 | echo "ssh=main=$SSH_AUTH_SOCK" >> "${GITHUB_OUTPUT}" |
82 | 83 |
|
83 | | - - name: Build and push (with cache) |
| 84 | + - name: Build (with cache) |
84 | 85 | if: ${{ inputs.cache_docker_layers }} |
85 | 86 | uses: docker/build-push-action@v5 |
86 | 87 | with: |
87 | 88 | context: ${{ inputs.build_context }} |
88 | 89 | file: ${{ inputs.file || format('{0}/Dockerfile', inputs.build_context) }} |
89 | | - push: true |
90 | | - tags: ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/${{ inputs.image_name }}:${{ inputs.image_tag }} |
| 90 | + load: true |
| 91 | + tags: ${{ env.IMAGE_TAG }} |
91 | 92 | cache-from: type=gha |
92 | 93 | cache-to: type=gha,mode=max |
93 | 94 | ssh: ${{ steps.set_ssh.outputs.ssh }} |
94 | 95 | provenance: false |
95 | 96 |
|
96 | | - - name: Build and push (without cache) |
| 97 | + - name: Build (without cache) |
97 | 98 | if: ${{ ! inputs.cache_docker_layers }} |
98 | 99 | uses: docker/build-push-action@v5 |
99 | 100 | with: |
100 | 101 | context: ${{ inputs.build_context }} |
101 | 102 | file: ${{ inputs.file || format('{0}/Dockerfile', inputs.build_context) }} |
102 | | - push: true |
103 | | - tags: ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/${{ inputs.image_name }}:${{ inputs.image_tag }} |
| 103 | + load: true |
| 104 | + tags: ${{ env.IMAGE_TAG }} |
104 | 105 | ssh: ${{ steps.set_ssh.outputs.ssh }} |
105 | 106 | provenance: false |
| 107 | + |
| 108 | + - name: Push to ECR |
| 109 | + run: | |
| 110 | + #!/bin/bash |
| 111 | + set -euo pipefail |
| 112 | + IFS=$'\n\t' |
| 113 | + if ! docker push "$IMAGE_TAG"; then |
| 114 | + # the first time we try to push the repository won't exist and will be dynamically created so we retry after 30 seconds |
| 115 | + sleep 30 |
| 116 | + docker push "$IMAGE_TAG" |
| 117 | + fi |
0 commit comments