From a3c2974dc247dcd071f19b8842335b1921ea514a Mon Sep 17 00:00:00 2001 From: Simonas Narbutas Date: Tue, 30 Jan 2024 17:31:49 +0200 Subject: [PATCH 1/2] PM-1118: gha build workflow + dockerfile --- .github/workflows/publish.yaml | 62 ++++++++++++++++++++++++++++++++++ Dockerfile | 9 +++++ 2 files changed, 71 insertions(+) create mode 100644 .github/workflows/publish.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..2e76c91 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,62 @@ +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: 🏗️ Install Dependencies + run: | + npm install + - name: 📦 Compile Mina Transactions Generator + run: | + npm run build + - 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 }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4956e74 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM node:alpine + +WORKDIR /usr/src/app + +COPY package*.json ./ + +COPY ./build ./ + +CMD ["node", "./src/entry.js"] From 422c35e7708001af5abe6d9ac03ff495b8de3538 Mon Sep 17 00:00:00 2001 From: Simonas Narbutas Date: Wed, 31 Jan 2024 10:59:51 +0200 Subject: [PATCH 2/2] PM-1118: rework Dockerfile. Adjust workflow --- .github/workflows/publish.yaml | 6 ------ Dockerfile | 19 +++++++++++++++---- tsconfig.json | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 2e76c91..482b97c 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -48,12 +48,6 @@ jobs: registry: ${{ env.ECR_REPOSITORY_URL}} repository: ${{ env.ECR_REPOSITORY_NAME }} tag: ${{ env.TAG }} - - name: 🏗️ Install Dependencies - run: | - npm install - - name: 📦 Compile Mina Transactions Generator - run: | - npm run build - 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 }} . diff --git a/Dockerfile b/Dockerfile index 4956e74..0224b9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,20 @@ -FROM node:alpine +FROM node:alpine as build WORKDIR /usr/src/app -COPY package*.json ./ +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 ./ -COPY ./build ./ +RUN npm install -CMD ["node", "./src/entry.js"] +CMD ["node", "./entry.js"] diff --git a/tsconfig.json b/tsconfig.json index ec3b101..de5d2ee 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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,