compose

package
v0.0.0-...-23384fa Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DryRunModePrefix = "DRY-RUN MODE - "
)

Variables

This section is empty.

Functions

func AddDockerComposeLabel

func AddDockerComposeLabel(project *types.Project)

AddDockerComposeLabel changes service.CustomLabels so that is can be found by docker compose v2.

func CompareProjectImage

func CompareProjectImage(old, new *types.Project) (onlyInOld, addedInNew []string)

CompareProjectImage compares 2 projects and return image names which only exists in old, new respectively.

If any of image is not tagged, it will resolve by adding `:latest`.

func DisableProfiles

func DisableProfiles(p *types.Project, profiles []string)

DisableProfiles disables service which does match selected profiles. Unlike (*types.Project).ApplyProfiles, DisableProfiles ignores already disabled services, or services which has no profile set.

func EnableAllService

func EnableAllService(p *types.Project)

EnableAllService sets p.Profile every possible profile in p.Services and p.DisabledServices, and call p.EnableServices with all service names.

func FindServicesByLabels

func FindServicesByLabels(p *types.Project, labels []string) []types.ServiceConfig

FindServicesByLabels selects services in p by given labels.

func InitializeDockerCli

func InitializeDockerCli(
	clientOpt *flags.ClientOptions,
	ops ...command.DockerCliOption,
) (cli *command.DockerCli, err error)

InitializeDockerCli initializes DockerCli.

If clientOpt is nil, cli will be initialized with &flags.ClientOptions{Context: "default"}.

ops will be applied twice, therefore all ops must be idempotent and/or must be aware of it. This is to encounter the case where passing malformed *flag.ClientOptions may cause it to exit by calling os.Exit(1). To prevent it from silently dying, this function sets err output stream to os.Stderr if it is not set. After initialization, it re-applies ops to ensure err output stream is what the caller wants to be.

func PreloadConfigDetails

func PreloadConfigDetails(conf types.ConfigDetails) (types.ConfigDetails, error)

PreloadConfigDetails loads content and parse content if each corresponding field is not present in given conf.

func Reverse

func Reverse(src, dst *types.Project) error

Reverse changes dst so that its enabled services are disabled in src.

Types

type ComposeOutput

type ComposeOutput struct {
	Resource map[string]ComposeOutputLine
	Out, Err string
}

func (*ComposeOutput) ParseOutput

func (o *ComposeOutput) ParseOutput(stdout, stderr string, projectName string, project *types.Project, isDryRunMode bool)

type ComposeOutputLine

type ComposeOutputLine struct {
	Name         string
	Num          int
	ResourceType ResourceType
	StateType    StateType
	Desc         string
	DryRunMode   bool
}

func DecodeComposeOutputLine

func DecodeComposeOutputLine(line string, projectName string, project *types.Project, isDryRunMode bool) (ComposeOutputLine, error)

type ComposeProjectLoader

type ComposeProjectLoader interface {
	Load(ctx context.Context) (*types.Project, error)
}

type ComposeService

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

func NewComposeService

func NewComposeService(
	projectName string,
	project *types.Project,
	dockerCli command.Cli,
) *ComposeService

NewComposeService returns a new wrapped compose service proxy. NewComposeService is not goroutine safe. It mutates given project.

func (*ComposeService) Create

func (s *ComposeService) Create(ctx context.Context, options api.CreateOptions) (ComposeOutput, error)

Create executes the equivalent to a `compose create`

func (*ComposeService) Down

func (s *ComposeService) Down(ctx context.Context, options api.DownOptions) (ComposeOutput, error)

Down executes the equivalent to a `compose down`

func (*ComposeService) DryRunMode

func (s *ComposeService) DryRunMode(ctx context.Context, dryRun bool) (context.Context, error)

DryRunMode switches c to dry run mode if dryRun is true. Implementations might not change back to normal mode even if dryRun is false. User must call this only once and only when the user whishes to use dry run client.

func (*ComposeService) Kill

func (s *ComposeService) Kill(ctx context.Context, options api.KillOptions) (ComposeOutput, error)

Kill executes the equivalent to a `compose kill`

func (*ComposeService) Ps

Ps executes the equivalent to a `compose ps`

func (*ComposeService) Remove

func (s *ComposeService) Remove(ctx context.Context, options api.RemoveOptions) (ComposeOutput, error)

Remove executes the equivalent to a `compose rm`

func (*ComposeService) Restart

func (s *ComposeService) Restart(ctx context.Context, options api.RestartOptions) (ComposeOutput, error)

Restart restarts containers

func (*ComposeService) Start

func (s *ComposeService) Start(ctx context.Context, options api.StartOptions) (ComposeOutput, error)

Start executes the equivalent to a `compose start`

func (*ComposeService) Stop

func (s *ComposeService) Stop(ctx context.Context, options api.StopOptions) (ComposeOutput, error)

Stop executes the equivalent to a `compose stop`

type ComposeServiceLoader

type ComposeServiceLoader interface {
	LoadComposeService(ctx context.Context, ops ...func(p *types.Project) error) (*ComposeService, error)
}

type Loader

type Loader struct {
	DockerCli     *command.DockerCli
	ProjectName   string
	ConfigDetails types.ConfigDetails
	Options       []func(*loader.Options)
}

func NewLoader

func NewLoader(
	projectName string,
	configDetails types.ConfigDetails,
	options []func(*loader.Options),
	clientOpt *flags.ClientOptions,
	ops ...command.DockerCliOption,
) (*Loader, error)

func (*Loader) Load

func (l *Loader) Load(ctx context.Context) (*types.Project, error)

func (*Loader) LoadComposeService

func (l *Loader) LoadComposeService(ctx context.Context, ops ...func(p *types.Project) error) (*ComposeService, error)

type LoaderProxy

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

func NewLoaderProxy

func NewLoaderProxy(
	projectName string,
	configDetails types.ConfigDetails,
	options []func(*loader.Options),
	clientOpt *flags.ClientOptions,
	ops ...command.DockerCliOption,
) (*LoaderProxy, error)

func (*LoaderProxy) ConfigDetails

func (p *LoaderProxy) ConfigDetails() types.ConfigDetails

func (*LoaderProxy) DockerCli

func (p *LoaderProxy) DockerCli() *command.DockerCli

func (*LoaderProxy) Load

func (p *LoaderProxy) Load(ctx context.Context) (*types.Project, error)

func (*LoaderProxy) LoadComposeService

func (p *LoaderProxy) LoadComposeService(ctx context.Context, ops ...func(p *types.Project) error) (*ComposeService, error)

func (*LoaderProxy) Options

func (p *LoaderProxy) Options() []func(*loader.Options)

func (*LoaderProxy) PreloadConfigDetails

func (p *LoaderProxy) PreloadConfigDetails() error

func (*LoaderProxy) ProjectName

func (p *LoaderProxy) ProjectName() string

func (*LoaderProxy) UpdateConfigDetails

func (p *LoaderProxy) UpdateConfigDetails(configDetails types.ConfigDetails)

func (*LoaderProxy) UpdateDockerCli

func (p *LoaderProxy) UpdateDockerCli(dockerCli *command.DockerCli)

func (*LoaderProxy) UpdateOptions

func (p *LoaderProxy) UpdateOptions(options []func(*loader.Options))

func (*LoaderProxy) UpdateProjectName

func (p *LoaderProxy) UpdateProjectName(projectName string)

type ResourceType

type ResourceType string
const (
	Container ResourceType = "Container"
	Volume    ResourceType = "Volume"
	Network   ResourceType = "Network"
)

type StateType

type StateType string

Copied from https://github.com/docker/compose/blob/19bbb12fac83e19f3ef888722cbb32825b4088e6/pkg/progress/event.go

const (
	Error      StateType = "Error"
	Creating   StateType = "Creating"
	Starting   StateType = "Starting"
	Started    StateType = "Started"
	Waiting    StateType = "Waiting"
	Healthy    StateType = "Healthy"
	Exited     StateType = "Exited"
	Restarting StateType = "Restarting"
	Restarted  StateType = "Restarted"
	Running    StateType = "Running"
	Created    StateType = "Created"
	Stopping   StateType = "Stopping"
	Stopped    StateType = "Stopped"
	Killing    StateType = "Killing"
	Killed     StateType = "Killed"
	Removing   StateType = "Removing"
	Removed    StateType = "Removed"
	Skipped    StateType = "Skipped" // depends_on is set, required is false and dependency service is not running nor present.
	Recreate   StateType = "Recreate"
	Recreated  StateType = "Recreated"
)

Jump to

Keyboard shortcuts

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