mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
don't put enabled services in the disabled slice
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
0a05bbc84e
commit
fada87ca19
@ -64,7 +64,11 @@ func runPull(ctx context.Context, opts pullOptions, services []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
project.DisabledServices = append(project.DisabledServices, project.Services...)
|
for _, s := range project.Services {
|
||||||
|
if !contains(services, s.Name) {
|
||||||
|
project.DisabledServices = append(project.DisabledServices, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
project.Services = enabled
|
project.Services = enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,11 @@ func runRun(ctx context.Context, opts runOptions) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
project.DisabledServices = append(project.DisabledServices, project.Services...)
|
for _, s := range project.Services {
|
||||||
|
if s.Name != opts.Service {
|
||||||
|
project.DisabledServices = append(project.DisabledServices, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
project.Services = types.Services{enabled}
|
project.Services = types.Services{enabled}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,12 @@ package compose
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/docker/compose-cli/api/client"
|
||||||
|
"github.com/docker/compose-cli/api/compose"
|
||||||
|
"github.com/docker/compose-cli/api/context/store"
|
||||||
|
"github.com/docker/compose-cli/api/progress"
|
||||||
|
"github.com/docker/compose-cli/cli/cmd"
|
||||||
|
"github.com/docker/compose-cli/cli/formatter"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -27,13 +33,6 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/client"
|
|
||||||
"github.com/docker/compose-cli/api/compose"
|
|
||||||
"github.com/docker/compose-cli/api/context/store"
|
|
||||||
"github.com/docker/compose-cli/api/progress"
|
|
||||||
"github.com/docker/compose-cli/cli/cmd"
|
|
||||||
"github.com/docker/compose-cli/cli/formatter"
|
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -89,6 +88,54 @@ func (o upOptions) dependenciesRecreateStrategy() string {
|
|||||||
return compose.RecreateDiverged
|
return compose.RecreateDiverged
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (opts upOptions) apply(project *types.Project, services []string) error {
|
||||||
|
if opts.noDeps {
|
||||||
|
enabled, err := project.GetServices(services...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, s := range project.Services {
|
||||||
|
if !contains(services, s.Name) {
|
||||||
|
project.DisabledServices = append(project.DisabledServices, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
project.Services = enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.exitCodeFrom != "" {
|
||||||
|
_, err := project.GetService(opts.exitCodeFrom)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.timeChanged {
|
||||||
|
timeoutValue := types.Duration(time.Duration(opts.timeout) * time.Second)
|
||||||
|
for i, s := range project.Services {
|
||||||
|
s.StopGracePeriod = &timeoutValue
|
||||||
|
project.Services[i] = s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, scale := range opts.scale {
|
||||||
|
split := strings.Split(scale, "=")
|
||||||
|
if len(split) != 2 {
|
||||||
|
return fmt.Errorf("invalid --scale option %q. Should be SERVICE=NUM", scale)
|
||||||
|
}
|
||||||
|
name := split[0]
|
||||||
|
replicas, err := strconv.Atoi(split[1])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = setServiceScale(project, name, replicas)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func upCommand(p *projectOptions, contextType string) *cobra.Command {
|
func upCommand(p *projectOptions, contextType string) *cobra.Command {
|
||||||
opts := upOptions{
|
opts := upOptions{
|
||||||
composeOptions: &composeOptions{
|
composeOptions: &composeOptions{
|
||||||
@ -157,7 +204,7 @@ func runUp(ctx context.Context, opts upOptions, services []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = applyScaleOpt(opts.scale, project)
|
err = opts.apply(project, services)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -176,34 +223,10 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.noDeps {
|
err = opts.apply(project, services)
|
||||||
enabled, err := project.GetServices(services...)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
project.DisabledServices = append(project.DisabledServices, project.Services...)
|
|
||||||
project.Services = enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
err = applyScaleOpt(opts.scale, project)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.exitCodeFrom != "" {
|
|
||||||
_, err := project.GetService(opts.exitCodeFrom)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts.timeChanged {
|
|
||||||
timeoutValue := types.Duration(time.Duration(opts.timeout) * time.Second)
|
|
||||||
for i, s := range project.Services {
|
|
||||||
s.StopGracePeriod = &timeoutValue
|
|
||||||
project.Services[i] = s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
||||||
err := c.ComposeService().Create(ctx, project, compose.CreateOptions{
|
err := c.ComposeService().Create(ctx, project, compose.CreateOptions{
|
||||||
@ -282,25 +305,6 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyScaleOpt(opts []string, project *types.Project) error {
|
|
||||||
for _, scale := range opts {
|
|
||||||
split := strings.Split(scale, "=")
|
|
||||||
if len(split) != 2 {
|
|
||||||
return fmt.Errorf("invalid --scale option %q. Should be SERVICE=NUM", scale)
|
|
||||||
}
|
|
||||||
name := split[0]
|
|
||||||
replicas, err := strconv.Atoi(split[1])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = setServiceScale(project, name, replicas)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setServiceScale(project *types.Project, name string, replicas int) error {
|
func setServiceScale(project *types.Project, name string, replicas int) error {
|
||||||
for i, s := range project.Services {
|
for i, s := range project.Services {
|
||||||
if s.Name == name {
|
if s.Name == name {
|
||||||
|
@ -34,7 +34,8 @@ func TestApplyScaleOpt(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err := applyScaleOpt([]string{"foo=2"}, &p)
|
opt := upOptions{scale: []string{"foo=2"}}
|
||||||
|
err := opt.apply(&p, nil)
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
foo, err := p.GetService("foo")
|
foo, err := p.GetService("foo")
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user