|
@@ -19,6 +19,7 @@ package compose
|
|
|
import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/docker/compose/v2/cmd/formatter"
|
|
|
|
|
@@ -48,6 +49,7 @@ type upOptions struct {
|
|
|
noAttach []string
|
|
|
timestamp bool
|
|
|
wait bool
|
|
|
+ waitTimeout int
|
|
|
}
|
|
|
|
|
|
func (opts upOptions) apply(project *types.Project, services []string) error {
|
|
@@ -76,7 +78,7 @@ func upCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cob
|
|
|
Short: "Create and start containers",
|
|
|
PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
|
|
|
create.pullChanged = cmd.Flags().Changed("pull")
|
|
|
- create.timeChanged = cmd.Flags().Changed("timeout")
|
|
|
+ create.timeChanged = cmd.Flags().Changed("waitTimeout")
|
|
|
return validateFlags(&up, &create)
|
|
|
}),
|
|
|
RunE: p.WithServices(func(ctx context.Context, project *types.Project, services []string) error {
|
|
@@ -102,7 +104,7 @@ func upCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cob
|
|
|
flags.BoolVar(&up.noStart, "no-start", false, "Don't start the services after creating them.")
|
|
|
flags.BoolVar(&up.cascadeStop, "abort-on-container-exit", false, "Stops all containers if any container was stopped. Incompatible with -d")
|
|
|
flags.StringVar(&up.exitCodeFrom, "exit-code-from", "", "Return the exit code of the selected service container. Implies --abort-on-container-exit")
|
|
|
- flags.IntVarP(&create.timeout, "timeout", "t", 10, "Use this timeout in seconds for container shutdown when attached or when containers are already running.")
|
|
|
+ flags.IntVarP(&create.timeout, "waitTimeout", "t", 10, "Use this waitTimeout in seconds for container shutdown when attached or when containers are already running.")
|
|
|
flags.BoolVar(&up.timestamp, "timestamps", false, "Show timestamps.")
|
|
|
flags.BoolVar(&up.noDeps, "no-deps", false, "Don't start linked services.")
|
|
|
flags.BoolVar(&create.recreateDeps, "always-recreate-deps", false, "Recreate dependent containers. Incompatible with --no-recreate.")
|
|
@@ -112,6 +114,7 @@ func upCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cob
|
|
|
flags.StringArrayVar(&up.attach, "attach", []string{}, "Attach to service output.")
|
|
|
flags.StringArrayVar(&up.noAttach, "no-attach", []string{}, "Don't attach to specified service.")
|
|
|
flags.BoolVar(&up.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.")
|
|
|
+ flags.IntVar(&up.waitTimeout, "wait-timeout", 0, "timeout waiting for application to be running|healthy.")
|
|
|
|
|
|
return upCmd
|
|
|
}
|
|
@@ -188,6 +191,8 @@ func runUp(ctx context.Context, streams api.Streams, backend api.Service, create
|
|
|
return backend.Create(ctx, project, create)
|
|
|
}
|
|
|
|
|
|
+ timeout := time.Duration(upOptions.waitTimeout) * time.Second
|
|
|
+
|
|
|
return backend.Up(ctx, project, api.UpOptions{
|
|
|
Create: create,
|
|
|
Start: api.StartOptions{
|
|
@@ -197,6 +202,7 @@ func runUp(ctx context.Context, streams api.Streams, backend api.Service, create
|
|
|
ExitCodeFrom: upOptions.exitCodeFrom,
|
|
|
CascadeStop: upOptions.cascadeStop,
|
|
|
Wait: upOptions.wait,
|
|
|
+ WaitTimeout: timeout,
|
|
|
Services: services,
|
|
|
},
|
|
|
})
|