From 85cdaf9ddfb5d7a09a7e2e1570afdac340d8a96e Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 3 Dec 2024 08:49:58 +0100 Subject: [PATCH] fix build with bake Signed-off-by: Nicolas De Loof --- pkg/compose/build_bake.go | 10 ++++++---- pkg/e2e/build_test.go | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/compose/build_bake.go b/pkg/compose/build_bake.go index c1211b062..2ff8c6b29 100644 --- a/pkg/compose/build_bake.go +++ b/pkg/compose/build_bake.go @@ -137,7 +137,7 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project } var group bakeGroup - for name, service := range serviceToBeBuild { + for _, service := range serviceToBeBuild { if service.Build == nil { continue } @@ -151,12 +151,14 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project args[k] = *v } - cfg.Targets[name] = bakeTarget{ + image := api.GetImageNameOrDefault(service, project.Name) + + cfg.Targets[image] = bakeTarget{ Context: build.Context, Dockerfile: dockerFilePath(build.Context, build.Dockerfile), Args: args, Labels: build.Labels, - Tags: build.Tags, + Tags: append(build.Tags, image), CacheFrom: build.CacheFrom, // CacheTo: TODO @@ -167,7 +169,7 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project Pull: options.Pull, NoCache: options.NoCache, } - group.Targets = append(group.Targets, name) + group.Targets = append(group.Targets, image) } cfg.Groups["default"] = group diff --git a/pkg/e2e/build_test.go b/pkg/e2e/build_test.go index f0ab24c29..ef8346857 100644 --- a/pkg/e2e/build_test.go +++ b/pkg/e2e/build_test.go @@ -33,7 +33,7 @@ import ( func TestLocalComposeBuild(t *testing.T) { - for _, env := range []string{"DOCKER_BUILDKIT=0", "DOCKER_BUILDKIT=1", "DOCKER_BUILDKIT=1,COMPOSE-BAKE=1"} { + for _, env := range []string{"DOCKER_BUILDKIT=0", "DOCKER_BUILDKIT=1", "DOCKER_BUILDKIT=1,COMPOSE_BAKE=1"} { c := NewCLI(t, WithEnv(strings.Split(env, ",")...)) t.Run(env+" build named and unnamed images", func(t *testing.T) { @@ -118,7 +118,7 @@ func TestLocalComposeBuild(t *testing.T) { }) t.Run(env+" rebuild when up --build", func(t *testing.T) { - res := c.RunDockerComposeCmd(t, "--workdir", "fixtures/build-test", "up", "-d", "--build") + res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "up", "-d", "--build") res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"}) res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"})