/
cmd.go
155 lines (138 loc) · 2.99 KB
/
cmd.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import (
"fmt"
"os"
"strings"
"github.com/magefile/mage/sh"
)
var (
GOPATH string
DockerGopath string
Platform string
Host_arch string
)
func dockerGoPath() {
var err error
GOPATH, err = sh.Output("go", "env", "GOPATH")
if err != nil || GOPATH == "" {
GOPATH = ".go"
}
DockerGopath = GOPATH
}
func platformGet() error {
var err error
Platform, err = sh.Output("uname", "-s")
if err != nil {
return err
}
Host_arch, err = sh.Output("uname", "-m")
if err != nil {
return err
}
return nil
}
func dockerRunAsUser() (string, error) {
if err := platformGet(); err != nil {
return "", fmt.Errorf("unable to get platform information: %v", err)
}
DockerRunAsUser := os.Getenv("DOCKER_RUN_AS_USER")
if DockerRunAsUser == "" && Platform != "windows32" {
userId, err := sh.Output("id", "-u")
if err != nil {
return "", fmt.Errorf("unable to get user id: %v", err)
}
groupId, err := sh.Output("id", "-g")
if err != nil {
return "", fmt.Errorf("unable to get group id: %v", err)
}
DockerRunAsUser = userId + ":" + groupId
}
return DockerRunAsUser, nil
}
func dockerNet() (string, error) {
platform, err := sh.Output("uname", "-s")
if err != nil {
return "", fmt.Errorf("unable to get platform information: %v", err)
} else if platform == "Darwin" {
return "", nil
}
return "--network=host", nil
}
func dockerGopathDir() (string, error) {
DockerGopath, err := sh.Output("go", "env", "GOPATH")
if err != nil || DockerGopath == "" {
DockerGopath = ".go"
}
DockerGopathToks := strings.Split(DockerGopath, ":")
if len(DockerGopathToks) == 0 {
return "", fmt.Errorf("unable to parse DockerGopath: %s", DockerGopath)
}
return DockerGopathToks[0], nil
}
func go_CMD() ([]string, error) {
dockerGoPath()
DOCKER_RUN_AS_USER, err := dockerRunAsUser()
if err != nil {
return nil, err
}
DOCKER_NET, err := dockerNet()
if err != nil {
return nil, err
}
DOCKER_GOPATH_DIR, err := dockerGopathDir()
if err != nil {
return nil, err
}
return []string{
"run",
"--rm",
"-u",
DOCKER_RUN_AS_USER,
"-v",
"${PWD}:/go/src/armada",
"-w",
"/go/src/armada",
DOCKER_NET,
"-e",
"GOPROXY",
"-e",
"GOPRIVATE",
"-e",
"GOCACHE=/go/cache",
"-e",
"INTEGRATION_ENABLED=true",
"-e",
"CGO_ENABLED=0",
"-e",
"GOOS=linux",
"-e",
"GARCH=amd64",
"-v",
fmt.Sprintf("%s:/go", DOCKER_GOPATH_DIR),
"golang:1.20.2-buster",
}, nil
}
func go_TEST_CMD() ([]string, error) {
TESTS_IN_DOCKER := os.Getenv("TESTS_IN_DOCKER")
if TESTS_IN_DOCKER == "true" {
return go_CMD()
} else {
return []string{}, nil
}
}
func dotnetCmd() []string {
wd, err := os.Getwd()
if err != nil {
panic(err)
}
dotnetcmd := []string{
"run",
"-v", fmt.Sprintf("%s:/go/src/armada", wd),
"-w", "/go/src/armada",
}
if useSystemCerts {
dotnetcmd = append(dotnetcmd, "-v", "${PWD}/build/ssl/certs/:/etc/ssl/certs", "-e", "SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt")
}
dotnetcmd = append(dotnetcmd, defaultDotnetDockerImg)
return dotnetcmd
}