mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
run only loads required service env_file and ignores others
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
9129abe516
commit
6a8c0988cf
@ -184,7 +184,12 @@ func runCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *
|
||||
return nil
|
||||
}),
|
||||
RunE: Adapt(func(ctx context.Context, args []string) error {
|
||||
project, _, err := p.ToProject(ctx, dockerCli, []string{options.Service}, cgo.WithResolvedPaths(true), cgo.WithDiscardEnvFile)
|
||||
project, _, err := p.ToProject(ctx, dockerCli, []string{options.Service}, cgo.WithResolvedPaths(true), cgo.WithoutEnvironmentResolution)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
project, err = project.WithServicesEnvironmentResolved(true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"gotest.tools/v3/assert"
|
||||
"gotest.tools/v3/icmd"
|
||||
)
|
||||
|
||||
func TestRawEnvFile(t *testing.T) {
|
||||
@ -37,3 +38,11 @@ func TestUnusedMissingEnvFile(t *testing.T) {
|
||||
|
||||
c.RunDockerComposeCmd(t, "-f", "./fixtures/env_file/compose.yaml", "up", "-d", "serviceA")
|
||||
}
|
||||
|
||||
func TestRunEnvFile(t *testing.T) {
|
||||
c := NewParallelCLI(t)
|
||||
defer c.cleanupWithDown(t, "run_dotenv")
|
||||
|
||||
res := c.RunDockerComposeCmd(t, "--project-directory", "./fixtures/env_file", "run", "serviceC", "env")
|
||||
res.Assert(t, icmd.Expected{Out: "FOO=BAR"})
|
||||
}
|
||||
|
@ -6,3 +6,9 @@ services:
|
||||
image: nginx:latest
|
||||
env_file:
|
||||
- /doesnotexist/.env
|
||||
|
||||
serviceC:
|
||||
profiles: ["test"]
|
||||
image: alpine
|
||||
env_file: test.env
|
||||
|
||||
|
1
pkg/e2e/fixtures/env_file/test.env
Normal file
1
pkg/e2e/fixtures/env_file/test.env
Normal file
@ -0,0 +1 @@
|
||||
FOO=BAR
|
Loading…
x
Reference in New Issue
Block a user