7e34d7c2d5
.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
49 lines
2.0 KiB
Bash
Executable File
49 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
|
|
echo "=== ScadaBridge Docker Build ==="
|
|
|
|
# Ensure the shared network exists
|
|
if ! docker network inspect scadabridge-net >/dev/null 2>&1; then
|
|
echo "Creating scadabridge-net network..."
|
|
docker network create scadabridge-net
|
|
fi
|
|
|
|
# Optional credentials for the private Gitea NuGet feed (ZB.MOM.WW.MxGateway.*).
|
|
# Read from the host environment so secrets are never committed. Leave unset for an
|
|
# anonymous feed. Export MXGW_NUGET_USER / MXGW_NUGET_PASS before running deploy.
|
|
NUGET_ARGS=()
|
|
if [ -n "${MXGW_NUGET_USER:-}" ]; then
|
|
NUGET_ARGS+=(--build-arg "NUGET_GITEA_USER=${MXGW_NUGET_USER}")
|
|
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:-<none>}"
|
|
|
|
# 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
|
|
# set -u raises on bash 3.2 (macOS default) when expanding an empty array.
|
|
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"
|