This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
clean.go
50 lines (46 loc) · 1.59 KB
/
clean.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
package application
import (
"fmt"
"io"
"path"
"github.com/Originate/exosphere/src/docker/compose"
"github.com/Originate/exosphere/src/docker/composebuilder"
"github.com/Originate/exosphere/src/types"
"github.com/Originate/exosphere/src/types/context"
"github.com/Originate/exosphere/src/util"
)
// CleanContainers cleans all cantainers listed in the yaml files under appDir/docker-compose
func CleanContainers(appContext *context.AppContext, writer io.Writer) error {
for _, dockerComposeFileName := range types.GetComposeFileNames() {
var composeProjectName string
if dockerComposeFileName == types.LocalTestComposeFileName {
composeProjectName = composebuilder.GetTestDockerComposeProjectName(appContext.Config.Name)
} else {
composeProjectName = composebuilder.GetDockerComposeProjectName(appContext.Config.Name)
}
err := killIfExists(appContext.Location, dockerComposeFileName, composeProjectName, writer)
if err != nil {
return err
}
}
return nil
}
func killIfExists(appDir, dockerComposeFileName, composeProjectName string, writer io.Writer) error {
dockerComposeFilePath := path.Join(appDir, "docker-compose", dockerComposeFileName)
exists, err := util.DoesFileExist(dockerComposeFilePath)
if err != nil {
return err
}
if exists {
err = compose.KillContainers(compose.CommandOptions{
DockerComposeDir: path.Dir(dockerComposeFilePath),
DockerComposeFileName: dockerComposeFileName,
Writer: writer,
Env: []string{
fmt.Sprintf("COMPOSE_PROJECT_NAME=%s", composeProjectName),
fmt.Sprintf("APP_PATH=%s", appDir),
},
})
}
return err
}