Skip to content

Commit 2b0f78b

Browse files
committed
Tagging for ECR and git.
1 parent 81e3dff commit 2b0f78b

1 file changed

Lines changed: 42 additions & 3 deletions

File tree

.github/workflows/build.yaml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12+
- name: Install AWS CLI
13+
run: sudo apt update && sudo apt-get install -y awscli
14+
1215
- name: Checkout code
1316
uses: actions/checkout@v3
1417

@@ -24,16 +27,52 @@ jobs:
2427
uses: aws-actions/amazon-ecr-login@v1
2528

2629
- name: Build Docker image
30+
run: docker build -t asyncdb:latest .
31+
32+
- name: Read version
33+
id: get_version
34+
run: |
35+
VERSION=$(cat version)
36+
echo "VERSION=$VERSION" >> $GITHUB_ENV
37+
38+
- name: Check if version exists in ECR
2739
run: |
28-
docker build -t asyncdb:latest .
40+
if aws ecr describe-images \
41+
--repository-name my-repo \
42+
--image-ids imageTag=$VERSION \
43+
--region eu-west-2 \
44+
--query 'imageDetails[0].imageTags[0]' \
45+
--output text 2>/dev/null | grep -q "$VERSION"; then
46+
echo "Image version $VERSION already exists in ECR. Exiting."
47+
exit 1
48+
else
49+
echo "Image version $VERSION does not exist. Proceeding."
50+
fi
51+
env:
52+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
53+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
54+
AWS_DEFAULT_REGION: eu-west-2
2955

3056
- name: Tag Docker image for ECR
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
3664
run: |
37-
IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:latest
65+
IMAGE_URI=${{ steps.ecr-login.outputs.registry }}/asyncdb:$VERSION
3866
docker push $IMAGE_URI
67+
env:
68+
VERSION: ${{ env.VERSION }}
69+
70+
- name: Tag Git repo with version
71+
run: |
72+
git config user.name "github-actions[bot]"
73+
git config user.email "github-actions[bot]@users.noreply.github.com"
74+
git tag "$VERSION"
75+
git push origin "$VERSION"
76+
env:
77+
VERSION: ${{ env.VERSION }}
3978

0 commit comments

Comments
 (0)