compose

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

package compose is a wrapper around the docker compose cli. it provides a programmatic interface for managing docker compose projects. it is not a complete 1:1 mapping of the docker compose cli, but provides a programmatic interface for managing docker compose projects in Go, making it useful for automation, tooling, or embedding docker compose behavior.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrComposeError        = fmt.Errorf("compose error")
	ErrComposeFlagError    = fmt.Errorf("compose flag error")
	ErrComposeUpError      = fmt.Errorf("compose up error")
	ErrComposeDownError    = fmt.Errorf("compose down error")
	ErrComposeLogsError    = fmt.Errorf("compose logs error")
	ErrComposeKillError    = fmt.Errorf("compose kill error")
	ErrComposeEventsError  = fmt.Errorf("compose events error")
	ErrComposePsError      = fmt.Errorf("compose ps error")
	ErrComposeStartError   = fmt.Errorf("compose start error")
	ErrComposeStopError    = fmt.Errorf("compose stop error")
	ErrComposeRestartError = fmt.Errorf("compose restart error")
	ErrComposeBuildError   = fmt.Errorf("compose build error")
	ErrComposePullError    = fmt.Errorf("compose pull error")
	ErrComposeExecError    = fmt.Errorf("compose exec error")
)

Errors for the compose command and its setters.

Functions

func IsComposeBuildError added in v0.2.0

func IsComposeBuildError(err error) bool

func IsComposeDownError

func IsComposeDownError(err error) bool

IsComposeDownError checks if the error is a ComposeDownError.

func IsComposeError

func IsComposeError(err error) bool

IsComposeError checks if the error is a ComposeError.

func IsComposeEventsError added in v0.1.7

func IsComposeEventsError(err error) bool

IsComposeEventsError checks if the error is a ComposeEventsError.

func IsComposeExecError added in v0.2.0

func IsComposeExecError(err error) bool

func IsComposeFlagError

func IsComposeFlagError(err error) bool

IsComposeFlagError checks if the error is a ComposeFlagError.

func IsComposeKillError added in v0.1.7

func IsComposeKillError(err error) bool

IsComposeKillError checks if the error is a ComposeKillError.

func IsComposeLogsError

func IsComposeLogsError(err error) bool

IsComposeLogsError checks if the error is a ComposeLogsError.

func IsComposePsError added in v0.2.0

func IsComposePsError(err error) bool

func IsComposePullError added in v0.2.0

func IsComposePullError(err error) bool

func IsComposeRestartError added in v0.2.0

func IsComposeRestartError(err error) bool

func IsComposeStartError added in v0.2.0

func IsComposeStartError(err error) bool

func IsComposeStopError added in v0.2.0

func IsComposeStopError(err error) bool

func IsComposeUpError

func IsComposeUpError(err error) bool

IsComposeUpError checks if the error is a ComposeUpError.

func NewCompose

func NewCompose(project *create.Project) *compose

Types

type ComposeBuildError added in v0.2.0

type ComposeBuildError struct {
	Message string
}

ComposeBuildError is the error for the compose build command

func NewComposeBuildError added in v0.2.0

func NewComposeBuildError(err error) *ComposeBuildError

func (*ComposeBuildError) Error added in v0.2.0

func (e *ComposeBuildError) Error() string

func (*ComposeBuildError) Unwrap added in v0.2.0

func (e *ComposeBuildError) Unwrap() error

type ComposeBuildOptions added in v0.2.0

type ComposeBuildOptions struct {
	BuildArg         []string // key=value, appended as --build-arg each
	Builder          string
	Check            bool
	Memory           string // e.g. "2G"
	NoCache          bool
	Print            bool
	Provenance       bool
	Pull             bool
	Push             bool
	Quiet            bool
	SBOM             bool
	SSH              []string // e.g. "default" or "key=path"
	WithDependencies bool
	Writer           io.Writer
	Profiles         []string
	ServiceNames     []string
	Flags            []string
}

ComposeBuildOptions is the options for the compose build command

func (*ComposeBuildOptions) GenerateFlags added in v0.2.0

func (opt *ComposeBuildOptions) GenerateFlags() ([]string, error)

type ComposeDownError

type ComposeDownError struct {
	Message string
}

ComposeDownError is the error for the compose down command

func NewComposeDownError

func NewComposeDownError(err error) *ComposeDownError

NewComposeDownError creates a new ComposeDownError with the given error message.

func (*ComposeDownError) Error

func (e *ComposeDownError) Error() string

func (*ComposeDownError) Unwrap

func (e *ComposeDownError) Unwrap() error

type ComposeDownOptions

type ComposeDownOptions struct {
	RemoveOrphans bool
	Timeout       *int
	RemoveImage   *string
	RemoveVolumes bool

	Flags    []string
	Writer   io.Writer
	Profiles []string
}

ComposeDownOptions is the options for the compose down command

func (*ComposeDownOptions) GenerateFlags

func (opt *ComposeDownOptions) GenerateFlags() ([]string, error)

type ComposeError

type ComposeError struct {
	Message string
}

ComposeError is the error for the compose command

func NewComposeError

func NewComposeError(err error) *ComposeError

func (*ComposeError) Error

func (e *ComposeError) Error() string

func (*ComposeError) Unwrap

func (e *ComposeError) Unwrap() error

type ComposeEventsError added in v0.1.7

type ComposeEventsError struct {
	Message string
}

ComposeEventsError is the error for the compose events command

func NewComposeEventsError added in v0.1.7

func NewComposeEventsError(err error) *ComposeEventsError

NewComposeEventsError creates a new ComposeEventsError with the given error message.

func (*ComposeEventsError) Error added in v0.1.7

func (e *ComposeEventsError) Error() string

func (*ComposeEventsError) Unwrap added in v0.1.7

func (e *ComposeEventsError) Unwrap() error

type ComposeExecError added in v0.2.0

type ComposeExecError struct {
	Message string
}

ComposeExecError is the error for the compose exec command

func NewComposeExecError added in v0.2.0

func NewComposeExecError(err error) *ComposeExecError

func (*ComposeExecError) Error added in v0.2.0

func (e *ComposeExecError) Error() string

func (*ComposeExecError) Unwrap added in v0.2.0

func (e *ComposeExecError) Unwrap() error

type ComposeExecOptions added in v0.2.0

type ComposeExecOptions struct {
	Detach     bool
	Env        []string // key=value, passed as -e each
	Index      *int     // --index for multi-replica services
	NoTTY      bool     // -T: disable TTY
	Privileged bool
	User       string // -u
	Workdir    string // -w
	Writer     io.Writer
	Stdin      io.Reader // optional; forwarded to the container after compose file is read
	Profiles   []string
	Service    string   // required: service name
	Command    []string // required: command and args (e.g. ["sh", "-c", "echo hi"])
}

ComposeExecOptions is the options for the compose exec command. Usage: docker compose exec [OPTIONS] SERVICE COMMAND [ARGS...] Service and Command are required; set via WithService and WithCommand.

func (*ComposeExecOptions) GenerateFlags added in v0.2.0

func (opt *ComposeExecOptions) GenerateFlags() ([]string, error)

type ComposeFlagError

type ComposeFlagError struct {
	Flag    string
	Message string
}

ComposeFlagError is the error for the compose flag

func NewComposeFlagError

func NewComposeFlagError(flag, message string) *ComposeFlagError

NewComposeFlagError makes a new ComposeFlagError with the given flag and message.

func (*ComposeFlagError) Error

func (e *ComposeFlagError) Error() string

func (*ComposeFlagError) Unwrap

func (e *ComposeFlagError) Unwrap() error

type ComposeKillError added in v0.1.7

type ComposeKillError struct {
	Message string
}

ComposeKillError is the error for the compose kill command

func NewComposeKillError added in v0.1.7

func NewComposeKillError(err error) *ComposeKillError

NewComposeKillError creates a new ComposeKillError with the given error message.

func (*ComposeKillError) Error added in v0.1.7

func (e *ComposeKillError) Error() string

func (*ComposeKillError) Unwrap added in v0.1.7

func (e *ComposeKillError) Unwrap() error

type ComposeKillOptions added in v0.1.7

type ComposeKillOptions struct {
	Signal        *string
	RemoveOrphans bool

	Flags    []string
	Writer   io.Writer
	Profiles []string
}

ComposeKillOptions is the options for the compose kill command

func (*ComposeKillOptions) GenerateFlags added in v0.1.7

func (opt *ComposeKillOptions) GenerateFlags() ([]string, error)

GenerateFlags generates the flags for the compose kill command

It will return a slice of flags to append to the command Eg.

[]string{"kill", "--signal", "SIGKILL", "--remove-orphans"}

type ComposeLogsError

type ComposeLogsError struct {
	Message string
}

ComposeLogsError is the error for the compose logs command

func NewComposeLogsError

func NewComposeLogsError(err error) *ComposeLogsError

NewComposeLogsError creates a new ComposeLogsError with the given error message.

func (*ComposeLogsError) Error

func (e *ComposeLogsError) Error() string

func (*ComposeLogsError) Unwrap

func (e *ComposeLogsError) Unwrap() error

type ComposeLogsOptions

type ComposeLogsOptions struct {
	Tail        *int
	Follow      bool
	NoLogPrefix bool

	Writer   io.Writer
	Flags    []string
	Profiles []string
}

ComposeLogsOptions is the options for the compose logs command

func (*ComposeLogsOptions) GenerateFlags

func (opt *ComposeLogsOptions) GenerateFlags() ([]string, error)

type ComposePsError added in v0.2.0

type ComposePsError struct {
	Message string
}

ComposePsError is the error for the compose ps command

func NewComposePsError added in v0.2.0

func NewComposePsError(err error) *ComposePsError

func (*ComposePsError) Error added in v0.2.0

func (e *ComposePsError) Error() string

func (*ComposePsError) Unwrap added in v0.2.0

func (e *ComposePsError) Unwrap() error

type ComposePsOptions added in v0.2.0

type ComposePsOptions struct {
	All          bool
	Filter       []string // e.g. "status=running"
	Format       string
	NoTrunc      bool
	Orphans      *bool // nil = default (true); false = --no-orphans
	Quiet        bool
	Services     bool // --services: display services
	Status       string
	Writer       io.Writer
	Profiles     []string
	ServiceNames []string
	Flags        []string
}

ComposePsOptions is the options for the compose ps command

func (*ComposePsOptions) GenerateFlags added in v0.2.0

func (opt *ComposePsOptions) GenerateFlags() ([]string, error)

type ComposePullError added in v0.2.0

type ComposePullError struct {
	Message string
}

ComposePullError is the error for the compose pull command

func NewComposePullError added in v0.2.0

func NewComposePullError(err error) *ComposePullError

func (*ComposePullError) Error added in v0.2.0

func (e *ComposePullError) Error() string

func (*ComposePullError) Unwrap added in v0.2.0

func (e *ComposePullError) Unwrap() error

type ComposePullOptions added in v0.2.0

type ComposePullOptions struct {
	IgnoreBuildable    bool
	IgnorePullFailures bool
	IncludeDeps        bool
	Policy             string // e.g. "missing", "always", "never"
	Quiet              bool
	Writer             io.Writer
	Profiles           []string
	ServiceNames       []string
	Flags              []string
}

ComposePullOptions is the options for the compose pull command

func (*ComposePullOptions) GenerateFlags added in v0.2.0

func (opt *ComposePullOptions) GenerateFlags() ([]string, error)

type ComposeRestartError added in v0.2.0

type ComposeRestartError struct {
	Message string
}

ComposeRestartError is the error for the compose restart command

func NewComposeRestartError added in v0.2.0

func NewComposeRestartError(err error) *ComposeRestartError

func (*ComposeRestartError) Error added in v0.2.0

func (e *ComposeRestartError) Error() string

func (*ComposeRestartError) Unwrap added in v0.2.0

func (e *ComposeRestartError) Unwrap() error

type ComposeRestartOptions added in v0.2.0

type ComposeRestartOptions struct {
	NoDeps       bool
	Timeout      *int
	Writer       io.Writer
	Profiles     []string
	ServiceNames []string
	Flags        []string
}

ComposeRestartOptions is the options for the compose restart command

func (*ComposeRestartOptions) GenerateFlags added in v0.2.0

func (opt *ComposeRestartOptions) GenerateFlags() ([]string, error)

type ComposeStartError added in v0.2.0

type ComposeStartError struct {
	Message string
}

ComposeStartError is the error for the compose start command

func NewComposeStartError added in v0.2.0

func NewComposeStartError(err error) *ComposeStartError

func (*ComposeStartError) Error added in v0.2.0

func (e *ComposeStartError) Error() string

func (*ComposeStartError) Unwrap added in v0.2.0

func (e *ComposeStartError) Unwrap() error

type ComposeStartOptions added in v0.2.0

type ComposeStartOptions struct {
	Wait         bool
	WaitTimeout  *int
	Writer       io.Writer
	Profiles     []string
	ServiceNames []string
	Flags        []string
}

ComposeStartOptions is the options for the compose start command

func (*ComposeStartOptions) GenerateFlags added in v0.2.0

func (opt *ComposeStartOptions) GenerateFlags() ([]string, error)

type ComposeStopError added in v0.2.0

type ComposeStopError struct {
	Message string
}

ComposeStopError is the error for the compose stop command

func NewComposeStopError added in v0.2.0

func NewComposeStopError(err error) *ComposeStopError

func (*ComposeStopError) Error added in v0.2.0

func (e *ComposeStopError) Error() string

func (*ComposeStopError) Unwrap added in v0.2.0

func (e *ComposeStopError) Unwrap() error

type ComposeStopOptions added in v0.2.0

type ComposeStopOptions struct {
	Timeout      *int
	Writer       io.Writer
	Profiles     []string
	ServiceNames []string
	Flags        []string
}

ComposeStopOptions is the options for the compose stop command

func (*ComposeStopOptions) GenerateFlags added in v0.2.0

func (opt *ComposeStopOptions) GenerateFlags() ([]string, error)

type ComposeUpError

type ComposeUpError struct {
	Message string
}

ComposeUpError is the error for the compose up command

func NewComposeUpError

func NewComposeUpError(err error) *ComposeUpError

NewComposeUpError creates a new ComposeUpError with the given error message.

func (*ComposeUpError) Error

func (e *ComposeUpError) Error() string

func (*ComposeUpError) Unwrap

func (e *ComposeUpError) Unwrap() error

type ComposeUpOptions

type ComposeUpOptions struct {
	Detach                  bool
	AbortOnContainerExit    bool
	AbortOnContainerFailure bool
	AlwaysRecreateDeps      bool
	Attach                  *string
	AttachDependencies      bool
	Build                   bool
	NoBuild                 bool
	ForceRecreate           bool
	Menu                    bool
	ExitCodeFrom            *string
	NoAttach                *string
	NoColor                 bool
	NoDeps                  bool
	NoLogPrefix             bool
	NoRecreate              bool
	Pull                    *string
	NoStart                 bool
	QuietPull               bool
	RemoveOrphans           bool
	RenewAnonVolumes        bool
	Scale                   []ComposeUpScale
	Timeout                 *int
	Timestamps              bool
	Wait                    bool
	WaitTimeout             *int
	Watch                   bool
	Yes                     bool

	Profiles []string
	Flags    []string
	Writer   io.Writer
	Errs     []error
}

ComposeUpOptions is the options for the compose up command

func (*ComposeUpOptions) GenerateFlags

func (opt *ComposeUpOptions) GenerateFlags() (flags []string, err error)

GenerateFlags generates the flags for the compose up command

It will return a slice of flags to append to the command Eg.

[]string{"up", "--detach", ...}

type ComposeUpScale

type ComposeUpScale struct {
	Service string
	Num     int
}

ComposeUpScale is the scale for the compose up command

type Events added in v0.1.7

type Events struct {
	// Core event fields
	Time    string `json:"time"`
	Type    string `json:"type"`
	Action  string `json:"action"`
	ID      string `json:"id"`
	Service string `json:"service"`
	// Attributes map containing event-specific information
	Attributes map[string]string `json:"attributes"`

	// Additional fields that may be present in some events
	Scope  string `json:"scope,omitempty"`
	Status string `json:"status,omitempty"`
	From   string `json:"from,omitempty"`
}

type SetComposeBuildOption added in v0.2.0

type SetComposeBuildOption func(*ComposeBuildOptions) error

SetComposeBuildOption is a function that sets a ComposeBuildOptions

type SetComposeDownOption

type SetComposeDownOption func(*ComposeDownOptions) error

SetComposeDownOption is a function that sets a ComposeDownOptions

type SetComposeExecOption added in v0.2.0

type SetComposeExecOption func(*ComposeExecOptions) error

SetComposeExecOption is a function that sets a ComposeExecOptions

type SetComposeKillOption added in v0.1.7

type SetComposeKillOption func(*ComposeKillOptions) error

SetComposeKillOption is a function that sets a ComposeKillOptions

type SetComposeLogsOption

type SetComposeLogsOption func(*ComposeLogsOptions) error

SetComposeLogsOption is a function that sets a ComposeLogsOptions

type SetComposePsOption added in v0.2.0

type SetComposePsOption func(*ComposePsOptions) error

SetComposePsOption is a function that sets a ComposePsOptions

type SetComposePullOption added in v0.2.0

type SetComposePullOption func(*ComposePullOptions) error

SetComposePullOption is a function that sets a ComposePullOptions

type SetComposeRestartOption added in v0.2.0

type SetComposeRestartOption func(*ComposeRestartOptions) error

SetComposeRestartOption is a function that sets a ComposeRestartOptions

type SetComposeStartOption added in v0.2.0

type SetComposeStartOption func(*ComposeStartOptions) error

SetComposeStartOption is a function that sets a ComposeStartOptions

type SetComposeStopOption added in v0.2.0

type SetComposeStopOption func(*ComposeStopOptions) error

SetComposeStopOption is a function that sets a ComposeStopOptions

type SetComposeUpOption

type SetComposeUpOption func(*ComposeUpOptions) error

SetComposeUpOption is a function that sets a ComposeUpOptions

Directories

Path Synopsis
options
build
Package build provides options for the compose build command
Package build provides options for the compose build command
down
Package down is the package for the compose down options
Package down is the package for the compose down options
exec
Package exec provides options for the compose exec command
Package exec provides options for the compose exec command
kill
Package kill is the package for the compose kill options
Package kill is the package for the compose kill options
logs
Package logs is the package for the compose logs options
Package logs is the package for the compose logs options
ps
Package ps provides options for the compose ps command
Package ps provides options for the compose ps command
pull
Package pull provides options for the compose pull command
Package pull provides options for the compose pull command
restart
Package restart provides options for the compose restart command
Package restart provides options for the compose restart command
start
Package start provides options for the compose start command
Package start provides options for the compose start command
stop
Package stop provides options for the compose stop command
Package stop provides options for the compose stop command
up
Package up provides options for the compose up command
Package up provides options for the compose up command

Jump to

Keyboard shortcuts

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