Build stamped binaries in a throwaway worktree of HEAD
This checkout is shared with another session. Its uncommitted Go changes must neither be compiled into a binary stamped with a commit revision nor block a deploy, and a dirty-tree refusal does both jobs badly. deploy/build.sh now builds in a detached worktree of the revision it stamps, and the container image is built the same way rather than from the live checkout. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+15
-11
@@ -5,18 +5,22 @@
|
|||||||
# worker's registration, which is what makes deployed identity evidence rather
|
# worker's registration, which is what makes deployed identity evidence rather
|
||||||
# than assumption.
|
# than assumption.
|
||||||
#
|
#
|
||||||
# Usage: deploy/build.sh [outdir]
|
# The build runs in a throwaway git worktree of HEAD, not in the checkout. This
|
||||||
|
# repository is shared: another session may have uncommitted Go changes in it,
|
||||||
|
# and those must neither be compiled into a stamped binary nor block a deploy.
|
||||||
|
#
|
||||||
|
# Usage: deploy/build.sh [outdir] [revision]
|
||||||
set -eu
|
set -eu
|
||||||
out=${1:-./build}
|
repo=$(cd "$(dirname "$0")/.." && pwd)
|
||||||
cd "$(dirname "$0")/.."
|
out=${1:-$repo/build}
|
||||||
if ! git diff --quiet || ! git diff --cached --quiet; then
|
rev=$(git -C "$repo" rev-parse "${2:-HEAD}")
|
||||||
echo "refusing to stamp a dirty tree with a commit revision" >&2
|
built=$(git -C "$repo" show -s --format=%cI "$rev")
|
||||||
exit 1
|
tree=$(mktemp -d)
|
||||||
fi
|
cleanup() { git -C "$repo" worktree remove --force "$tree" >/dev/null 2>&1 || rm -rf "$tree"; }
|
||||||
rev=$(git rev-parse HEAD)
|
trap cleanup EXIT
|
||||||
built=$(git show -s --format=%cI HEAD)
|
git -C "$repo" worktree add --detach --quiet "$tree" "$rev"
|
||||||
flags="-s -w -X orchestra/internal/buildinfo.Revision=$rev -X orchestra/internal/buildinfo.Time=$built -X orchestra/internal/buildinfo.Dirty=false"
|
flags="-s -w -X orchestra/internal/buildinfo.Revision=$rev -X orchestra/internal/buildinfo.Time=$built -X orchestra/internal/buildinfo.Dirty=false"
|
||||||
mkdir -p "$out"
|
mkdir -p "$out"
|
||||||
go build -trimpath -ldflags="$flags" -o "$out/orchestra" ./cmd/orchestra
|
(cd "$tree" && go build -trimpath -ldflags="$flags" -o "$out/orchestra" ./cmd/orchestra)
|
||||||
go build -trimpath -ldflags="$flags" -o "$out/orchestra-worker" ./cmd/orchestra-worker
|
(cd "$tree" && go build -trimpath -ldflags="$flags" -o "$out/orchestra-worker" ./cmd/orchestra-worker)
|
||||||
echo "$rev"
|
echo "$rev"
|
||||||
|
|||||||
Reference in New Issue
Block a user