diff --git a/build/opt.go b/build/opt.go index d522c16b5ead..51ab9c8b41ba 100644 --- a/build/opt.go +++ b/build/opt.go @@ -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 } } @@ -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 { diff --git a/build/opt_test.go b/build/opt_test.go index 00b9bdd2c652..fd7d449ce197 100644 --- a/build/opt_test.go +++ b/build/opt_test.go @@ -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"}, + 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)) + }) + } +}