Skip to content

Commit 1f354f2

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

1 file changed

Lines changed: 45 additions & 3 deletions

File tree

.github/workflows/build.yaml

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

1111
steps:
12+
- name: Install AWS CLI
13+
run: |
14+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
15+
unzip awscliv2.zip
16+
sudo ./aws/install
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

Comments
 (0)