Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions docs/DESIRED-STATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,72 @@ Uninstall removes the controller, timers, rendered environment, and active insta

No mode uses global Docker prune or removes unrelated workloads.

### Upgrade a pre-proxy manager

In [#113](https://github.com/RandomDevelopment/ci-fleet/issues/113), installed
manager `791a15b8c474c6f1053237ff0b86b6b37cf0ac92` activated engine
`312d22d712d5a5e87bdb14796bf2c40f33d53f92` with
`compose ... up -d --no-deps controller`. The new controller entered a
restart loop because the manager had skipped `docker-socket-proxy`. The
candidate installer included dependency startup, but the installed manager
was the installer executing the upgrade.

Use a protected checkout at a reviewed engine commit that includes this
transition procedure. Record the legacy reconcile timer's enabled and active
states, then run `sudo systemctl disable --now ci-fleet-reconcile.timer` and
suspend any external dispatcher before offering a new engine pin. Let any
in-flight reconciliation finish. Retain the exact incumbent source and both local image objects for
rollback. Record the installed configuration and engine SHAs, the manager
revision, the running controller image ID, and its health.

1. Follow the [image-free manager staging sequence](#managed-image-scalar-semantics-and-predecessor-evidence).
Integrate incumbent active evidence, then target pending evidence, then an
image-free configuration selecting the reviewed manager. Run
`--upgrade` for that exact configuration SHA using the installer from the
protected checkout. Require `MANAGER_STAGED`. Run `--check` from that
checkout with the same arguments and require `CHECK_STAGED`. Confirm the
manager pointer advanced and the incumbent runtime and installed
configuration still match the baseline.
2. Integrate the reviewed managed image values for the selected engine in a
later configuration commit. Keep the active and pending evidence through
activation. Run `--upgrade` from
`/opt/ci-fleet/manager/current/scripts/install-worker-controller.sh` with
that exact configuration SHA. This manager checkpoints the incumbent,
waits for active jobs to finish, and starts the controller through Compose's
healthy dependency condition. Startup uses verified local images and has a
60-second deadline.
3. Require `CHECK_OK` for the new configuration. Confirm that
`/var/lib/ci-fleet/install-state.json` records the requested configuration
and engine SHAs and both release pointers select that engine. Inspect the
controller's OCI revision, actual image ID, and running state. Its image ID
must match `CI_FLEET_CONTROLLER_RUNTIME_IMAGE_ID` in the protected rendered
environment. Inspect `ci-fleet-docker-socket-proxy-1` for the same image ID
and healthy status. Require a fresh local health report with the
`docker_socket_proxy` check passing. Review any warnings, promote the
runtime evidence in its own commit, and restore the previous reconcile
schedule.

If dependency startup or controller activation fails, keep reconciliation
suspended and read the installer result. A verified rollback restores the
incumbent installed state, actual controller image, and runtime release. It
keeps the staged manager from the checkpoint. Verify those identities against
the baseline, verify that the candidate proxy is absent, and read the fresh
incumbent health report before retrying. If Docker keeps restarting the
candidate, rollback disables its restart policy and stops that container
without invoking graceful shutdown. It then waits for managed runners to finish.
If rollback is unverified, keep the checkpoint and use the reviewed installer
for recovery after checking that the checkpoint and both prior image objects
are usable. Follow the host's reviewed reinstall procedure if recovery cannot
be verified.

For a host already stranded by the original failed transition, reconcile the
actual image and restart state with installed metadata before choosing a
recovery action. The 2026-10-11 comment on #113 records an operator workaround
that verified the exact candidate Compose and image, started only the
candidate proxy under the installer lock, verified proxy health, and retried
reconciliation. That recorded recovery applies to the diagnosed host and
requires separate review before reuse.

## Drift and reviewed updates

`ci-fleet-drift.timer` checks the host every fifteen minutes against the exact configuration SHA recorded at installation. It detects host edits, missing or stale runtime and installer-manager releases, runtime-state mismatch, altered metadata, and missing maintenance timers without applying changes.
Expand Down
10 changes: 6 additions & 4 deletions docs/LOCAL-VALIDATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,19 @@ roots. Installer fixtures that mutate Git history or reviewed files use their ow
repository copies, preserving the candidate checkout and its Git metadata.
They do not prove deployment on a real prepared host.

Installer fixture preparation seeds its three hard-pinned historical engine inputs
before installing synthetic Git transport: pre-health
Installer fixture preparation seeds four historical engine commits before
installing synthetic Git transport. The pre-proxy engine is
`791a15b8c474c6f1053237ff0b86b6b37cf0ac92`. The other pins are pre-health
`af9c0c13cd12866ce75dd6c43a4cda01915507e1`, pre-telemetry
`8bd27a2e7451806a1e37f79a15eeb7c677a12c3e`, and pre-adapter
`003de44f7e27d7bfe5bb753098efb6eb5f9712f1`. It prefers available original-source
objects; a missing object requires a canonical pinned fetch during that admitted
preparation phase. It verifies each requested commit without changing the selected
HEAD. Subsequent installed synthetic-engine fetches use only the prepared local
fixture repository, retaining canonical origin metadata. There is no runtime
network fallback. These historical inputs test compatibility refusals and removal;
they are not rollout engine selections or evidence of native image acceptance.
network fallback. The historical inputs cover the pre-proxy upgrade and
rollback, compatibility refusals, and removal. The fixtures use simulated
Docker and systemd and leave live fleets untouched.

## Complete engine command

Expand Down
92 changes: 66 additions & 26 deletions scripts/install-worker-controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ trap cleanup_temporary EXIT

require_commands() {
local command docker_root disk_used os_id os_release os_version socket
local -a required=(python3 docker install readlink systemctl stat awk grep date flock mktemp)
local -a required=(python3 docker install readlink systemctl stat awk grep date flock mktemp timeout)
if [[ "$mode" != rollback && "$mode" != uninstall ]]; then required+=(git tar cmp); fi
for command in "${required[@]}"; do
command -v "$command" >/dev/null || die "$command is required"
Expand Down Expand Up @@ -563,15 +563,18 @@ PY
compose() {
local release=$1 env_file=$2 variable
local -a clean_environment=(env -i "PATH=$PATH" "HOME=${HOME:-/root}")
local -a deadline=()
shift 2
# Bound the dependency wait during Compose startup, including older Compose v2 releases.
if [[ "$1" == up ]]; then deadline=(timeout --kill-after=5s 60s); fi
for variable in DOCKER_HOST DOCKER_CONTEXT DOCKER_TLS_VERIFY DOCKER_CERT_PATH DOCKER_CONFIG XDG_RUNTIME_DIR; do
[[ ! -v $variable ]] || clean_environment+=("$variable=${!variable}")
done
if [[ "$testing" == 1 ]]; then
clean_environment+=("CI_FLEET_ROOT_PREFIX=$root_prefix")
for variable in ${!FAKE_@}; do clean_environment+=("$variable=${!variable}"); done
fi
"${clean_environment[@]}" docker compose --project-name ci-fleet --env-file "$env_file" -f "$release/deploy/compose.yaml" "$@"
"${deadline[@]}" "${clean_environment[@]}" docker compose --project-name ci-fleet --env-file "$env_file" -f "$release/deploy/compose.yaml" "$@"
}

build_managed_images() {
Expand Down Expand Up @@ -1830,7 +1833,7 @@ make_checkpoint() {
}

try_drain_current() {
local deadline count old_release='' status paused=false force_nonterminal=${1:-false}
local deadline remaining count old_release='' status identity container_id stopped paused=false pause_retried=false stop_retried=false force_nonterminal=${1:-false}
local drain_env=${2:-$rendered_env} fallback_release=${3:-} shutdown_timeout=${CI_FLEET_DRAIN_TIMEOUT_SECONDS:-300}
drain_error=
status=$(controller_status)
Expand All @@ -1840,6 +1843,26 @@ try_drain_current() {
return 1
}
fi
if [[ "$status" == paused && "$force_nonterminal" == true ]]; then status=running; fi
while [[ "$status" == running ]]; do
if [[ ! -f "$drain_env" ]]; then drain_error='cannot safely drain a running controller without its rendered environment'; return 1; fi
if [[ -z "$old_release" || ! -f "$old_release/deploy/compose.yaml" ]]; then drain_error='cannot locate the running controller Compose release for safe adoption'; return 1; fi
if [[ $(docker inspect --format '{{.State.Paused}}' "$controller_container" 2>/dev/null || true) == true ]] \
|| compose "$old_release" "$drain_env" pause controller >/dev/null; then
paused=true
break
fi
if [[ "$force_nonterminal" == true ]]; then
case "$(controller_status)" in
restarting) status=restarting; break ;;
running|paused)
if [[ "$pause_retried" == false ]]; then pause_retried=true; continue; fi
;;
esac
fi
drain_error='could not pause the controller for drain'
return 1
done
case "$status" in
running|'') ;;
exited|created|dead)
Expand All @@ -1848,35 +1871,52 @@ try_drain_current() {
compose "$old_release" "$drain_env" stop --timeout "$shutdown_timeout" controller >/dev/null 2>&1 || { drain_error="failed to stop restartable controller state: $status"; return 1; }
status=
;;
*)
restarting)
if [[ "$force_nonterminal" != true ]]; then
drain_error="cannot safely drain controller in non-terminal state: $status"
return 1
fi
[[ -f "$drain_env" ]] || { drain_error='cannot stop a non-terminal candidate without its rendered environment'; return 1; }
[[ -n "$old_release" ]] || { drain_error='cannot stop a non-terminal candidate without its runtime release'; return 1; }
if [[ "$status" == paused ]]; then
compose "$old_release" "$drain_env" unpause controller >/dev/null 2>&1 || { drain_error="failed to unpause non-terminal candidate state: $status"; return 1; }
identity=$(docker inspect --format '{{.Id}} {{index .Config.Labels "com.docker.compose.project"}} {{index .Config.Labels "com.docker.compose.service"}}' "$controller_container" 2>/dev/null) || {
drain_error='could not identify the restarting controller'
return 1
}
container_id=${identity%% *}
if [[ ! "$container_id" =~ ^[0-9a-f]{64}$ || "$identity" != "$container_id ci-fleet controller" ]] \
|| ! docker update --restart=no "$container_id" >/dev/null; then
drain_error='could not disable restart for the restarting controller'
return 1
fi
compose "$old_release" "$drain_env" stop --timeout "$shutdown_timeout" controller >/dev/null 2>&1 || { drain_error="failed to stop non-terminal candidate state: $status"; return 1; }
status=
# The process could resume during recovery. SIGTERM would force-remove its runners.
deadline=$((SECONDS + shutdown_timeout))
while remaining=$((deadline - SECONDS)); ((remaining > 0)); do
timeout --kill-after=1 "$remaining" docker kill "$container_id" >/dev/null 2>&1 || true
remaining=$((deadline - SECONDS))
((remaining > 0)) || break
stopped=$(timeout --kill-after=1 "$remaining" docker inspect --format '{{.State.Status}} {{.HostConfig.RestartPolicy.Name}}' "$container_id" 2>/dev/null) || break
case "$stopped" in
'created no'|'exited no'|'dead no') status=; break ;;
'running no'|'restarting no')
if [[ "$stop_retried" == true ]]; then sleep 1; fi
stop_retried=true
;;
*) break ;;
esac
done
[[ -z "$status" ]] || { drain_error='could not verify the restarting controller stopped'; return 1; }
;;
esac
if [[ "$status" == running ]]; then
if [[ ! -f "$drain_env" ]]; then drain_error='cannot safely drain a running controller without its rendered environment'; return 1; fi
if [[ -z "$old_release" || ! -f "$old_release/deploy/compose.yaml" ]]; then drain_error='cannot locate the running controller Compose release for safe adoption'; return 1; fi
if [[ $(docker inspect --format '{{.State.Paused}}' "$controller_container" 2>/dev/null || true) == true ]]; then
paused=true
elif compose "$old_release" "$drain_env" pause controller >/dev/null; then
paused=true
else
drain_error='could not pause the controller for drain'
*)
drain_error="cannot safely drain controller in non-terminal state: $status"
return 1
fi
fi
;;
esac
deadline=$((SECONDS + ${CI_FLEET_DRAIN_TIMEOUT_SECONDS:-300}))
while :; do
count=$(managed_runner_count)
if ! count=$(managed_runner_count); then
if [[ "$paused" == true ]]; then compose "$old_release" "$drain_env" unpause controller >/dev/null || true; fi
drain_error='could not verify the managed runner count'
return 1
fi
if [[ "$count" == 0 ]]; then break; fi
if ((SECONDS >= deadline)); then
if [[ "$paused" == true ]]; then compose "$old_release" "$drain_env" unpause controller >/dev/null || true; fi
Expand Down Expand Up @@ -2050,7 +2090,7 @@ PY
mv -f "$staged_state" "$state_file"
if [[ "$target_state" == active ]]; then
prepare_disk_admission_export "$release_dir" || die 'disk admission export preparation failed'
compose "$release_dir" "$rendered_env" up -d --remove-orphans controller
compose "$release_dir" "$rendered_env" up -d --no-build --pull never --remove-orphans controller
sleep "${CI_FLEET_STARTUP_WAIT_SECONDS:-2}"
runtime_matches active || die 'controller did not remain running after activation'
else
Expand Down Expand Up @@ -2259,7 +2299,7 @@ retag_checkpoint_image() {
}

restore_checkpoint() {
local target restored_state actual index runtime_target expected_owner=0 failed=0 checkpoint_release='' drain_env=$rendered_env drain_release='' restore_images=false new_format=false checkpoint_format='' current_temporary='' validated_current_target='' validated_manager_target=''
local target restored_state actual count index runtime_target expected_owner=0 failed=0 checkpoint_release='' drain_env=$rendered_env drain_release='' restore_images=false new_format=false checkpoint_format='' current_temporary='' validated_current_target='' validated_manager_target=''
local restore_controller_tag_after_start=false fresh_path identifier image_environment=$checkpoint_dir/ci-fleet.env
local -a fresh_checkpoint_images=()
local format_marker=$checkpoint_dir/format-version image_ids=$checkpoint_dir/image-ids.env
Expand Down Expand Up @@ -2594,11 +2634,11 @@ PY
failed=1
fi
if [[ "$restored_state" == active && "$failed" == 0 ]]; then
if [[ $(managed_runner_count) != 0 ]]; then
if ! count=$(managed_runner_count) || [[ "$count" != 0 ]]; then
failed=1
else
prepare_disk_admission_export "$release_dir" || failed=1
if ((failed == 0)); then compose "$release_dir" "$rendered_env" up -d --remove-orphans controller || failed=1; fi
if ((failed == 0)); then compose "$release_dir" "$rendered_env" up -d --no-build --pull never --remove-orphans controller || failed=1; fi
if ((failed == 0)); then run_health_check "$release_dir" "$rendered_env" true || failed=1; fi
fi
fi
Expand Down
Loading