forked from CoinHippo-Labs/axelarscan-api
-
Notifications
You must be signed in to change notification settings - Fork 6
61 lines (54 loc) · 1.98 KB
/
build-latest-docker-image.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: Build and push latest docker image
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build-and-push-latest-docker-image:
strategy:
matrix:
os:
- ubuntu-20.04
runs-on: ${{ matrix.os }}
permissions:
id-token: write
contents: read
env:
REPOSITORY: axelarscan-api
IMAGE_TAG: ${{ github.sha }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: fetch tags
run: |
git fetch --unshallow
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-2
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/ghwf-${{ github.event.repository.name }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: check if an image already build on same commit hash
id: image-tag-check
run: |
app_version="v$(jq -r .version package.json)"
if [ ${{ github.ref }} != 'refs/heads/main' ]; then
app_version="${app_version}-dev_${GITHUB_RUN_NUMBER}.${GITHUB_RUN_ATTEMPT}"
fi
image_tag_exists=$(aws ecr batch-get-image --repository-name ${REPOSITORY} --image-ids "imageTag=${app_version}" | jq '.images | length')
echo "image_tag_exists=${image_tag_exists}" >> $GITHUB_OUTPUT
echo "IMAGE_TAG=${app_version}" >> $GITHUB_ENV
- name: Build docker image
if: steps.image-tag-check.outputs.image_tag_exists == 0
run: |
docker build --platform linux/amd64 -t axelarscan/axelarscan-api .
- name: Push to ECR
if: steps.image-tag-check.outputs.image_tag_exists == 0
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker image tag axelarscan/axelarscan-api "${ECR_REGISTRY}/${REPOSITORY}:${IMAGE_TAG}"
docker push "${ECR_REGISTRY}/${REPOSITORY}:${IMAGE_TAG}"