From a6db8833f57a748fc3818f96e59f525057a8db12 Mon Sep 17 00:00:00 2001 From: Florian Thelliez <44224782+floriantz@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:12:12 +0200 Subject: [PATCH 1/3] chore(docker-tag): do not fail if tag already exists to make action more idempotent --- .github/workflows/docker-tag-v1.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-tag-v1.yml b/.github/workflows/docker-tag-v1.yml index 331a747..707d0fc 100644 --- a/.github/workflows/docker-tag-v1.yml +++ b/.github/workflows/docker-tag-v1.yml @@ -70,5 +70,10 @@ jobs: - name: Tag image run: | - MANIFEST=$(aws ecr batch-get-image --repository-name ${{ inputs.image_name }} --image-ids imageTag=${{ inputs.image_tag_from }} --output text --query 'images[].imageManifest') - aws ecr put-image --repository-name ${{ inputs.image_name }} --image-tag ${{ inputs.image_tag_to}} --image-manifest "$MANIFEST" + IMAGE_EXISTS=$(aws ecr describe-images --repository-name ${{ inputs.image_name }} --image-ids imageTag=${{ inputs.image_tag_to}}) + if [[ -z "$IMAGE_EXISTS" ]]; then + MANIFEST=$(aws ecr batch-get-image --repository-name ${{ inputs.image_name }} --image-ids imageTag=${{ inputs.image_tag_from }} --output text --query 'images[].imageManifest') + aws ecr put-image --repository-name ${{ inputs.image_name }} --image-tag ${{ inputs.image_tag_to }} --image-manifest "$MANIFEST" + else + echo "image ${{ inputs.image_name }}" tag ${{ inputs.image_tag_to }} already exists. Skipping..." + fi From a67cd36fdb4bc210372f3c1587d8a8f457ab9254 Mon Sep 17 00:00:00 2001 From: Florian Thelliez <44224782+floriantz@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:40:58 +0200 Subject: [PATCH 2/3] fix(bash): fixscript --- .github/workflows/docker-tag-v1.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-tag-v1.yml b/.github/workflows/docker-tag-v1.yml index 707d0fc..eb220f3 100644 --- a/.github/workflows/docker-tag-v1.yml +++ b/.github/workflows/docker-tag-v1.yml @@ -75,5 +75,5 @@ jobs: MANIFEST=$(aws ecr batch-get-image --repository-name ${{ inputs.image_name }} --image-ids imageTag=${{ inputs.image_tag_from }} --output text --query 'images[].imageManifest') aws ecr put-image --repository-name ${{ inputs.image_name }} --image-tag ${{ inputs.image_tag_to }} --image-manifest "$MANIFEST" else - echo "image ${{ inputs.image_name }}" tag ${{ inputs.image_tag_to }} already exists. Skipping..." + echo "image ${{ inputs.image_name }} tag ${{ inputs.image_tag_to }} already exists. Skipping..." fi From 18f79b13b558c895c0e1daa435b4fc02b02f486c Mon Sep 17 00:00:00 2001 From: Florian Thelliez <44224782+floriantz@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:43:52 +0200 Subject: [PATCH 3/3] fix(script): handle error properly --- .github/workflows/docker-tag-v1.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-tag-v1.yml b/.github/workflows/docker-tag-v1.yml index eb220f3..0867a82 100644 --- a/.github/workflows/docker-tag-v1.yml +++ b/.github/workflows/docker-tag-v1.yml @@ -70,7 +70,7 @@ jobs: - name: Tag image run: | - IMAGE_EXISTS=$(aws ecr describe-images --repository-name ${{ inputs.image_name }} --image-ids imageTag=${{ inputs.image_tag_to}}) + IMAGE_EXISTS=$(aws ecr describe-images --repository-name ${{ inputs.image_name }} --image-ids imageTag=${{ inputs.image_tag_to }} 2>/dev/null) if [[ -z "$IMAGE_EXISTS" ]]; then MANIFEST=$(aws ecr batch-get-image --repository-name ${{ inputs.image_name }} --image-ids imageTag=${{ inputs.image_tag_from }} --output text --query 'images[].imageManifest') aws ecr put-image --repository-name ${{ inputs.image_name }} --image-tag ${{ inputs.image_tag_to }} --image-manifest "$MANIFEST"