Skip to content

Commit

Permalink
exclude one-off container running convergence
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof authored and glours committed Jan 8, 2025
1 parent 2ebb475 commit b6db138
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions pkg/compose/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ func (s *composeService) getSpecifiedContainer(ctx context.Context, projectName
// containerPredicate define a predicate we want container to satisfy for filtering operations
type containerPredicate func(c moby.Container) bool

func matches(c moby.Container, predicates ...containerPredicate) bool {
for _, predicate := range predicates {
if !predicate(c) {
return false
}
}
return true
}

func isService(services ...string) containerPredicate {
return func(c moby.Container) bool {
service := c.Labels[api.ServiceLabel]
Expand Down Expand Up @@ -148,10 +157,10 @@ func isNotOneOff(c moby.Container) bool {
}

// filter return Containers with elements to match predicate
func (containers Containers) filter(predicate containerPredicate) Containers {
func (containers Containers) filter(predicates ...containerPredicate) Containers {
var filtered Containers
for _, c := range containers {
if predicate(c) {
if matches(c, predicates...) {
filtered = append(filtered, c)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/compose/convergence.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
continue
}

waitingFor := containers.filter(isService(dep))
waitingFor := containers.filter(isService(dep), isNotOneOff)
w.Events(containerEvents(waitingFor, progress.Waiting))
if len(waitingFor) == 0 {
if config.Required {
Expand Down

0 comments on commit b6db138

Please sign in to comment.