66
77jobs :
88 build-and-push :
9- runs-on : ubuntu -latest
9+ runs-on : fedora -latest
1010
1111 steps :
12+ - name : Install AWS CLI
13+ run : |
14+ sudo dnf update
15+ sudo dnf install -y awscli2
16+
1217 - name : Checkout code
1318 uses : actions/checkout@v3
1419
@@ -24,16 +29,52 @@ jobs:
2429 uses : aws-actions/amazon-ecr-login@v1
2530
2631 - name : Build Docker image
32+ run : docker build -t asyncdb:latest .
33+
34+ - name : Read version
35+ id : get_version
2736 run : |
28- docker build -t asyncdb:latest .
37+ VERSION=$(cat version)
38+ echo "VERSION=$VERSION" >> $GITHUB_ENV
39+
40+ - name : Check if version exists in ECR
41+ run : |
42+ if aws ecr describe-images \
43+ --repository-name my-repo \
44+ --image-ids imageTag=$VERSION \
45+ --region eu-west-2 \
46+ --query 'imageDetails[0].imageTags[0]' \
47+ --output text 2>/dev/null | grep -q "$VERSION"; then
48+ echo "Image version $VERSION already exists in ECR. Exiting."
49+ exit 1
50+ else
51+ echo "Image version $VERSION does not exist. Proceeding."
52+ fi
53+ env :
54+ AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
55+ AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
56+ AWS_DEFAULT_REGION : eu-west-2
2957
3058 - name : Tag Docker image for ECR
3159 run : |
32- IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:latest
60+ IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION
3361 docker tag asyncdb:latest $IMAGE_URI
62+ env :
63+ VERSION : ${{ env.VERSION }}
3464
3565 - name : Push Docker image to ECR
3666 run : |
37- IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:latest
67+ IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION
3868 docker push $IMAGE_URI
69+ env :
70+ VERSION : ${{ env.VERSION }}
71+
72+ - name : Tag Git repo with version
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