Skip to content

updater

Portable Docker auto-update orchestration for Go applications.

updater is a Docker auto-update module. It pulls newer images, recreates the containers running them, and restarts whatever depended on those containers. It handles Compose projects, registry digest checks, and containers that must update themselves.

It works against the local Docker environment out of the box. Persistence, notifications, and self-upgrade behavior are adapters, so a host application provides only the parts it owns.

Module
kit.getarcane.app/updater
Reference
pkg.go.dev
Terminal window
go get kit.getarcane.app/updater@latest

Everything runs through a Service. The zero Config is valid:

import "kit.getarcane.app/updater"
service, err := updater.New(updater.Config{})
if err != nil {
return err
}
defer service.Close()
result, err := service.UpdateContainer(ctx, containerID, updater.Options{})

To apply recorded pending updates instead of updating one named container:

store := updater.NewMemoryPendingStore(updater.ImageUpdateRecord{
ID: "sha256:old-image-id",
Repository: "nginx",
Tag: "1.27",
HasUpdate: true,
UpdateType: updater.UpdateTypeDigest,
})
service, err := updater.New(updater.Config{PendingStore: store})
if err != nil {
return err
}
defer service.Close()
result, err := service.ApplyPending(ctx, updater.Options{})

ApplyPending applies each pending update, then restarts the containers still running the images it replaced. Options{DryRun: true} reports what would change without touching anything.

Every Config field is a seam. If you leave one nil, the updater supplies a Docker-backed default. For the purely optional fields, it skips that behavior. Override only what you own:

service, err := updater.New(updater.Config{
// Replace a default.
DockerClientProvider: updater.NewDockerClientProvider(client.WithHost("tcp://docker-proxy:2375")),
PendingStore: myStore,
// Add optional behavior.
Notifier: myNotifier, // told about each successful update
EventRecorder: myEvents, // receives lifecycle events
SelfUpdater: myUpgrader, // handles the container we run in
// Restrict which containers are in scope.
LabelPolicy: updater.LabelPolicy{
IsUpdateDisabledFunc: func(l map[string]string) bool { return l["updates"] == "off" },
},
OperationTimeout: 30 * time.Second,
})
Field Default when nil
DockerClientProvider NewDockerClientProvider(), which reads the standard Docker environment variables
ImagePuller NewImagePuller(provider), which uses Docker’s ImagePull API
PendingStore NewMemoryPendingStore(), which starts empty
RegistryDigestResolver NewRegistryDigestResolver(), which uses local Docker credentials
RegistryTagLister NewRegistryTagLister(), which uses local Docker credentials
ProjectUpdater NewDockerComposeProjectUpdater(provider), which shells out to docker compose
LabelPolicy DefaultLabelPolicy(), merged field by field. UnmanagedReasonFunc has no default
RunRecorder, Settings, Notifier, EventRecorder, UsedImageCollector Behavior disabled
SelfUpdater Self-update targets fail with ErrSelfUpdaterRequired
Logger slog.Default()

LabelPolicy merges field by field. New applies DefaultLabelPolicy().Merge(config.LabelPolicy), so overriding IsUpdateDisabledFunc above keeps the default tag policy and the self-update, agent, server, Swarm, and stop-signal detection.

Set UnmanagedReasonFunc when another tool owns some containers’ updates. It returns a reason, or "" when the updater may touch the container. Containers with a reason are always skipped, even when a run ignores opt-outs.

Set SelfContainerID to the ID (or ID prefix) of the container your application runs in. That container always goes to the SelfUpdater, whatever its labels.

Service.Close shuts down the Docker client that New created. If you supplied your own DockerClientProvider, its lifecycle stays yours and Close does nothing.

  1. Resolve a pullable image reference for each in-scope container. Image IDs and digest-pinned references are skipped, because pulling them again can never produce a newer image.
  2. Skip containers the LabelPolicy disables, containers the host excludes through SettingsProvider, Swarm tasks, and containers UnmanagedReasonFunc reports as owned by another tool. A user-requested run can skip the first two checks. See Overriding opt-outs.
  3. Select a newer eligible version tag, or compare the configured tag’s digest. See the Tag policies tab.
  4. Pull the target image. Container-scoped and tag updates are pulled and recreated one dependency unit at a time. A unit is a set of containers joined by dependencies or a Compose project. The next unit is pulled only after the previous one is recreated, so a canceled run never leaves running containers on an image whose tag a pull already moved.
  5. Recreate the container. Compose services go through the ProjectUpdater, grouped by project and then checked to confirm they no longer run the old image. Standalone containers are recreated directly, following the Docker and Compose rules for what to keep. See Standalone recreation.
  6. Restart containers that depend on what just changed, in dependency order.
  7. Hand self-update targets to the SelfUpdater last, since updating them may stop the calling process.

Scheduling, durable persistence, and user-facing notifications are not the module’s job. Supply adapters for those.

  1. Stop the container with its configured stop signal.
  2. Rename it to <name>-arcane-update-<unix time> so it is kept as a backup.
  3. Create the replacement under the original name. Named, anonymous, and image-declared volumes are reattached by name, so their data is kept. A container:<id> network mode is rewritten to the owner’s name.
  4. Start the replacement only if the original was running.
  5. Remove the backup once the replacement has started.

If create or start fails, the replacement is removed and the backup gets its original name back. It is started again if it was running. A container created with --rm is removed by Docker when it stops, so it has no backup. It is recreated from its old image ID instead.

Options{IgnoreSettingsExclusions: true} is for runs a user asked for, such as a manual update. It lets UpdateContainer and ApplyPending update the containers they target even when:

  • the SettingsProvider excludes them, or
  • the com.getarcaneapp.arcane.updater label opts them out.

The exclusion and the label stay in place. Some checks still apply:

  • Containers restarted only because a dependency changed still honor both opt-outs.
  • Swarm tasks, unmanaged containers, and image IDs or digest-pinned references stay ineligible.
result, err := service.UpdateContainer(ctx, containerID, updater.Options{
IgnoreSettingsExclusions: true,
})

To restart containers still running replaced images yourself, pass a RestartTargets:

restarted, err := service.RestartContainersUsingOldImages(ctx, updater.RestartTargets{
ByOldID: map[string]string{"sha256:old-image-id": "nginx:1.27"},
ByOldRef: map[string]string{"nginx:1.26": "nginx:1.27"},
})

RestartTargets.IgnoreSettingsExclusions works like the Options field above.

check, err := service.CheckContainerUpdate(ctx, containerID)
if err != nil {
return err
}
if check.UpdateAvailable {
fmt.Printf("%s -> %s (%s)\n", check.CurrentRef, check.TargetRef, check.UpdateType)
}

CheckContainerUpdate and CheckImageUpdate never pull, recreate, or write pending records. Status() returns a snapshot of the containers and projects currently being updated.

The default LabelPolicy reads these labels. They are also exported from updater/labels.

Label Effect
com.getarcaneapp.arcane.updater false (or 0, no, off) opts the container out of updates
com.getarcaneapp.arcane.updater.strategy digest, tag, or auto
com.getarcaneapp.arcane.updater.constraint Semver range for tag updates
com.getarcaneapp.arcane.updater.tag-pattern Regex that selects tags and captures their version
com.getarcaneapp.arcane.depends-on Comma-separated container names to restart in dependency order
com.getarcaneapp.arcane.stop-signal Custom stop signal
com.getarcaneapp.arcane / .agent Marks a self-update target, which is handed to the SelfUpdater
Package Contents
updater Service, Config, the adapter interfaces, and the result types
updater/refs Image reference normalization and pullability checks
updater/digest OCI digest parsing and canonicalization
updater/labels The container label keys and the functions that read them
updater/registry Registry tag listing, digest lookups, and pull rate limits. FetchTags, FetchDigest, and FetchRegistryRateLimit take a registry.Request
updater/types Policy, CheckRequest, CheckResult, and Compose adapter contracts
updater/pkg/utils/tagpolicy Semantic-version tag selection

Match these with errors.Is: ErrContainerNotFound, ErrSelfUpdaterRequired, ErrSelfUpdateContainer, ErrPendingStoreRequired, ErrImagePullerRequired, ErrDockerClientProviderRequired, ErrNilDockerClient. New returns a *ConfigError naming the Config field it could not accept.