Ver Fonte

local backend to rely on dockerCli's LoadDefaultConfigFile

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof há 4 anos atrás
pai
commit
85af8cdaaa

+ 1 - 5
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) {

+ 4 - 2
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
 }
 

+ 5 - 1
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),
 	}
 }
 

+ 1 - 8
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
 	}

+ 6 - 3
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 {

+ 1 - 7
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