Browse code

Move cli.Configdir away (in `flags`).

This makes integration not depend anymore of `cli` and thus not
require `cobra` and other packages to compile.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2017/05/30 08:22:33
Showing 7 changed files
1 1
deleted file mode 100644
... ...
@@ -1,25 +0,0 @@
1
-package cli
2
-
3
-import (
4
-	"os"
5
-	"path/filepath"
6
-
7
-	"github.com/docker/docker/pkg/homedir"
8
-)
9
-
10
-var (
11
-	configDir     = os.Getenv("DOCKER_CONFIG")
12
-	configFileDir = ".docker"
13
-)
14
-
15
-// ConfigurationDir returns the path to the configuration directory as specified by the DOCKER_CONFIG environment variable.
16
-// TODO: this was copied from cli/config/configfile and should be removed once cmd/dockerd moves
17
-func ConfigurationDir() string {
18
-	return configDir
19
-}
20
-
21
-func init() {
22
-	if configDir == "" {
23
-		configDir = filepath.Join(homedir.Get(), configFileDir)
24
-	}
25
-}
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"path/filepath"
7 7
 
8 8
 	"github.com/Sirupsen/logrus"
9
-	"github.com/docker/docker/cli"
10 9
 	"github.com/docker/docker/opts"
11 10
 	"github.com/docker/go-connections/tlsconfig"
12 11
 	"github.com/spf13/pflag"
... ...
@@ -46,7 +45,7 @@ func NewCommonOptions() *CommonOptions {
46 46
 // InstallFlags adds flags for the common options on the FlagSet
47 47
 func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) {
48 48
 	if dockerCertPath == "" {
49
-		dockerCertPath = cli.ConfigurationDir()
49
+		dockerCertPath = ConfigurationDir()
50 50
 	}
51 51
 
52 52
 	flags.BoolVarP(&commonOpts.Debug, "debug", "D", false, "Enable debug mode")
... ...
@@ -4,7 +4,6 @@ import (
4 4
 	"path/filepath"
5 5
 	"testing"
6 6
 
7
-	"github.com/docker/docker/cli"
8 7
 	"github.com/spf13/pflag"
9 8
 	"github.com/stretchr/testify/assert"
10 9
 )
... ...
@@ -26,7 +25,7 @@ func TestCommonOptionsInstallFlags(t *testing.T) {
26 26
 }
27 27
 
28 28
 func defaultPath(filename string) string {
29
-	return filepath.Join(cli.ConfigurationDir(), filename)
29
+	return filepath.Join(ConfigurationDir(), filename)
30 30
 }
31 31
 
32 32
 func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
33 33
new file mode 100644
... ...
@@ -0,0 +1,25 @@
0
+package flags
1
+
2
+import (
3
+	"os"
4
+	"path/filepath"
5
+
6
+	"github.com/docker/docker/pkg/homedir"
7
+)
8
+
9
+var (
10
+	configDir     = os.Getenv("DOCKER_CONFIG")
11
+	configFileDir = ".docker"
12
+)
13
+
14
+// ConfigurationDir returns the path to the configuration directory as specified by the DOCKER_CONFIG environment variable.
15
+// TODO: this was copied from cli/config/configfile and should be removed once cmd/dockerd moves
16
+func ConfigurationDir() string {
17
+	return configDir
18
+}
19
+
20
+func init() {
21
+	if configDir == "" {
22
+		configDir = filepath.Join(homedir.Get(), configFileDir)
23
+	}
24
+}
... ...
@@ -12,7 +12,7 @@ import (
12 12
 	"testing"
13 13
 
14 14
 	"github.com/docker/docker/api/types/swarm"
15
-	dcli "github.com/docker/docker/cli"
15
+	"github.com/docker/docker/cli/flags"
16 16
 	"github.com/docker/docker/integration-cli/cli"
17 17
 	"github.com/docker/docker/integration-cli/cli/build/fakestorage"
18 18
 	"github.com/docker/docker/integration-cli/daemon"
... ...
@@ -406,7 +406,7 @@ func (s *DockerTrustSuite) TearDownTest(c *check.C) {
406 406
 	}
407 407
 
408 408
 	// Remove trusted keys and metadata after test
409
-	os.RemoveAll(filepath.Join(dcli.ConfigurationDir(), "trust"))
409
+	os.RemoveAll(filepath.Join(flags.ConfigurationDir(), "trust"))
410 410
 	s.ds.TearDownTest(c)
411 411
 }
412 412
 
... ...
@@ -12,7 +12,7 @@ import (
12 12
 	"sync"
13 13
 
14 14
 	"github.com/docker/distribution/reference"
15
-	dcli "github.com/docker/docker/cli"
15
+	"github.com/docker/docker/cli/flags"
16 16
 	"github.com/docker/docker/integration-cli/checker"
17 17
 	"github.com/docker/docker/integration-cli/cli"
18 18
 	"github.com/docker/docker/integration-cli/cli/build"
... ...
@@ -294,7 +294,7 @@ func (s *DockerTrustSuite) TestTrustedPush(c *check.C) {
294 294
 	})
295 295
 
296 296
 	// Assert that we rotated the snapshot key to the server by checking our local keystore
297
-	contents, err := ioutil.ReadDir(filepath.Join(dcli.ConfigurationDir(), "trust/private/tuf_keys", privateRegistryURL, "dockerclitrusted/pushtest"))
297
+	contents, err := ioutil.ReadDir(filepath.Join(flags.ConfigurationDir(), "trust/private/tuf_keys", privateRegistryURL, "dockerclitrusted/pushtest"))
298 298
 	c.Assert(err, check.IsNil, check.Commentf("Unable to read local tuf key files"))
299 299
 	// Check that we only have 1 key (targets key)
300 300
 	c.Assert(contents, checker.HasLen, 1)
... ...
@@ -399,7 +399,7 @@ func (s *DockerTrustSuite) TestTrustedPushWithReleasesDelegationOnly(c *check.C)
399 399
 	s.assertTargetNotInRoles(c, repoName, "latest", "targets")
400 400
 
401 401
 	// Try pull after push
402
-	os.RemoveAll(filepath.Join(dcli.ConfigurationDir(), "trust"))
402
+	os.RemoveAll(filepath.Join(flags.ConfigurationDir(), "trust"))
403 403
 
404 404
 	cli.Docker(cli.Args("pull", targetName), trustedCmd).Assert(c, icmd.Expected{
405 405
 		Out: "Status: Image is up to date",
... ...
@@ -436,7 +436,7 @@ func (s *DockerTrustSuite) TestTrustedPushSignsAllFirstLevelRolesWeHaveKeysFor(c
436 436
 	s.assertTargetNotInRoles(c, repoName, "latest", "targets")
437 437
 
438 438
 	// Try pull after push
439
-	os.RemoveAll(filepath.Join(dcli.ConfigurationDir(), "trust"))
439
+	os.RemoveAll(filepath.Join(flags.ConfigurationDir(), "trust"))
440 440
 
441 441
 	// pull should fail because none of these are the releases role
442 442
 	cli.Docker(cli.Args("pull", targetName), trustedCmd).Assert(c, icmd.Expected{
... ...
@@ -472,7 +472,7 @@ func (s *DockerTrustSuite) TestTrustedPushSignsForRolesWithKeysAndValidPaths(c *
472 472
 	s.assertTargetNotInRoles(c, repoName, "latest", "targets")
473 473
 
474 474
 	// Try pull after push
475
-	os.RemoveAll(filepath.Join(dcli.ConfigurationDir(), "trust"))
475
+	os.RemoveAll(filepath.Join(flags.ConfigurationDir(), "trust"))
476 476
 
477 477
 	// pull should fail because none of these are the releases role
478 478
 	cli.Docker(cli.Args("pull", targetName), trustedCmd).Assert(c, icmd.Expected{
... ...
@@ -11,7 +11,7 @@ import (
11 11
 	"strings"
12 12
 	"time"
13 13
 
14
-	dcli "github.com/docker/docker/cli"
14
+	"github.com/docker/docker/cli/flags"
15 15
 	"github.com/docker/docker/integration-cli/checker"
16 16
 	"github.com/docker/docker/integration-cli/cli"
17 17
 	icmd "github.com/docker/docker/pkg/testutil/cmd"
... ...
@@ -108,7 +108,7 @@ func newTestNotary(c *check.C) (*testNotary, error) {
108 108
 		"skipTLSVerify": true
109 109
 	}
110 110
 }`
111
-	if _, err = fmt.Fprintf(clientConfig, template, filepath.Join(dcli.ConfigurationDir(), "trust"), notaryURL); err != nil {
111
+	if _, err = fmt.Fprintf(clientConfig, template, filepath.Join(flags.ConfigurationDir(), "trust"), notaryURL); err != nil {
112 112
 		os.RemoveAll(tmp)
113 113
 		return nil, err
114 114
 	}