Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion build/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func toSolveOpt(ctx context.Context, np *noderesolver.ResolvedNode, multiDriver
}

for k, v := range node.ProxyConfig {
if _, ok := opt.BuildArgs[k]; !ok {
if !proxyArgKeyExists(opt.BuildArgs, k) {
so.FrontendAttrs["build-arg:"+k] = v
}
}
Expand Down Expand Up @@ -586,6 +586,15 @@ func toSolveOpt(ctx context.Context, np *noderesolver.ResolvedNode, multiDriver
return &so, releaseF, nil
}

func proxyArgKeyExists(buildArgs map[string]string, key string) bool {
for k := range buildArgs {
if strings.EqualFold(k, key) {
return true
}
}
return false
}

func configureSourcePolicy(ctx context.Context, np *noderesolver.ResolvedNode, opt *Options, cfg *confutil.Config, bopts gateway.BuildOpts, so *client.SolveOpt, pw progress.Writer) (defers []func(error), err error) {
if opt.Inputs.policy == nil {
if len(opt.Policy) > 0 {
Expand Down
40 changes: 40 additions & 0 deletions build/opt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,43 @@ func TestCreateExports_RegistryUnpack(t *testing.T) {
})
}
}

func TestProxyArgKeyExists(t *testing.T) {
tests := []struct {
name string
proxyArgs map[string]string
key string
want bool
}{
{
name: "exact match",
proxyArgs: map[string]string{"NO_PROXY": "cli"},
key: "NO_PROXY",
want: true,
},
{
name: "case insensitive match",
proxyArgs: map[string]string{"no_proxy": "cli"},
Comment on lines +174 to +175
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know in the CLI and daemon we only consider NO_PROXY and no_proxy, but don't consider nO_pRoXy; perhaps worth considering.

(I can dig up a link to the code if needed)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g.;

https://github.com/docker/cli/blob/5927d80c76b3ce5cf782be818922966e8a0d87a3/cli/config/configfile/file.go#L218-L253

Also possibly relevant; if either HTTP_PROXY or http_proxy is set, we set both (because upper/lowercase depends on implementation, and there's no official standard)
https://github.com/moby/moby/blob/83bca512aa7ffc1bb4f37ce1107e0d3e3489ad43/daemon/command/daemon.go#L1119-L1132

func configureProxyEnv(ctx context.Context, cfg config.Proxies) {
	if p := cfg.HTTPProxy; p != "" {
		overrideProxyEnv(ctx, "HTTP_PROXY", p)
		overrideProxyEnv(ctx, "http_proxy", p)
	}
	if p := cfg.HTTPSProxy; p != "" {
		overrideProxyEnv(ctx, "HTTPS_PROXY", p)
		overrideProxyEnv(ctx, "https_proxy", p)
	}
	if p := cfg.NoProxy; p != "" {
		overrideProxyEnv(ctx, "NO_PROXY", p)
		overrideProxyEnv(ctx, "no_proxy", p)
	}
}

key: "NO_PROXY",
want: true,
},
{
name: "no match",
proxyArgs: map[string]string{"HTTP_PROXY": "cli"},
key: "NO_PROXY",
want: false,
},
{
name: "nil map",
proxyArgs: nil,
key: "NO_PROXY",
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, proxyArgKeyExists(tt.proxyArgs, tt.key))
})
}
}