77jobs :
88 build-and-push :
99 runs-on : ubuntu-latest
10-
10+ container :
11+ image : amazon/aws-cli:latest
1112 steps :
13+ - name : Install dependencies
14+ run : |
15+ dnf update
16+ dnf install -y git
17+
1218 - name : Checkout code
1319 uses : actions/checkout@v3
1420
@@ -24,16 +30,52 @@ jobs:
2430 uses : aws-actions/amazon-ecr-login@v1
2531
2632 - name : Build Docker image
33+ run : docker build -t asyncdb:latest .
34+
35+ - name : Read version
36+ id : get_version
2737 run : |
28- docker build -t asyncdb:latest .
38+ VERSION=$(cat version)
39+ echo "VERSION=$VERSION" >> $GITHUB_ENV
40+
41+ - name : Check if version exists in ECR
42+ run : |
43+ if aws ecr describe-images \
44+ --repository-name my-repo \
45+ --image-ids imageTag=$VERSION \
46+ --region eu-west-2 \
47+ --query 'imageDetails[0].imageTags[0]' \
48+ --output text 2>/dev/null | grep -q "$VERSION"; then
49+ echo "Image version $VERSION already exists in ECR. Exiting."
50+ exit 1
51+ else
52+ echo "Image version $VERSION does not exist. Proceeding."
53+ fi
54+ env :
55+ AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
56+ AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
57+ AWS_DEFAULT_REGION : eu-west-2
2958
3059 - name : Tag Docker image for ECR
3160 run : |
32- IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:latest
61+ IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION
3362 docker tag asyncdb:latest $IMAGE_URI
63+ env :
64+ VERSION : ${{ env.VERSION }}
3465
3566 - name : Push Docker image to ECR
3667 run : |
37- IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:latest
68+ IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION
3869 docker push $IMAGE_URI
70+ env :
71+ VERSION : ${{ env.VERSION }}
72+
73+ - name : Tag Git repo with version
74+ run : |
75+ git config user.name "github-actions[bot]"
76+ git config user.email "github-actions[bot]@users.noreply.github.com"
77+ git tag "$VERSION"
78+ git push origin "$VERSION"
79+ env :
80+ VERSION : ${{ env.VERSION }}
3981
0 commit comments