diff --git a/docker/Dockerfile b/docker/Dockerfile index 85ecb1bf..39a86bb3 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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+" 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 diff --git a/docker/build.sh b/docker/build.sh index a8919b5b..377e85e3 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -21,6 +21,19 @@ if [ -n "${MXGW_NUGET_USER:-}" ]; then NUGET_ARGS+=(--build-arg "NUGET_GITEA_PASS=${MXGW_NUGET_PASS:-}") fi +# Commit stamp for the image's informational version (ScadaBridge#134). .git/ stays +# out of the build context (.dockerignore), so the in-container publish cannot read +# the commit itself; pass it in. "-dirty" marks a build from an uncommitted tree. +# Outside a git checkout this is left empty and the image stamps a bare "1.0.0". +SOURCE_REVISION="${SOURCE_REVISION:-}" +if [ -z "$SOURCE_REVISION" ] && git -C "$REPO_ROOT" rev-parse --git-dir >/dev/null 2>&1; then + SOURCE_REVISION="$(git -C "$REPO_ROOT" rev-parse HEAD)" + if [ -n "$(git -C "$REPO_ROOT" status --porcelain --untracked-files=no)" ]; then + SOURCE_REVISION="${SOURCE_REVISION}-dirty" + fi +fi +echo "Source revision: ${SOURCE_REVISION:-}" + # Build from repo root (so COPY paths in Dockerfile resolve correctly) echo "Building scadabridge:latest image..." # Note: ${NUGET_ARGS[@]+...} guards against the "unbound variable" error that @@ -29,6 +42,7 @@ docker build \ -t scadabridge:latest \ -f "$SCRIPT_DIR/Dockerfile" \ ${NUGET_ARGS[@]+"${NUGET_ARGS[@]}"} \ + --build-arg "SOURCE_REVISION=${SOURCE_REVISION}" \ "$REPO_ROOT" echo "Build complete: scadabridge:latest"