fix: auto-detect version from version.go in Dockerfile, pass git tag in CI release

This commit is contained in:
2026-04-08 21:37:49 +02:00
parent dd4af5b25c
commit 3a860914d5
4 changed files with 10 additions and 4 deletions
+2
View File
@@ -59,6 +59,8 @@ jobs:
with:
context: .
push: true
build-args: |
VERSION=${{ steps.version.outputs.tag }}
tags: |
${{ steps.version.outputs.registry }}/${{ secrets.REGISTRY_USER }}/${{ env.IMAGE_NAME }}:latest
${{ steps.version.outputs.registry }}/${{ secrets.REGISTRY_USER }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.tag }}
+6 -2
View File
@@ -12,8 +12,12 @@ RUN go mod download
COPY . .
ARG VERSION=dev
RUN CGO_ENABLED=1 GOOS=linux go build -o keywarden -ldflags="-s -w -X git.techniverse.net/scriptos/keywarden/internal/version.Version=${VERSION}" ./cmd/keywarden/
ARG VERSION=""
RUN set -e; \
if [ -z "$VERSION" ]; then \
VERSION=$(grep 'var Version' internal/version/version.go | sed 's/.*"\(.*\)".*/\1/'); \
fi; \
CGO_ENABLED=1 GOOS=linux go build -o keywarden -ldflags="-s -w -X git.techniverse.net/scriptos/keywarden/internal/version.Version=${VERSION}" ./cmd/keywarden/
# Stage 2: Runtime
FROM alpine:3.21
+1 -1
View File
@@ -223,7 +223,7 @@ Navigate to **System** to view runtime information:
Keywarden automatically checks for new releases in the background by querying the Gitea releases API. If a newer version is available, a yellow update badge is displayed in the top header for **Admin** and **Owner** users. The badge links directly to the release page on Gitea.
The update checker is only active when the application was built with a version tag (via `--build-arg VERSION=...`). Development builds (`dev`) skip the check entirely.
The update checker is only active when the application was built with a proper version tag. Development builds without a version skip the check entirely.
## Admin Settings (Owner Only)
+1 -1
View File
@@ -46,7 +46,7 @@ The Dockerfile uses a two-stage build:
The runtime container runs as a non-root user (`keywarden`).
The build accepts an optional `VERSION` build arg (e.g. `--build-arg VERSION=v1.0.0`) which is injected into the binary via `-ldflags`. This enables the built-in update checker to compare the running version against the latest Gitea release. If omitted, the version defaults to `dev` and the update checker is disabled.
The build accepts an optional `VERSION` build arg (e.g. `--build-arg VERSION=v1.0.0`) which is injected into the binary via `-ldflags`. If omitted, the version is automatically extracted from `internal/version/version.go`. The CI release pipeline passes the Git tag as `VERSION` automatically.
### Docker Compose