diff --git a/internal/releaseupdate/install_script_test.go b/internal/releaseupdate/install_script_test.go index b8664e8d1..321b725d1 100644 --- a/internal/releaseupdate/install_script_test.go +++ b/internal/releaseupdate/install_script_test.go @@ -18,6 +18,8 @@ func TestUpdateInstallGatewayOnlySkipsRuntimeWork(t *testing.T) { }) assertCallContains(t, calls, "git pull --ff-only") + assertCallContains(t, calls, "git -C", "rev-parse --verify refs/tags/archied/v1.13.0^{commit}") + assertCallContains(t, calls, "git -C", "worktree add --detach") assertCallContains(t, calls, "go build", "main.runtimeVersion=1.9.9", "./cmd/archied") assertCallAbsent(t, calls, "./cmd/archie-agent") assertCallAbsent(t, calls, "docker compose build agent") @@ -131,8 +133,20 @@ func runUpdateInstallScript(t *testing.T, environment map[string]string) (Result writeFakeCommand(t, fakeDir, "git", ` printf '%s\n' "git $*" >> "$ARCHIE_TEST_CALLS" case "$*" in - *"--match archied/v*"*) echo archied/v1.13.0 ;; - *"--match archie/v*"*) echo archie/v1.9.9 ;; + *"rev-parse --verify refs/tags/"*) echo approved-release-commit ;; + *"worktree add --detach"*) + while [ "$#" -gt 0 ]; do + if [ "$1" = "--detach" ]; then + source_dir="$2" + mkdir -p "$source_dir" + /usr/bin/cp -R "$ARCHIE_REPO_DIR/scripts" "$source_dir/scripts" + : > "$source_dir/docker-compose.yml" + break + fi + shift + done + ;; + *"worktree remove --force"*) ;; esac `) writeFakeCommand(t, fakeDir, "go", ` diff --git a/scripts/archie-update-install b/scripts/archie-update-install index 0c9ef52fc..a46d73be4 100755 --- a/scripts/archie-update-install +++ b/scripts/archie-update-install @@ -41,18 +41,56 @@ if [ -z "$components" ]; then exit 0 fi +valid_release_version() { + [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+([+-][0-9A-Za-z.-]+)?$ ]] +} + +for target in "$GW_TARGET" "$RT_TARGET"; do + if [ -n "$target" ] && ! valid_release_version "$target"; then + echo "refusing non-release component version '$target'" >&2 + exit 1 + fi +done + cd "$REPO" echo "==> fetching approved component releases" git pull --ff-only -# Refresh adapters from the fetched checkout. The running shell continues with -# this copy; subsequent updates use the current contract. -install -m755 "$REPO/scripts/archie-update-install" "$BIN_DIR/archie-update-install" -install -m755 "$REPO/scripts/archie-update-watchdog" "$BIN_DIR/archie-update-watchdog" -install -m755 "$REPO/scripts/archie-update-check" "$BIN_DIR/archie-update-check" +# Build from the exact approved release commit, not the moving branch tip. A +# temporary worktree keeps the operator's main checkout on its branch. +if [[ ",$components," == *,daemon,* ]]; then + gw_commit="$(git -C "$REPO" rev-parse --verify "refs/tags/archied/v$GW^{commit}")" +fi +if [[ ",$components," == *,agent,* ]]; then + rt_commit="$(git -C "$REPO" rev-parse --verify "refs/tags/archie/v$RT^{commit}")" +fi +case "$components" in + daemon) build_commit="$gw_commit" ;; + agent) build_commit="$rt_commit" ;; + daemon,agent) + if [ "$gw_commit" != "$rt_commit" ]; then + echo "approved component tags do not identify the same source commit" >&2 + exit 1 + fi + build_commit="$gw_commit" + ;; +esac tmp="$(mktemp -d)" -trap 'rm -rf "$tmp"' EXIT +source_dir="$tmp/source" +cleanup() { + git -C "$REPO" worktree remove --force "$source_dir" >/dev/null 2>&1 || true + rm -rf "$tmp" +} +trap cleanup EXIT +git -C "$REPO" worktree add --detach "$source_dir" "$build_commit" +cd "$source_dir" + +# Refresh adapters from the approved release source. The running shell +# continues with this copy; subsequent updates use the current contract. +install -m755 "$source_dir/scripts/archie-update-install" "$BIN_DIR/archie-update-install" +install -m755 "$source_dir/scripts/archie-update-watchdog" "$BIN_DIR/archie-update-watchdog" +install -m755 "$source_dir/scripts/archie-update-check" "$BIN_DIR/archie-update-check" if [[ ",$components," == *,daemon,* ]]; then echo "==> building archied $GW" @@ -93,7 +131,7 @@ systemd-run --user --unit=archied-update-restart --collect --quiet \ --setenv=ARCHIE_UPDATE_PREVIOUS_RUNTIME="$PREV_RT" \ --setenv=ARCHIE_UPDATE_INSTALLED_GATEWAY="$GW" \ --setenv=ARCHIE_UPDATE_INSTALLED_RUNTIME="$RT" \ - "$REPO/scripts/archie-update-watchdog" + "$BIN_DIR/archie-update-watchdog" case "$components" in daemon)