-
Notifications
You must be signed in to change notification settings - Fork 7
/
undeploy.go
83 lines (66 loc) · 2 KB
/
undeploy.go
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
package main
import (
"os"
"path"
"runtime"
"strings"
"github.com/portainer/portainer/pkg/libstack"
"github.com/portainer/portainer/pkg/libstack/compose"
"github.com/rs/zerolog/log"
)
func (cmd *UndeployCommand) Run(cmdCtx *CommandExecutionContext) error {
log.Info().
Str("repository", cmd.GitRepository).
Strs("composePath", cmd.ComposeRelativeFilePaths).
Msg("Undeploying Compose stack from Git repository")
if strings.LastIndex(cmd.GitRepository, "/") == -1 {
log.Error().
Str("repository", cmd.GitRepository).
Msg("Invalid Git repository URL")
return errDeployComposeFailure
}
mountPath := makeWorkingDir(cmd.Destination, cmd.ProjectName)
deployer := compose.NewComposeDeployer()
log.Debug().
Str("projectName", cmd.ProjectName).
Msg("Undeploying Compose stack")
if err := deployer.Remove(cmdCtx.context, cmd.ProjectName, nil, libstack.RemoveOptions{}); err != nil {
log.Error().
Err(err).
Msg("Failed to remove Compose stack")
return errDeployComposeFailure
}
log.Info().Msg("Compose stack remove complete")
if !cmd.Keep { //stack stop request
if err := os.RemoveAll(mountPath); err != nil {
log.Error().
Err(err).
Msg("Failed to remove Compose stack project folder")
}
}
return nil
}
func (cmd *SwarmUndeployCommand) Run(cmdCtx *CommandExecutionContext) error {
log.Info().
Str("stack name", cmd.ProjectName).
Str("destination", cmd.Destination).
Msg("Undeploying Swarm stack from Git repository")
command := path.Join(BIN_PATH, "docker")
if runtime.GOOS == "windows" {
command = path.Join(BIN_PATH, "docker.exe")
}
args := make([]string, 0)
args = append(args, "stack", "rm", cmd.ProjectName)
if err := runCommandAndCaptureStdErr(command, args, nil, ""); err != nil {
return err
}
mountPath := makeWorkingDir(cmd.Destination, cmd.ProjectName)
if !cmd.Keep { //stack stop request
if err := os.RemoveAll(mountPath); err != nil {
log.Error().
Err(err).
Msg("Failed to remove Compose stack project folder")
}
}
return nil
}