Skip to content

Commit 85cdaf9

Browse files
committed
fix build with bake
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent a8469db commit 85cdaf9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

pkg/compose/build_bake.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
137137
}
138138
var group bakeGroup
139139

140-
for name, service := range serviceToBeBuild {
140+
for _, service := range serviceToBeBuild {
141141
if service.Build == nil {
142142
continue
143143
}
@@ -151,12 +151,14 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
151151
args[k] = *v
152152
}
153153

154-
cfg.Targets[name] = bakeTarget{
154+
image := api.GetImageNameOrDefault(service, project.Name)
155+
156+
cfg.Targets[image] = bakeTarget{
155157
Context: build.Context,
156158
Dockerfile: dockerFilePath(build.Context, build.Dockerfile),
157159
Args: args,
158160
Labels: build.Labels,
159-
Tags: build.Tags,
161+
Tags: append(build.Tags, image),
160162

161163
CacheFrom: build.CacheFrom,
162164
// CacheTo: TODO
@@ -167,7 +169,7 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
167169
Pull: options.Pull,
168170
NoCache: options.NoCache,
169171
}
170-
group.Targets = append(group.Targets, name)
172+
group.Targets = append(group.Targets, image)
171173
}
172174

173175
cfg.Groups["default"] = group

pkg/e2e/build_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333

3434
func TestLocalComposeBuild(t *testing.T) {
3535

36-
for _, env := range []string{"DOCKER_BUILDKIT=0", "DOCKER_BUILDKIT=1", "DOCKER_BUILDKIT=1,COMPOSE-BAKE=1"} {
36+
for _, env := range []string{"DOCKER_BUILDKIT=0", "DOCKER_BUILDKIT=1", "DOCKER_BUILDKIT=1,COMPOSE_BAKE=1"} {
3737
c := NewCLI(t, WithEnv(strings.Split(env, ",")...))
3838

3939
t.Run(env+" build named and unnamed images", func(t *testing.T) {
@@ -118,7 +118,7 @@ func TestLocalComposeBuild(t *testing.T) {
118118
})
119119

120120
t.Run(env+" rebuild when up --build", func(t *testing.T) {
121-
res := c.RunDockerComposeCmd(t, "--workdir", "fixtures/build-test", "up", "-d", "--build")
121+
res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/build-test", "up", "-d", "--build")
122122

123123
res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
124124
res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"})

0 commit comments

Comments
 (0)