fix(docker-dev): stamp the git commit into rig image versions via a SOURCE_REVISION build arg (#893)
v2-ci / unit-tests (push) Has been cancelled
v2-ci / unit-tests (push) Has been cancelled
.dockerignore keeps .git/ out of the build context, so the in-image publish had no repository and AssemblyInformationalVersion (Telemetry service.version) was a bare 1.0.0. The Dockerfile now takes ARG SOURCE_REVISION and passes it to dotnet publish as SourceRevisionId; docker-compose.yml forwards it as a build arg for the host and migrator images; the new docker-dev/compose.sh wrapper exports git rev-parse HEAD (suffixed -dirty for an uncommitted tree; an explicit value wins) and runs docker compose with the base file. Without the arg the build still succeeds as 1.0.0. The ARG sits after restore so a new commit does not bust the restore layer. Mirrors ScadaBridge 7e34d7c2 (ScadaBridge#134). Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# docker compose wrapper for the docker-dev rig that stamps the git commit into the images (#893).
|
||||
#
|
||||
# .dockerignore keeps .git/ out of the build context, so the in-image `dotnet publish` cannot read the
|
||||
# commit itself and AssemblyInformationalVersion would be a bare "1.0.0". This exports SOURCE_REVISION
|
||||
# (git rev-parse HEAD, suffixed "-dirty" for an uncommitted tree) for the compose `build.args`, which
|
||||
# the Dockerfile hands to the SDK as SourceRevisionId -> "1.0.0+<sha>". An explicit SOURCE_REVISION in
|
||||
# the environment wins; outside a git checkout it stays empty and the images stamp a bare "1.0.0".
|
||||
#
|
||||
# Usage (any docker compose arguments; the base compose file is always passed first):
|
||||
# docker-dev/compose.sh up -d --build
|
||||
# docker-dev/compose.sh -f docker-dev/docker-compose.questdb.yml up -d --build central-1 central-2
|
||||
# docker-dev/compose.sh build central-1
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
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
|
||||
export SOURCE_REVISION
|
||||
echo "Source revision: ${SOURCE_REVISION:-<none>}" >&2
|
||||
|
||||
exec docker compose -f "$SCRIPT_DIR/docker-compose.yml" "$@"
|
||||
Reference in New Issue
Block a user