From 85af8cdaaa1f5d170e41449493284b0167b2c721 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Thu, 15 Apr 2021 09:09:35 +0200 Subject: [PATCH] local backend to rely on dockerCli's LoadDefaultConfigFile Signed-off-by: Nicolas De Loof --- cli/cmd/compose/convert.go | 6 +----- ecs/local/backend.go | 6 ++++-- local/backend.go | 6 +++++- local/compose/build.go | 9 +-------- local/compose/compose.go | 9 ++++++--- local/compose/pull.go | 8 +------- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/cli/cmd/compose/convert.go b/cli/cmd/compose/convert.go index a01d10be7..01b0fbe52 100644 --- a/cli/cmd/compose/convert.go +++ b/cli/cmd/compose/convert.go @@ -32,7 +32,6 @@ import ( "github.com/spf13/cobra" "github.com/docker/compose-cli/api/compose" - "github.com/docker/compose-cli/api/config" "github.com/docker/compose-cli/utils" ) @@ -109,10 +108,7 @@ func runConvert(ctx context.Context, backend compose.Service, opts convertOption } if opts.resolve { - configFile, err := cliconfig.Load(config.Dir()) - if err != nil { - return err - } + configFile := cliconfig.LoadDefaultConfigFile(os.Stderr) resolver := remotes.CreateResolver(configFile) err = project.ResolveImages(func(named reference.Named) (digest.Digest, error) { diff --git a/ecs/local/backend.go b/ecs/local/backend.go index 8e26b768e..0b521ff1e 100644 --- a/ecs/local/backend.go +++ b/ecs/local/backend.go @@ -17,8 +17,9 @@ package local import ( - local_compose "github.com/docker/compose-cli/local/compose" + "os" + cliconfig "github.com/docker/cli/cli/config" "github.com/docker/docker/client" "github.com/docker/compose-cli/api/backend" @@ -29,6 +30,7 @@ import ( "github.com/docker/compose-cli/api/resources" "github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/volumes" + local_compose "github.com/docker/compose-cli/local/compose" ) const backendType = store.EcsLocalSimulationContextType @@ -50,7 +52,7 @@ func service() (backend.Service, error) { return &ecsLocalSimulation{ moby: apiClient, - compose: local_compose.NewComposeService(apiClient), + compose: local_compose.NewComposeService(apiClient, cliconfig.LoadDefaultConfigFile(os.Stderr)), }, nil } diff --git a/local/backend.go b/local/backend.go index e315f5a08..7050180c4 100644 --- a/local/backend.go +++ b/local/backend.go @@ -17,6 +17,9 @@ package local import ( + "os" + + cliconfig "github.com/docker/cli/cli/config" "github.com/docker/docker/client" "github.com/docker/compose-cli/api/backend" @@ -36,10 +39,11 @@ type local struct { // NewService build a backend for "local" context, using Docker API client func NewService(apiClient client.APIClient) backend.Service { + file := cliconfig.LoadDefaultConfigFile(os.Stderr) return &local{ containerService: &containerService{apiClient}, volumeService: &volumeService{apiClient}, - composeService: local_compose.NewComposeService(apiClient), + composeService: local_compose.NewComposeService(apiClient, file), } } diff --git a/local/compose/build.go b/local/compose/build.go index 5afb17116..9b2b1339f 100644 --- a/local/compose/build.go +++ b/local/compose/build.go @@ -28,13 +28,11 @@ import ( "github.com/docker/buildx/driver" _ "github.com/docker/buildx/driver/docker" // required to get default driver registered "github.com/docker/buildx/util/progress" - cliconfig "github.com/docker/cli/cli/config" moby "github.com/docker/docker/api/types" bclient "github.com/moby/buildkit/client" specs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/docker/compose-cli/api/compose" - "github.com/docker/compose-cli/api/config" composeprogress "github.com/docker/compose-cli/api/progress" "github.com/docker/compose-cli/cli/metrics" "github.com/docker/compose-cli/utils" @@ -195,12 +193,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opts } const drivername = "default" - configFile, err := cliconfig.Load(config.Dir()) - if err != nil { - return nil, err - } - - d, err := driver.GetDriver(ctx, drivername, nil, s.apiClient, configFile, nil, nil, "", nil, nil, project.WorkingDir) + d, err := driver.GetDriver(ctx, drivername, nil, s.apiClient, s.configFile, nil, nil, "", nil, nil, project.WorkingDir) if err != nil { return nil, err } diff --git a/local/compose/compose.go b/local/compose/compose.go index 038ac615c..db60cbf5e 100644 --- a/local/compose/compose.go +++ b/local/compose/compose.go @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/docker/cli/cli/config/configfile" "strings" "github.com/docker/compose-cli/api/compose" @@ -32,14 +33,16 @@ import ( ) // NewComposeService create a local implementation of the compose.Service API -func NewComposeService(apiClient client.APIClient) compose.Service { +func NewComposeService(apiClient client.APIClient, configFile *configfile.ConfigFile) compose.Service { return &composeService{ - apiClient: apiClient, + apiClient: apiClient, + configFile: configFile, } } type composeService struct { - apiClient client.APIClient + apiClient client.APIClient + configFile *configfile.ConfigFile } func (s *composeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error { diff --git a/local/compose/pull.go b/local/compose/pull.go index 7e114b487..0df5e45c7 100644 --- a/local/compose/pull.go +++ b/local/compose/pull.go @@ -27,23 +27,17 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/distribution/distribution/v3/reference" "github.com/docker/buildx/driver" - cliconfig "github.com/docker/cli/cli/config" moby "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/registry" "golang.org/x/sync/errgroup" "github.com/docker/compose-cli/api/compose" - "github.com/docker/compose-cli/api/config" "github.com/docker/compose-cli/api/progress" "github.com/docker/compose-cli/cli/metrics" ) func (s *composeService) Pull(ctx context.Context, project *types.Project, opts compose.PullOptions) error { - configFile, err := cliconfig.Load(config.Dir()) - if err != nil { - return err - } info, err := s.apiClient.Info(ctx) if err != nil { return err @@ -67,7 +61,7 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project, opts continue } eg.Go(func() error { - err := s.pullServiceImage(ctx, service, info, configFile, w) + err := s.pullServiceImage(ctx, service, info, s.configFile, w) if err != nil { if !opts.IgnoreFailures { return err