mirror of
https://github.com/docker/compose.git
synced 2026-02-09 10:09:26 +08:00
fix run --build support for service:* reference in additional_context
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
committed by
Guillaume Lours
parent
cb3691154b
commit
09689400e5
@@ -79,16 +79,19 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
|
||||
policy = types.IncludeDependencies
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
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
|
||||
project, err = project.WithServicesEnabled(options.Services...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
project, err = project.WithSelectedServices(options.Services)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user