service

package
v0.0.0-...-dbbdc9a Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 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.

In contrast to compose/v2, AddDockerComposeLabel adds labels also to Disabled services.

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 EnableAll

func EnableAll(p *types.Project) *types.Project

EnableAll adds DisabledServices to Services and set empty Services to DisabledServices.

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,
	opts ...command.CLIOption,
) (cli *command.DockerCli, err error)

InitializeDockerCli initializes DockerCli.

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

opts 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 *types.Project) (dst *types.Project, err error)

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

Types

type ComposeProjectLoader

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

type ComposeServiceLoader

type ComposeServiceLoader interface {
	LoadComposeService(ctx context.Context, ops ...func(p *types.Project) error) (*Service, 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.CLIOption,
) (*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) (*Service, 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) (*Service, 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 NamedResource

type NamedResource struct {
	Resource Resource
	Name     string
}

func (NamedResource) String

func (nr NamedResource) String() string

type Output

type Output struct {
	Resource map[NamedResource]OutputLine
	Out, Err string
}

func (*Output) ParseOutput

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

type OutputLine

type OutputLine struct {
	Name       string
	Num        int
	Resource   Resource
	State      State
	Desc       string
	DryRunMode bool
}

func DecodeComposeOutputLine

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

type Resource

type Resource string
const (
	ResourceContainer Resource = "Container"
	ResourceVolume    Resource = "Volume"
	ResourceNetwork   Resource = "Network"
)

type Service

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

func NewService

func NewService(
	projectName string,
	project *types.Project,
	dockerCli command.Cli,
) *Service

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

func (*Service) Client

func (s *Service) Client() client.APIClient

func (*Service) Create

func (s *Service) Create(ctx context.Context, options api.CreateOptions) (Output, error)

Create executes the equivalent to a `compose create`

func (*Service) Down

func (s *Service) Down(ctx context.Context, options api.DownOptions) (Output, error)

Down executes the equivalent to a `compose down`

func (*Service) DryRunMode

func (s *Service) DryRunMode(ctx context.Context) (*Service, context.Context, error)

DryRunMode switches c to dry run mode if dryRun is true. Once stepped, 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 (*Service) Kill

func (s *Service) Kill(ctx context.Context, options api.KillOptions) (Output, error)

Kill executes the equivalent to a `compose kill`

func (*Service) Ps

func (s *Service) Ps(ctx context.Context, options api.PsOptions) ([]api.ContainerSummary, error)

Ps executes the equivalent to a `compose ps`

func (*Service) Remove

func (s *Service) Remove(ctx context.Context, options api.RemoveOptions) (Output, error)

Remove executes the equivalent to a `compose rm`

func (*Service) Restart

func (s *Service) Restart(ctx context.Context, options api.RestartOptions) (Output, error)

Restart restarts containers

func (*Service) Start

func (s *Service) Start(ctx context.Context, options api.StartOptions) (Output, error)

Start executes the equivalent to a `compose start`

func (*Service) Stop

func (s *Service) Stop(ctx context.Context, options api.StopOptions) (Output, error)

Stop executes the equivalent to a `compose stop`

func (*Service) UpdateProject

func (s *Service) UpdateProject(mutators ...func(p *types.Project) *types.Project)

type State

type State string

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

const (
	StateError      State = "Error"
	StateCreating   State = "Creating"
	StateStarting   State = "Starting"
	StateStarted    State = "Started"
	StateWaiting    State = "Waiting"
	StateHealthy    State = "Healthy"
	StateExited     State = "Exited"
	StateRestarting State = "Restarting"
	StateRestarted  State = "Restarted"
	StateRunning    State = "Running"
	StateCreated    State = "Created"
	StateStopping   State = "Stopping"
	StateStopped    State = "Stopped"
	StateKilling    State = "Killing"
	StateKilled     State = "Killed"
	StateRemoving   State = "Removing"
	StateRemoved    State = "Removed"
	StateSkipped    State = "Skipped" // depends_on is set, required is false and dependency service is not running nor present.
	StateRecreate   State = "Recreate"
	StateRecreated  State = "Recreated"
)

Jump to

Keyboard shortcuts

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