Skip to content

Commit

Permalink
Merge pull request #4 from MinaFoundation/PM-1118-create-a-gha-workfl…
Browse files Browse the repository at this point in the history
…ow-to-build-publish-images

PM-1118: add gha build workflow + Dockerfile
  • Loading branch information
simisimis authored Jan 31, 2024
2 parents ee2190e + 422c35e commit 3970c4d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
56 changes: 56 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Publish

on:
push:
tags:
- '*'
workflow_dispatch:
inputs:
docker_tag_prefix:
description: "Enter the Docker Tag Prefix (e.g adhoc-test)"
required: true
type: string
env:
ECR_REPOSITORY_URL: 673156464838.dkr.ecr.us-west-2.amazonaws.com
ECR_REPOSITORY_NAME: mina-transactions-generator
DOCKER_TAG_PREFIX: ${{ github.event.inputs.docker_tag_prefix }}

# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: '${{ github.workflow }} @ ${{ github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
build-docker-image:
name: Build and Push Docker Image
runs-on: minafoundation-default-runners
steps:
- name: 📥 Checkout
uses: actions/checkout@v3
- name: 🏷️ Generate Tag
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
PREFIX=${{ env.DOCKER_TAG_PREFIX }}
elif [ "${{ github.event_name }}" == "push" ] && [ -n "${{ github.event.ref }}" ]; then
PREFIX=$(basename ${{ github.ref }})
else
echo "Invalid event. Exiting..."
exit 1
fi
echo "TAG=$PREFIX-$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
- name: 🔑 ECR Login
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: 🔍 Check if Tag already exists
id: checktag
uses: tyriis/docker-image-tag-exists@main
with:
registry: ${{ env.ECR_REPOSITORY_URL}}
repository: ${{ env.ECR_REPOSITORY_NAME }}
tag: ${{ env.TAG }}
- name: 🛠️ Build Mina Transactions Generator Docker Image
if: steps.checktag.outputs.tag == 'not found'
run: DOCKER_BUILDKIT=1 docker build -t ${{ env.ECR_REPOSITORY_URL}}/${{ env.ECR_REPOSITORY_NAME }}:${{ env.TAG }} .
- name: 🚚 Push Mina Transactions Generator Docker Image
if: steps.checktag.outputs.tag == 'not found'
run: docker push ${{ env.ECR_REPOSITORY_URL}}/${{ env.ECR_REPOSITORY_NAME }}:${{ env.TAG }}
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:alpine as build

WORKDIR /usr/src/app

COPY package*.json tsconfig.json ./
COPY src ./src

RUN npm install && npm run build

FROM node:alpine

WORKDIR /app

COPY --from=build /usr/src/app/build ./

COPY --from=build /usr/src/app/package*.json ./

RUN npm install

CMD ["node", "./entry.js"]
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"module": "es2022",
"lib": ["dom", "esnext"],
"outDir": "./build",
"rootDir": ".",
"rootDir": "./src",
"strict": true,
"strictPropertyInitialization": false, // to enable generic constructors, e.g. on CircuitValue
"skipLibCheck": true,
Expand Down

0 comments on commit 3970c4d

Please sign in to comment.