diff --git a/tools/wasme/changelog/v0.0.32/proxy-env-vars.yaml b/tools/wasme/changelog/v0.0.32/proxy-env-vars.yaml new file mode 100644 index 00000000..2837c522 --- /dev/null +++ b/tools/wasme/changelog/v0.0.32/proxy-env-vars.yaml @@ -0,0 +1,6 @@ +changelog: + - type: NEW_FEATURE + description: >- + When using the ee-builder container, wasme will now pass in the http_proxy, + https_proxy, no_proxy, and GOPROXY environment variables. + issueLink: https://github.com/solo-io/wasm/issues/119 \ No newline at end of file diff --git a/tools/wasme/cli/pkg/cmd/build/assemblyscript.go b/tools/wasme/cli/pkg/cmd/build/assemblyscript.go index ffadd48d..db6abe99 100644 --- a/tools/wasme/cli/pkg/cmd/build/assemblyscript.go +++ b/tools/wasme/cli/pkg/cmd/build/assemblyscript.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" + "github.com/solo-io/wasm/tools/wasme/cli/pkg/defaults" "github.com/solo-io/wasm/tools/wasme/pkg/util" "github.com/sirupsen/logrus" @@ -55,6 +56,8 @@ func runNpmBuild(build buildOptions, npm npmOpts) (string, error) { args = append(args, "-e", "NPM_USERNAME="+npm.username, "-e", "NPM_PASSWORD="+npm.password, "-e", "NPM_EMAIL="+npm.email) } + args = append(args, defaults.GetProxyEnvArgs()...) + log.WithFields(logrus.Fields{ "args": args, }).Debug("running npm-in-docker build...") diff --git a/tools/wasme/cli/pkg/cmd/build/cpp.go b/tools/wasme/cli/pkg/cmd/build/cpp.go index eee22f01..fd6aa32a 100644 --- a/tools/wasme/cli/pkg/cmd/build/cpp.go +++ b/tools/wasme/cli/pkg/cmd/build/cpp.go @@ -6,6 +6,7 @@ import ( "path/filepath" "github.com/sirupsen/logrus" + "github.com/solo-io/wasm/tools/wasme/cli/pkg/defaults" "github.com/solo-io/wasm/tools/wasme/pkg/util" "github.com/spf13/cobra" ) @@ -54,6 +55,8 @@ func runBazelBuild(build buildOptions, bazel bazelOptions) (string, error) { "-e", "BUILD_TOOL=bazel", // required by build-filter.sh in container } + args = append(args, defaults.GetProxyEnvArgs()...) + log.WithFields(logrus.Fields{ "args": args, }).Debug("running bazel-in-docker build...") diff --git a/tools/wasme/cli/pkg/cmd/build/tinygo.go b/tools/wasme/cli/pkg/cmd/build/tinygo.go index 84f61577..a99a376d 100644 --- a/tools/wasme/cli/pkg/cmd/build/tinygo.go +++ b/tools/wasme/cli/pkg/cmd/build/tinygo.go @@ -6,6 +6,7 @@ import ( "path/filepath" "github.com/sirupsen/logrus" + "github.com/solo-io/wasm/tools/wasme/cli/pkg/defaults" "github.com/solo-io/wasm/tools/wasme/pkg/util" "github.com/spf13/cobra" ) @@ -40,6 +41,8 @@ func runTinyGoBuild(build buildOptions) (string, error) { "-e", "BUILD_TOOL=tinygo", // required by build-filter.sh in container } + args = append(args, defaults.GetProxyEnvArgs()...) + log.WithFields(logrus.Fields{ "args": args, }).Debug("running TinyGo-in-docker build...") diff --git a/tools/wasme/cli/pkg/defaults/defaults_suite_test.go b/tools/wasme/cli/pkg/defaults/defaults_suite_test.go new file mode 100644 index 00000000..c203a736 --- /dev/null +++ b/tools/wasme/cli/pkg/defaults/defaults_suite_test.go @@ -0,0 +1,13 @@ +package defaults_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestDefaults(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Defaults Suite") +} diff --git a/tools/wasme/cli/pkg/defaults/proxyenv.go b/tools/wasme/cli/pkg/defaults/proxyenv.go new file mode 100644 index 00000000..450d650f --- /dev/null +++ b/tools/wasme/cli/pkg/defaults/proxyenv.go @@ -0,0 +1,27 @@ +package defaults + +import ( + "fmt" + "os" +) + +var passThroughVars = []string{ + "http_proxy", + "https_proxy", + "no_proxy", + "GOPROXY", +} + +// GetProxyEnvArgs reads several environment variables and returns +// the arguments to pass them into the docker container used +// during a wasme build command +func GetProxyEnvArgs() []string { + var proxyEnvArgs []string + for _, envVar := range passThroughVars { + val, isSet := os.LookupEnv(envVar) + if isSet { + proxyEnvArgs = append(proxyEnvArgs, "-e", fmt.Sprintf("%s=%s", envVar, val)) + } + } + return proxyEnvArgs +} diff --git a/tools/wasme/cli/pkg/defaults/proxyenv_test.go b/tools/wasme/cli/pkg/defaults/proxyenv_test.go new file mode 100644 index 00000000..da11df9d --- /dev/null +++ b/tools/wasme/cli/pkg/defaults/proxyenv_test.go @@ -0,0 +1,42 @@ +package defaults_test + +import ( + "os" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + . "github.com/solo-io/wasm/tools/wasme/cli/pkg/defaults" +) + +var _ = Describe("Env Proxy Args Passthrough", func() { + It("should not pass through any extra env vars if none are set", func() { + result := GetProxyEnvArgs() + Expect(result).To(HaveLen(0), "shouldn't generate extra args") + }) + + It("should pass a single env var when set", func() { + os.Setenv("http_proxy", "http://example.com") + result := GetProxyEnvArgs() + Expect(result).To(HaveLen(2)) + Expect(result[0]).To(Equal("-e")) + Expect(result[1]).To(Equal("http_proxy=http://example.com")) + }) + + It("should pass multiple env vars when set", func() { + os.Setenv("http_proxy", "http://example.com") + os.Setenv("https_proxy", "https://example.com") + os.Setenv("no_proxy", "https://example.com/foo") + os.Setenv("GOPROXY", "https://example.com/bar") + result := GetProxyEnvArgs() + Expect(result).To(HaveLen(8)) + Expect(result[0]).To(Equal("-e")) + Expect(result[1]).To(Equal("http_proxy=http://example.com")) + Expect(result[2]).To(Equal("-e")) + Expect(result[3]).To(Equal("https_proxy=https://example.com")) + Expect(result[4]).To(Equal("-e")) + Expect(result[5]).To(Equal("no_proxy=https://example.com/foo")) + Expect(result[6]).To(Equal("-e")) + Expect(result[7]).To(Equal("GOPROXY=https://example.com/bar")) + }) +})