Skip to content

Modern Docker Management, Designed for Everyone

fix: pass version to docker file builds

Kyle Mendellc28abd4798df
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index d60cc86b7..f78236cf3 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -105,6 +105,9 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
+ build-args: |
+ VERSION=${{ github.ref_name }}
+ REVISION=${{ github.sha }}
outputs:
digest: ${{ steps.build.outputs.digest }}
@@ -144,6 +147,9 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
+ build-args: |
+ VERSION=${{ github.ref_name }}
+ REVISION=${{ github.sha }}
outputs:
digest: ${{ steps.build.outputs.digest }}
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 66767974f..c7c8388af 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -16,16 +16,17 @@ RUN pnpm -C frontend build
# Stage 2: Build Backend
FROM golang:1.25-alpine AS backend-builder
ARG BUILD_TAGS
-ARG VERSION
-ARG REVISION
WORKDIR /build
RUN apk add --no-cache ca-certificates curl git tzdata
+COPY ./.version ./VERSION
COPY ./backend/go.mod ./backend/go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod go mod download
COPY ./backend ./
COPY --from=frontend-builder /build/frontend/dist ./frontend/dist
-RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 \
- GOOS=linux \
+RUN --mount=type=cache,target=/root/.cache/go-build \
+ VERSION=$(cat VERSION | tr -d '[:space:]') && \
+ REVISION=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") && \
+ CGO_ENABLED=0 GOOS=linux \
go build \
-tags "${BUILD_TAGS}" \
-ldflags "-w -s -X github.com/ofkm/arcane-backend/internal/config.Version=${VERSION} -X github.com/ofkm/arcane-backend/internal/config.Revision=${REVISION}" \
diff --git a/docker/Dockerfile-agent b/docker/Dockerfile-agent
index 280b4d16c..6a8168747 100644
--- a/docker/Dockerfile-agent
+++ b/docker/Dockerfile-agent
@@ -4,20 +4,20 @@ ARG REVISION="unknown"
FROM golang:1.25-alpine AS agent-builder
ARG BUILD_TAGS="exclude_frontend"
-ARG VERSION
-ARG REVISION
WORKDIR /build
RUN apk add --no-cache git ca-certificates tzdata curl
+COPY ./.version ./VERSION
COPY ./backend/go.mod ./backend/go.sum ./
RUN go mod download
COPY ./backend ./backend
WORKDIR /build/backend
-RUN CGO_ENABLED=0 \
- GOOS=linux \
+RUN VERSION=$(cat ../VERSION | tr -d '[:space:]') && \
+ REVISION=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") && \
+ CGO_ENABLED=0 GOOS=linux \
go build \
-tags "${BUILD_TAGS}" \
-ldflags "-w -s -X github.com/ofkm/arcane-backend/internal/config.Version=${VERSION} -X github.com/ofkm/arcane-backend/internal/config.Revision=${REVISION}" \