Fix test and load dockerconfig in the backend

Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
aiordache 2021-03-04 17:59:09 +01:00
parent d26783c322
commit 6f1d88e3bc
3 changed files with 13 additions and 13 deletions

View File

@ -47,7 +47,6 @@ import (
"github.com/docker/compose-cli/cli/mobycli" "github.com/docker/compose-cli/cli/mobycli"
cliopts "github.com/docker/compose-cli/cli/options" cliopts "github.com/docker/compose-cli/cli/options"
cliconfig "github.com/docker/cli/cli/config"
cliflags "github.com/docker/cli/cli/flags" cliflags "github.com/docker/cli/cli/flags"
// Backend registrations // Backend registrations
@ -214,12 +213,6 @@ func main() {
volume.Command(ctype), volume.Command(ctype),
) )
configFile, err := cliconfig.Load(opts.Config)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to load docker config: %s\n", opts.Config)
os.Exit(1)
}
ctx = apicontext.WithConfig(ctx, *configFile)
ctx = apicontext.WithCurrentContext(ctx, currentContext) ctx = apicontext.WithCurrentContext(ctx, currentContext)
cnxOptions := cliflags.CommonOptions{ cnxOptions := cliflags.CommonOptions{

View File

@ -22,13 +22,17 @@ import (
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/compose-cli/api/backend" "github.com/docker/compose-cli/api/backend"
"github.com/docker/compose-cli/api/cloud" "github.com/docker/compose-cli/api/cloud"
"github.com/docker/compose-cli/api/compose" "github.com/docker/compose-cli/api/compose"
apiconfig "github.com/docker/compose-cli/api/config"
"github.com/docker/compose-cli/api/containers" "github.com/docker/compose-cli/api/containers"
apicontext "github.com/docker/compose-cli/api/context" apicontext "github.com/docker/compose-cli/api/context"
"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" local_compose "github.com/docker/compose-cli/local/compose"
cliconfig "github.com/docker/cli/cli/config"
) )
type local struct { type local struct {
@ -43,9 +47,12 @@ func init() {
func service(ctx context.Context) (backend.Service, error) { func service(ctx context.Context) (backend.Service, error) {
options := apicontext.CliOptions(ctx) options := apicontext.CliOptions(ctx)
config := apicontext.Config(ctx) config := apiconfig.Dir(ctx)
configFile, err := cliconfig.Load(config)
apiClient, err := command.NewAPIClientFromFlags(&options, &config) if err != nil {
return nil, err
}
apiClient, err := command.NewAPIClientFromFlags(&options, configFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -396,11 +396,11 @@ func TestLegacy(t *testing.T) {
}) })
t.Run("host flag", func(t *testing.T) { t.Run("host flag", func(t *testing.T) {
stderr := "Cannot connect to the Docker daemon at tcp://localhost:123" stderr := "nonexistent: Name or service not known"
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
stderr = "error during connect: Get http://localhost:123" stderr = "error during connect: Get http://nonexitent:123"
} }
res := c.RunDockerOrExitError("-H", "tcp://localhost:123", "version") res := c.RunDockerOrExitError("-H", "tcp://nonexistent:123", "version")
res.Assert(t, icmd.Expected{ res.Assert(t, icmd.Expected{
ExitCode: 1, ExitCode: 1,
Err: stderr, Err: stderr,