99 runs-on : ubuntu-latest
1010
1111 steps :
12+
1213 - name : Checkout code
1314 uses : actions/checkout@v3
1415
@@ -24,16 +25,53 @@ 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. Exiting."
45+ exit 0
46+ else
47+ echo "Image version $VERSION does not exist. Proceeding."
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
3156 run : |
32- IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:latest
57+ IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION
3358 docker tag asyncdb:latest $IMAGE_URI
59+ env :
60+ VERSION : ${{ env.VERSION }}
3461
3562 - name : Push Docker image to ECR
3663 run : |
37- IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:latest
64+ IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION
3865 docker push $IMAGE_URI
66+ env :
67+ VERSION : ${{ env.VERSION }}
68+
69+ - name : Tag Git repo with version
70+ run : |
71+ git config user.name "github-actions[bot]"
72+ git config user.email "github-actions[bot]@users.noreply.github.com"
73+ git tag "$VERSION"
74+ git push origin "$VERSION"
75+ env :
76+ VERSION : ${{ env.VERSION }}
3977
0 commit comments