Documentation
¶
Overview ¶
Package compose turns a rendered compose manifest into the Swarm specs a stack is made of.
It is the half of charts.Backend that needs no daemon: a manifest string goes in, an ordered set of service, network, config and secret specs comes out. Applying them is backend's job.
The transformation is docker/cli's own — cli/compose/{loader,schema,convert}, which are exported — rather than a second implementation. `docker stack deploy` is unusable as an applier for the reasons in swarmcli-cd#1 (--prune touches services only and swallows its own list error, networks are silently never updated, no dry-run, --detach returns before convergence, update order is Go map iteration), but every one of those is a defect of the *command*, not of the conversion underneath it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Network ¶
type Network struct {
// Name is already namespace-scoped, unless the manifest set an explicit
// `name:`, in which case it is that.
Name string
Spec network.CreateOptions
}
Network pairs a network's name on the swarm with what to create.
type Service ¶
type Service struct {
// Name is the service's name in the manifest, unscoped.
Name string
Spec swarm.ServiceSpec
}
Service pairs the name the manifest used with the spec it produced.
Both are needed and neither is derivable from the other in general: Spec.Name is namespace-scoped, and Namespace.Descope would be a guess for a service whose own name contains the separator.
type Stack ¶
type Stack struct {
// Namespace scopes every name. A stack is a name prefix plus a
// com.docker.stack.namespace label — Swarm has no /stacks endpoint, no
// server-side desired state and no owner references.
Namespace convert.Namespace
Services []Service
Networks []Network
Configs []swarm.ConfigSpec
Secrets []swarm.SecretSpec
// ExternalNetworks names networks the manifest expects to already exist.
// They are not ours to create, and a missing one is a pre-flight failure
// rather than something to conjure.
ExternalNetworks []string
}
Stack is everything one rendered manifest says should exist.
Every slice is sorted by name. Go map iteration order is one of the named defects of `docker stack deploy`, and reproducing it here would be self-inflicted: two reconciles of an unchanged manifest must produce the same work list in the same order, or a diff of the plan is noise and an operator reading the log sees a different deploy every time.
func Convert ¶
Convert loads a rendered compose manifest and converts it to Swarm specs.
The api client is used only for what conversion genuinely cannot do offline: resolving the secret and config names a service references to their ids, and reading the negotiated API version that gates a few spec fields. Nothing is written.