mirror of https://github.com/docker/compose.git
Merge pull request #11060 from Juneezee/refactor/redundant-len-check
refactor(cmd/compose/run): remove redundant `len` check
This commit is contained in:
commit
6ab41d629f
|
@ -80,11 +80,10 @@ func (options runOptions) apply(project *types.Project) error {
|
|||
|
||||
target.Tty = !options.noTty
|
||||
target.StdinOpen = options.interactive
|
||||
|
||||
// --service-ports and --publish are incompatible
|
||||
if !options.servicePorts {
|
||||
target.Ports = []types.ServicePortConfig{}
|
||||
}
|
||||
if len(options.publish) > 0 {
|
||||
target.Ports = []types.ServicePortConfig{}
|
||||
for _, p := range options.publish {
|
||||
config, err := types.ParsePortConfig(p)
|
||||
if err != nil {
|
||||
|
@ -93,14 +92,13 @@ func (options runOptions) apply(project *types.Project) error {
|
|||
target.Ports = append(target.Ports, config...)
|
||||
}
|
||||
}
|
||||
if len(options.volumes) > 0 {
|
||||
for _, v := range options.volumes {
|
||||
volume, err := loader.ParseVolume(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
target.Volumes = append(target.Volumes, volume)
|
||||
|
||||
for _, v := range options.volumes {
|
||||
volume, err := loader.ParseVolume(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
target.Volumes = append(target.Volumes, volume)
|
||||
}
|
||||
|
||||
for i, s := range project.Services {
|
||||
|
|
|
@ -96,10 +96,18 @@ func TestLocalComposeRun(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("compose run --publish", func(t *testing.T) {
|
||||
c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/compose.yaml", "run", "--publish", "8081:80", "-d", "back",
|
||||
c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/ports.yaml", "run", "--publish", "8081:80", "-d", "back",
|
||||
"/bin/sh", "-c", "sleep 1")
|
||||
res := c.RunDockerCmd(t, "ps")
|
||||
assert.Assert(t, strings.Contains(res.Stdout(), "8081->80/tcp"), res.Stdout())
|
||||
assert.Assert(t, !strings.Contains(res.Stdout(), "8082->80/tcp"), res.Stdout())
|
||||
})
|
||||
|
||||
t.Run("compose run --service-ports", func(t *testing.T) {
|
||||
c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/ports.yaml", "run", "--service-ports", "-d", "back",
|
||||
"/bin/sh", "-c", "sleep 1")
|
||||
res := c.RunDockerCmd(t, "ps")
|
||||
assert.Assert(t, strings.Contains(res.Stdout(), "8082->80/tcp"), res.Stdout())
|
||||
})
|
||||
|
||||
t.Run("compose run orphan", func(t *testing.T) {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
version: '3.8'
|
||||
services:
|
||||
back:
|
||||
image: alpine
|
||||
ports:
|
||||
- 8082:80
|
Loading…
Reference in New Issue