diff --git a/internal/commands/cnab.go b/internal/commands/cnab.go index 0ddd9a6fb..9b1e27343 100644 --- a/internal/commands/cnab.go +++ b/internal/commands/cnab.go @@ -195,20 +195,22 @@ func requiredClaimBindMount(c claim.Claim, targetContextName string, dockerCli c specifiedOrchestrator = rawOrchestrator.(string) } - return requiredBindMount(targetContextName, specifiedOrchestrator, dockerCli) + return requiredBindMount(targetContextName, specifiedOrchestrator, dockerCli.ContextStore()) } -func requiredBindMount(targetContextName string, targetOrchestrator string, dockerCli command.Cli) (bindMount, error) { +func requiredBindMount(targetContextName string, targetOrchestrator string, s store.Store) (bindMount, error) { if targetOrchestrator == "kubernetes" { return bindMount{}, nil } - // TODO:smarter handling of default context required if targetContextName == "" { - return bindMount{true, defaultSocketPath}, nil + targetContextName = "default" } - ctxMeta, err := dockerCli.ContextStore().GetContextMetadata(targetContextName) + // in case of docker desktop, we want to rewrite the context in cases where it targets the local swarm or Kubernetes + s = &dockerDesktopAwareStore{Store: s} + + ctxMeta, err := s.GetContextMetadata(targetContextName) if err != nil { return bindMount{}, err } diff --git a/internal/commands/cnab_test.go b/internal/commands/cnab_test.go index 4a16f643b..31b6e4473 100644 --- a/internal/commands/cnab_test.go +++ b/internal/commands/cnab_test.go @@ -4,12 +4,14 @@ import ( "testing" "github.com/docker/cli/cli/command" + cliflags "github.com/docker/cli/cli/flags" "gotest.tools/assert" ) func TestRequiresBindMount(t *testing.T) { dockerCli, err := command.NewDockerCli() assert.NilError(t, err) + dockerCli.Initialize(cliflags.NewClientOptions()) testCases := []struct { name string @@ -39,7 +41,7 @@ func TestRequiresBindMount(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { - result, err := requiredBindMount(testCase.targetContextName, testCase.targetOrchestrator, dockerCli) + result, err := requiredBindMount(testCase.targetContextName, testCase.targetOrchestrator, dockerCli.ContextStore()) if testCase.expectedError == "" { assert.NilError(t, err) } else { diff --git a/internal/commands/install.go b/internal/commands/install.go index 878b77129..866e04b21 100644 --- a/internal/commands/install.go +++ b/internal/commands/install.go @@ -73,7 +73,7 @@ func runInstall(dockerCli command.Cli, appname string, opts installOptions) erro return errors.New("with-registry-auth is not supported at the moment") } targetContext := getTargetContext(opts.targetContext, dockerCli.CurrentContext()) - bind, err := requiredBindMount(targetContext, opts.orchestrator, dockerCli) + bind, err := requiredBindMount(targetContext, opts.orchestrator, dockerCli.ContextStore()) if err != nil { return err }