Skip to content

Commit

Permalink
improve error reporting
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Oct 27, 2021
1 parent e1e2d06 commit 5df5f77
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func upCommand(p *projectOptions, backend api.Service) *cobra.Command {
flags.BoolVar(&up.attachDependencies, "attach-dependencies", false, "Attach to dependent containers.")
flags.BoolVar(&create.quietPull, "quiet-pull", false, "Pull without printing progress information.")
flags.StringArrayVar(&up.attach, "attach", []string{}, "Attach to service output.")
flags.StringArrayVar(&up.wait, "wait", []string{}, "[SERVICE:]CONDITION Wait for service(s) to reach condition (started|healthy|completed_successfully). implies detached mode.")
flags.StringArrayVar(&up.wait, "wait", []string{}, "[SERVICE:]CONDITION Wait for service(s) to reach condition (started|healthy|completed_successfully). Implies detached mode.")

return upCmd
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type StartOptions struct {
CascadeStop bool
// ExitCodeFrom return exit code from specified service
ExitCodeFrom string
// WaitCondition define condition to wait for before considering project is up
// WaitCondition define conditions to wait for before considering project is up. format is [SERVICE:]CONDITION
WaitCondition []string
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ func getDeployResources(s types.ServiceConfig) container.Resources {
MemorySwap: int64(s.MemSwapLimit),
MemorySwappiness: swappiness,
MemoryReservation: int64(s.MemReservation),
OomKillDisable: &s.OomKillDisable,
CPUCount: s.CPUCount,
CPUPeriod: s.CPUPeriod,
CPUQuota: s.CPUQuota,
Expand All @@ -503,6 +504,10 @@ func getDeployResources(s types.ServiceConfig) container.Resources {
CpusetCpus: s.CPUSet,
}

if s.PidsLimit != 0 {
resources.PidsLimit = &s.PidsLimit
}

setBlkio(s.BlkioConfig, &resources)

if s.Deploy != nil {
Expand Down
30 changes: 17 additions & 13 deletions pkg/compose/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package compose

import (
"context"
"fmt"
"strings"

"github.com/compose-spec/compose-go/types"
Expand All @@ -27,6 +28,7 @@ import (

"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/progress"
"github.com/docker/compose/v2/pkg/utils"
)

func (s *composeService) Start(ctx context.Context, project *types.Project, options api.StartOptions) error {
Expand Down Expand Up @@ -60,12 +62,7 @@ func (s *composeService) start(ctx context.Context, project *types.Project, opti
return err
}

err = s.startService(ctx, project, service)
if err != nil {
return err
}

return nil
return s.startService(ctx, project, service)
})
if err != nil {
return err
Expand All @@ -92,19 +89,26 @@ func (s *composeService) waitServices(ctx context.Context, project *types.Projec
Condition: condition,
}
} else {
condition := "service_" + split[0]
condition := split[0]
if len(condition) == 0 {
return errors.New("a wait condition must be set")
}
serviceCondition := "service_" + condition
supportedValues := []string{
types.ServiceConditionStarted,
types.ServiceConditionHealthy,
types.ServiceConditionCompletedSuccessfully}
if !utils.StringContains(supportedValues, serviceCondition) {
return fmt.Errorf("unsupported service condition %s", condition)
}
for _, s := range project.Services {
depends[s.Name] = types.ServiceDependency{
Condition: condition,
Condition: serviceCondition,
}
}
}
}
err := s.waitDependencies(ctx, project, depends)
if err != nil {
return err
}
return nil
return s.waitDependencies(ctx, project, depends)
}

type containerWatchFn func(container moby.Container) error
Expand Down

0 comments on commit 5df5f77

Please sign in to comment.