-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Proxy Configuration in config.json #93
Conversation
cli/command/container/run.go
Outdated
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/api/types/container" | ||
"github.com/docker/docker/opts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#82, this should use github.com/docker/cli/opts
cli/command/container/run.go
Outdated
@@ -295,3 +299,44 @@ func runStartContainerErr(err error) error { | |||
|
|||
return statusError | |||
} | |||
|
|||
func parseProxyConfig(cfg *configfile.ConfigFile, host string, o opts.ListOpts) opts.ListOpts { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more descriptive variable name for o
would be great.
Since we're only using this as a map[string]string
, either passing in the []string
or map[string]string
would be good.
cli/command/container/run.go
Outdated
} | ||
|
||
config, _ := cfg.Proxies[cfgKey] | ||
permitted := map[string]*string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be a *string
? It seems it's only storing string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It only stores a string
... but as we're assigning to *string
further down in the code, it's easier to make it *string
here as you can't take the address of map values (e.g &permitted["HTTP_PROXY"]
)
cli/command/image/build.go
Outdated
@@ -469,3 +471,34 @@ func replaceDockerfileTarWrapper(ctx context.Context, inputTarStream io.ReadClos | |||
|
|||
return pipeReader | |||
} | |||
|
|||
func createBuildArgs(cfg *configfile.ConfigFile, host string, o opts.ListOpts) map[string]*string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of duplication between this and parseProxyConfig()
. I think that should be easy to fix.
If you move createBuildArgs()
to cli/config/configfile
and make it ParseProxyConfig()
, you could call it directly from this package, and in container/run.go
you could call it and perform the last step of converting to a ListOpts again.
A test case for the new function would be great as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Design LGTM
The client user config seems like a reasonable place to provide proxy information considering the current method is from client environment variables.
Thanks @dnephin I'll address your review comments and add some unit tests tomorrow |
@dnephin comments addressed. I realised I'd touched vendored code directly when git did it's apply magic. I've opened moby/moby#33253 to cover the moby/moby side of the changes. This will fail CI until such time as I can vendor and updated |
We actually pass in |
cli/config/configfile/file.go
Outdated
@@ -152,6 +163,39 @@ func (configFile *ConfigFile) Save() error { | |||
return configFile.SaveToWriter(f) | |||
} | |||
|
|||
// ParseProxyConfig computes proxy configuration by retreiving the config for the provided host and | |||
// then checking this against any environment variables provided to the container | |||
func (configFile *ConfigFile) ParseProxyConfig(host string, runOpts opts.ListOpts) map[string]*string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function only needs a []string
since it's calling GetAll()
on runOpts
and not using it in any other way. Could we have it accept a []string
instead? That should make testing easier as well.
cli/config/configfile/file_test.go
Outdated
proxyConfig := cfg.ParseProxyConfig("/var/run/docker.sock", opts.NewListOpts(nil)) | ||
|
||
if *proxyConfig["HTTP_PROXY"] != httpProxy { | ||
t.Fatalf("HTTP_PROXY value is incorrect.\nGot: %s\nExpected: %s\n", *proxyConfig["HTTP_PROXY"], httpProxy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a lot less verbose, and would avoid any misleading error messages by using assertions:
assert.Equal(t, httpProxy, proxyConfig["HTTP_PROXY"])
...
You can even do it as a single assertion by creating an "expected" struct to match proxyConfig
:
assert.Equal(t, expected, proxyConfig)
3de2451
to
10f5490
Compare
Codecov Report
@@ Coverage Diff @@
## master #93 +/- ##
==========================================
+ Coverage 45.67% 45.72% +0.04%
==========================================
Files 171 171
Lines 11513 11542 +29
==========================================
+ Hits 5259 5278 +19
- Misses 5947 5956 +9
- Partials 307 308 +1 |
@dnephin requested changes made. I've also vendored a newer |
ping @dnephin - does this need more attention or is it good to merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Design LGTM
cc @tonistiigi
LGTM |
This commit modifies config.json to allow for any proxies allowed in build-args to be configured. These values will then be used by default as build-args in docker build. Signed-off-by: Dave Tucker <dt@docker.com>
Rebased. It'd be nice for this to merge soon, assuming it passes CI 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ping @dave-tucker @mstanleyjones looks like this change didn't make it into the documentation; there's a section in the reference docs describing the options that are available in |
As per the implementation in docker/cli#93 the proxy server addresses are specified per docker daemon or as defaults. Updated the example to show the default option. Fixes docker#4686
* Update documentation of proxy server configuration As per the implementation in docker/cli#93 the proxy server addresses are specified per docker daemon or as defaults. Updated the example to show the default option. Fixes #4686 * Fix table layout of proxy environment variables
Docker 17.07 and up allow the CLI to be configured to set default proxy env-vars to be used (both as build-arg and as env for docker run), see docker/cli#93, so setting these here should be redundant. If someone needs these env-vars set, they should be configured in the cli's `~/.docker/config.json` instead. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Docker 17.07 and up allow the CLI to be configured to set default proxy env-vars to be used (both as build-arg and as env for docker run), see docker/cli#93, so setting these here should be redundant. If someone needs these env-vars set, they should be configured in the cli's `~/.docker/config.json` instead. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: ec9c8545f8408e747f283a33d4552187f6cec13f Component: engine
Docker 17.07 and up allow the CLI to be configured to set default proxy env-vars to be used (both as build-arg and as env for docker run), see docker/cli#93, so setting these here should be redundant. If someone needs these env-vars set, they should be configured in the cli's `~/.docker/config.json` instead. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This is moby/moby#32966 re-openend against docker/cli
The above PR was a redux of moby/moby#30588 rebased and after the repo move!
- What I did
Added a mechanism to allow HTTP/HTTPS/FTP/NO proxy variables to be configured in
config.json
. These are then automatically populated in adocker run
command as environment variables or asbuild-args
indocker build
!This makes it easier for users suffering behind an HTTP Proxy as they only need to configure this once as opposed to creating custom aliases or forgetting the args and being denied buildage/runnage.
Updates #30323
- How I did it
Extended the
configfile
with some new proxy related variables.These are scoped per Docker Host with a
default
catchall.The config file is then read by the
build
orrun
command and the necessary variables are exported.A
-e
flag or--build-arg
provided on the CLI will override these default settings.- How to verify it
config.json
with{ "proxies": {"default": { "httpProxy": "http://127.0.0.1:3001" }}}
docker --config /path/to/config build -t configtest .
HTTP_PROXY
variable is as configureddocker run --rm configtest env
- Description for the changelog
Added HTTP/HTTPS/FTP proxy configuration to
config.json
- A picture of a cute animal (not mandatory but encouraged)