Skip to content

Commit

Permalink
feat: docker build pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
RiceAndMeet committed Apr 25, 2024
1 parent cfc8f2b commit bc1817e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform
.gitignore
README.md
LICENSE
yarn.lock
.env.example
.env
.git
test
node_modules
63 changes: 63 additions & 0 deletions .github/workflows/build-latest-docker-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build and push latest docker image

on:
push:
branches:
- main
- feat/dockerize-build
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 }}
AWS_ACCOUNT_ID: 499786161782
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::${{ env.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}"
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM public.ecr.aws/lambda/nodejs:20

COPY --from=public.ecr.aws/datadog/lambda-extension:55 /opt/extensions/ /opt/extensions

COPY . ${LAMBDA_TASK_ROOT}

RUN npm install yarn --global
RUN npm install datadog-lambda-js dd-trace

RUN yarn

CMD [ "index.handler" ]

0 comments on commit bc1817e

Please sign in to comment.