Browse code

added authConfig to docker build

Victor Vieux authored on 2013/12/07 07:27:10
Showing 4 changed files
... ...
@@ -912,6 +912,17 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
912 912
 	rawRm := r.FormValue("rm")
913 913
 	repoName, tag := utils.ParseRepositoryTag(repoName)
914 914
 
915
+	authEncoded := r.Header.Get("X-Registry-Auth")
916
+	authConfig := &auth.AuthConfig{}
917
+	if authEncoded != "" {
918
+		authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
919
+		if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
920
+			// for a pull it is not an error if no auth was given
921
+			// to increase compatibility with the existing api it is defaulting to be empty
922
+			authConfig = &auth.AuthConfig{}
923
+		}
924
+	}
925
+
915 926
 	var context io.Reader
916 927
 
917 928
 	if remoteURL == "" {
... ...
@@ -978,7 +989,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
978 978
 			Writer:          utils.NewWriteFlusher(w),
979 979
 			StreamFormatter: sf,
980 980
 		},
981
-		!suppressOutput, !noCache, rm, utils.NewWriteFlusher(w), sf)
981
+		!suppressOutput, !noCache, rm, utils.NewWriteFlusher(w), sf, authConfig)
982 982
 	id, err := b.Build(context)
983 983
 	if err != nil {
984 984
 		if sf.Used() {
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"encoding/json"
5 5
 	"fmt"
6 6
 	"github.com/dotcloud/docker/archive"
7
+	"github.com/dotcloud/docker/auth"
7 8
 	"github.com/dotcloud/docker/utils"
8 9
 	"io"
9 10
 	"io/ioutil"
... ...
@@ -33,6 +34,8 @@ type buildFile struct {
33 33
 	utilizeCache bool
34 34
 	rm           bool
35 35
 
36
+	authConfig *auth.AuthConfig
37
+
36 38
 	tmpContainers map[string]struct{}
37 39
 	tmpImages     map[string]struct{}
38 40
 
... ...
@@ -57,7 +60,7 @@ func (b *buildFile) CmdFrom(name string) error {
57 57
 	if err != nil {
58 58
 		if b.runtime.graph.IsNotExist(err) {
59 59
 			remote, tag := utils.ParseRepositoryTag(name)
60
-			if err := b.srv.ImagePull(remote, tag, b.outOld, b.sf, nil, nil, true); err != nil {
60
+			if err := b.srv.ImagePull(remote, tag, b.outOld, b.sf, b.authConfig, nil, true); err != nil {
61 61
 				return err
62 62
 			}
63 63
 			image, err = b.runtime.repositories.LookupImage(name)
... ...
@@ -568,7 +571,7 @@ func (b *buildFile) Build(context io.Reader) (string, error) {
568 568
 	return "", fmt.Errorf("An error occurred during the build\n")
569 569
 }
570 570
 
571
-func NewBuildFile(srv *Server, outStream, errStream io.Writer, verbose, utilizeCache, rm bool, outOld io.Writer, sf *utils.StreamFormatter) BuildFile {
571
+func NewBuildFile(srv *Server, outStream, errStream io.Writer, verbose, utilizeCache, rm bool, outOld io.Writer, sf *utils.StreamFormatter, auth *auth.AuthConfig) BuildFile {
572 572
 	return &buildFile{
573 573
 		runtime:       srv.runtime,
574 574
 		srv:           srv,
... ...
@@ -581,6 +584,7 @@ func NewBuildFile(srv *Server, outStream, errStream io.Writer, verbose, utilizeC
581 581
 		utilizeCache:  utilizeCache,
582 582
 		rm:            rm,
583 583
 		sf:            sf,
584
+		authConfig:    auth,
584 585
 		outOld:        outOld,
585 586
 	}
586 587
 }
... ...
@@ -226,6 +226,12 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
226 226
 	}
227 227
 
228 228
 	headers := http.Header(make(map[string][]string))
229
+	buf, err := json.Marshal(cli.configFile)
230
+	if err != nil {
231
+		return err
232
+	}
233
+	headers.Add("X-Registry-Auth", base64.URLEncoding.EncodeToString(buf))
234
+
229 235
 	if context != nil {
230 236
 		headers.Set("Content-Type", "application/tar")
231 237
 	}
... ...
@@ -1026,6 +1026,7 @@ Build an image from Dockerfile via stdin
1026 1026
    :query q: suppress verbose build output
1027 1027
    :query nocache: do not use the cache when building the image
1028 1028
    :reqheader Content-type: should be set to ``"application/tar"``.
1029
+   :reqheader X-Registry-Auth: base64-encoded AuthConfig object
1029 1030
    :statuscode 200: no error
1030 1031
    :statuscode 500: server error
1031 1032