local backend to rely on dockerCli's LoadDefaultConfigFile

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-04-15 09:09:35 +02:00
parent 0bdad7e551
commit 85af8cdaaa
6 changed files with 18 additions and 26 deletions

View File

@ -32,7 +32,6 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/config"
"github.com/docker/compose-cli/utils" "github.com/docker/compose-cli/utils"
) )
@ -109,10 +108,7 @@ func runConvert(ctx context.Context, backend compose.Service, opts convertOption
} }
if opts.resolve { if opts.resolve {
configFile, err := cliconfig.Load(config.Dir()) configFile := cliconfig.LoadDefaultConfigFile(os.Stderr)
if err != nil {
return err
}
resolver := remotes.CreateResolver(configFile) resolver := remotes.CreateResolver(configFile)
err = project.ResolveImages(func(named reference.Named) (digest.Digest, error) { err = project.ResolveImages(func(named reference.Named) (digest.Digest, error) {

View File

@ -17,8 +17,9 @@
package local package local
import ( 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/docker/client"
"github.com/docker/compose-cli/api/backend" "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/resources"
"github.com/docker/compose-cli/api/secrets" "github.com/docker/compose-cli/api/secrets"
"github.com/docker/compose-cli/api/volumes" "github.com/docker/compose-cli/api/volumes"
local_compose "github.com/docker/compose-cli/local/compose"
) )
const backendType = store.EcsLocalSimulationContextType const backendType = store.EcsLocalSimulationContextType
@ -50,7 +52,7 @@ func service() (backend.Service, error) {
return &ecsLocalSimulation{ return &ecsLocalSimulation{
moby: apiClient, moby: apiClient,
compose: local_compose.NewComposeService(apiClient), compose: local_compose.NewComposeService(apiClient, cliconfig.LoadDefaultConfigFile(os.Stderr)),
}, nil }, nil
} }

View File

@ -17,6 +17,9 @@
package local package local
import ( import (
"os"
cliconfig "github.com/docker/cli/cli/config"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/compose-cli/api/backend" "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 // NewService build a backend for "local" context, using Docker API client
func NewService(apiClient client.APIClient) backend.Service { func NewService(apiClient client.APIClient) backend.Service {
file := cliconfig.LoadDefaultConfigFile(os.Stderr)
return &local{ return &local{
containerService: &containerService{apiClient}, containerService: &containerService{apiClient},
volumeService: &volumeService{apiClient}, volumeService: &volumeService{apiClient},
composeService: local_compose.NewComposeService(apiClient), composeService: local_compose.NewComposeService(apiClient, file),
} }
} }

View File

@ -28,13 +28,11 @@ import (
"github.com/docker/buildx/driver" "github.com/docker/buildx/driver"
_ "github.com/docker/buildx/driver/docker" // required to get default driver registered _ "github.com/docker/buildx/driver/docker" // required to get default driver registered
"github.com/docker/buildx/util/progress" "github.com/docker/buildx/util/progress"
cliconfig "github.com/docker/cli/cli/config"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
bclient "github.com/moby/buildkit/client" bclient "github.com/moby/buildkit/client"
specs "github.com/opencontainers/image-spec/specs-go/v1" specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/compose"
"github.com/docker/compose-cli/api/config"
composeprogress "github.com/docker/compose-cli/api/progress" composeprogress "github.com/docker/compose-cli/api/progress"
"github.com/docker/compose-cli/cli/metrics" "github.com/docker/compose-cli/cli/metrics"
"github.com/docker/compose-cli/utils" "github.com/docker/compose-cli/utils"
@ -195,12 +193,7 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opts
} }
const drivername = "default" const drivername = "default"
configFile, err := cliconfig.Load(config.Dir()) d, err := driver.GetDriver(ctx, drivername, nil, s.apiClient, s.configFile, nil, nil, "", nil, nil, project.WorkingDir)
if err != nil {
return nil, err
}
d, err := driver.GetDriver(ctx, drivername, nil, s.apiClient, configFile, nil, nil, "", nil, nil, project.WorkingDir)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -20,6 +20,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/docker/cli/cli/config/configfile"
"strings" "strings"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/compose"
@ -32,14 +33,16 @@ import (
) )
// NewComposeService create a local implementation of the compose.Service API // 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{ return &composeService{
apiClient: apiClient, apiClient: apiClient,
configFile: configFile,
} }
} }
type composeService struct { 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 { func (s *composeService) Up(ctx context.Context, project *types.Project, options compose.UpOptions) error {

View File

@ -27,23 +27,17 @@ import (
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
"github.com/distribution/distribution/v3/reference" "github.com/distribution/distribution/v3/reference"
"github.com/docker/buildx/driver" "github.com/docker/buildx/driver"
cliconfig "github.com/docker/cli/cli/config"
moby "github.com/docker/docker/api/types" moby "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"github.com/docker/compose-cli/api/compose" "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/api/progress"
"github.com/docker/compose-cli/cli/metrics" "github.com/docker/compose-cli/cli/metrics"
) )
func (s *composeService) Pull(ctx context.Context, project *types.Project, opts compose.PullOptions) error { 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) info, err := s.apiClient.Info(ctx)
if err != nil { if err != nil {
return err return err
@ -67,7 +61,7 @@ func (s *composeService) Pull(ctx context.Context, project *types.Project, opts
continue continue
} }
eg.Go(func() error { 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 err != nil {
if !opts.IgnoreFailures { if !opts.IgnoreFailures {
return err return err