Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix build with bake #12344

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pkg/compose/build_bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"})
Expand Down
Loading