added authConfig to docker build
| ... | ... |
@@ -889,12 +889,25 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ |
| 889 | 889 |
if version < 1.3 {
|
| 890 | 890 |
return fmt.Errorf("Multipart upload for build is no longer supported. Please upgrade your docker client.")
|
| 891 | 891 |
} |
| 892 |
- remoteURL := r.FormValue("remote")
|
|
| 893 |
- repoName := r.FormValue("t")
|
|
| 894 |
- rawSuppressOutput := r.FormValue("q")
|
|
| 895 |
- rawNoCache := r.FormValue("nocache")
|
|
| 896 |
- rawRm := r.FormValue("rm")
|
|
| 897 |
- repoName, tag := utils.ParseRepositoryTag(repoName) |
|
| 892 |
+ var ( |
|
| 893 |
+ remoteURL = r.FormValue("remote")
|
|
| 894 |
+ repoName = r.FormValue("t")
|
|
| 895 |
+ rawSuppressOutput = r.FormValue("q")
|
|
| 896 |
+ rawNoCache = r.FormValue("nocache")
|
|
| 897 |
+ rawRm = r.FormValue("rm")
|
|
| 898 |
+ authEncoded = r.Header.Get("X-Registry-Auth")
|
|
| 899 |
+ authConfig = &auth.AuthConfig{}
|
|
| 900 |
+ tag string |
|
| 901 |
+ ) |
|
| 902 |
+ repoName, tag = utils.ParseRepositoryTag(repoName) |
|
| 903 |
+ if authEncoded != "" {
|
|
| 904 |
+ authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) |
|
| 905 |
+ if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
|
|
| 906 |
+ // for a pull it is not an error if no auth was given |
|
| 907 |
+ // to increase compatibility with the existing api it is defaulting to be empty |
|
| 908 |
+ authConfig = &auth.AuthConfig{}
|
|
| 909 |
+ } |
|
| 910 |
+ } |
|
| 898 | 911 |
|
| 899 | 912 |
var context io.Reader |
| 900 | 913 |
|
| ... | ... |
@@ -962,7 +975,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ |
| 962 | 962 |
Writer: utils.NewWriteFlusher(w), |
| 963 | 963 |
StreamFormatter: sf, |
| 964 | 964 |
}, |
| 965 |
- !suppressOutput, !noCache, rm, utils.NewWriteFlusher(w), sf) |
|
| 965 |
+ !suppressOutput, !noCache, rm, utils.NewWriteFlusher(w), sf, authConfig) |
|
| 966 | 966 |
id, err := b.Build(context) |
| 967 | 967 |
if err != nil {
|
| 968 | 968 |
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 |
} |
| ... | ... |
@@ -227,6 +227,12 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
| 227 | 227 |
} |
| 228 | 228 |
|
| 229 | 229 |
headers := http.Header(make(map[string][]string)) |
| 230 |
+ buf, err := json.Marshal(cli.configFile) |
|
| 231 |
+ if err != nil {
|
|
| 232 |
+ return err |
|
| 233 |
+ } |
|
| 234 |
+ headers.Add("X-Registry-Auth", base64.URLEncoding.EncodeToString(buf))
|
|
| 235 |
+ |
|
| 230 | 236 |
if context != nil {
|
| 231 | 237 |
headers.Set("Content-Type", "application/tar")
|
| 232 | 238 |
} |
| ... | ... |
@@ -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 |
|
| ... | ... |
@@ -266,7 +266,7 @@ func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, u |
| 266 | 266 |
} |
| 267 | 267 |
dockerfile := constructDockerfile(context.dockerfile, ip, port) |
| 268 | 268 |
|
| 269 |
- buildfile := docker.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, useCache, false, ioutil.Discard, utils.NewStreamFormatter(false)) |
|
| 269 |
+ buildfile := docker.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, useCache, false, ioutil.Discard, utils.NewStreamFormatter(false), nil) |
|
| 270 | 270 |
id, err := buildfile.Build(mkTestContext(dockerfile, context.files, t)) |
| 271 | 271 |
if err != nil {
|
| 272 | 272 |
return nil, err |
| ... | ... |
@@ -516,7 +516,7 @@ func TestForbiddenContextPath(t *testing.T) {
|
| 516 | 516 |
} |
| 517 | 517 |
dockerfile := constructDockerfile(context.dockerfile, ip, port) |
| 518 | 518 |
|
| 519 |
- buildfile := docker.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false)) |
|
| 519 |
+ buildfile := docker.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false), nil) |
|
| 520 | 520 |
_, err = buildfile.Build(mkTestContext(dockerfile, context.files, t)) |
| 521 | 521 |
|
| 522 | 522 |
if err == nil {
|
| ... | ... |
@@ -562,7 +562,7 @@ func TestBuildADDFileNotFound(t *testing.T) {
|
| 562 | 562 |
} |
| 563 | 563 |
dockerfile := constructDockerfile(context.dockerfile, ip, port) |
| 564 | 564 |
|
| 565 |
- buildfile := docker.NewBuildFile(mkServerFromEngine(eng, t), ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false)) |
|
| 565 |
+ buildfile := docker.NewBuildFile(mkServerFromEngine(eng, t), ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false), nil) |
|
| 566 | 566 |
_, err = buildfile.Build(mkTestContext(dockerfile, context.files, t)) |
| 567 | 567 |
|
| 568 | 568 |
if err == nil {
|