From 63259ef8bbccd3a167caf6cb5637a453474a78be Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 14 Sep 2026 23:25:06 +1000 Subject: [PATCH] fix(update): build each component from its own approved release tag Components are independently versioned (RELEASING.md), so the newest archied/v* and archie/v* tags usually sit on different commits -- gateway-only releases are the norm. The installer required both tags to resolve to the same commit whenever both components changed, which refused every update once the two newest releases diverged (archied/v1.24.0 at 8950bde, archie/v1.23.0 at 6cf73db). Build each changed component from its own tag's commit instead: daemon binaries and the adapter refresh from the daemon release, the managed worker image from the agent release. --- internal/releaseupdate/install_script_test.go | 55 ++++++++++++++++++- scripts/archie-update-install | 29 +++++----- 2 files changed, 68 insertions(+), 16 deletions(-) diff --git a/internal/releaseupdate/install_script_test.go b/internal/releaseupdate/install_script_test.go index 6c52450f1..7ca49d194 100644 --- a/internal/releaseupdate/install_script_test.go +++ b/internal/releaseupdate/install_script_test.go @@ -27,7 +27,7 @@ func TestUpdateInstallGatewayOnlySkipsRuntimeWork(t *testing.T) { assertCallContains(t, calls, "fetch --quiet --tags origin") assertCallAbsent(t, calls, "git pull") assertCallContains(t, calls, "git -C", "rev-parse --verify refs/tags/archied/v1.13.0^{commit}") - assertCallContains(t, calls, "checkout --quiet --detach approved-release-commit") + assertCallContains(t, calls, "checkout --quiet --detach archied-v1.13.0") assertCallContains(t, calls, "go build", "internal/app/archied.runtimeVersion=1.9.9", "./cmd/archied") assertCallAbsent(t, calls, "./cmd/archie-agent") assertCallAbsent(t, calls, "docker compose build agent") @@ -78,6 +78,54 @@ func TestUpdateInstallBothComponentsBuildsDaemonAndManagedWorkerImage(t *testing } } +// Components are independently versioned (RELEASING.md), so the newest +// archied/v* and archie/v* tags usually sit on different commits -- gateway-only +// releases are the norm. Each changed component must be built from its own +// approved tag; forcing both tags onto one commit refuses every update once +// the two components' newest releases diverge. +func TestUpdateInstallBuildsEachComponentFromItsOwnTag(t *testing.T) { + result, calls := runUpdateInstallScript(t, map[string]string{ + "ARCHIE_UPDATE_DAEMON_PREVIOUS": "1.12.0", + "ARCHIE_UPDATE_DAEMON_VERSION": "1.13.0", + "ARCHIE_UPDATE_AGENT_PREVIOUS": "1.9.9", + "ARCHIE_UPDATE_AGENT_VERSION": "1.10.0", + }) + + if result.Installed[ComponentDaemon] != "1.13.0" || result.Installed[ComponentAgent] != "1.10.0" { + t.Fatalf("installed = %#v, want both release versions", result.Installed) + } + // The derived fake commits differ per tag, so these assertions fail if + // either component is built from the other's release. + daemonCheckout := indexOfCallContaining(t, calls, "checkout --quiet --detach archied-v1.13.0") + agentCheckout := indexOfCallContaining(t, calls, "checkout --quiet --detach archie-v1.10.0") + daemonBuild := indexOfCallContaining(t, calls, "go build", "./cmd/archied") + agentImageBuild := indexOfCallContaining(t, calls, "docker build") + if daemonCheckout < 0 || agentCheckout < 0 || daemonBuild < 0 || agentImageBuild < 0 { + t.Fatalf("missing expected step: daemon checkout %d, daemon build %d, agent checkout %d, agent image build %d", + daemonCheckout, daemonBuild, agentCheckout, agentImageBuild) + } + if daemonCheckout > daemonBuild { + t.Errorf("daemon binaries must be built from the daemon tag's commit; calls = %#v", calls) + } + if agentCheckout > agentImageBuild { + t.Errorf("the managed worker image must be built from the agent tag's commit; calls = %#v", calls) + } +} + +func indexOfCallContaining(t *testing.T, calls []string, fragments ...string) int { + t.Helper() + for i, call := range calls { + matched := true + for _, fragment := range fragments { + matched = matched && strings.Contains(call, fragment) + } + if matched { + return i + } + } + return -1 +} + func TestUpdateInstallNoopDoesNotFetchBuildInstallOrRestart(t *testing.T) { result, calls := runUpdateInstallScript(t, map[string]string{ "ARCHIE_UPDATE_DAEMON_PREVIOUS": "1.13.0", @@ -326,7 +374,10 @@ case "$*" in done : > "$source_dir/docker-compose.yml" ;; - *"rev-parse --verify refs/tags/"*) echo approved-release-commit ;; + *"rev-parse --verify refs/tags/"*) + tag="$(printf '%s' "$*" | sed 's/.*refs\/tags\///; s/\^.*//')" + echo "${tag//\//-}" + ;; esac `) writeFakeCommand(t, fakeDir, "go", ` diff --git a/scripts/archie-update-install b/scripts/archie-update-install index 0e4972a20..059cdd662 100755 --- a/scripts/archie-update-install +++ b/scripts/archie-update-install @@ -136,26 +136,23 @@ echo "==> fetching approved component releases" git clone --quiet --filter=blob:none --no-checkout "$SOURCE_URL" "$source_dir" git -C "$source_dir" fetch --quiet --tags origin -# Build from the exact approved release commit, not the moving branch tip. A -# temporary worktree keeps the operator's main checkout on its branch. +# Build from the exact approved release commit, not the moving branch tip. +# Resolve each changed component's tag commit independently: components are +# independently versioned (RELEASING.md), so the daemon and agent tags usually +# sit on different commits -- most releases are gateway-only. The first +# checkout is the daemon release when one is being installed, because the +# adapter refresh below reads the scripts of the release being installed; the +# agent image is rebuilt from its own tag's commit further down. +gw_commit="" +rt_commit="" if [[ ",$components," == *,daemon,* ]]; then gw_commit="$(git -C "$source_dir" rev-parse --verify "refs/tags/archied/v$GW^{commit}")" fi if [[ ",$components," == *,agent,* ]]; then rt_commit="$(git -C "$source_dir" 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 - +build_commit="$gw_commit" +[ -n "$build_commit" ] || build_commit="$rt_commit" git -C "$source_dir" checkout --quiet --detach "$build_commit" cd "$source_dir" @@ -228,6 +225,10 @@ if [[ ",$components," == *,daemon,* ]]; then done fi if [[ ",$components," == *,agent,* ]]; then + # Independent versioning: the agent tag usually points at a different + # commit than the daemon's, so switch back to it for the image build (a + # no-op checkout for an agent-only update, which never left this commit). + git checkout --quiet --detach "$rt_commit" echo "==> saving managed worker image $AGENT_IMAGE for rollback" docker image save --output "$AGENT_IMAGE_BACKUP" "$AGENT_IMAGE" echo "==> rebuilding managed worker image $AGENT_IMAGE for runtime $RT"