Skip to content
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
21 changes: 9 additions & 12 deletions pkg/compose/build_bake.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -140,11 +140,10 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
Targets: map[string]bakeTarget{},
}
var (
group bakeGroup
privileged bool
read []string
expectedImages = make(map[string]string, len(serviceToBeBuild)) // service name -> expected image
targets = make(map[string]string, len(serviceToBeBuild)) // service name -> build target
group bakeGroup
privileged bool
read []string
targets = make(map[string]string, len(serviceToBeBuild)) // service name -> build target
)

// produce a unique ID for service used as bake target
Expand DownExpand Up@@ -173,9 +172,6 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
args[k] = *v
}

image := api.GetImageNameOrDefault(service, project.Name)
expectedImages[serviceName] = image

entitlements := build.Entitlements
if slices.Contains(build.Entitlements, "security.insecure") {
privileged = true
Expand DownExpand Up@@ -213,7 +209,7 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
DockerfileInline: strings.ReplaceAll(build.DockerfileInline, "${", "$${"),
Args: args,
Labels: build.Labels,
Tags: append(build.Tags, image),
Tags: append(build.Tags, api.GetImageNameOrDefault(service, project.Name)),

CacheFrom: build.CacheFrom,
// CacheTo: TODO
Expand DownExpand Up@@ -360,10 +356,11 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project

cw := progress.ContextWriter(ctx)
results := map[string]string{}
for service, name := range expectedImages {
built, ok := md[targets[service]]
for name := range serviceToBeBuild {
target := targets[name]
built, ok := md[target]
if !ok {
return nil, fmt.Errorf("build result not found in Bake metadata for service %s", service)
return nil, fmt.Errorf("build result not found in Bake metadata for service %s", name)
}
results[name] = built.Digest
cw.Event(progress.BuiltEvent(name))
Expand Down
28 changes: 28 additions & 0 deletions pkg/e2e/build_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -536,3 +536,31 @@ func TestBuildDependsOn(t *testing.T) {
out := res.Combined()
assert.Check(t, strings.Contains(out, "test1 Built"))
}

func TestBuildSubset(t *testing.T) {
c := NewParallelCLI(t)

t.Cleanup(func() {
c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/subset/compose.yaml", "down", "--rmi=local")
})

res := c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/subset/compose.yaml", "build", "main")
out := res.Combined()
assert.Check(t, strings.Contains(out, "main Built"))
}

func TestBuildDependentImage(t *testing.T) {
c := NewParallelCLI(t)

t.Cleanup(func() {
c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/dependencies/compose.yaml", "down", "--rmi=local")
})

res := c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/dependencies/compose.yaml", "build", "firstbuild")
out := res.Combined()
assert.Check(t, strings.Contains(out, "firstbuild Built"))

res = c.RunDockerComposeCmd(t, "-f", "fixtures/build-test/dependencies/compose.yaml", "build", "secondbuild")
out = res.Combined()
assert.Check(t, strings.Contains(out, "secondbuild Built"))
}
26 changes: 26 additions & 0 deletions pkg/e2e/fixtures/build-test/dependencies/compose.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
services:
firstbuild:
build:
dockerfile_inline: |
FROM alpine
additional_contexts:
dep1: service:dep1
entrypoint: ["echo", "Hello from firstbuild"]
depends_on:
- dep1

secondbuild:
build:
dockerfile_inline: |
FROM alpine
additional_contexts:
dep1: service:dep1
entrypoint: ["echo", "Hello from secondbuild"]
depends_on:
- dep1

dep1:
build:
dockerfile_inline: |
FROM alpine
entrypoint: ["echo", "Hello from dep1"]
14 changes: 14 additions & 0 deletions pkg/e2e/fixtures/build-test/subset/compose.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
services:
main:
build:
dockerfile_inline: |
FROM alpine
entrypoint: ["echo", "Hello from main"]
depends_on:
- dep1

dep1:
build:
dockerfile_inline: |
FROM alpine
entrypoint: ["echo", "Hello from dep1"]