deploy

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package deploy performs rolling container deployments across one or more Docker hosts, using docker.Client instances for the underlying operations.

Index

Constants

This section is empty.

Variables

View Source
var ErrInProgress = errors.New("a deployment for this container is already in progress")

ErrInProgress means a deployment for the same container is already running. Overlapping deploys are rejected rather than serialized to avoid interleaving rename/stop/run steps on the same container.

View Source
var ErrIncompatible = errors.New("image is incompatible with the running container")

ErrIncompatible means the requested image could not be applied to the existing container (bad/missing image, or create/start failed with the preserved spec). The previous container is restored when possible.

View Source
var ErrNotRunning = errors.New("container is not running on any configured host")

ErrNotRunning means the named container was not found running on any configured Docker host.

View Source
var ErrUnavailable = errors.New("docker host unavailable")

ErrUnavailable means a Docker host/operation failed for infrastructural reasons (list/inspect/rename/stop, connectivity, etc.).

Functions

func HTTPStatus

func HTTPStatus(err error) int

HTTPStatus maps a Deploy error to an HTTP status for the webhook. Prefer Result.HTTPStatus when a Result is available (handles partial 207).

func PublicError

func PublicError(err error) string

PublicError returns a short, non-sensitive error label suitable for HTTP responses and CI logs. Detailed causes stay in server logs only.

Types

type Client

type Client interface {
	Host() string
	ListRunningNames(ctx context.Context) ([]string, error)
	Pull(ctx context.Context, image string) error
	Inspect(ctx context.Context, container string) (*docker.ContainerSpec, error)
	Rename(ctx context.Context, oldName, newName string) error
	Stop(ctx context.Context, container string) error
	Run(ctx context.Context, spec *docker.ContainerSpec) (string, error)
	Start(ctx context.Context, container string) error
	Remove(ctx context.Context, container string) error
}

Client is the subset of *docker.Client the deployer needs. It is satisfied by *docker.Client and can be faked in tests.

type HostResult

type HostResult struct {
	// Index is the position of this host in the service's configured client
	// list (0-based). Prefer this over Host when returning data to callers.
	Index int
	Host  string
	Err   error
}

HostResult is the outcome of a deployment on a single host.

type Result

type Result struct {
	Container string
	Image     string
	Hosts     []HostResult
}

Result aggregates per-host outcomes for one Deploy call.

func (Result) Err

func (r Result) Err() error

Err joins the errors from any failed hosts, or returns nil if all succeeded.

func (Result) HTTPStatus

func (r Result) HTTPStatus() int

HTTPStatus picks the webhook status for this result. Partial updates → 207; otherwise delegates to HTTPStatus(err) / 200.

func (Result) Partial

func (r Result) Partial() bool

Partial reports whether at least one selected host was updated and at least one selected host failed. In that case the fleet is intentionally left in a mixed state (fail-fast rolling), and callers should surface HTTP 207.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service performs rolling deployments across a fixed set of Docker hosts.

func NewService

func NewService(logger *zap.Logger, clients ...Client) *Service

NewService returns a Service that can deploy to the given clients.

func (*Service) Deploy

func (s *Service) Deploy(ctx context.Context, container, image string) (Result, error)

Deploy replaces container with a new instance running image, but only on hosts where that container is already running. Hosts without a matching running container are skipped. Selected hosts are updated one at a time; the first failure stops the roll so a bad image does not take down the rest of the matched fleet. Hosts already updated are left on the new image (partial success → Result.Partial() / HTTP 207).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL