@ -12,6 +12,9 @@ on:
environment:
environment:
required : true
required : true
type : string
type : string
release_tag:
required : false
type : string
concurrency:
concurrency:
group : deploy-${{ inputs.environment }}
group : deploy-${{ inputs.environment }}
@ -45,8 +48,13 @@ jobs:
with:
with:
mask-password : 'true'
mask-password : 'true'
- name : Check if image with tag already exists
run : |
echo "image-exists=$(if aws ecr list-images --repository-name=$repository --query "imageIds[*].imageTag" | grep -q ${{ github.sha }}; then echo true; else echo false; fi)" >> $GITHUB_ENV
- name : Build, tag, and push docker image to ECR
- name : Build, tag, and push docker image to ECR
id : build-image
id : build-image
if : ${{ env.image-exists == 'false' }}
env:
env:
registry : ${{ steps.ecr-login.outputs.registry }}
registry : ${{ steps.ecr-login.outputs.registry }}
commit_tag : ${{ github.sha }}
commit_tag : ${{ github.sha }}
@ -77,11 +85,16 @@ jobs:
id : timestamp
id : timestamp
run : echo "timestamp=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
run : echo "timestamp=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
- name : Get additional tag
run : |
echo "additional-tag=$(if [[ ${{ inputs.environment }} == 'production' ]]; then echo ${{ inputs.release_tag }}-${{ env.timestamp }}; else echo ${{ env.timestamp }}; fi)" >> $GITHUB_ENV
- name : Add environment tag to existing image
- name : Add environment tag to existing image
id : update-image-tags
env:
env:
registry : ${{ steps.ecr-login.outputs.registry }}
registry : ${{ steps.ecr-login.outputs.registry }}
commit_tag : ${{ github.sha }}
commit_tag : ${{ github.sha }}
readable_tag : ${{ inputs.environment }}-${{ env.timestamp }}
readable_tag : ${{ inputs.environment }}-${{ env.additional-tag }}
run : |
run : |
manifest=$(aws ecr batch-get-image --repository-name $repository --image-ids imageTag=$commit_tag --output text --query images[].imageManifest)
manifest=$(aws ecr batch-get-image --repository-name $repository --image-ids imageTag=$commit_tag --output text --query images[].imageManifest)
aws ecr put-image --repository-name $repository --image-tag $readable_tag --image-manifest "$manifest"
aws ecr put-image --repository-name $repository --image-tag $readable_tag --image-manifest "$manifest"