99 runs-on : ubuntu-latest
1010
1111 steps :
12+
1213 - name : Checkout code
1314 uses : actions/checkout@v3
1415
@@ -24,16 +25,56 @@ jobs:
2425 uses : aws-actions/amazon-ecr-login@v1
2526
2627 - name : Build Docker image
28+ run : docker build -t asyncdb:latest .
29+
30+ - name : Read version
31+ id : get_version
32+ run : |
33+ VERSION=$(cat version)
34+ echo "VERSION=$VERSION" >> $GITHUB_ENV
35+
36+ - name : Check if version exists in ECR
2737 run : |
28- docker build -t asyncdb:latest .
38+ if aws ecr describe-images \
39+ --repository-name asyncdb \
40+ --image-ids imageTag=$VERSION \
41+ --region eu-west-2 \
42+ --query 'imageDetails[0].imageTags[0]' \
43+ --output text 2>/dev/null | grep -q "$VERSION"; then
44+ echo "Image version $VERSION already exists in ECR."
45+ echo "publish=true" >> $GITHUB_OUTPUT
46+ else
47+ echo "publish=false" >> $GITHUB_OUTPUT
48+ fi
49+ env :
50+ AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
51+ AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
52+ AWS_DEFAULT_REGION : eu-west-2
53+ VERSION : ${{ env.VERSION }}
2954
3055 - name : Tag Docker image for ECR
56+ if : steps.check_version.outputs.publish == 'true'
3157 run : |
32- IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:latest
58+ IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION
3359 docker tag asyncdb:latest $IMAGE_URI
60+ env :
61+ VERSION : ${{ env.VERSION }}
3462
3563 - name : Push Docker image to ECR
64+ if : steps.check_version.outputs.publish == 'true'
3665 run : |
37- IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:latest
66+ IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION
3867 docker push $IMAGE_URI
68+ env :
69+ VERSION : ${{ env.VERSION }}
70+
71+ - name : Tag Git repo with version
72+ if : steps.check_version.outputs.publish == 'true'
73+ run : |
74+ git config user.name "github-actions[bot]"
75+ git config user.email "github-actions[bot]@users.noreply.github.com"
76+ git tag "$VERSION"
77+ git push origin "$VERSION"
78+ env :
79+ VERSION : ${{ env.VERSION }}
3980
0 commit comments