build: agent is the image's default entrypoint; drop the old server examples (#7)

This commit is contained in:
2026-10-12 18:45:47 +02:00
parent 601c6da0d4
commit 55f8021b0a
6 changed files with 51 additions and 92 deletions
+29 -2
View File
@@ -16,6 +16,7 @@ import (
"github.com/shcizo/package-updater/internal/agent/config"
"github.com/shcizo/package-updater/internal/agent/conn"
"github.com/shcizo/package-updater/internal/agent/inventory"
"github.com/shcizo/package-updater/internal/agent/updater"
"github.com/shcizo/package-updater/internal/logging"
)
@@ -42,19 +43,45 @@ func run() error {
}
defer dockerCli.Close()
auth, err := updater.LoadRegistryAuth(cfg.DockerConfig, logger)
if err != nil {
return fmt.Errorf("registry auth: %w", err)
}
resolver := updater.NewResolver(dockerCli, auth)
exec := updater.NewDispatch(
updater.NewComposeExecutor(dockerCli, resolver, cfg.SelfID, updater.ExecDocker),
updater.NewSwarmExecutor(dockerCli, resolver, auth),
)
runner := updater.NewRunner(exec, cfg.UpdateTimeout)
collector := inventory.New(dockerCli, cfg.SelfID)
agent := conn.New(conn.Config{
URL: cfg.MasterURL, Token: cfg.Token, Fingerprint: cfg.MasterKey, Version: version,
}, collector, logger)
}, collector, runner, logger)
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
logMounts(ctx, dockerCli, cfg.SelfID, logger)
go runner.Run(ctx)
go watchLoop(ctx, dockerCli, agent, logger)
logger.Info("agent_starting", "version", version, "master_url", cfg.MasterURL)
logger.Info("agent_starting", "version", version, "master_url", cfg.MasterURL,
"update_timeout", cfg.UpdateTimeout.String(), "registry_auth", auth != nil)
return agent.Run(ctx)
}
// logMounts warns at startup when Compose updates cannot work. Each job reads
// the mounts again itself; this is only for the operator.
func logMounts(ctx context.Context, cli updater.SelfInspector, selfID string, log *slog.Logger) {
roots, err := updater.MountRoots(ctx, cli, selfID)
if err != nil || len(roots) == 0 {
log.Warn("no_stack_mounts", "error", err,
"hint", "Compose updates will fail; mount each stacks directory at the same path, read-write")
return
}
log.Info("stack_mounts", "roots", roots)
}
// watchLoop keeps a Docker event subscription alive. When the stream breaks
// (daemon restart), it resubscribes and asks for a refresh, because events
// may have been missed in between. It also asks for a full re-inventory every