build(version): inject real build version via ldflags (#47)
Dockerfile takes ARG VERSION (default "dev") and stamps it into main.version with -X. CD passes --build-arg VERSION=<git tag on v* builds, else the short sha>, so the running pod logs the actual build instead of "dev". Verified locally: `-ldflags -X main.version=...` embeds the string. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -60,7 +60,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
REGISTRY="localhost:5000"
|
REGISTRY="localhost:5000"
|
||||||
REF="${REGISTRY}/${{ env.IMAGE }}:${{ steps.meta.outputs.sha-tag }}"
|
REF="${REGISTRY}/${{ env.IMAGE }}:${{ steps.meta.outputs.sha-tag }}"
|
||||||
|
# Stamp the real build version: the git tag on a v* build, else the short sha.
|
||||||
|
VERSION="${{ steps.meta.outputs.version-tag }}"
|
||||||
|
[ -z "$VERSION" ] && VERSION="${{ steps.meta.outputs.sha-tag }}"
|
||||||
buildah build \
|
buildah build \
|
||||||
|
--build-arg VERSION="${VERSION}" \
|
||||||
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
--label "org.opencontainers.image.revision=${{ github.sha }}" \
|
||||||
--label "org.opencontainers.image.source=${{ github.repositoryUrl }}" \
|
--label "org.opencontainers.image.source=${{ github.repositoryUrl }}" \
|
||||||
-t ${REF} \
|
-t ${REF} \
|
||||||
|
|||||||
+4
-1
@@ -14,7 +14,10 @@ ENV GOSUMDB=off
|
|||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o /out/gitea-mcp ./cmd/gitea-mcp
|
# Build version stamped in by CI (--build-arg VERSION=<tag|sha>); defaults to
|
||||||
|
# "dev" for a plain `docker build` (#47).
|
||||||
|
ARG VERSION=dev
|
||||||
|
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w -X main.version=${VERSION}" -o /out/gitea-mcp ./cmd/gitea-mcp
|
||||||
|
|
||||||
FROM gcr.io/distroless/static-debian12:nonroot
|
FROM gcr.io/distroless/static-debian12:nonroot
|
||||||
COPY --from=build /out/gitea-mcp /gitea-mcp
|
COPY --from=build /out/gitea-mcp /gitea-mcp
|
||||||
|
|||||||
Reference in New Issue
Block a user