From d301b246096b0dfa1d39a98c99b1881f910a39c1 Mon Sep 17 00:00:00 2001 From: Frederico Sabino <3332770+fmrsabino@users.noreply.github.com> Date: Mon, 4 Dec 2023 14:18:35 +0000 Subject: [PATCH] Add VERSION and BUILD_NUMBER args (#261) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The provided docker image now requires a `VERSION` and `BUILD_NUMBER` to be set. These are provided as build arguments to the image – https://docs.docker.com/engine/reference/builder/#arg - The `BUILD_NUMBER` will be the first seven characters of the commit hash that triggered the build. - The `VERSION` will be the `ref_name` of the commit that triggered the build. For a branch, that will be the branch name (e.g.: `main`) and for a release it will be the release tag. --- .github/workflows/ci.yml | 12 ++++++++++++ Dockerfile | 7 +++++++ package.json | 1 - src/config/configuration.ts | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4db153..aeee6e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,6 +59,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - run: | + BUILD_NUMBER=${{ github.sha }} + echo "BUILD_NUMBER=${BUILD_NUMBER::7}" >> "$GITHUB_ENV" - uses: docker/setup-qemu-action@v3.0.0 with: platforms: arm64 @@ -73,6 +76,9 @@ jobs: with: platforms: linux/amd64,linux/arm64 push: true + build-args: | + BUILD_NUMBER=${{ env.BUILD_NUMBER }} + VERSION=${{ github.ref_name }} tags: ${{ env.DOCKER_IMAGE_TAG }} # Use inline cache storage https://docs.docker.com/build/cache/backends/inline/ cache-from: type=registry,ref=${{ env.DOCKER_IMAGE_TAG }} @@ -84,6 +90,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - run: | + BUILD_NUMBER=${{ github.sha }} + echo "BUILD_NUMBER=${BUILD_NUMBER::7}" >> "$GITHUB_ENV" - uses: docker/setup-qemu-action@v3.0.0 with: platforms: arm64 @@ -96,6 +105,9 @@ jobs: with: platforms: linux/amd64,linux/arm64 push: true + build-args: | + BUILD_NUMBER=${{ env.BUILD_NUMBER }} + VERSION=${{ github.ref_name }} tags: | safeglobal/safe-gelato-relay-service:${{ github.event.release.tag_name }} safeglobal/safe-gelato-relay-service:latest diff --git a/Dockerfile b/Dockerfile index 9304808..350f4b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,13 @@ RUN yarn run build # FROM node:18-alpine as production USER node + +ARG VERSION +ARG BUILD_NUMBER + +ENV APPLICATION_VERSION=${VERSION} \ + APPLICATION_BUILD_NUMBER=${BUILD_NUMBER} + COPY --chown=node:node --from=base /app/node_modules ./node_modules COPY --chown=node:node --from=base /app/dist ./dist CMD [ "node", "dist/main.js" ] diff --git a/package.json b/package.json index bb32e2e..608af0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { "name": "safe-gelato-relay-service", - "version": "0.14.0", "description": "", "author": "", "private": true, diff --git a/src/config/configuration.ts b/src/config/configuration.ts index c170828..bb0d19d 100644 --- a/src/config/configuration.ts +++ b/src/config/configuration.ts @@ -9,6 +9,8 @@ const API_KEYS: Record = { export default () => ({ about: { name: 'safe-gelato-relay-service', + version: process.env.APPLICATION_VERSION, + buildNumber: process.env.APPLICATION_BUILD_NUMBER, }, applicationPort: process.env.APPLICATION_PORT || '3000', redis: {