Skip to content

Commit

Permalink
Bake: sort ssh entries
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Warren <sumner_warren@brown.edu>
  • Loading branch information
sumnerwarren committed May 9, 2024
1 parent 225bbab commit 9fad805
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions bake/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"sort"
"strings"

"github.com/compose-spec/compose-go/v2/dotenv"
Expand Down Expand Up @@ -112,6 +113,7 @@ func ParseCompose(cfgs []composetypes.ConfigFile, envs map[string]string) (*Conf
sshkey := composeToBuildkitSSH(bkey)
ssh = append(ssh, sshkey)
}
sort.Strings(ssh)

var secrets []string
for _, bs := range s.Build.Secrets {
Expand Down Expand Up @@ -332,6 +334,7 @@ func (t *Target) composeExtTarget(exts map[string]interface{}) error {
}
if len(xb.SSH) > 0 {
t.SSH = dedupSlice(append(t.SSH, xb.SSH...))
sort.Strings(t.SSH)
}
if len(xb.Platforms) > 0 {
t.Platforms = dedupSlice(append(t.Platforms, xb.Platforms...))
Expand Down
5 changes: 3 additions & 2 deletions bake/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ services:
cache_to:
- type=local,dest=path/to/cache
ssh:
- default
- key=path/to/key
- default
secrets:
- token
- aws
Expand Down Expand Up @@ -294,6 +294,7 @@ services:
- ct-addon:foo
- ct-addon:alp
ssh:
- default
- other=path/to/otherkey
platforms:
- linux/amd64
Expand Down Expand Up @@ -337,7 +338,7 @@ services:
require.Equal(t, []string{"linux/amd64", "linux/arm64"}, c.Targets[0].Platforms)
require.Equal(t, []string{"user/app:cache", "type=local,src=path/to/cache"}, c.Targets[0].CacheFrom)
require.Equal(t, []string{"user/app:cache", "type=local,dest=path/to/cache"}, c.Targets[0].CacheTo)
require.Equal(t, []string{"key=path/to/key", "other=path/to/otherkey"}, c.Targets[0].SSH)
require.Equal(t, []string{"default", "key=path/to/key", "other=path/to/otherkey"}, c.Targets[0].SSH)
require.Equal(t, newBool(true), c.Targets[0].Pull)
require.Equal(t, map[string]string{"alpine": "docker-image://alpine:3.13"}, c.Targets[0].Contexts)
require.Equal(t, []string{"ct-fake-aws:bar"}, c.Targets[1].Tags)
Expand Down

0 comments on commit 9fad805

Please sign in to comment.