Skip to content

Commit ac8f715

Browse files
authored
Merge pull request #3789 from crazy-max/bake-hosts-order
bake: sort extra-hosts before generating build options
2 parents 43fe71e + 09f288c commit ac8f715

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

bake/bake.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,8 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
15131513
}
15141514

15151515
var extraHosts []string
1516-
for k, v := range t.ExtraHosts {
1516+
for _, k := range slices.Sorted(maps.Keys(t.ExtraHosts)) {
1517+
v := t.ExtraHosts[k]
15171518
if v == nil {
15181519
continue
15191520
}

bake/bake_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,28 @@ func TestAttestDuplicates(t *testing.T) {
18121812
}, opts["default"].Attests)
18131813
}
18141814

1815+
func TestExtraHostsDeterministicOrder(t *testing.T) {
1816+
expected := []string{
1817+
"alpha.example.com=1.1.1.1",
1818+
"beta.example.com=2.2.2.2",
1819+
"delta.example.com=4.4.4.4",
1820+
"gamma.example.com=3.3.3.3",
1821+
}
1822+
for range 64 {
1823+
bo, err := toBuildOpt(&Target{
1824+
DockerfileInline: ptrstr("FROM scratch"),
1825+
ExtraHosts: map[string]*string{
1826+
"gamma.example.com": ptrstr("3.3.3.3"),
1827+
"alpha.example.com": ptrstr("1.1.1.1"),
1828+
"delta.example.com": ptrstr("4.4.4.4"),
1829+
"beta.example.com": ptrstr("2.2.2.2"),
1830+
},
1831+
}, &Input{})
1832+
require.NoError(t, err)
1833+
require.Equal(t, expected, bo.ExtraHosts)
1834+
}
1835+
}
1836+
18151837
func TestAnnotations(t *testing.T) {
18161838
fp := File{
18171839
Name: "docker-bake.hcl",

0 commit comments

Comments
 (0)