Skip to content

Commit 0c6bdf6

Browse files
committed
Tagging for ECR and git.
1 parent 81e3dff commit 0c6bdf6

1 file changed

Lines changed: 42 additions & 4 deletions

File tree

.github/workflows/build.yaml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ on:
77
jobs:
88
build-and-push:
99
runs-on: ubuntu-latest
10-
10+
container:
11+
image: amazon/aws-cli:latest
1112
steps:
13+
1214
- name: Checkout code
1315
uses: actions/checkout@v3
1416

@@ -24,16 +26,52 @@ jobs:
2426
uses: aws-actions/amazon-ecr-login@v1
2527

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

Comments
 (0)