forked from concourse/docker-image-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request concourse#141 from boazy/propgate_proxy_settings
Propagate worker proxy settings when building docker images
- Loading branch information
Showing
2 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package docker_image_resource_test | |
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os/exec" | ||
|
||
"encoding/json" | ||
|
@@ -20,9 +21,21 @@ var _ = Describe("Out", func() { | |
os.Setenv("LOG_FILE", "/dev/stderr") | ||
}) | ||
|
||
put := func(params map[string]interface{}) *gexec.Session { | ||
putWithEnv := func(params map[string]interface{}, extraEnv map[string]string) *gexec.Session { | ||
command := exec.Command("/opt/resource/out", "/tmp") | ||
|
||
// Get current process environment variables | ||
newEnv := os.Environ() | ||
if extraEnv != nil { | ||
// Append each extra environment variable to new process environment | ||
// variable list | ||
for name, value := range extraEnv { | ||
newEnv = append(newEnv, fmt.Sprintf("%s=%s", name, value)) | ||
} | ||
} | ||
|
||
command.Env = newEnv | ||
|
||
resourceInput, err := json.Marshal(params) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
|
@@ -34,6 +47,10 @@ var _ = Describe("Out", func() { | |
return session | ||
} | ||
|
||
put := func(params map[string]interface{}) *gexec.Session { | ||
return putWithEnv(params, nil) | ||
} | ||
|
||
dockerarg := func(cmd string) string { | ||
return "DOCKER ARG: " + cmd | ||
} | ||
|
@@ -145,4 +162,57 @@ var _ = Describe("Out", func() { | |
Expect(session.Err).To(gbytes.Say(docker("pull 123123.dkr.ecr.us-west-2.amazonaws.com:443/testing"))) | ||
}) | ||
}) | ||
|
||
Context("When all proxy settings are provided with build args", func() { | ||
It("passes the arguments correctly to the docker daemon", func() { | ||
session := putWithEnv(map[string]interface{}{ | ||
"source": map[string]interface{}{ | ||
"repository": "test", | ||
}, | ||
"params": map[string]interface{}{ | ||
"build": "/docker-image-resource/tests/fixtures/build", | ||
"build_args": map[string]string{ | ||
"arg1": "arg with space", | ||
"arg2": "arg with\nnewline", | ||
"arg3": "normal", | ||
}, | ||
}, | ||
}, map[string]string{ | ||
"no_proxy": "10.1.1.1", | ||
"http_proxy": "http://admin:[email protected]:8080", | ||
"https_proxy": "http://another.proxy.net", | ||
}) | ||
|
||
Expect(session.Err).To(gbytes.Say(dockerarg(`--build-arg`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`http_proxy=http://admin:[email protected]:8080`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`--build-arg`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`https_proxy=http://another.proxy.net`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`--build-arg`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`no_proxy=10.1.1.1`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`--build-arg`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`arg1=arg with space`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`--build-arg`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`arg2=arg with\nnewline`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`--build-arg`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`arg3=normal`))) | ||
}) | ||
}) | ||
|
||
Context("When only http_proxy setting is provided, with no build arguments", func() { | ||
It("passes the arguments correctly to the docker daemon", func() { | ||
session := putWithEnv(map[string]interface{}{ | ||
"source": map[string]interface{}{ | ||
"repository": "test", | ||
}, | ||
"params": map[string]interface{}{ | ||
"build": "/docker-image-resource/tests/fixtures/build", | ||
}, | ||
}, map[string]string{ | ||
"http_proxy": "http://admin:[email protected]:8080", | ||
}) | ||
|
||
Expect(session.Err).To(gbytes.Say(dockerarg(`--build-arg`))) | ||
Expect(session.Err).To(gbytes.Say(dockerarg(`http_proxy=http://admin:[email protected]:8080`))) | ||
}) | ||
}) | ||
}) |