Skip to content
This repository was archived by the owner on Aug 14, 2020. It is now read-only.

Commit bc6d25a

Browse files
committed
Allow specifying custom GOPATH
This change adds an '--go-path' option for overriding the default GOPATH setting. Normally GOPATH is set to some directory in /tmp, so go get will download the project and its dependencies. This is good for isolation and reproducibility, but inconvenient. Overriding GOPATH with --go-path option allows user to reuse already downloaded project and its dependencies to create ACI. Another upside is creating ACI from a local version of a project without pushing changes to repository.
1 parent 8417bdc commit bc6d25a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Diff for: goaci.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
// TODO(jonboulle): allow user to add assets to the ACI
4-
// TODO(jonboulle): support user-specified GOPATHs/local packages. Right now we pull down a fresh copy of the specified package every time. This is better in terms of isolation and reproducibility, but inconvenient.
54
// TODO(jonboulle): add git SHA as a label in the image manifest
65
// TODO(jonboulle): support passing user-supplied arguments to `go get`? this might be tricky as we need to set a lot ourselves, and what if they conflict?
76
// TODO(jonboulle): support multiple executables?
@@ -58,6 +57,7 @@ func main() {
5857
execOpts StringVector
5958
goDefaultBinaryDesc string
6059
goBinaryOpt string
60+
goPathOpt string
6161
)
6262

6363
// Find the go binary
@@ -70,9 +70,10 @@ func main() {
7070
goDefaultBinaryDesc = "Go binary to use (default: whatever go in $PATH)"
7171
}
7272
flag.StringVar(&goBinaryOpt, "go-binary", gocmd, goDefaultBinaryDesc)
73+
flag.StringVar(&goPathOpt, "go-path", "", "Custom GOPATH (default: a temporary directory)")
7374
flag.Parse()
7475
if os.Getenv("GOPATH") != "" {
75-
warn("GOPATH envvar is ignored")
76+
warn("GOPATH envvar is ignored, use --go-path=\"$GOPATH\" option instead")
7677
}
7778
if os.Getenv("GOROOT") != "" {
7879
warn("GOROOT envvar is ignored, use --go-binary=\"$GOROOT/bin/go\" option instead")
@@ -91,11 +92,14 @@ func main() {
9192
die("error setting up temporary directory: %v", err)
9293
}
9394
defer os.RemoveAll(tmpdir)
95+
if goPathOpt == "" {
96+
goPathOpt = tmpdir
97+
}
9498

9599
// Scratch build dir for aci
96100
acidir := filepath.Join(tmpdir, "aci")
97101

98-
// Be explicit with gobin
102+
// Let's put final binary in tmpdir
99103
gobin := filepath.Join(tmpdir, "bin")
100104

101105
// Construct args for a go get that does a static build
@@ -133,7 +137,7 @@ func main() {
133137

134138
cmd := exec.Cmd{
135139
Env: []string{
136-
"GOPATH=" + tmpdir,
140+
"GOPATH=" + goPathOpt,
137141
"GOBIN=" + gobin,
138142
"CGO_ENABLED=0",
139143
"PATH=" + os.Getenv("PATH"),

0 commit comments

Comments
 (0)