Kaynağa Gözat

Fix #22240 do not pull all the tags implicitely

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Vincent Demeester 9 yıl önce
ebeveyn
işleme
54ebe42de9

+ 3 - 2
api/client/pull.go

@@ -63,10 +63,10 @@ func (cli *DockerCli) CmdPull(args ...string) error {
 		return cli.trustedPull(repoInfo, registryRef, authConfig, requestPrivilege)
 	}
 
-	return cli.imagePullPrivileged(authConfig, distributionRef.String(), requestPrivilege)
+	return cli.imagePullPrivileged(authConfig, distributionRef.String(), requestPrivilege, *allTags)
 }
 
-func (cli *DockerCli) imagePullPrivileged(authConfig types.AuthConfig, ref string, requestPrivilege types.RequestPrivilegeFunc) error {
+func (cli *DockerCli) imagePullPrivileged(authConfig types.AuthConfig, ref string, requestPrivilege types.RequestPrivilegeFunc, all bool) error {
 
 	encodedAuth, err := encodeAuthToBase64(authConfig)
 	if err != nil {
@@ -75,6 +75,7 @@ func (cli *DockerCli) imagePullPrivileged(authConfig types.AuthConfig, ref strin
 	options := types.ImagePullOptions{
 		RegistryAuth:  encodedAuth,
 		PrivilegeFunc: requestPrivilege,
+		All:           all,
 	}
 
 	responseBody, err := cli.client.ImagePull(context.Background(), ref, options)

+ 1 - 1
api/client/trust.go

@@ -377,7 +377,7 @@ func (cli *DockerCli) trustedPull(repoInfo *registry.RepositoryInfo, ref registr
 		if err != nil {
 			return err
 		}
-		if err := cli.imagePullPrivileged(authConfig, ref.String(), requestPrivilege); err != nil {
+		if err := cli.imagePullPrivileged(authConfig, ref.String(), requestPrivilege, false); err != nil {
 			return err
 		}
 

+ 14 - 0
integration-cli/docker_cli_pull_test.go

@@ -237,6 +237,20 @@ func (s *DockerHubPullSuite) TestPullAllTagsFromCentralRegistry(c *check.C) {
 	c.Assert(splitLatest, checker.DeepEquals, splitCurrent, check.Commentf("busybox:latest was changed after pulling all tags"))
 }
 
+// TestRunImplicitPullWithNoTagOnlyPullDefaultTag should pull implicitely only the default tag (latest)
+func (s *DockerHubPullSuite) TestRunImplicitPullWithNoTagOnlyPullDefaultTag(c *check.C) {
+	// run with an image we don't have
+	testRequires(c, DaemonIsLinux)
+	out := s.Cmd(c, "run", "busybox")
+
+	c.Assert(out, checker.Contains, "Unable to find image 'busybox:latest' locally")
+
+	// There should be only one line for busybox, the one with busybox:latest
+	outImageCmd := s.Cmd(c, "images", "busybox")
+	splitOutImageCmd := strings.Split(strings.TrimSpace(outImageCmd), "\n")
+	c.Assert(splitOutImageCmd, checker.HasLen, 2)
+}
+
 // TestPullClientDisconnect kills the client during a pull operation and verifies that the operation
 // gets cancelled.
 //