Skip to content

Commit 3b2afd8

Browse files
authored
Pass proxy env vars when using the ee-builder container (#223)
* Pass proxy env vars when using the ee-builder container * Add unit tests * Move env var logic to a better home
1 parent 011cdc6 commit 3b2afd8

File tree

7 files changed

+97
-0
lines changed

7 files changed

+97
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
changelog:
2+
- type: NEW_FEATURE
3+
description: >-
4+
When using the ee-builder container, wasme will now pass in the http_proxy,
5+
https_proxy, no_proxy, and GOPROXY environment variables.
6+
issueLink: https://github.com/solo-io/wasm/issues/119

tools/wasme/cli/pkg/cmd/build/assemblyscript.go

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77

8+
"github.com/solo-io/wasm/tools/wasme/cli/pkg/defaults"
89
"github.com/solo-io/wasm/tools/wasme/pkg/util"
910

1011
"github.com/sirupsen/logrus"
@@ -55,6 +56,8 @@ func runNpmBuild(build buildOptions, npm npmOpts) (string, error) {
5556
args = append(args, "-e", "NPM_USERNAME="+npm.username, "-e", "NPM_PASSWORD="+npm.password, "-e", "NPM_EMAIL="+npm.email)
5657
}
5758

59+
args = append(args, defaults.GetProxyEnvArgs()...)
60+
5861
log.WithFields(logrus.Fields{
5962
"args": args,
6063
}).Debug("running npm-in-docker build...")

tools/wasme/cli/pkg/cmd/build/cpp.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"path/filepath"
77

88
"github.com/sirupsen/logrus"
9+
"github.com/solo-io/wasm/tools/wasme/cli/pkg/defaults"
910
"github.com/solo-io/wasm/tools/wasme/pkg/util"
1011
"github.com/spf13/cobra"
1112
)
@@ -54,6 +55,8 @@ func runBazelBuild(build buildOptions, bazel bazelOptions) (string, error) {
5455
"-e", "BUILD_TOOL=bazel", // required by build-filter.sh in container
5556
}
5657

58+
args = append(args, defaults.GetProxyEnvArgs()...)
59+
5760
log.WithFields(logrus.Fields{
5861
"args": args,
5962
}).Debug("running bazel-in-docker build...")

tools/wasme/cli/pkg/cmd/build/tinygo.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"path/filepath"
77

88
"github.com/sirupsen/logrus"
9+
"github.com/solo-io/wasm/tools/wasme/cli/pkg/defaults"
910
"github.com/solo-io/wasm/tools/wasme/pkg/util"
1011
"github.com/spf13/cobra"
1112
)
@@ -40,6 +41,8 @@ func runTinyGoBuild(build buildOptions) (string, error) {
4041
"-e", "BUILD_TOOL=tinygo", // required by build-filter.sh in container
4142
}
4243

44+
args = append(args, defaults.GetProxyEnvArgs()...)
45+
4346
log.WithFields(logrus.Fields{
4447
"args": args,
4548
}).Debug("running TinyGo-in-docker build...")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package defaults_test
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
func TestDefaults(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
RunSpecs(t, "Defaults Suite")
13+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package defaults
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
var passThroughVars = []string{
9+
"http_proxy",
10+
"https_proxy",
11+
"no_proxy",
12+
"GOPROXY",
13+
}
14+
15+
// GetProxyEnvArgs reads several environment variables and returns
16+
// the arguments to pass them into the docker container used
17+
// during a wasme build command
18+
func GetProxyEnvArgs() []string {
19+
var proxyEnvArgs []string
20+
for _, envVar := range passThroughVars {
21+
val, isSet := os.LookupEnv(envVar)
22+
if isSet {
23+
proxyEnvArgs = append(proxyEnvArgs, "-e", fmt.Sprintf("%s=%s", envVar, val))
24+
}
25+
}
26+
return proxyEnvArgs
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package defaults_test
2+
3+
import (
4+
"os"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
9+
. "github.com/solo-io/wasm/tools/wasme/cli/pkg/defaults"
10+
)
11+
12+
var _ = Describe("Env Proxy Args Passthrough", func() {
13+
It("should not pass through any extra env vars if none are set", func() {
14+
result := GetProxyEnvArgs()
15+
Expect(result).To(HaveLen(0), "shouldn't generate extra args")
16+
})
17+
18+
It("should pass a single env var when set", func() {
19+
os.Setenv("http_proxy", "http://example.com")
20+
result := GetProxyEnvArgs()
21+
Expect(result).To(HaveLen(2))
22+
Expect(result[0]).To(Equal("-e"))
23+
Expect(result[1]).To(Equal("http_proxy=http://example.com"))
24+
})
25+
26+
It("should pass multiple env vars when set", func() {
27+
os.Setenv("http_proxy", "http://example.com")
28+
os.Setenv("https_proxy", "https://example.com")
29+
os.Setenv("no_proxy", "https://example.com/foo")
30+
os.Setenv("GOPROXY", "https://example.com/bar")
31+
result := GetProxyEnvArgs()
32+
Expect(result).To(HaveLen(8))
33+
Expect(result[0]).To(Equal("-e"))
34+
Expect(result[1]).To(Equal("http_proxy=http://example.com"))
35+
Expect(result[2]).To(Equal("-e"))
36+
Expect(result[3]).To(Equal("https_proxy=https://example.com"))
37+
Expect(result[4]).To(Equal("-e"))
38+
Expect(result[5]).To(Equal("no_proxy=https://example.com/foo"))
39+
Expect(result[6]).To(Equal("-e"))
40+
Expect(result[7]).To(Equal("GOPROXY=https://example.com/bar"))
41+
})
42+
})

0 commit comments

Comments
 (0)