99 runs-on : ubuntu-latest
1010
1111 steps :
12+
1213 - name : Checkout code
1314 uses : actions/checkout@v3
1415
@@ -24,16 +25,52 @@ 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 my-repo \
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 1
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
2953
3054 - name : Tag Docker image for ECR
3155 run : |
32- IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:latest
56+ IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION
3357 docker tag asyncdb:latest $IMAGE_URI
58+ env :
59+ VERSION : ${{ env.VERSION }}
3460
3561 - name : Push Docker image to ECR
3662 run : |
37- IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:latest
63+ IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION
3864 docker push $IMAGE_URI
65+ env :
66+ VERSION : ${{ env.VERSION }}
67+
68+ - name : Tag Git repo with version
69+ run : |
70+ git config user.name "github-actions[bot]"
71+ git config user.email "github-actions[bot]@users.noreply.github.com"
72+ git tag "$VERSION"
73+ git push origin "$VERSION"
74+ env :
75+ VERSION : ${{ env.VERSION }}
3976
0 commit comments