diff --git a/bake/compose.go b/bake/compose.go index 261f5972f..dd431dd89 100644 --- a/bake/compose.go +++ b/bake/compose.go @@ -157,6 +157,16 @@ func ParseCompose(cfgs []composetypes.ConfigFile, envs map[string]string) (*Conf return nil, err } + var noCache *bool + if s.Build.NoCache { + noCache = &s.Build.NoCache + } + + var pull *bool + if s.Build.Pull { + pull = &s.Build.Pull + } + g.Targets = append(g.Targets, targetName) t := &Target{ Name: targetName, @@ -183,6 +193,8 @@ func ParseCompose(cfgs []composetypes.ConfigFile, envs map[string]string) (*Conf Ulimits: ulimits, ExtraHosts: extraHosts, Attest: attests, + NoCache: noCache, + Pull: pull, } if err = t.composeExtTarget(s.Build.Extensions); err != nil { return nil, err diff --git a/bake/compose_test.go b/bake/compose_test.go index 23422796b..832672dbf 100644 --- a/bake/compose_test.go +++ b/bake/compose_test.go @@ -1073,6 +1073,42 @@ services: require.Nil(t, attestMap["provenance"]) } +func TestParseComposePull(t *testing.T) { + dt := []byte(` +services: + app: + build: + context: . + pull: true +`) + + c, err := ParseCompose([]composetypes.ConfigFile{{Content: dt}}, nil) + require.NoError(t, err) + require.Equal(t, 1, len(c.Targets)) + + target := c.Targets[0] + require.Equal(t, "app", target.Name) + require.Equal(t, true, *target.Pull) +} + +func TestParseComposeNoCache(t *testing.T) { + dt := []byte(` +services: + app: + build: + context: . + no_cache: true +`) + + c, err := ParseCompose([]composetypes.ConfigFile{{Content: dt}}, nil) + require.NoError(t, err) + require.Equal(t, 1, len(c.Targets)) + + target := c.Targets[0] + require.Equal(t, "app", target.Name) + require.Equal(t, true, *target.NoCache) +} + // chdir changes the current working directory to the named directory, // and then restore the original working directory at the end of the test. func chdir(t *testing.T, dir string) {