Browse code

Pass authentication credentials through to build

In Docker 1.10 and earlier, "docker build" can do a build FROM a private
repository that hasn't yet been pulled. This doesn't work on master. I
bisected this to https://github.com/docker/docker/pull/19414.
AuthConfigs is deserialized from the HTTP request, but not included in
the builder options.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>

Aaron Lehmann authored on 2016/02/13 02:08:45
Showing 2 changed files
... ...
@@ -159,6 +159,8 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *
159 159
 		buildOptions.Dockerfile = dockerfileName
160 160
 	}
161 161
 
162
+	buildOptions.AuthConfigs = authConfigs
163
+
162 164
 	out = output
163 165
 	if buildOptions.SuppressOutput {
164 166
 		out = notVerboseBuffer
... ...
@@ -6534,3 +6534,26 @@ func (s *DockerSuite) TestBuildWorkdirWindowsPath(c *check.C) {
6534 6534
 		c.Fatal(err)
6535 6535
 	}
6536 6536
 }
6537
+
6538
+func (s *DockerRegistryAuthSuite) TestBuildFromAuthenticatedRegistry(c *check.C) {
6539
+	dockerCmd(c, "login", "-u", s.reg.username, "-p", s.reg.password, "-e", s.reg.email, privateRegistryURL)
6540
+
6541
+	baseImage := privateRegistryURL + "/baseimage"
6542
+
6543
+	_, err := buildImage(baseImage, `
6544
+	FROM busybox
6545
+	ENV env1 val1
6546
+	`, true)
6547
+
6548
+	c.Assert(err, checker.IsNil)
6549
+
6550
+	dockerCmd(c, "push", baseImage)
6551
+	dockerCmd(c, "rmi", baseImage)
6552
+
6553
+	_, err = buildImage(baseImage, fmt.Sprintf(`
6554
+	FROM %s
6555
+	ENV env2 val2
6556
+	`, baseImage), true)
6557
+
6558
+	c.Assert(err, checker.IsNil)
6559
+}