fix(release): ship archie-agent beside archied so Kit runs have one to mount

This commit is contained in:
sam committed 2026-10-27 02:49:31 +11:00
1 parent dfce3360b2
commit 6ca5c7f851
8 files changed
+58 -25

No files matched your search

+10 -5
View File
@@ -316,8 +316,10 @@ jobs:
# Packages every host-run binary (archied, archie-gateway,
# archie-state-store, archie-ui, archie-messaging) as a
# linux/amd64 zip for a
# non-Docker install. It waits only for the agent image, whose digest
# release.json pins; archie-agent itself never ships as a host binary.
# non-Docker install, plus archie-agent: it has no unit, but a Kit run
# mounts it from archied's directory, so a host without it parks them.
# It waits only for the agent image, whose digest
# release.json pins.
dist-zip:
needs: [gate, agent-image]
# Not gated on github.ref. A release is pushed as main plus both tags at
@@ -364,9 +366,12 @@ jobs:
# 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/installtype.buildType=binary -X github.com/samcharles93/archie-core/internal/buildinfo.Version=${{ steps.version.outputs.version }} -X github.com/samcharles93/archie-core/internal/buildinfo.Runtime=${{ steps.version.outputs.version }}"
ldflags="-X github.com/samcharles93/archie-core/internal/installtype.buildType=binary -X github.com/samcharles93/archie-core/internal/buildinfo.Version=${{ steps.version.outputs.version }} -X github.com/samcharles93/archie-core/internal/buildinfo.Runtime=${{ steps.version.outputs.version }} -X github.com/samcharles93/archie-core/internal/app/agentworker.version=${{ steps.version.outputs.version }}"
mkdir -p dist
for cmd in $(jq -r '.required_topology.units[]' release.json); do
# Units first, then the binaries that run beside them without one.
# The agentworker stamp only lands in archie-agent; the linker
# ignores -X for a symbol a binary does not import.
for cmd in $(jq -r '.required_topology.units[], .required_topology.binaries[]?' release.json); do
go build -ldflags "$ldflags" -o "dist/$cmd" "./cmd/$cmd"
done
@@ -376,7 +381,7 @@ jobs:
set -e
name="archie-core-archied-v${{ steps.version.outputs.version }}-linux-amd64"
mkdir -p "$name"
for cmd in $(jq -r '.required_topology.units[]' release.json); do
for cmd in $(jq -r '.required_topology.units[], .required_topology.binaries[]?' release.json); do
cp "dist/$cmd" "$name/"
done
cp deployments/INSTRUCTIONS.md CHANGELOG.md "$name/"
+7
View File
@@ -55,12 +55,19 @@ func runCommand(args []string, getenv func(string) string, stderr io.Writer, run
natsURLFlag := flags.String("nats-url", "", "NATS server URL (defaults to NATS_URL)")
stateStoreURLFlag := flags.String("state-store-url", "", "State Store gRPC target (defaults to STATE_STORE_URL; required -- the legacy NATS storerpc path is deleted)")
stateStoreTokenFlag := flags.String("state-store-token", "", "State Store bearer token (defaults to STATE_STORE_TOKEN)")
showVersion := flags.Bool("version", false, "print the version and exit")
if err := flags.Parse(args); err != nil {
if errors.Is(err, flag.ErrHelp) {
return 0
}
return 2
}
// The release and its updater read this line to prove a shipped
// archie-agent belongs to the release being installed.
if *showVersion {
fmt.Printf("archie-agent %s\n", agentworker.Version())
return 0
}
natsURL, natsToken := natsConnectionSettings(*natsURLFlag, getenv)
if natsURL == "" {
+4 -3
View File
@@ -19,9 +19,10 @@ daemon, and `archied playbooks serve` is its language server for editors.
Without `archie-messaging` the channels are simply absent, so it needs a unit
of its own (`deployments/systemd-user-service.md`).
`archie-agent` (the per-task sandboxed runtime) is **not** in this archive —
it only ever runs inside the Docker container `archied` spawns per task, never
as a host binary. Pull it from GHCR: `ghcr.io/samcharles93/archie-agent`.
`archie-agent` (the per-task sandboxed runtime) has no unit of its own: it
ships beside `archied` because a Kit run mounts it from that directory. The
agent image `ghcr.io/samcharles93/archie-agent` is a separate thing, pulled by
digest for the containers `archied` spawns per task.
## Quickstart
+9 -5
View File
@@ -149,9 +149,9 @@ if [ "${FROM_SOURCE}" = true ]; then
STAGE="${TMP}/stage"
mkdir -p "${STAGE}"
# A source build is not a release: it says `dev`, and buildType=binary lets
# it self-update.
LDFLAGS="-X github.com/${REPO}/internal/buildinfo.Version=dev -X github.com/${REPO}/internal/buildinfo.Runtime=dev -X github.com/${REPO}/internal/installtype.buildType=binary"
for cmd in $(jq -er '.required_topology.units | join(" ")' "${SRC_DIR}/release.json"); do
# it self-update. The agentworker stamp only lands in archie-agent.
LDFLAGS="-X github.com/${REPO}/internal/buildinfo.Version=dev -X github.com/${REPO}/internal/buildinfo.Runtime=dev -X github.com/${REPO}/internal/installtype.buildType=binary -X github.com/${REPO}/internal/app/agentworker.version=dev"
for cmd in $(jq -er '[.required_topology.units[], .required_topology.binaries[]?] | join(" ")' "${SRC_DIR}/release.json"); do
(cd "${SRC_DIR}" && go build -ldflags "${LDFLAGS}" -o "${STAGE}/${cmd}" "./cmd/${cmd}")
done
cp "${SRC_DIR}/release.json" "${STAGE}/"
@@ -177,10 +177,14 @@ else
fi
TOPOLOGY_UNITS="$(tr -d '\n' <"${STAGE}/release.json" | sed -n 's/.*"units": *\[\([^]]*\)\].*/\1/p' | tr -d '" ' | tr , ' ')"
for cmd in ${TOPOLOGY_UNITS}; do
# Binaries that run beside the units without a service of their own: a Kit run
# mounts archie-agent from archied's directory, so it must be installed with
# them and replaced with them.
TOPOLOGY_BINARIES="$(tr -d '\n' <"${STAGE}/release.json" | sed -n 's/.*"binaries": *\[\([^]]*\)\].*/\1/p' | tr -d '" ' | tr , ' ')"
for cmd in ${TOPOLOGY_UNITS} ${TOPOLOGY_BINARIES}; do
install -m755 "${STAGE}/${cmd}" "${ARCHIE_BIN_DIR}/${cmd}"
done
echo " Installed ${TOPOLOGY_UNITS} to ${ARCHIE_BIN_DIR}/"
echo " Installed ${TOPOLOGY_UNITS} ${TOPOLOGY_BINARIES} to ${ARCHIE_BIN_DIR}/"
# 3. Configuration. archied setup asks every question and writes config.toml
# plus any secrets to the env file beside it; this script asks nothing itself.
+9 -7
View File
@@ -18,6 +18,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"strings"
"time"
@@ -90,8 +91,8 @@ func (t *Transaction) Prepare(ctx context.Context, req PrepareRequest) (Result,
return Result{}, err
}
if err := t.stage(req, release, j); err != nil {
for _, unit := range j.Units {
_ = os.Remove(t.staged(unit))
for _, app := range append(slices.Clone(j.Units), j.Binaries...) {
_ = os.Remove(t.staged(app))
}
return Result{}, err
}
@@ -128,13 +129,13 @@ func (t *Transaction) fetch(ctx context.Context, req PrepareRequest, work string
if err != nil {
return "", Manifest{}, err
}
for _, unit := range manifest.Required.Units {
reported, err := reportedVersion(ctx, filepath.Join(release, unit), unit)
for _, binary := range manifest.Required.apps() {
reported, err := reportedVersion(ctx, filepath.Join(release, binary), binary)
if err != nil {
return "", Manifest{}, err
}
if !sameVersion(reported, req.Version) {
return "", Manifest{}, fmt.Errorf("candidate %s reports %q, not %s", unit, reported, req.Version)
return "", Manifest{}, fmt.Errorf("candidate %s reports %q, not %s", binary, reported, req.Version)
}
}
return release, manifest, nil
@@ -167,6 +168,7 @@ func (t *Transaction) snapshotHost(ctx context.Context, req PrepareRequest, mani
ComponentAgent: installedAgent(t.BinDir),
},
Units: manifest.Required.Units,
Binaries: manifest.Required.Binaries,
Managed: managed,
Image: imageChange{Previous: image, Candidate: manifest.AgentImage},
SchemaBefore: schema,
@@ -189,7 +191,7 @@ func (t *Transaction) stage(req PrepareRequest, release string, j journal) error
if err := installFile(filepath.Join(release, WatchdogBinary), filepath.Join(preparing, WatchdogBinary), 0o700); err != nil {
return fmt.Errorf("freeze the watchdog: %w", err)
}
for _, unit := range j.Units {
for _, unit := range append(slices.Clone(j.Units), j.Binaries...) {
live := filepath.Join(t.BinDir, unit)
if _, err := os.Stat(live); err == nil {
if err := installFile(live, filepath.Join(preparing, "previous", unit), 0o755); err != nil {
@@ -340,7 +342,7 @@ func readManifest(path string) (Manifest, error) {
if len(manifest.Required.Units) == 0 {
return Manifest{}, errors.New("release has no required_topology")
}
for _, unit := range manifest.Required.Units {
for _, unit := range manifest.Required.apps() {
if !releaseUnit.MatchString(unit) {
return Manifest{}, fmt.Errorf("invalid release unit %q", unit)
}
+13 -1
View File
@@ -1,12 +1,24 @@
package releaseupdate
import "fmt"
import (
"fmt"
"slices"
)
type Topology struct {
Units []string `json:"units"`
ConfigSections []string `json:"config_sections"`
// Binaries are the release's host binaries that run beside the units
// without a service of their own, such as the archie-agent a Kit run
// mounts from archied's directory. They are installed and switched with
// the units and are never started, stopped or demanded as a unit.
Binaries []string `json:"binaries,omitempty"`
}
// apps returns the binaries the release installs: its units, and the host
// binaries that run beside them without a service.
func (t Topology) apps() []string { return append(slices.Clone(t.Units), t.Binaries...) }
// MigrationPlan preserves the release's dependency order. Unknown observations
// require every step to be checked manually rather than assuming a partial host.
func (t Topology) MigrationPlan(units, sections map[string]bool) []string {
+5 -4
View File
@@ -106,6 +106,7 @@ type journal struct {
Version string `json:"version"`
Previous map[string]string `json:"previous"`
Units []string `json:"units"`
Binaries []string `json:"binaries,omitempty"`
Managed bool `json:"managed"`
Image imageChange `json:"image"`
SchemaBefore int64 `json:"schema_before"`
@@ -180,7 +181,7 @@ func (t *Transaction) switchOver(ctx context.Context, j *journal) error {
if err := t.stopUnits(ctx, *j); err != nil {
return err
}
for _, unit := range j.Units {
for _, unit := range append(slices.Clone(j.Units), j.Binaries...) {
if err := os.Rename(t.staged(unit), filepath.Join(t.BinDir, unit)); err != nil {
return fmt.Errorf("switch %s: %w", unit, err)
}
@@ -250,8 +251,8 @@ func (t *Transaction) rollback(ctx context.Context, j journal) error {
// abandon discards a transaction that never switched anything.
func (t *Transaction) abandon(ctx context.Context, j journal) error {
t.say("update to %s was staged but never started; discarding it", j.Version)
for _, unit := range j.Units {
if err := os.Remove(t.staged(unit)); err != nil && !errors.Is(err, os.ErrNotExist) {
for _, app := range append(slices.Clone(j.Units), j.Binaries...) {
if err := os.Remove(t.staged(app)); err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
}
@@ -273,7 +274,7 @@ func (t *Transaction) incomplete(err error) error {
func (t *Transaction) restoreFiles(j journal) error {
previous := filepath.Join(JournalPath(t.StateDir), "previous")
for _, unit := range j.Units {
for _, unit := range append(slices.Clone(j.Units), j.Binaries...) {
live := filepath.Join(t.BinDir, unit)
saved := filepath.Join(previous, unit)
if _, err := os.Stat(saved); errors.Is(err, os.ErrNotExist) {
+1
View File
@@ -1,6 +1,7 @@
{
"required_topology": {
"units": ["archie-state-store", "archie-gateway", "archie-ui", "archie-messaging", "archied"],
"binaries": ["archie-agent"],
"config_sections": ["services.state", "services.gateway"]
}
}