Skip to content

Commit 80d794d

Browse files
committed
fix: move project version retrieval outside Dockerfile
1 parent bd79b81 commit 80d794d

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ coverage
1313

1414
.gitignore
1515
.gitattributes
16+
.git
1617

1718
.DS_Store
1819
.idea

.github/workflows/build-container.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3
1919
- uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
2020

21-
- name: Set ALL_TAGS
21+
- name: Set build variables
2222
env:
2323
REPOSITORY: '${{ github.repository }}'
2424
run: |
@@ -45,6 +45,13 @@ jobs:
4545
ALL_TAGS=$(printf ',%s' "${image_paths[@]}")
4646
echo "ALL_TAGS=${ALL_TAGS:1}" >>$GITHUB_ENV
4747
48+
PROJECT_VERSION="$(git describe --tags --always)"
49+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
50+
PROJECT_VERSION="${{ github.ref_name }}"
51+
fi
52+
echo "PROJECT_VERSION=$PROJECT_VERSION" >>$GITHUB_ENV
53+
echo "PROJECT_COMMIT_HASH=${{ github.sha }}" >>$GITHUB_ENV
54+
4855
- name: Login to ghcr.io
4956
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
5057
with:
@@ -59,3 +66,6 @@ jobs:
5966
platforms: linux/amd64,linux/arm64
6067
push: true
6168
tags: ${{ env.ALL_TAGS }}
69+
build-args: |
70+
PROJECT_VERSION=${{ env.PROJECT_VERSION }}
71+
PROJECT_COMMIT_HASH=${{ env.PROJECT_COMMIT_HASH }}

Dockerfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ COPY . .
1414
ENV CI=true
1515
RUN pnpm run build && pnpm prune --prod
1616

17-
# Versioning metadata, served by the app at runtime
18-
RUN apt-get update && \
19-
apt-get install -y --no-install-recommends git ca-certificates && \
20-
rm -rf /var/lib/apt/lists/*
21-
RUN (git describe --tags --always > PROJECT_VERSION || echo "unknown" > PROJECT_VERSION) && \
22-
date +%s > PROJECT_BUILD_DATE && \
23-
(git rev-parse HEAD > PROJECT_COMMIT_HASH || echo "unknown" > PROJECT_COMMIT_HASH)
17+
# Versioning metadata, served by the app at runtime.
18+
# Values are injected by CI via build args and default to local-friendly values.
19+
ARG PROJECT_VERSION=local
20+
ARG PROJECT_COMMIT_HASH=local
21+
RUN PROJECT_BUILD_DATE="$(date -u +%s)" && \
22+
printf '%s\n' "$PROJECT_VERSION" > PROJECT_VERSION && \
23+
printf '%s\n' "$PROJECT_BUILD_DATE" > PROJECT_BUILD_DATE && \
24+
printf '%s\n' "$PROJECT_COMMIT_HASH" > PROJECT_COMMIT_HASH
2425

2526
# ---- Runtime stage ----
2627
FROM node:24-slim@sha256:bf22df20270b654c4e9da59d8d4a3516cce6ba2852e159b27288d645b7a7eedc AS runtime

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"start:dev": "nest start --watch",
1616
"start:debug": "nest start --debug --watch",
1717
"start:prod": "node dist/main",
18+
"docker:build": "docker build --build-arg PROJECT_VERSION=\"$(git describe --tags --always)\" --build-arg PROJECT_COMMIT_HASH=\"$(git rev-parse HEAD)\" -t verifier-indexer-api:local .",
1819
"-----Linting-----": "echo \"Linting scripts\"",
1920
"lint:fix": "eslint \"{src,test}/**/*.ts\" --fix",
2021
"lint:check": "eslint \"{src,test}/**/*.ts\"",

0 commit comments

Comments
 (0)