-
Notifications
You must be signed in to change notification settings - Fork 13
/
format.go
92 lines (82 loc) · 2.54 KB
/
format.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
84
85
86
87
88
89
90
91
92
package meli
import (
"os"
"path/filepath"
"strings"
)
func formatContainerName(containerName, curentDir string) string {
// container names are supposed to be unique
// we are using the docker-compose service name as well as current dir as the container name
f := func(c rune) bool {
return c == 58 // 58 is the ':' character
}
formattedContainerName := strings.FieldsFunc(containerName, f)[0]
contName := "meli_" + formattedContainerName + curentDir
return contName
}
func formatLabels(label string) []string {
f := func(c rune) bool {
if c == 58 {
// 58 is the ':' character
return true
} else if c == 61 {
//61 is '=' char
return true
}
return false
}
// TODO: we should trim any whitespace before returning.
// this will prevent labels like type= web
return strings.FieldsFunc(label, f)
}
func formatPorts(port string) []string {
f := func(c rune) bool {
if c == 58 {
// 58 is the ':' character
return true
} else if c == 61 {
//61 is '=' char
return true
}
return false
}
// TODO: we should trim any whitespace before returning.
// this will prevent labels like type= web
return strings.FieldsFunc(port, f)
}
func formatServiceVolumes(volume, dockerComposeFile string) []string {
f := func(c rune) bool {
return c == 58 // 58 is the ':' character
}
volume = os.ExpandEnv(volume)
// TODO: we should trim any whitespace before returning.
// this will prevent labels like type= web
hostAndContainerPath := strings.FieldsFunc(volume, f)
dockerComposeFileDir := filepath.Dir(dockerComposeFile)
if strings.Contains(hostAndContainerPath[0], "./") {
dockerComposeFilePath, _ := filepath.Abs(hostAndContainerPath[0])
hostPath := filepath.Join(dockerComposeFilePath, dockerComposeFileDir)
hostAndContainerPath[0] = hostPath
} else if strings.HasPrefix(hostAndContainerPath[0], ".") {
dockerComposeFileDirAbs, _ := filepath.Abs(dockerComposeFileDir)
hostPath := filepath.Join(dockerComposeFileDirAbs, hostAndContainerPath[0])
hostAndContainerPath[0] = hostPath
}
return hostAndContainerPath
}
func formatRegistryAuth(auth string) []string {
f := func(c rune) bool {
return c == 58 // 58 is the ':' character
}
// TODO: we should trim any whitespace before returning.
// this will prevent labels like type= web
return strings.FieldsFunc(auth, f)
}
func formatComposePath(path string) []string {
f := func(c rune) bool {
// TODO; check if this is cross platform
return c == 47 // 47 is the '/' character
}
// TODO: we should trim any whitespace before returning.
return strings.FieldsFunc(path, f)
}