Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Rewrite Docker Desktop contexts before testing for required bind mounts
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
  • Loading branch information
simonferquel committed Mar 15, 2019
1 parent 5e0aa7e commit 1121210
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 7 additions & 5 deletions internal/commands/cnab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion internal/commands/cnab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 1121210

Please sign in to comment.