Skip to content

Commit c4b5d67

Browse files
authored
Merge pull request #3697 from crazy-max/build-arg-proxy
build: make proxy build-arg override check case-insensitive
2 parents b046c39 + 189633f commit c4b5d67

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

build/opt.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ func toSolveOpt(ctx context.Context, np *noderesolver.ResolvedNode, multiDriver
527527
}
528528

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

589+
func proxyArgKeyExists(buildArgs map[string]string, key string) bool {
590+
for k := range buildArgs {
591+
if strings.EqualFold(k, key) {
592+
return true
593+
}
594+
}
595+
return false
596+
}
597+
589598
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) {
590599
if opt.Inputs.policy == nil {
591600
if len(opt.Policy) > 0 {

build/opt_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,43 @@ func TestCreateExports_RegistryUnpack(t *testing.T) {
156156
})
157157
}
158158
}
159+
160+
func TestProxyArgKeyExists(t *testing.T) {
161+
tests := []struct {
162+
name string
163+
proxyArgs map[string]string
164+
key string
165+
want bool
166+
}{
167+
{
168+
name: "exact match",
169+
proxyArgs: map[string]string{"NO_PROXY": "cli"},
170+
key: "NO_PROXY",
171+
want: true,
172+
},
173+
{
174+
name: "case insensitive match",
175+
proxyArgs: map[string]string{"no_proxy": "cli"},
176+
key: "NO_PROXY",
177+
want: true,
178+
},
179+
{
180+
name: "no match",
181+
proxyArgs: map[string]string{"HTTP_PROXY": "cli"},
182+
key: "NO_PROXY",
183+
want: false,
184+
},
185+
{
186+
name: "nil map",
187+
proxyArgs: nil,
188+
key: "NO_PROXY",
189+
want: false,
190+
},
191+
}
192+
193+
for _, tt := range tests {
194+
t.Run(tt.name, func(t *testing.T) {
195+
assert.Equal(t, tt.want, proxyArgKeyExists(tt.proxyArgs, tt.key))
196+
})
197+
}
198+
}

0 commit comments

Comments
 (0)