Skip to content

Commit 9a56c6d

Browse files
author
utam0k
committed
Give priority to variables declared later.
1 parent 71083e5 commit 9a56c6d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pkg/dazzle/combiner.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,19 @@ func mergeEnv(base *ociv1.Image, others []*ociv1.Image, vars []EnvVarCombination
319319
vss []string
320320
idx = make(map[string]struct{})
321321
)
322-
for _, v := range vs {
322+
lenVS := len(vs) - 1
323+
for i := range vs {
324+
v := vs[lenVS-i]
323325
if _, exists := idx[v]; exists {
324326
continue
325327
}
326328
idx[v] = struct{}{}
327329
vss = append(vss, v)
328330
}
331+
332+
for i, j := 0, len(vss)-1; i < j; i, j = i+1, j-1 {
333+
vss[i], vss[j] = vss[j], vss[i]
334+
}
329335
envs[k] = strings.Join(vss, ":")
330336
}
331337
log.WithFields(log.Fields{

pkg/dazzle/combiner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestMergeEnv(t *testing.T) {
6262
{
6363
Config: ociv1.ImageConfig{
6464
Env: []string{
65-
"PATH=seventh:eighth:seventh:common-value",
65+
"PATH=eighth:seventh:eighth:common-value",
6666
},
6767
},
6868
},
@@ -73,7 +73,7 @@ func TestMergeEnv(t *testing.T) {
7373
Action: EnvVarCombineMergeUnique,
7474
},
7575
},
76-
expect: []string{"PATH=first:second:third:common-value:fourth:fifth:sixth:seventh:eighth"},
76+
expect: []string{"PATH=first:second:third:fourth:fifth:sixth:seventh:eighth:common-value"},
7777
},
7878
{
7979
name: "EnvVarCombineMerge",

0 commit comments

Comments
 (0)