Skip to content

Commit c6d1e39

Browse files
authored
Merge pull request #3352 from crazy-max/compose-pull-nocache
bake: pull and no-cache support for compose
2 parents 7c43413 + 669fd1d commit c6d1e39

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

bake/compose.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ func ParseCompose(cfgs []composetypes.ConfigFile, envs map[string]string) (*Conf
157157
return nil, err
158158
}
159159

160+
var noCache *bool
161+
if s.Build.NoCache {
162+
noCache = &s.Build.NoCache
163+
}
164+
165+
var pull *bool
166+
if s.Build.Pull {
167+
pull = &s.Build.Pull
168+
}
169+
160170
g.Targets = append(g.Targets, targetName)
161171
t := &Target{
162172
Name: targetName,
@@ -183,6 +193,8 @@ func ParseCompose(cfgs []composetypes.ConfigFile, envs map[string]string) (*Conf
183193
Ulimits: ulimits,
184194
ExtraHosts: extraHosts,
185195
Attest: attests,
196+
NoCache: noCache,
197+
Pull: pull,
186198
}
187199
if err = t.composeExtTarget(s.Build.Extensions); err != nil {
188200
return nil, err

bake/compose_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,42 @@ services:
10731073
require.Nil(t, attestMap["provenance"])
10741074
}
10751075

1076+
func TestParseComposePull(t *testing.T) {
1077+
dt := []byte(`
1078+
services:
1079+
app:
1080+
build:
1081+
context: .
1082+
pull: true
1083+
`)
1084+
1085+
c, err := ParseCompose([]composetypes.ConfigFile{{Content: dt}}, nil)
1086+
require.NoError(t, err)
1087+
require.Equal(t, 1, len(c.Targets))
1088+
1089+
target := c.Targets[0]
1090+
require.Equal(t, "app", target.Name)
1091+
require.Equal(t, true, *target.Pull)
1092+
}
1093+
1094+
func TestParseComposeNoCache(t *testing.T) {
1095+
dt := []byte(`
1096+
services:
1097+
app:
1098+
build:
1099+
context: .
1100+
no_cache: true
1101+
`)
1102+
1103+
c, err := ParseCompose([]composetypes.ConfigFile{{Content: dt}}, nil)
1104+
require.NoError(t, err)
1105+
require.Equal(t, 1, len(c.Targets))
1106+
1107+
target := c.Targets[0]
1108+
require.Equal(t, "app", target.Name)
1109+
require.Equal(t, true, *target.NoCache)
1110+
}
1111+
10761112
// chdir changes the current working directory to the named directory,
10771113
// and then restore the original working directory at the end of the test.
10781114
func chdir(t *testing.T, dir string) {

0 commit comments

Comments
 (0)