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
19 changes: 11 additions & 8 deletions pkg/compose/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,19 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
policy = types.IncludeDependencies
}

if len(options.Services) == 0 {
options.Services = project.ServiceNames()
}

// also include services used as additional_contexts with service: prefix
options.Services = addBuildDependencies(options.Services, project)
// Some build dependencies we just introduced may not be enabled
var err error
if len(options.Services) > 0 {
// As user requested some services to be built, also include those used as additional_contexts
options.Services = addBuildDependencies(options.Services, project)
// Some build dependencies we just introduced may not be enabled
project, err = project.WithServicesEnabled(options.Services...)
if err != nil {
return nil, err
}
project, err = project.WithServicesEnabled(options.Services...)
if err != nil {
return nil, err
}

project, err = project.WithSelectedServices(options.Services)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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,COMPOSE_BAKE=0", "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
6 changes: 6 additions & 0 deletions pkg/e2e/compose_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,10 @@ func TestLocalComposeRun(t *testing.T) {
"front", "env")
res.Assert(t, icmd.Expected{Out: "FOO=BAR"})
})

t.Run("compose run --build", func(t *testing.T) {
c.cleanupWithDown(t, "run-test", "--rmi=local")
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/compose.yaml", "run", "build", "echo", "hello world")
res.Assert(t, icmd.Expected{Out: "hello world"})
})
}
8 changes: 8 additions & 0 deletions pkg/e2e/fixtures/run-test/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ services:
image: nginx:alpine
networks:
- frontnet
build:
build:
dockerfile_inline: "FROM base"
additional_contexts:
base: "service:build_base"
build_base:
build:
dockerfile_inline: "FROM alpine"
networks:
frontnet:
backnet:
Expand Down