2020-06-18 16:13:24 +02:00
|
|
|
/*
|
2020-09-22 12:13:00 +02:00
|
|
|
Copyright 2020 Docker Compose CLI authors
|
2020-06-18 16:13:24 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-06-14 16:26:14 +02:00
|
|
|
package api
|
2020-05-05 10:58:24 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-03-05 10:09:27 +01:00
|
|
|
"fmt"
|
2021-02-23 10:36:23 +01:00
|
|
|
"strings"
|
2021-02-15 13:54:55 +01:00
|
|
|
"time"
|
2020-07-02 16:05:45 +02:00
|
|
|
|
2020-08-20 16:42:37 +02:00
|
|
|
"github.com/compose-spec/compose-go/types"
|
2023-03-16 14:32:50 +01:00
|
|
|
"github.com/docker/compose/v2/pkg/utils"
|
2020-05-05 10:58:24 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Service manages a compose project
|
|
|
|
type Service interface {
|
2020-11-30 12:03:13 +01:00
|
|
|
// Build executes the equivalent to a `compose build`
|
2021-03-02 09:03:04 +01:00
|
|
|
Build(ctx context.Context, project *types.Project, options BuildOptions) error
|
2022-08-31 17:18:25 +02:00
|
|
|
// Push executes the equivalent to a `compose push`
|
2021-03-05 13:20:13 +01:00
|
|
|
Push(ctx context.Context, project *types.Project, options PushOptions) error
|
2020-12-03 12:22:01 +01:00
|
|
|
// Pull executes the equivalent of a `compose pull`
|
2022-04-13 09:49:01 +02:00
|
|
|
Pull(ctx context.Context, project *types.Project, options PullOptions) error
|
2020-12-02 18:23:01 +01:00
|
|
|
// Create executes the equivalent to a `compose create`
|
2022-04-13 09:49:01 +02:00
|
|
|
Create(ctx context.Context, project *types.Project, options CreateOptions) error
|
2020-12-02 18:23:01 +01:00
|
|
|
// Start executes the equivalent to a `compose start`
|
2022-02-05 07:57:52 +01:00
|
|
|
Start(ctx context.Context, projectName string, options StartOptions) error
|
2021-03-09 22:09:45 +01:00
|
|
|
// Restart restarts containers
|
2022-02-05 07:57:52 +01:00
|
|
|
Restart(ctx context.Context, projectName string, options RestartOptions) error
|
2021-01-20 13:35:06 +01:00
|
|
|
// Stop executes the equivalent to a `compose stop`
|
2022-02-05 07:57:52 +01:00
|
|
|
Stop(ctx context.Context, projectName string, options StopOptions) error
|
2020-05-05 10:58:24 +02:00
|
|
|
// Up executes the equivalent to a `compose up`
|
2020-12-16 16:16:39 +01:00
|
|
|
Up(ctx context.Context, project *types.Project, options UpOptions) error
|
2020-05-05 10:58:24 +02:00
|
|
|
// Down executes the equivalent to a `compose down`
|
2020-12-16 16:16:39 +01:00
|
|
|
Down(ctx context.Context, projectName string, options DownOptions) error
|
2020-08-07 10:16:12 +02:00
|
|
|
// Logs executes the equivalent to a `compose logs`
|
2020-12-16 16:58:54 +01:00
|
|
|
Logs(ctx context.Context, projectName string, consumer LogConsumer, options LogOptions) error
|
2020-08-07 10:16:12 +02:00
|
|
|
// Ps executes the equivalent to a `compose ps`
|
2021-01-29 14:41:44 +01:00
|
|
|
Ps(ctx context.Context, projectName string, options PsOptions) ([]ContainerSummary, error)
|
2020-09-04 13:20:11 +02:00
|
|
|
// List executes the equivalent to a `docker stack ls`
|
2021-02-24 12:06:17 +01:00
|
|
|
List(ctx context.Context, options ListOptions) ([]Stack, error)
|
2020-08-18 08:58:37 +02:00
|
|
|
// Convert translate compose model into backend's native format
|
2023-01-27 10:04:52 +01:00
|
|
|
Config(ctx context.Context, project *types.Project, options ConfigOptions) ([]byte, error)
|
2021-01-31 18:42:13 +01:00
|
|
|
// Kill executes the equivalent to a `compose kill`
|
2022-04-13 09:49:01 +02:00
|
|
|
Kill(ctx context.Context, projectName string, options KillOptions) error
|
2020-12-16 15:25:31 +01:00
|
|
|
// RunOneOffContainer creates a service oneoff container and starts its dependencies
|
2021-02-12 17:33:59 +01:00
|
|
|
RunOneOffContainer(ctx context.Context, project *types.Project, opts RunOptions) (int, error)
|
2021-02-15 09:13:41 +01:00
|
|
|
// Remove executes the equivalent to a `compose rm`
|
2022-04-13 09:49:01 +02:00
|
|
|
Remove(ctx context.Context, projectName string, options RemoveOptions) error
|
2021-02-15 09:56:34 +01:00
|
|
|
// Exec executes a command in a running service container
|
2022-04-13 09:49:01 +02:00
|
|
|
Exec(ctx context.Context, projectName string, options RunOptions) (int, error)
|
2021-05-02 03:20:52 +02:00
|
|
|
// Copy copies a file/folder between a service container and the local filesystem
|
2022-04-13 09:49:01 +02:00
|
|
|
Copy(ctx context.Context, projectName string, options CopyOptions) error
|
2021-02-22 10:25:40 +01:00
|
|
|
// Pause executes the equivalent to a `compose pause`
|
2022-04-13 09:49:01 +02:00
|
|
|
Pause(ctx context.Context, projectName string, options PauseOptions) error
|
2021-02-22 10:25:40 +01:00
|
|
|
// UnPause executes the equivalent to a `compose unpause`
|
2022-04-13 09:49:01 +02:00
|
|
|
UnPause(ctx context.Context, projectName string, options PauseOptions) error
|
2021-03-05 12:40:56 +01:00
|
|
|
// Top executes the equivalent to a `compose top`
|
|
|
|
Top(ctx context.Context, projectName string, services []string) ([]ContainerProcSummary, error)
|
2021-03-05 10:09:27 +01:00
|
|
|
// Events executes the equivalent to a `compose events`
|
2022-04-13 09:49:01 +02:00
|
|
|
Events(ctx context.Context, projectName string, options EventsOptions) error
|
2021-03-19 09:49:14 +01:00
|
|
|
// Port executes the equivalent to a `compose port`
|
2022-12-05 23:11:45 +01:00
|
|
|
Port(ctx context.Context, projectName string, service string, port uint16, options PortOptions) (string, int, error)
|
2021-04-07 13:16:22 +02:00
|
|
|
// Images executes the equivalent of a `compose images`
|
|
|
|
Images(ctx context.Context, projectName string, options ImagesOptions) ([]ImageSummary, error)
|
2022-11-30 12:08:26 +01:00
|
|
|
// MaxConcurrency defines upper limit for concurrent operations against engine API
|
|
|
|
MaxConcurrency(parallel int)
|
2023-01-11 16:38:57 +01:00
|
|
|
// DryRunMode defines if dry run applies to the command
|
2023-01-27 16:43:48 +01:00
|
|
|
DryRunMode(ctx context.Context, dryRun bool) (context.Context, error)
|
2023-01-11 11:52:19 +01:00
|
|
|
// Watch services' development context and sync/notify/rebuild/restart on changes
|
|
|
|
Watch(ctx context.Context, project *types.Project, services []string, options WatchOptions) error
|
2023-04-03 01:26:24 +02:00
|
|
|
// Viz generates a graphviz graph of the project services
|
|
|
|
Viz(ctx context.Context, project *types.Project, options VizOptions) (string, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type VizOptions struct {
|
|
|
|
// IncludeNetworks if true, network names a container is attached to should appear in the graph node
|
|
|
|
IncludeNetworks bool
|
|
|
|
// IncludePorts if true, ports a container exposes should appear in the graph node
|
|
|
|
IncludePorts bool
|
|
|
|
// IncludeImageName if true, name of the image used to create a container should appear in the graph node
|
|
|
|
IncludeImageName bool
|
|
|
|
// Indentation string to be used to indent graphviz code, e.g. "\t", " "
|
|
|
|
Indentation string
|
2023-01-11 11:52:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// WatchOptions group options of the Watch API
|
|
|
|
type WatchOptions struct {
|
2020-12-16 16:16:39 +01:00
|
|
|
}
|
|
|
|
|
2021-03-02 09:03:04 +01:00
|
|
|
// BuildOptions group options of the Build API
|
|
|
|
type BuildOptions struct {
|
|
|
|
// Pull always attempt to pull a newer version of the image
|
|
|
|
Pull bool
|
2023-01-06 17:30:55 +01:00
|
|
|
// Push pushes service images
|
|
|
|
Push bool
|
2021-03-02 09:14:09 +01:00
|
|
|
// Progress set type of progress output ("auto", "plain", "tty")
|
|
|
|
Progress string
|
2021-03-02 17:37:49 +01:00
|
|
|
// Args set build-time args
|
2021-04-28 18:17:37 +02:00
|
|
|
Args types.MappingWithEquals
|
2021-03-26 18:13:39 +01:00
|
|
|
// NoCache disables cache use
|
|
|
|
NoCache bool
|
2021-04-13 13:53:07 +02:00
|
|
|
// Quiet make the build process not output to the console
|
|
|
|
Quiet bool
|
2021-08-26 14:57:43 +02:00
|
|
|
// Services passed in the command line to be built
|
|
|
|
Services []string
|
2022-03-30 11:47:34 +02:00
|
|
|
// Ssh authentications passed in the command line
|
|
|
|
SSHs []types.SSHKey
|
2023-04-24 10:51:40 +02:00
|
|
|
// Memory limit for the build container
|
|
|
|
Memory int64
|
2021-03-02 09:03:04 +01:00
|
|
|
}
|
|
|
|
|
2023-03-16 14:32:50 +01:00
|
|
|
// Apply mutates project according to build options
|
|
|
|
func (o BuildOptions) Apply(project *types.Project) error {
|
|
|
|
platform := project.Environment["DOCKER_DEFAULT_PLATFORM"]
|
|
|
|
for i, service := range project.Services {
|
|
|
|
if service.Image == "" && service.Build == nil {
|
|
|
|
return fmt.Errorf("invalid service %q. Must specify either image or build", service.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if service.Build == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
service.Image = GetImageNameOrDefault(service, project.Name)
|
|
|
|
if platform != "" {
|
|
|
|
if len(service.Build.Platforms) > 0 && !utils.StringContains(service.Build.Platforms, platform) {
|
|
|
|
return fmt.Errorf("service %q build.platforms does not support value set by DOCKER_DEFAULT_PLATFORM: %s", service.Name, platform)
|
|
|
|
}
|
|
|
|
service.Platform = platform
|
|
|
|
}
|
|
|
|
if service.Platform != "" {
|
|
|
|
if len(service.Build.Platforms) > 0 && !utils.StringContains(service.Build.Platforms, service.Platform) {
|
|
|
|
return fmt.Errorf("service %q build configuration does not support platform: %s", service.Name, service.Platform)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
service.Build.Pull = service.Build.Pull || o.Pull
|
|
|
|
service.Build.NoCache = service.Build.NoCache || o.NoCache
|
|
|
|
|
|
|
|
project.Services[i] = service
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-06 14:23:37 +01:00
|
|
|
// CreateOptions group options of the Create API
|
|
|
|
type CreateOptions struct {
|
2021-03-01 17:45:52 +01:00
|
|
|
// Services defines the services user interacts with
|
|
|
|
Services []string
|
2021-01-06 14:23:37 +01:00
|
|
|
// Remove legacy containers for services that are not defined in the project
|
|
|
|
RemoveOrphans bool
|
2021-09-24 08:22:50 +02:00
|
|
|
// Ignore legacy containers for services that are not defined in the project
|
|
|
|
IgnoreOrphans bool
|
2021-01-28 15:00:46 +01:00
|
|
|
// Recreate define the strategy to apply on existing containers
|
|
|
|
Recreate string
|
2021-03-01 17:45:52 +01:00
|
|
|
// RecreateDependencies define the strategy to apply on dependencies services
|
|
|
|
RecreateDependencies string
|
2021-03-02 08:38:15 +01:00
|
|
|
// Inherit reuse anonymous volumes from previous container
|
|
|
|
Inherit bool
|
2021-03-02 14:33:26 +01:00
|
|
|
// Timeout set delay to wait for container to gracelfuly stop before sending SIGKILL
|
|
|
|
Timeout *time.Duration
|
2021-03-04 06:46:19 +01:00
|
|
|
// QuietPull makes the pulling process quiet
|
|
|
|
QuietPull bool
|
2021-01-06 14:23:37 +01:00
|
|
|
}
|
|
|
|
|
2021-02-08 11:04:46 +01:00
|
|
|
// StartOptions group options of the Start API
|
|
|
|
type StartOptions struct {
|
2022-04-11 10:58:20 +02:00
|
|
|
// Project is the compose project used to define this app. Might be nil if user ran command just with project name
|
2022-04-07 12:13:30 +02:00
|
|
|
Project *types.Project
|
2021-06-07 14:21:55 +02:00
|
|
|
// Attach to container and forward logs if not nil
|
|
|
|
Attach LogConsumer
|
|
|
|
// AttachTo set the services to attach to
|
|
|
|
AttachTo []string
|
|
|
|
// CascadeStop stops the application when a container stops
|
|
|
|
CascadeStop bool
|
|
|
|
// ExitCodeFrom return exit code from specified service
|
|
|
|
ExitCodeFrom string
|
2021-10-11 17:52:31 +02:00
|
|
|
// Wait won't return until containers reached the running|healthy state
|
2023-02-13 17:42:11 +01:00
|
|
|
Wait bool
|
|
|
|
WaitTimeout time.Duration
|
2022-09-06 20:31:42 +02:00
|
|
|
// Services passed in the command line to be started
|
|
|
|
Services []string
|
2021-02-08 11:04:46 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 22:09:45 +01:00
|
|
|
// RestartOptions group options of the Restart API
|
|
|
|
type RestartOptions struct {
|
2022-04-11 10:58:20 +02:00
|
|
|
// Project is the compose project used to define this app. Might be nil if user ran command just with project name
|
|
|
|
Project *types.Project
|
2021-03-09 22:09:45 +01:00
|
|
|
// Timeout override container restart timeout
|
|
|
|
Timeout *time.Duration
|
2021-05-20 08:09:14 +02:00
|
|
|
// Services passed in the command line to be restarted
|
|
|
|
Services []string
|
2021-03-09 22:09:45 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 13:54:55 +01:00
|
|
|
// StopOptions group options of the Stop API
|
|
|
|
type StopOptions struct {
|
2022-04-11 10:58:20 +02:00
|
|
|
// Project is the compose project used to define this app. Might be nil if user ran command just with project name
|
|
|
|
Project *types.Project
|
2021-02-15 13:54:55 +01:00
|
|
|
// Timeout override container stop timeout
|
|
|
|
Timeout *time.Duration
|
2021-04-20 15:56:48 +02:00
|
|
|
// Services passed in the command line to be stopped
|
|
|
|
Services []string
|
2021-02-15 13:54:55 +01:00
|
|
|
}
|
|
|
|
|
2020-12-16 16:16:39 +01:00
|
|
|
// UpOptions group options of the Up API
|
|
|
|
type UpOptions struct {
|
2021-06-07 14:21:55 +02:00
|
|
|
Create CreateOptions
|
|
|
|
Start StartOptions
|
2020-12-16 16:16:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// DownOptions group options of the Down API
|
|
|
|
type DownOptions struct {
|
|
|
|
// RemoveOrphans will cleanup containers that are not declared on the compose model but own the same labels
|
|
|
|
RemoveOrphans bool
|
2021-01-14 15:59:57 +01:00
|
|
|
// Project is the compose project used to define this app. Might be nil if user ran `down` just with project name
|
|
|
|
Project *types.Project
|
2021-02-15 13:54:55 +01:00
|
|
|
// Timeout override container stop timeout
|
|
|
|
Timeout *time.Duration
|
2021-02-17 15:22:26 +01:00
|
|
|
// Images remove image used by services. 'all': Remove all images. 'local': Remove only images that don't have a tag
|
|
|
|
Images string
|
|
|
|
// Volumes remove volumes, both declared in the `volumes` section and anonymous ones
|
|
|
|
Volumes bool
|
2023-05-10 15:21:34 +02:00
|
|
|
// Services passed in the command line to be stopped
|
|
|
|
Services []string
|
2020-12-16 16:16:39 +01:00
|
|
|
}
|
|
|
|
|
2023-01-27 10:04:52 +01:00
|
|
|
// ConfigOptions group options of the Config API
|
|
|
|
type ConfigOptions struct {
|
2020-12-16 16:16:39 +01:00
|
|
|
// Format define the output format used to dump converted application model (json|yaml)
|
|
|
|
Format string
|
2021-02-05 17:16:20 +01:00
|
|
|
// Output defines the path to save the application model
|
|
|
|
Output string
|
2022-11-29 09:59:56 +01:00
|
|
|
// Resolve image reference to digests
|
|
|
|
ResolveImageDigests bool
|
2020-05-05 10:58:24 +02:00
|
|
|
}
|
2020-08-17 17:48:52 +02:00
|
|
|
|
2021-03-05 13:20:13 +01:00
|
|
|
// PushOptions group options of the Push API
|
|
|
|
type PushOptions struct {
|
2022-02-13 18:10:54 +01:00
|
|
|
Quiet bool
|
2021-03-05 13:20:13 +01:00
|
|
|
IgnoreFailures bool
|
|
|
|
}
|
|
|
|
|
2021-06-03 13:57:56 +02:00
|
|
|
// PullOptions group options of the Pull API
|
2021-03-22 22:50:46 +01:00
|
|
|
type PullOptions struct {
|
2023-01-03 10:54:03 +01:00
|
|
|
Quiet bool
|
|
|
|
IgnoreFailures bool
|
|
|
|
IgnoreBuildable bool
|
2021-03-22 22:50:46 +01:00
|
|
|
}
|
|
|
|
|
2021-04-07 13:16:22 +02:00
|
|
|
// ImagesOptions group options of the Images API
|
|
|
|
type ImagesOptions struct {
|
|
|
|
Services []string
|
|
|
|
}
|
|
|
|
|
2021-01-31 18:42:13 +01:00
|
|
|
// KillOptions group options of the Kill API
|
|
|
|
type KillOptions struct {
|
2022-08-19 04:04:46 +02:00
|
|
|
// RemoveOrphans will cleanup containers that are not declared on the compose model but own the same labels
|
|
|
|
RemoveOrphans bool
|
|
|
|
// Project is the compose project used to define this app. Might be nil if user ran command just with project name
|
|
|
|
Project *types.Project
|
2021-09-20 12:31:41 +02:00
|
|
|
// Services passed in the command line to be killed
|
|
|
|
Services []string
|
2021-01-31 18:42:13 +01:00
|
|
|
// Signal to send to containers
|
|
|
|
Signal string
|
|
|
|
}
|
|
|
|
|
2021-02-15 09:13:41 +01:00
|
|
|
// RemoveOptions group options of the Remove API
|
|
|
|
type RemoveOptions struct {
|
2022-04-11 10:58:20 +02:00
|
|
|
// Project is the compose project used to define this app. Might be nil if user ran command just with project name
|
|
|
|
Project *types.Project
|
2023-02-08 22:40:07 +01:00
|
|
|
// Stop option passed in the command line
|
|
|
|
Stop bool
|
2021-02-15 09:13:41 +01:00
|
|
|
// Volumes remove anonymous volumes
|
|
|
|
Volumes bool
|
|
|
|
// Force don't ask to confirm removal
|
|
|
|
Force bool
|
2021-04-20 15:56:48 +02:00
|
|
|
// Services passed in the command line to be removed
|
|
|
|
Services []string
|
2021-02-15 09:13:41 +01:00
|
|
|
}
|
|
|
|
|
2021-03-05 10:09:27 +01:00
|
|
|
// RunOptions group options of the Run API
|
2020-12-03 09:24:15 +01:00
|
|
|
type RunOptions struct {
|
2022-04-11 10:58:20 +02:00
|
|
|
// Project is the compose project used to define this app. Might be nil if user ran command just with project name
|
|
|
|
Project *types.Project
|
2021-03-04 14:45:04 +01:00
|
|
|
Name string
|
|
|
|
Service string
|
|
|
|
Command []string
|
|
|
|
Entrypoint []string
|
|
|
|
Detach bool
|
|
|
|
AutoRemove bool
|
|
|
|
Tty bool
|
2022-03-09 17:52:30 +01:00
|
|
|
Interactive bool
|
2021-03-04 14:45:04 +01:00
|
|
|
WorkingDir string
|
|
|
|
User string
|
|
|
|
Environment []string
|
|
|
|
Labels types.Labels
|
|
|
|
Privileged bool
|
|
|
|
UseNetworkAliases bool
|
2021-09-14 19:22:07 +02:00
|
|
|
NoDeps bool
|
2021-11-21 16:49:54 +01:00
|
|
|
// QuietPull makes the pulling process quiet
|
|
|
|
QuietPull bool
|
2021-02-23 10:36:23 +01:00
|
|
|
// used by exec
|
|
|
|
Index int
|
|
|
|
}
|
|
|
|
|
2021-03-05 10:09:27 +01:00
|
|
|
// EventsOptions group options of the Events API
|
|
|
|
type EventsOptions struct {
|
|
|
|
Services []string
|
|
|
|
Consumer func(event Event) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Event is a container runtime event served by Events API
|
|
|
|
type Event struct {
|
|
|
|
Timestamp time.Time
|
|
|
|
Service string
|
|
|
|
Container string
|
|
|
|
Status string
|
|
|
|
Attributes map[string]string
|
|
|
|
}
|
|
|
|
|
2021-03-19 09:49:14 +01:00
|
|
|
// PortOptions group options of the Port API
|
|
|
|
type PortOptions struct {
|
|
|
|
Protocol string
|
|
|
|
Index int
|
|
|
|
}
|
|
|
|
|
2021-03-05 10:09:27 +01:00
|
|
|
func (e Event) String() string {
|
|
|
|
t := e.Timestamp.Format("2006-01-02 15:04:05.000000")
|
|
|
|
var attr []string
|
|
|
|
for k, v := range e.Attributes {
|
|
|
|
attr = append(attr, fmt.Sprintf("%s=%s", k, v))
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s container %s %s (%s)\n", t, e.Status, e.Container, strings.Join(attr, ", "))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-24 12:06:17 +01:00
|
|
|
// ListOptions group options of the ls API
|
|
|
|
type ListOptions struct {
|
|
|
|
All bool
|
|
|
|
}
|
|
|
|
|
2021-01-29 14:41:44 +01:00
|
|
|
// PsOptions group options of the Ps API
|
|
|
|
type PsOptions struct {
|
2022-08-02 21:08:15 +02:00
|
|
|
Project *types.Project
|
2021-05-04 00:59:07 +02:00
|
|
|
All bool
|
|
|
|
Services []string
|
2021-01-29 14:41:44 +01:00
|
|
|
}
|
|
|
|
|
2021-05-02 03:20:52 +02:00
|
|
|
// CopyOptions group options of the cp API
|
|
|
|
type CopyOptions struct {
|
|
|
|
Source string
|
|
|
|
Destination string
|
2021-05-02 04:24:07 +02:00
|
|
|
All bool
|
2021-05-02 03:20:52 +02:00
|
|
|
Index int
|
|
|
|
FollowLink bool
|
|
|
|
CopyUIDGID bool
|
|
|
|
}
|
|
|
|
|
2020-08-18 16:56:42 +02:00
|
|
|
// PortPublisher hold status about published port
|
2020-08-18 11:38:23 +02:00
|
|
|
type PortPublisher struct {
|
2020-08-17 17:48:52 +02:00
|
|
|
URL string
|
|
|
|
TargetPort int
|
|
|
|
PublishedPort int
|
|
|
|
Protocol string
|
|
|
|
}
|
|
|
|
|
2020-12-07 14:46:36 +01:00
|
|
|
// ContainerSummary hold high-level description of a container
|
|
|
|
type ContainerSummary struct {
|
|
|
|
ID string
|
|
|
|
Name string
|
2022-12-10 21:34:31 +01:00
|
|
|
Image any
|
2021-06-22 11:21:27 +02:00
|
|
|
Command string
|
2020-12-07 14:46:36 +01:00
|
|
|
Project string
|
|
|
|
Service string
|
2022-12-10 21:34:31 +01:00
|
|
|
Created int64
|
2020-12-07 14:46:36 +01:00
|
|
|
State string
|
2022-12-10 21:34:31 +01:00
|
|
|
Status string
|
2021-02-01 16:53:34 +01:00
|
|
|
Health string
|
2021-05-17 09:04:52 +02:00
|
|
|
ExitCode int
|
2021-09-21 15:21:28 +02:00
|
|
|
Publishers PortPublishers
|
|
|
|
}
|
|
|
|
|
|
|
|
// PortPublishers is a slice of PortPublisher
|
|
|
|
type PortPublishers []PortPublisher
|
|
|
|
|
|
|
|
// Len implements sort.Interface
|
|
|
|
func (p PortPublishers) Len() int {
|
|
|
|
return len(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Less implements sort.Interface
|
|
|
|
func (p PortPublishers) Less(i, j int) bool {
|
|
|
|
left := p[i]
|
|
|
|
right := p[j]
|
|
|
|
if left.URL != right.URL {
|
|
|
|
return left.URL < right.URL
|
|
|
|
}
|
|
|
|
if left.TargetPort != right.TargetPort {
|
|
|
|
return left.TargetPort < right.TargetPort
|
|
|
|
}
|
|
|
|
if left.PublishedPort != right.PublishedPort {
|
|
|
|
return left.PublishedPort < right.PublishedPort
|
|
|
|
}
|
|
|
|
return left.Protocol < right.Protocol
|
|
|
|
}
|
|
|
|
|
|
|
|
// Swap implements sort.Interface
|
|
|
|
func (p PortPublishers) Swap(i, j int) {
|
|
|
|
p[i], p[j] = p[j], p[i]
|
2020-12-07 14:46:36 +01:00
|
|
|
}
|
|
|
|
|
2021-03-05 12:40:56 +01:00
|
|
|
// ContainerProcSummary holds container processes top data
|
|
|
|
type ContainerProcSummary struct {
|
|
|
|
ID string
|
|
|
|
Name string
|
|
|
|
Processes [][]string
|
|
|
|
Titles []string
|
|
|
|
}
|
|
|
|
|
2021-04-07 13:16:22 +02:00
|
|
|
// ImageSummary holds container image description
|
|
|
|
type ImageSummary struct {
|
|
|
|
ID string
|
|
|
|
ContainerName string
|
|
|
|
Repository string
|
|
|
|
Tag string
|
|
|
|
Size int64
|
|
|
|
}
|
|
|
|
|
2020-08-18 16:56:42 +02:00
|
|
|
// ServiceStatus hold status about a service
|
2020-08-17 17:48:52 +02:00
|
|
|
type ServiceStatus struct {
|
2020-08-18 16:56:42 +02:00
|
|
|
ID string
|
|
|
|
Name string
|
|
|
|
Replicas int
|
|
|
|
Desired int
|
|
|
|
Ports []string
|
|
|
|
Publishers []PortPublisher
|
2020-08-18 11:38:23 +02:00
|
|
|
}
|
2020-09-04 13:30:11 +02:00
|
|
|
|
2020-12-16 16:58:54 +01:00
|
|
|
// LogOptions defines optional parameters for the `Log` API
|
|
|
|
type LogOptions struct {
|
2022-09-08 22:26:00 +02:00
|
|
|
Project *types.Project
|
2021-02-18 16:50:39 +01:00
|
|
|
Services []string
|
|
|
|
Tail string
|
2021-06-14 18:14:30 +02:00
|
|
|
Since string
|
2021-06-16 02:55:53 +02:00
|
|
|
Until string
|
2021-02-18 16:50:39 +01:00
|
|
|
Follow bool
|
|
|
|
Timestamps bool
|
2020-12-16 16:58:54 +01:00
|
|
|
}
|
|
|
|
|
2021-04-07 15:00:42 +02:00
|
|
|
// PauseOptions group options of the Pause API
|
|
|
|
type PauseOptions struct {
|
|
|
|
// Services passed in the command line to be started
|
|
|
|
Services []string
|
2022-04-11 10:58:20 +02:00
|
|
|
// Project is the compose project used to define this app. Might be nil if user ran command just with project name
|
|
|
|
Project *types.Project
|
2021-04-07 15:00:42 +02:00
|
|
|
}
|
|
|
|
|
2020-09-04 13:20:11 +02:00
|
|
|
const (
|
2020-09-04 13:30:11 +02:00
|
|
|
// STARTING indicates that stack is being deployed
|
2020-09-04 18:11:02 +02:00
|
|
|
STARTING string = "Starting"
|
2020-09-04 13:30:11 +02:00
|
|
|
// RUNNING indicates that stack is deployed and services are running
|
2020-09-04 18:11:02 +02:00
|
|
|
RUNNING string = "Running"
|
2020-09-04 13:30:11 +02:00
|
|
|
// UPDATING indicates that some stack resources are being recreated
|
2020-09-04 18:11:02 +02:00
|
|
|
UPDATING string = "Updating"
|
2020-09-04 13:30:11 +02:00
|
|
|
// REMOVING indicates that stack is being deleted
|
2020-09-04 18:11:02 +02:00
|
|
|
REMOVING string = "Removing"
|
|
|
|
// UNKNOWN indicates unknown stack state
|
|
|
|
UNKNOWN string = "Unknown"
|
|
|
|
// FAILED indicates that stack deployment failed
|
|
|
|
FAILED string = "Failed"
|
2020-09-04 13:20:11 +02:00
|
|
|
)
|
|
|
|
|
2021-01-28 15:00:46 +01:00
|
|
|
const (
|
|
|
|
// RecreateDiverged to recreate services which configuration diverges from compose model
|
|
|
|
RecreateDiverged = "diverged"
|
|
|
|
// RecreateForce to force service container being recreated
|
|
|
|
RecreateForce = "force"
|
|
|
|
// RecreateNever to never recreate existing service containers
|
|
|
|
RecreateNever = "never"
|
|
|
|
)
|
|
|
|
|
2020-09-04 13:30:11 +02:00
|
|
|
// Stack holds the name and state of a compose application/stack
|
2020-09-04 13:20:11 +02:00
|
|
|
type Stack struct {
|
2022-02-14 15:55:47 +01:00
|
|
|
ID string
|
|
|
|
Name string
|
|
|
|
Status string
|
|
|
|
ConfigFiles string
|
|
|
|
Reason string
|
2020-09-04 13:20:11 +02:00
|
|
|
}
|
2020-12-07 09:09:12 +01:00
|
|
|
|
|
|
|
// LogConsumer is a callback to process log messages from services
|
|
|
|
type LogConsumer interface {
|
2022-12-13 08:51:55 +01:00
|
|
|
Log(containerName, message string)
|
|
|
|
Err(containerName, message string)
|
2021-03-16 14:56:26 +01:00
|
|
|
Status(container, msg string)
|
|
|
|
Register(container string)
|
2021-02-08 11:42:42 +01:00
|
|
|
}
|
|
|
|
|
2021-02-10 14:20:32 +01:00
|
|
|
// ContainerEventListener is a callback to process ContainerEvent from services
|
|
|
|
type ContainerEventListener func(event ContainerEvent)
|
|
|
|
|
2021-03-16 14:56:26 +01:00
|
|
|
// ContainerEvent notify an event has been collected on source container implementing Service
|
2021-02-09 16:51:48 +01:00
|
|
|
type ContainerEvent struct {
|
2022-09-08 22:26:00 +02:00
|
|
|
Type int
|
|
|
|
// Container is the name of the container _without the project prefix_.
|
|
|
|
//
|
|
|
|
// This is only suitable for display purposes within Compose, as it's
|
|
|
|
// not guaranteed to be unique across services.
|
2021-03-16 14:56:26 +01:00
|
|
|
Container string
|
2023-02-03 14:36:39 +01:00
|
|
|
ID string
|
2021-03-16 14:56:26 +01:00
|
|
|
Service string
|
|
|
|
Line string
|
2021-05-26 12:17:37 +02:00
|
|
|
// ContainerEventExit only
|
|
|
|
ExitCode int
|
|
|
|
Restarting bool
|
2020-12-07 09:09:12 +01:00
|
|
|
}
|
2021-02-09 16:51:48 +01:00
|
|
|
|
|
|
|
const (
|
2022-12-13 08:51:55 +01:00
|
|
|
// ContainerEventLog is a ContainerEvent of type log on stdout. Line is set
|
2021-02-09 16:51:48 +01:00
|
|
|
ContainerEventLog = iota
|
2022-12-13 08:51:55 +01:00
|
|
|
// ContainerEventErr is a ContainerEvent of type log on stderr. Line is set
|
|
|
|
ContainerEventErr
|
2021-02-12 10:02:05 +01:00
|
|
|
// ContainerEventAttach is a ContainerEvent of type attach. First event sent about a container
|
|
|
|
ContainerEventAttach
|
2021-12-08 17:59:48 +01:00
|
|
|
// ContainerEventStopped is a ContainerEvent of type stopped.
|
|
|
|
ContainerEventStopped
|
2023-02-03 14:36:39 +01:00
|
|
|
// ContainerEventRecreated let consumer know container stopped but his being replaced
|
|
|
|
ContainerEventRecreated
|
2021-02-09 16:51:48 +01:00
|
|
|
// ContainerEventExit is a ContainerEvent of type exit. ExitCode is set
|
|
|
|
ContainerEventExit
|
2021-02-23 15:13:51 +01:00
|
|
|
// UserCancel user cancelled compose up, we are stopping containers
|
|
|
|
UserCancel
|
2021-02-09 16:51:48 +01:00
|
|
|
)
|
2022-02-16 15:51:10 +01:00
|
|
|
|
2022-07-29 18:55:22 +02:00
|
|
|
// Separator is used for naming components
|
|
|
|
var Separator = "-"
|
|
|
|
|
2022-02-16 15:51:10 +01:00
|
|
|
// GetImageNameOrDefault computes the default image name for a service, used to tag built images
|
|
|
|
func GetImageNameOrDefault(service types.ServiceConfig, projectName string) string {
|
|
|
|
imageName := service.Image
|
|
|
|
if imageName == "" {
|
2022-07-29 18:55:22 +02:00
|
|
|
imageName = projectName + Separator + service.Name
|
2022-02-16 15:51:10 +01:00
|
|
|
}
|
|
|
|
return imageName
|
|
|
|
}
|