From 1e35245390f82c62355d677355ceb83635078c3c Mon Sep 17 00:00:00 2001 From: Milas Bowman Date: Wed, 21 Jul 2021 10:59:06 -0400 Subject: [PATCH] Print services in dependency order Currently, `compose config --services` outputs the services in a random/non-deterministic order. In Compose v1, this was implicitly topologically sorted because the project services were pre-sorted. With `compose-go`, the services are unordered, and the `WithServices()` helper can be used to iterate in dependency order. Signed-off-by: Milas Bowman --- cmd/compose/convert.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/compose/convert.go b/cmd/compose/convert.go index 8dd606aa0..69b008cb2 100644 --- a/cmd/compose/convert.go +++ b/cmd/compose/convert.go @@ -27,6 +27,7 @@ import ( "github.com/cnabio/cnab-to-oci/remotes" "github.com/compose-spec/compose-go/cli" + "github.com/compose-spec/compose-go/types" "github.com/distribution/distribution/v3/reference" cliconfig "github.com/docker/cli/cli/config" "github.com/opencontainers/go-digest" @@ -153,10 +154,10 @@ func runServices(opts convertOptions) error { if err != nil { return err } - for _, s := range project.Services { + return project.WithServices(project.ServiceNames(), func(s types.ServiceConfig) error { fmt.Println(s.Name) - } - return nil + return nil + }) } func runVolumes(opts convertOptions) error {