diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 698bfc5e9..aa9c27a8b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -199,8 +199,9 @@ jobs: cache-from: type=gha,scope=archie-agent cache-to: type=gha,mode=max,scope=archie-agent - # Packages the host-run binaries (archied, archie-gateway, - # archie-state-store, archie-playbooks) as a linux/amd64 zip for a + # Packages every host-run binary (archied, archie-gateway, + # archie-state-store, archie-ui, archie-messaging, archie-playbooks) as a + # linux/amd64 zip for a # non-Docker install. Independent of build-and-push: it never touches the # archied/archie-agent image jobs, and a gateway-only release (no # archie/v* tag) still produces this zip -- it's keyed to the archied tag @@ -246,9 +247,16 @@ jobs: # every one of them carries the archied version it was cut from: # they are one release, and an operator matching binaries by eye # needs each to say so. + # + # That claim is load-bearing and this list is the whole of it: the + # v1.30.0 messaging extraction moved Telegram/email/webhook out of + # archied and nothing added archie-messaging here, so a host install + # ran on with a dead Telegram bot and no error anywhere + # (archie-core-1c01). TestDistZipShipsEveryHostCommand fails if this + # list and the copy list below stop matching the commands in cmd/. ldflags="-X github.com/samcharles93/archie-core/internal/app/archied.gatewayVersion=${{ steps.version.outputs.version }} -X github.com/samcharles93/archie-core/internal/installtype.buildType=binary" mkdir -p dist - for cmd in archied archie-gateway archie-state-store archie-ui archie-playbooks; do + for cmd in archied archie-gateway archie-state-store archie-ui archie-messaging archie-playbooks; do go build -ldflags "$ldflags" -o "dist/$cmd" "./cmd/$cmd" done @@ -258,7 +266,7 @@ jobs: set -e name="archie-core-archied-v${{ steps.version.outputs.version }}-linux-amd64" mkdir -p "$name" - cp dist/archied dist/archie-gateway dist/archie-state-store dist/archie-ui dist/archie-playbooks "$name/" + cp dist/archied dist/archie-gateway dist/archie-state-store dist/archie-ui dist/archie-messaging dist/archie-playbooks "$name/" cp deployments/INSTRUCTIONS.md CHANGELOG.md CHANGELOG.archied.md CHANGELOG.archie.md "$name/" # README.md doesn't exist yet in this repo; include it once it does # rather than fail the release on its absence. diff --git a/RELEASING.md b/RELEASING.md index 91f9f8e5e..3682ab2af 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -74,7 +74,8 @@ Tagging both components at one commit produces, from a single `deploy` run: and the host pulls the new image. - **A GitHub Release with a distribution zip** — `dist-zip` builds every process the reference deployment runs (`archied`, `archie-gateway`, - `archie-state-store`, `archie-ui`, `archie-playbooks`) for linux/amd64, packs + `archie-state-store`, `archie-ui`, `archie-messaging`, `archie-playbooks`) for + linux/amd64, packs them with `deployments/INSTRUCTIONS.md` and the changelogs, and attaches the zip to the Release for the **archied** tag. The Release body is that version's `CHANGELOG.archied.md` section. Both jobs are keyed to the archied diff --git a/deploy_workflow_test.go b/deploy_workflow_test.go index f48f8597c..7288e6bb5 100644 --- a/deploy_workflow_test.go +++ b/deploy_workflow_test.go @@ -1,6 +1,9 @@ package configtemplate import ( + "os" + "path/filepath" + "sort" "strings" "testing" ) @@ -80,3 +83,174 @@ func TestPullRequestsRunTheDefinitiveGateWithoutPublishAccess(t *testing.T) { } } } + +// unpackagedCommands are commands that deliberately never ship as a host binary. +// Naming each one with its reason keeps an omission a decision rather than an +// oversight -- which is exactly how archied's channels were lost. +var unpackagedCommands = map[string]string{ + "archie-agent": "runs only inside the Docker image build-and-push publishes, never as a host binary", +} + +// cliOnlyCommands ship in the zip but must never be restarted by the updater: +// they are not services. +var cliOnlyCommands = map[string]bool{"archie-playbooks": true} + +// TestHostCommandListsCannotDrift is why archie-core-1c01 went unnoticed for two +// days. The v1.30.0 extraction moved Telegram, email and webhook out of archied +// into a new cmd/archie-messaging that nothing packaged: the release zip omitted +// it, and scripts/archie-update-install omitted it from both of its lists, so a +// host install ran on with a dead Telegram bot and no error logged anywhere. The +// daemon looked healthy throughout. +// +// The host component set was enumerated independently in three places (the zip's +// build loop, the zip's copy list, and the installer's two lists), so two +// coordinated edits would have drifted again. Every list is pinned to cmd/ here +// instead: adding a command fails this test until it is packaged, and extracting +// one fails it until the previous command is removed. +func TestHostCommandListsCannotDrift(t *testing.T) { + workflow := readDeploymentFile(t, ".github/workflows/deploy.yml") + installer := readDeploymentFile(t, filepath.Join("scripts", "archie-update-install")) + + want := hostRunCommands(t) + wantBinaries := want + wantServices := withoutCLIOnly(want) + + built := wordsAfter(t, workflow, "for cmd in ", "; do", nil) + // The marker consumes the prefix of the first word only, so restore it for + // whichever word the marker ended inside. + var shipped []string + for _, word := range wordsAfter(t, workflow, "cp dist/", ` "$name/"`, nil) { + if !strings.HasPrefix(word, "dist/") { + word = "dist/" + word + } + shipped = append(shipped, strings.TrimPrefix(word, "dist/")) + } + services := wordsAfter(t, installer, `GATEWAY_SERVICES="`, `"`, nil) + binaries := wordsAfter(t, installer, `GATEWAY_BINARIES="`, `"`, map[string][]string{"$GATEWAY_SERVICES": services}) + + for _, list := range []struct { + name string + got []string + want []string + }{ + {"deploy.yml dist-zip build loop", built, wantBinaries}, + {"deploy.yml dist-zip copy list", shipped, wantBinaries}, + {"archie-update-install GATEWAY_BINARIES", binaries, wantBinaries}, + {"archie-update-install GATEWAY_SERVICES", services, wantServices}, + } { + if diff := setDifference(list.want, list.got); diff != "" { + t.Errorf("%s does not match the host-run commands in cmd/: %s", list.name, diff) + } + } + + // The installer now REFUSES an update when a service unit is missing and + // tells the operator to create it from this runbook, so a service the + // runbook never shows is a dead end rather than a documentation gap. + runbook := readDeploymentFile(t, filepath.Join("deployments", "systemd-user-service.md")) + var undocumented []string + for _, service := range wantServices { + if !strings.Contains(runbook, "/bin/"+service+" ") { + undocumented = append(undocumented, service) + } + } + if len(undocumented) > 0 { + t.Errorf("deployments/systemd-user-service.md documents no unit for: %s", strings.Join(undocumented, " ")) + } +} + +// hostRunCommands is every command under cmd/, minus the deliberately +// unpackaged ones. Deriving it is the point: a list written out here would drift +// from cmd/ exactly as the packaged lists did. +func hostRunCommands(t *testing.T) []string { + t.Helper() + entries, err := os.ReadDir("cmd") + if err != nil { + t.Fatalf("read cmd/: %v", err) + } + var commands []string + for _, entry := range entries { + if !entry.IsDir() { + continue + } + if _, skip := unpackagedCommands[entry.Name()]; skip { + continue + } + commands = append(commands, entry.Name()) + } + if len(commands) == 0 { + t.Fatal("cmd/ holds no commands: this guard would assert nothing") + } + sort.Strings(commands) + return commands +} + +func withoutCLIOnly(commands []string) []string { + out := make([]string, 0, len(commands)) + for _, command := range commands { + if cliOnlyCommands[command] { + continue + } + out = append(out, command) + } + return out +} + +// wordsAfter returns the whitespace-separated words between two markers on the +// same line. expand maps a word to the words it stands for, which is how the +// installer's "$GATEWAY_SERVICES" reference is followed to what it names. +func wordsAfter(t *testing.T, source, marker, terminator string, expand map[string][]string) []string { + t.Helper() + start := strings.Index(source, marker) + if start < 0 { + t.Fatalf("no %q in the file under test", marker) + } + rest := source[start+len(marker):] + end := strings.Index(rest, terminator) + if end < 0 { + t.Fatalf("no %q after %q", terminator, marker) + } + var words []string + for word := range strings.FieldsSeq(rest[:end]) { + if replacement, ok := expand[word]; ok { + words = append(words, replacement...) + continue + } + words = append(words, word) + } + return words +} + +// setDifference names what is missing from and extra in got, so a failure says +// which side moved rather than that two lists differ. +func setDifference(want, got []string) string { + present := make(map[string]bool, len(got)) + for _, item := range got { + present[item] = true + } + var missing []string + for _, item := range want { + if !present[item] { + missing = append(missing, item) + } + } + expected := make(map[string]bool, len(want)) + for _, item := range want { + expected[item] = true + } + var extra []string + for _, item := range got { + if !expected[item] { + extra = append(extra, item) + } + } + sort.Strings(missing) + sort.Strings(extra) + var problems []string + if len(missing) > 0 { + problems = append(problems, "missing "+strings.Join(missing, " ")) + } + if len(extra) > 0 { + problems = append(problems, "unexpected "+strings.Join(extra, " ")) + } + return strings.Join(problems, "; ") +} diff --git a/deployments/INSTRUCTIONS.md b/deployments/INSTRUCTIONS.md index d86a4f804..6b78be68a 100644 --- a/deployments/INSTRUCTIONS.md +++ b/deployments/INSTRUCTIONS.md @@ -1,6 +1,6 @@ # Running this distribution -This archive contains five linux/amd64 binaries: +This archive contains six linux/amd64 binaries: - **`archied`** — the resident daemon: polls your forge for assigned issues and dispatches them into sandboxed `archie-agent` containers. It serves no @@ -9,9 +9,15 @@ This archive contains five linux/amd64 binaries: - **`archie-ui`** — serves the operator dashboard and the webhook capture receiver, dialing the Gateway and State Store gRPC contracts. Reads only `[services.*]`, `[web]` and `[capture]` from the shared `config.toml`. -- **`archie-gateway`** — serves the chat (`ChatContract`) surface `archied` - and `archie-ui` dial for Telegram/webhook chat. Runs as its own process; - `archied` never embeds a gateway. +- **`archie-gateway`** — serves the chat (`ChatContract`) surface `archied`, + `archie-ui` and `archie-messaging` dial. Runs as its own process; `archied` + never embeds a gateway. +- **`archie-messaging`** — serves the Telegram, email and webhook channels, + dialing the Gateway for the chat contract and the State Store for the stored + channel settings. `archied` runs no gateway for those channels, so without + this process they are simply absent — and nothing logs an error + (`archie-core-1c01`), which is why it has a unit of its own in + `deployments/systemd-user-service.md`. - **`archie-state-store`** — owns the single `archie.db` SQLite file behind a gRPC contract. `archied` and `archie-gateway` are gRPC clients of it, not owners of the database. @@ -40,12 +46,14 @@ as a host binary. Pull it from GHCR: `ghcr.io/samcharles93/archie-agent`. providers) and place any secrets in `~/.config/archie/env` or referenced `secret://` locations. -3. Start the four processes, in order (`archie-state-store` and - `archie-gateway` first — `archied` and `archie-ui` dial both at startup): +3. Start the five processes, in order (`archie-state-store` and + `archie-gateway` first — `archied`, `archie-ui` and `archie-messaging` dial + both at startup): ```bash ./archie-state-store -config ~/.config/archie/config.toml -listen 127.0.0.1:9090 & ./archie-gateway -config ~/.config/archie/config.toml -listen 127.0.0.1:8585 & + ./archie-messaging -config ~/.config/archie/config.toml & ./archie-ui -config ~/.config/archie/config.toml & ./archied -config ~/.config/archie/config.toml ``` @@ -72,7 +80,14 @@ playbooks directory before pointing `archied` at it. ## Version This archive's binaries are built from the `archied` release tag in its -filename; `archie-ui`, `archie-gateway`, `archie-state-store`, and -`archie-playbooks` ship at that same version rather than being independently -tagged (see `RELEASING.md` in the source repository for why only `archied` -and `archie-agent` are independently versioned). +filename; `archie-ui`, `archie-gateway`, `archie-state-store`, +`archie-messaging` and `archie-playbooks` ship at that same version rather than +being independently tagged (see `RELEASING.md` in the source repository for why +only `archied` and `archie-agent` are independently versioned). + +`archie-state-store`, `archie-gateway`, `archie-messaging`, `archie-ui` and +`archied` are services that must be running and addressable; `archie-messaging` +carries the Telegram, email and webhook channels since the v1.30.0 extraction, so +an install (or an upgrade across v1.30.0) needs its unit as well -- see +`deployments/systemd-user-service.md`. `archie-playbooks` is a CLI and runs on +demand. diff --git a/deployments/README.md b/deployments/README.md index 2783b6446..24c9c4d20 100644 --- a/deployments/README.md +++ b/deployments/README.md @@ -35,6 +35,7 @@ Edit API keys in `~/.config/archie/env` or directly in `config.toml`, then launc ```bash archie-gateway -config ~/.config/archie/config.toml -listen 127.0.0.1:8585 & archie-state-store -config ~/.config/archie/config.toml -listen 127.0.0.1:9090 & +archie-messaging -config ~/.config/archie/config.toml & archie-ui -config ~/.config/archie/config.toml & archied -config ~/.config/archie/config.toml # or via systemd: diff --git a/deployments/systemd-user-service.md b/deployments/systemd-user-service.md index 9e78729ba..6b198240e 100644 --- a/deployments/systemd-user-service.md +++ b/deployments/systemd-user-service.md @@ -71,6 +71,38 @@ WantedBy=default.target --- +### Messaging Service Unit (`~/.config/systemd/user/archie-messaging.service`) + +The Telegram, email and webhook channels are served by `archie-messaging`, not +by `archied`, since the v1.30.0 extraction. `archied` starts no gateway for them +and logs nothing when one is absent, so a host that updates across v1.30.0 +without this unit runs on with dead channels and a daemon that looks perfectly +healthy -- that was `archie-core-1c01`, found after two days of a silently dead +Telegram bot. `scripts/archie-update-install` refuses an update when a service +unit is missing and names what is missing, so create this one before updating. + +It dials the Gateway for the chat contract and the State Store for the stored +channel settings, and reads the same `config.toml`. Like `archie-ui` it resolves +`GATEWAY_TOKEN` and `STATE_STORE_TOKEN` from its process environment, hence the +`EnvironmentFile`: + +```ini +[Unit] +Description=Archie Messaging Service +After=network.target archie-gateway.service archie-state-store.service +Wants=archie-gateway.service archie-state-store.service + +[Service] +Type=simple +ExecStart=%h/.local/bin/archie-messaging -config %h/.config/archie/config.toml +EnvironmentFile=-%h/.config/archie/env +Restart=on-failure +RestartSec=5s + +[Install] +WantedBy=default.target +``` + ## 2. UI Service Unit (`~/.config/systemd/user/archie-ui.service`) The dashboard is served by the standalone UI Service, not by `archied` @@ -158,7 +190,7 @@ systemctl --user daemon-reload Enable and start the service immediately: ```bash -systemctl --user enable --now archie-gateway archie-ui archied +systemctl --user enable --now archie-state-store archie-gateway archie-messaging archie-ui archied ``` Check service status: diff --git a/internal/releaseupdate/install_script_test.go b/internal/releaseupdate/install_script_test.go index 77f58e27e..594a9d4ad 100644 --- a/internal/releaseupdate/install_script_test.go +++ b/internal/releaseupdate/install_script_test.go @@ -369,7 +369,7 @@ case "$*" in source_dir="${@: -1}" mkdir -p "$source_dir" /usr/bin/cp -R "$ARCHIE_TEST_SOURCE_DIR/scripts" "$source_dir/scripts" - for c in archied archie-gateway archie-state-store archie-ui archie-playbooks archie-agent; do + for c in archied archie-gateway archie-state-store archie-ui archie-messaging archie-playbooks archie-agent; do mkdir -p "$source_dir/cmd/$c" done : > "$source_dir/docker-compose.yml" @@ -641,16 +641,16 @@ func TestUpdateInstallBuildsEveryReleaseBinary(t *testing.T) { "ARCHIE_UPDATE_AGENT_PREVIOUS": "1.21.0", }) - for _, cmd := range []string{"archied", "archie-gateway", "archie-state-store", "archie-ui", "archie-playbooks"} { + for _, cmd := range []string{"archied", "archie-gateway", "archie-state-store", "archie-ui", "archie-messaging", "archie-playbooks"} { assertCallContains(t, calls, "go build", "internal/app/archied.gatewayVersion=1.23.0", "./cmd/"+cmd) assertCallContains(t, calls, "install -m755", "/"+cmd) } assertCallAbsent(t, calls, "./cmd/archie-agent") // The watchdog cannot restart what it is not told about. assertCallContains(t, calls, "systemd-run", - "--setenv=ARCHIE_UPDATE_UNITS=archie-state-store archie-gateway archied archie-ui") + "--setenv=ARCHIE_UPDATE_UNITS=archie-state-store archie-gateway archied archie-ui archie-messaging") assertCallContains(t, calls, "systemd-run", - "--setenv=ARCHIE_UPDATE_BINARIES=archie-state-store archie-gateway archied archie-ui archie-playbooks") + "--setenv=ARCHIE_UPDATE_BINARIES=archie-state-store archie-gateway archied archie-ui archie-messaging archie-playbooks") } // Installing binaries for processes the host has no unit for produces exactly diff --git a/scripts/archie-update-install b/scripts/archie-update-install index 30c43bef4..04cb83ff1 100755 --- a/scripts/archie-update-install +++ b/scripts/archie-update-install @@ -81,14 +81,20 @@ TASK_DB_PATH="${ARCHIE_TASK_DB_PATH:-$(configured_task_db_path)}" TASK_DB_BACKUP="${ARCHIE_TASK_DB_BACKUP:-$BIN_DIR/archie-task-db.prev.sqlite}" # The archied release is a set of processes, not one binary. Listed in start -# order: the State Store owns archie.db and every other process dials it, and -# the Gateway serves the chat contract archied and the UI dial, so each comes -# up before its consumers. archie-playbooks is a CLI, so it is installed but -# never restarted. deployments/systemd-user-service.md is the reference -# deployment; installing archied alone leaves the rest on the previous -# release, which is why a 1.23.0 update failed its health check +# order: the State Store owns archie.db and every other process dials it, the +# Gateway serves the chat contract archied, the UI and the Messaging Service +# dial, and each comes up before its consumers. archie-playbooks is a CLI, so +# it is installed but never restarted. deployments/systemd-user-service.md is +# the reference deployment; installing archied alone leaves the rest on the +# previous release, which is why a 1.23.0 update failed its health check # (archie-core-hbqk). -GATEWAY_SERVICES="archie-state-store archie-gateway archied archie-ui" +# +# archie-messaging is a service, not a CLI: it owns the Telegram, email and +# webhook channels since the v1.30.0 extraction, so a host that updates without +# it keeps running with dead channels and no error anywhere +# (archie-core-1c01). TestUpdateInstallCoversEveryHostRunCommand fails if this +# list and GATEWAY_BINARIES stop covering the commands the release zip ships. +GATEWAY_SERVICES="archie-state-store archie-gateway archied archie-ui archie-messaging" GATEWAY_BINARIES="$GATEWAY_SERVICES archie-playbooks" PREV_GW="${ARCHIE_UPDATE_DAEMON_PREVIOUS:-}"