Documentation
¶
Overview ¶
Package composeadapter hides everything that talks to `docker compose`.
The v0 implementation shells out. A future SDK-backed implementation can satisfy the same Adapter interface without touching callers.
Index ¶
- Variables
- func AllServicesHealthy(statuses []ContainerStatus) bool
- type Adapter
- type ContainerStatus
- type Exec
- type RenderedConfig
- type RenderedService
- type ShellAdapter
- func (a *ShellAdapter) PsJSON(ctx context.Context) ([]ContainerStatus, error)
- func (a *ShellAdapter) Pull(ctx context.Context, services []string, progress io.Writer) error
- func (a *ShellAdapter) RenderConfigJSON(ctx context.Context) (*RenderedConfig, error)
- func (a *ShellAdapter) Up(ctx context.Context, opts UpOptions, progress io.Writer) error
- func (a *ShellAdapter) Validate(ctx context.Context) error
- func (a *ShellAdapter) Version(ctx context.Context) (VersionInfo, error)
- type ShellOptions
- type UpOptions
- type VersionInfo
Constants ¶
This section is empty.
Variables ¶
var ErrHyphenatedCompose = errors.New("docker-compose (hyphen form) is not supported; install Compose v2/v5 and use `docker compose`")
ErrHyphenatedCompose indicates the caller invoked `docker-compose` (v1), which c2quay explicitly does not support.
Functions ¶
func AllServicesHealthy ¶
func AllServicesHealthy(statuses []ContainerStatus) bool
AllServicesHealthy returns true when every container is either running (healthy or without a healthcheck) or has exited cleanly with code 0. Init containers that exit 0 are treated as success so that `docker compose up --wait` false-positives (docker/compose#10596) don't mark the deploy as failed when it actually succeeded.
Types ¶
type Adapter ¶
type Adapter interface {
// Version returns the installed `docker compose` version.
Version(ctx context.Context) (VersionInfo, error)
// Validate runs `docker compose config --quiet` to confirm the file is valid.
Validate(ctx context.Context) error
// RenderConfigJSON returns the fully-resolved project configuration.
// This is the source of truth for services and image references.
RenderConfigJSON(ctx context.Context) (*RenderedConfig, error)
// PsJSON returns the current container states for the project.
PsJSON(ctx context.Context) ([]ContainerStatus, error)
// Pull runs `docker compose pull <services>`, streaming progress to the
// supplied writer. Empty services means "every service in the project".
// See ADR 0010.
Pull(ctx context.Context, services []string, progress io.Writer) error
// Up runs `docker compose up -d` with the configured options, streaming
// progress output to progress.
Up(ctx context.Context, opts UpOptions, progress io.Writer) error
}
type ContainerStatus ¶
type ContainerStatus struct {
Name string `json:"Name"`
Service string `json:"Service"`
State string `json:"State"`
Health string `json:"Health"`
Status string `json:"Status"`
ExitCode int `json:"ExitCode"`
}
ContainerStatus is a projection of `docker compose ps --format json`.
func ParsePsJSON ¶
func ParsePsJSON(raw []byte) ([]ContainerStatus, error)
ParsePsJSON handles both shapes that `docker compose ps --format json` can emit: a JSON array (older Compose) or a stream of newline-separated JSON objects (newer Compose).
type Exec ¶
type Exec interface {
Output(ctx context.Context, name string, args ...string) ([]byte, []byte, error)
RunWithStream(ctx context.Context, progress io.Writer, name string, args ...string) error
}
Exec is injectable for tests. Real code uses the exec package.
type RenderedConfig ¶
type RenderedConfig struct {
Name string `json:"name"`
Services map[string]RenderedService `json:"services"`
}
RenderedConfig is a trimmed projection of `docker compose config --format json`. We only pull the fields c2quay needs.
func ParseRenderedConfig ¶
func ParseRenderedConfig(raw []byte) (*RenderedConfig, error)
ParseRenderedConfig decodes the output of `docker compose config --format json`. Only the fields c2quay needs are extracted.
func (*RenderedConfig) ImagesByService ¶
func (rc *RenderedConfig) ImagesByService() map[string]string
ImagesByService returns a service-name to image-ref mapping for all services that have an image field. Services without image are skipped.
type RenderedService ¶
type RenderedService struct {
Image string `json:"image"`
}
RenderedService is the sliver of a Compose service definition c2quay uses.
type ShellAdapter ¶
type ShellAdapter struct {
// contains filtered or unexported fields
}
func NewShell ¶
func NewShell(opts ShellOptions) *ShellAdapter
func (*ShellAdapter) PsJSON ¶
func (a *ShellAdapter) PsJSON(ctx context.Context) ([]ContainerStatus, error)
func (*ShellAdapter) Pull ¶ added in v0.4.9
Pull runs `docker compose pull <services>`, streaming progress to the supplied writer. See ADR 0010.
func (*ShellAdapter) RenderConfigJSON ¶
func (a *ShellAdapter) RenderConfigJSON(ctx context.Context) (*RenderedConfig, error)
func (*ShellAdapter) Up ¶
Up runs `docker compose up -d [--wait] [--remove-orphans] [--force-recreate]`. It compensates for a known bug (docker/compose#10596) where `--wait` returns exit 1 even when every service is healthy, by cross-checking `ps` after the call.
func (*ShellAdapter) Version ¶
func (a *ShellAdapter) Version(ctx context.Context) (VersionInfo, error)
type ShellOptions ¶
type UpOptions ¶
type UpOptions struct {
Services []string
RemoveOrphans bool
Wait bool
Timeout time.Duration
// ForceRecreate passes `--force-recreate` to compose up. Intended as a
// per-deploy debug escape hatch for the fresh-build-same-tag case where
// Compose's digest-diff misfires. See ADR 0011.
ForceRecreate bool
// ExtraFiles are appended after the adapter's base compose files for this
// single call. Used by the rollback flow to inject a pinned-image override
// without rebuilding the adapter.
ExtraFiles []string
}
UpOptions controls `docker compose up -d`.
type VersionInfo ¶
type VersionInfo struct {
Raw string
Parsed doctor.ComposeVersion
SupportsWait bool
SupportsJSONOut bool
IsHyphenated bool
}
VersionInfo reports the installed Compose version and the capabilities c2quay cares about.