Skip to content

Commit

Permalink
adopt graph.InDependencyOrder
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 Dec 7, 2023
1 parent 5e61c62 commit 0c93a2d
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 907 deletions.
8 changes: 4 additions & 4 deletions cmd/compose/config.go
Expand Up @@ -159,10 +159,10 @@ func runServices(ctx context.Context, dockerCli command.Cli, opts configOptions)
if err != nil {
return err
}
return project.WithServices(project.ServiceNames(), func(s types.ServiceConfig) error {
fmt.Fprintln(dockerCli.Out(), s.Name)
return nil
})
for _, name := range project.ServiceNames() {
fmt.Fprintln(dockerCli.Out(), name)
}
return nil

Check warning on line 165 in cmd/compose/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/compose/config.go#L162-L165

Added lines #L162 - L165 were not covered by tests
}

func runVolumes(ctx context.Context, dockerCli command.Cli, opts configOptions) error {
Expand Down
4 changes: 2 additions & 2 deletions cmd/compose/up.go
Expand Up @@ -229,9 +229,9 @@ func runUp(
if upOptions.attachDependencies {
dependencyOpt = types.IncludeDependencies
}
if err := project.WithServices(services, func(s types.ServiceConfig) error {
if err := project.WithServices(services, func(name string, s types.ServiceConfig) error {
if s.Attach == nil || *s.Attach {
attachSet.Add(s.Name)
attachSet.Add(name)
}
return nil
}, dependencyOpt); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Expand Up @@ -174,3 +174,5 @@ require (
sigs.k8s.io/yaml v1.3.0 // indirect
tags.cncf.io/container-device-interface v0.6.2 // indirect
)

replace github.com/compose-spec/compose-go/v2 => github.com/ndeloof/compose-go/v2 v2.0.0-20231207163150-0eb507e0904b
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -132,8 +132,6 @@ github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4 h1:/inchEIKaYC1Akx+H+g
github.com/cncf/xds/go v0.0.0-20230607035331-e9ce68804cb4/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
github.com/compose-spec/compose-go/v2 v2.0.0-beta.1 h1:/A+2QMQVSsAmr9Gn5fm6YwaufjRZmWBnHYjr0oCyGiw=
github.com/compose-spec/compose-go/v2 v2.0.0-beta.1/go.mod h1:PWCgeD8cxiI/DmdpBM407CuLDrZ2W4xuS6/Z9jAi0YQ=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
Expand Down Expand Up @@ -454,6 +452,8 @@ github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7P
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/ndeloof/compose-go/v2 v2.0.0-20231207163150-0eb507e0904b h1:d4DfO5xGakgBGrbiwkWYXy5StKDwUs7dswBXyoj7dk4=
github.com/ndeloof/compose-go/v2 v2.0.0-20231207163150-0eb507e0904b/go.mod h1:PWCgeD8cxiI/DmdpBM407CuLDrZ2W4xuS6/Z9jAi0YQ=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU=
Expand Down
13 changes: 5 additions & 8 deletions pkg/compose/build.go
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"path/filepath"

"github.com/compose-spec/compose-go/v2/graph"
"github.com/moby/buildkit/util/progress/progressui"

"github.com/compose-spec/compose-go/v2/types"
Expand Down Expand Up @@ -79,7 +80,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti

imageIDs := map[string]string{}
serviceToBeBuild := map[string]serviceToBuild{}
err = project.WithServices(options.Services, func(service types.ServiceConfig) error {
err = project.WithServices(options.Services, func(name string, service types.ServiceConfig) error {
if service.Build == nil {
return nil
}
Expand All @@ -88,7 +89,6 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
if localImagePresent && service.PullPolicy != types.PullPolicyBuild {
return nil
}
name := service.Name
serviceToBeBuild[name] = serviceToBuild{name: name, service: service}
return nil
}, types.IgnoreDependencies)
Expand Down Expand Up @@ -145,15 +145,14 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
}
return -1
}
err = InDependencyOrder(ctx, project, func(ctx context.Context, name string) error {
err = graph.InDependencyOrder(ctx, project, func(ctx context.Context, name string, service types.ServiceConfig) error {
if len(options.Services) > 0 && !utils.Contains(options.Services, name) {
return nil
}
serviceToBuild, ok := serviceToBeBuild[name]
_, ok := serviceToBeBuild[name]
if !ok {
return nil
}
service := serviceToBuild.service

if !buildkitEnabled {
id, err := s.doBuildClassic(ctx, project, service, options)
Expand Down Expand Up @@ -184,9 +183,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
builtDigests[getServiceIndex(name)] = digest

return nil
}, func(traversal *graphTraversal) {
traversal.maxConcurrency = s.maxConcurrency
})
}, graph.WithMaxConcurrency(s.maxConcurrency))

// enforce all build event get consumed
if buildkitEnabled {
Expand Down
10 changes: 3 additions & 7 deletions pkg/compose/convergence.go
Expand Up @@ -26,6 +26,7 @@ import (
"sync"
"time"

"github.com/compose-spec/compose-go/v2/graph"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"

Expand Down Expand Up @@ -91,20 +92,15 @@ func newConvergence(services []string, state Containers, s *composeService) *con
}

func (c *convergence) apply(ctx context.Context, project *types.Project, options api.CreateOptions) error {
return InDependencyOrder(ctx, project, func(ctx context.Context, name string) error {
service, err := project.GetService(name)
if err != nil {
return err
}

return graph.InDependencyOrder(ctx, project, func(ctx context.Context, name string, service types.ServiceConfig) error {
return tracing.SpanWrapFunc("service/apply", tracing.ServiceOptions(service), func(ctx context.Context) error {
strategy := options.RecreateDependencies
if utils.StringContains(options.Services, name) {
strategy = options.Recreate
}
return c.ensureService(ctx, project, service, strategy, options.Inherit, options.Timeout)
})(ctx)
})
}, graph.WithMaxConcurrency(c.service.maxConcurrency))
}

var mu sync.Mutex
Expand Down

0 comments on commit 0c93a2d

Please sign in to comment.