Skip to content

Commit

Permalink
Pass proxy env vars when using the ee-builder container (#223)
Browse files Browse the repository at this point in the history
* Pass proxy env vars when using the ee-builder container
* Add unit tests
* Move env var logic to a better home
  • Loading branch information
Sodman authored Dec 3, 2020
1 parent 011cdc6 commit 3b2afd8
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/wasme/changelog/v0.0.32/proxy-env-vars.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions tools/wasme/cli/pkg/cmd/build/assemblyscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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...")
Expand Down
3 changes: 3 additions & 0 deletions tools/wasme/cli/pkg/cmd/build/cpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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...")
Expand Down
3 changes: 3 additions & 0 deletions tools/wasme/cli/pkg/cmd/build/tinygo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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...")
Expand Down
13 changes: 13 additions & 0 deletions tools/wasme/cli/pkg/defaults/defaults_suite_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
27 changes: 27 additions & 0 deletions tools/wasme/cli/pkg/defaults/proxyenv.go
Original file line number Diff line number Diff line change
@@ -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
}
42 changes: 42 additions & 0 deletions tools/wasme/cli/pkg/defaults/proxyenv_test.go
Original file line number Diff line number Diff line change
@@ -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"))
})
})

0 comments on commit 3b2afd8

Please sign in to comment.