mirror of https://github.com/docker/compose.git
Merge pull request #1343 from docker/up_timeout
add --timeout option to compose up
This commit is contained in:
commit
e23e9d6bcb
|
@ -45,6 +45,7 @@ type runOptions struct {
|
||||||
entrypoint string
|
entrypoint string
|
||||||
labels []string
|
labels []string
|
||||||
name string
|
name string
|
||||||
|
noDeps bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCommand(p *projectOptions) *cobra.Command {
|
func runCommand(p *projectOptions) *cobra.Command {
|
||||||
|
@ -75,6 +76,7 @@ func runCommand(p *projectOptions) *cobra.Command {
|
||||||
flags.StringVarP(&opts.user, "user", "u", "", "Run as specified username or uid")
|
flags.StringVarP(&opts.user, "user", "u", "", "Run as specified username or uid")
|
||||||
flags.StringVarP(&opts.workdir, "workdir", "w", "", "Working directory inside the container")
|
flags.StringVarP(&opts.workdir, "workdir", "w", "", "Working directory inside the container")
|
||||||
flags.StringVar(&opts.entrypoint, "entrypoint", "", "Override the entrypoint of the image")
|
flags.StringVar(&opts.entrypoint, "entrypoint", "", "Override the entrypoint of the image")
|
||||||
|
flags.BoolVar(&opts.noDeps, "no-deps", false, "Don't start linked services.")
|
||||||
|
|
||||||
flags.SetInterspersed(false)
|
flags.SetInterspersed(false)
|
||||||
return cmd
|
return cmd
|
||||||
|
@ -86,6 +88,15 @@ func runRun(ctx context.Context, opts runOptions) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.noDeps {
|
||||||
|
enabled, err := project.GetService(opts.Service)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
project.DisabledServices = append(project.DisabledServices, project.Services...)
|
||||||
|
project.Services = types.Services{enabled}
|
||||||
|
}
|
||||||
|
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
||||||
return "", startDependencies(ctx, c, *project, opts.Service)
|
return "", startDependencies(ctx, c, *project, opts.Service)
|
||||||
})
|
})
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/client"
|
"github.com/docker/compose-cli/api/client"
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
|
@ -61,6 +62,9 @@ type upOptions struct {
|
||||||
scale []string
|
scale []string
|
||||||
noColor bool
|
noColor bool
|
||||||
noPrefix bool
|
noPrefix bool
|
||||||
|
timeChanged bool
|
||||||
|
timeout int
|
||||||
|
noDeps bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o upOptions) recreateStrategy() string {
|
func (o upOptions) recreateStrategy() string {
|
||||||
|
@ -83,6 +87,7 @@ func upCommand(p *projectOptions, contextType string) *cobra.Command {
|
||||||
Use: "up [SERVICE...]",
|
Use: "up [SERVICE...]",
|
||||||
Short: "Create and start containers",
|
Short: "Create and start containers",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
opts.timeChanged = cmd.Flags().Changed("timeout")
|
||||||
switch contextType {
|
switch contextType {
|
||||||
case store.LocalContextType, store.DefaultContextType, store.EcsLocalSimulationContextType:
|
case store.LocalContextType, store.DefaultContextType, store.EcsLocalSimulationContextType:
|
||||||
if opts.exitCodeFrom != "" {
|
if opts.exitCodeFrom != "" {
|
||||||
|
@ -122,6 +127,8 @@ func upCommand(p *projectOptions, contextType string) *cobra.Command {
|
||||||
flags.BoolVar(&opts.noStart, "no-start", false, "Don't start the services after creating them.")
|
flags.BoolVar(&opts.noStart, "no-start", false, "Don't start the services after creating them.")
|
||||||
flags.BoolVar(&opts.cascadeStop, "abort-on-container-exit", false, "Stops all containers if any container was stopped. Incompatible with -d")
|
flags.BoolVar(&opts.cascadeStop, "abort-on-container-exit", false, "Stops all containers if any container was stopped. Incompatible with -d")
|
||||||
flags.StringVar(&opts.exitCodeFrom, "exit-code-from", "", "Return the exit code of the selected service container. Implies --abort-on-container-exit")
|
flags.StringVar(&opts.exitCodeFrom, "exit-code-from", "", "Return the exit code of the selected service container. Implies --abort-on-container-exit")
|
||||||
|
flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Use this timeout in seconds for container shutdown when attached or when containers are already running.")
|
||||||
|
flags.BoolVar(&opts.noDeps, "no-deps", false, "Don't start linked services.")
|
||||||
}
|
}
|
||||||
|
|
||||||
return upCmd
|
return upCmd
|
||||||
|
@ -152,6 +159,15 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.noDeps {
|
||||||
|
enabled, err := project.GetServices(services)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
project.DisabledServices = append(project.DisabledServices, project.Services...)
|
||||||
|
project.Services = enabled
|
||||||
|
}
|
||||||
|
|
||||||
err = applyScaleOpt(opts.scale, project)
|
err = applyScaleOpt(opts.scale, project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -164,6 +180,14 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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{
|
||||||
RemoveOrphans: opts.removeOrphans,
|
RemoveOrphans: opts.removeOrphans,
|
||||||
|
|
Loading…
Reference in New Issue