-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathdocker_compose_stack.go
More file actions
87 lines (73 loc) · 2.7 KB
/
docker_compose_stack.go
File metadata and controls
87 lines (73 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package exec
import (
"context"
"github.com/portainer/agent"
libstack "github.com/portainer/portainer/pkg/libstack"
"github.com/portainer/portainer/pkg/libstack/compose"
"github.com/rs/zerolog/log"
)
// DockerComposeStackService represents a service for managing stacks by using the Docker binary.
type DockerComposeStackService struct {
deployer libstack.Deployer
}
// NewDockerComposeStackService initializes a new DockerStackService service.
// It also updates the configuration of the Docker CLI binary.
func NewDockerComposeStackService(binaryPath string) (*DockerComposeStackService, error) {
deployer, err := compose.NewComposeDeployer(binaryPath, "")
if err != nil {
return nil, err
}
service := &DockerComposeStackService{
deployer: deployer,
}
return service, nil
}
// Deploy executes the docker stack deploy command.
func (service *DockerComposeStackService) Deploy(ctx context.Context, name string, filePaths []string, options agent.DeployOptions) error {
if options.Task != "" {
log.Debug().
Str("task name", options.Task).
Msg("Detected short lived task run")
return service.deployer.Run(ctx, filePaths, options.Task, libstack.RunOptions{
Options: libstack.Options{
ProjectName: name,
WorkingDir: options.WorkingDir,
Env: options.Env,
},
Remove: true,
})
}
return service.deployer.Deploy(ctx, filePaths, libstack.DeployOptions{
Options: libstack.Options{
ProjectName: name,
WorkingDir: options.WorkingDir,
Env: options.Env,
},
})
}
// Pull executes the docker pull command.
func (service *DockerComposeStackService) Pull(ctx context.Context, name string, filePaths []string, options agent.PullOptions) error {
return service.deployer.Pull(ctx, filePaths, libstack.Options{
ProjectName: name,
WorkingDir: options.WorkingDir,
Env: options.Env,
})
}
// Remove executes the docker stack rm command.
func (service *DockerComposeStackService) Remove(ctx context.Context, name string, filePaths []string, options agent.RemoveOptions) error {
return service.deployer.Remove(ctx, name, filePaths, libstack.Options{
ProjectName: name,
WorkingDir: options.WorkingDir,
Env: options.Env,
})
}
// Validate executes docker config command to validate file format
func (service *DockerComposeStackService) Validate(ctx context.Context, name string, filePaths []string, options agent.ValidateOptions) error {
return service.deployer.Validate(ctx, filePaths, libstack.Options{
WorkingDir: options.WorkingDir,
Env: options.Env,
})
}
func (service *DockerComposeStackService) WaitForStatus(ctx context.Context, name string, status libstack.Status) <-chan string {
return service.deployer.WaitForStatus(ctx, name, status)
}