fix(docker): stamp the git commit into rig image versions via a SOURCE_REVISION build arg (#134)

.dockerignore keeps .git/ out of the build context, so the in-container
publish had no repository and AssemblyInformationalVersion (service.version,
VersionInfo) was a bare 1.0.0. docker/build.sh (used by docker/deploy.sh and
docker-env2/deploy.sh) now passes git rev-parse HEAD, suffixed -dirty for an
uncommitted tree, and the Dockerfile hands it to dotnet publish as
SourceRevisionId. Without the arg the build still succeeds as 1.0.0. The ARG
sits after the source COPY so a new commit does not bust the restore layer.

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-12 22:04:50 -05:00
parent 482ac66548
commit 7e34d7c2d5
2 changed files with 25 additions and 1 deletions
+11 -1
View File
@@ -46,8 +46,18 @@ RUN dotnet restore src/ZB.MOM.WW.ScadaBridge.Host/ZB.MOM.WW.ScadaBridge.Host.csp
# Stage 2: Build + Publish
FROM restore AS build
COPY src/ src/
# Commit stamp (ScadaBridge#134). .dockerignore keeps .git/ out of the build context,
# so SourceLink has no repository to read and the informational version would be a
# bare "1.0.0". docker/build.sh passes the host's `git rev-parse HEAD` (plus "-dirty"
# for an uncommitted tree) and it is handed to the SDK as SourceRevisionId, which
# yields "1.0.0+<sha>" in AssemblyInformationalVersion (and so service.version / the
# Windows ProductVersion equivalent). Left empty, the build still succeeds as "1.0.0".
# Declared here, after the source COPY, so a new commit does not bust the restore layer.
ARG SOURCE_REVISION=
RUN dotnet publish src/ZB.MOM.WW.ScadaBridge.Host/ZB.MOM.WW.ScadaBridge.Host.csproj \
-c Release -o /app/publish
-c Release -o /app/publish \
${SOURCE_REVISION:+-p:SourceRevisionId=${SOURCE_REVISION}}
# Stage 3: Runtime (minimal image, no SDK)
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime