Skip to content

Commit 12bf2e7

Browse files
authored
feat(docker-push): retry docker push (#185)
1 parent f77189d commit 12bf2e7

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

.github/workflows/docker-push-v4.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
AWS_DEFAULT_REGION: ${{ inputs.aws_region }}
4747
AWS_ACCOUNT_ID: ${{ vars.AWS_ACCOUNT_ID }}
4848
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 }}
4950
permissions:
5051
id-token: write
5152
contents: read
@@ -80,26 +81,37 @@ jobs:
8081
run: |
8182
echo "ssh=main=$SSH_AUTH_SOCK" >> "${GITHUB_OUTPUT}"
8283
83-
- name: Build and push (with cache)
84+
- name: Build (with cache)
8485
if: ${{ inputs.cache_docker_layers }}
8586
uses: docker/build-push-action@v5
8687
with:
8788
context: ${{ inputs.build_context }}
8889
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 }}
9192
cache-from: type=gha
9293
cache-to: type=gha,mode=max
9394
ssh: ${{ steps.set_ssh.outputs.ssh }}
9495
provenance: false
9596

96-
- name: Build and push (without cache)
97+
- name: Build (without cache)
9798
if: ${{ ! inputs.cache_docker_layers }}
9899
uses: docker/build-push-action@v5
99100
with:
100101
context: ${{ inputs.build_context }}
101102
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 }}
104105
ssh: ${{ steps.set_ssh.outputs.ssh }}
105106
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

Comments
 (0)