mirror of https://github.com/docker/docs.git
added authConfig to docker build
This commit is contained in:
parent
7fd64e0196
commit
228091c79e
13
api.go
13
api.go
|
@ -912,6 +912,17 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
|
||||||
rawRm := r.FormValue("rm")
|
rawRm := r.FormValue("rm")
|
||||||
repoName, tag := utils.ParseRepositoryTag(repoName)
|
repoName, tag := utils.ParseRepositoryTag(repoName)
|
||||||
|
|
||||||
|
authEncoded := r.Header.Get("X-Registry-Auth")
|
||||||
|
authConfig := &auth.AuthConfig{}
|
||||||
|
if authEncoded != "" {
|
||||||
|
authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
|
||||||
|
if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
|
||||||
|
// for a pull it is not an error if no auth was given
|
||||||
|
// to increase compatibility with the existing api it is defaulting to be empty
|
||||||
|
authConfig = &auth.AuthConfig{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var context io.Reader
|
var context io.Reader
|
||||||
|
|
||||||
if remoteURL == "" {
|
if remoteURL == "" {
|
||||||
|
@ -978,7 +989,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ
|
||||||
Writer: utils.NewWriteFlusher(w),
|
Writer: utils.NewWriteFlusher(w),
|
||||||
StreamFormatter: sf,
|
StreamFormatter: sf,
|
||||||
},
|
},
|
||||||
!suppressOutput, !noCache, rm, utils.NewWriteFlusher(w), sf)
|
!suppressOutput, !noCache, rm, utils.NewWriteFlusher(w), sf, authConfig)
|
||||||
id, err := b.Build(context)
|
id, err := b.Build(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if sf.Used() {
|
if sf.Used() {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/archive"
|
"github.com/dotcloud/docker/archive"
|
||||||
|
"github.com/dotcloud/docker/auth"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -33,6 +34,8 @@ type buildFile struct {
|
||||||
utilizeCache bool
|
utilizeCache bool
|
||||||
rm bool
|
rm bool
|
||||||
|
|
||||||
|
authConfig *auth.AuthConfig
|
||||||
|
|
||||||
tmpContainers map[string]struct{}
|
tmpContainers map[string]struct{}
|
||||||
tmpImages map[string]struct{}
|
tmpImages map[string]struct{}
|
||||||
|
|
||||||
|
@ -57,7 +60,7 @@ func (b *buildFile) CmdFrom(name string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if b.runtime.graph.IsNotExist(err) {
|
if b.runtime.graph.IsNotExist(err) {
|
||||||
remote, tag := utils.ParseRepositoryTag(name)
|
remote, tag := utils.ParseRepositoryTag(name)
|
||||||
if err := b.srv.ImagePull(remote, tag, b.outOld, b.sf, nil, nil, true); err != nil {
|
if err := b.srv.ImagePull(remote, tag, b.outOld, b.sf, b.authConfig, nil, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
image, err = b.runtime.repositories.LookupImage(name)
|
image, err = b.runtime.repositories.LookupImage(name)
|
||||||
|
@ -568,7 +571,7 @@ func (b *buildFile) Build(context io.Reader) (string, error) {
|
||||||
return "", fmt.Errorf("An error occurred during the build\n")
|
return "", fmt.Errorf("An error occurred during the build\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBuildFile(srv *Server, outStream, errStream io.Writer, verbose, utilizeCache, rm bool, outOld io.Writer, sf *utils.StreamFormatter) BuildFile {
|
func NewBuildFile(srv *Server, outStream, errStream io.Writer, verbose, utilizeCache, rm bool, outOld io.Writer, sf *utils.StreamFormatter, auth *auth.AuthConfig) BuildFile {
|
||||||
return &buildFile{
|
return &buildFile{
|
||||||
runtime: srv.runtime,
|
runtime: srv.runtime,
|
||||||
srv: srv,
|
srv: srv,
|
||||||
|
@ -581,6 +584,7 @@ func NewBuildFile(srv *Server, outStream, errStream io.Writer, verbose, utilizeC
|
||||||
utilizeCache: utilizeCache,
|
utilizeCache: utilizeCache,
|
||||||
rm: rm,
|
rm: rm,
|
||||||
sf: sf,
|
sf: sf,
|
||||||
|
authConfig: auth,
|
||||||
outOld: outOld,
|
outOld: outOld,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,6 +226,12 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := http.Header(make(map[string][]string))
|
headers := http.Header(make(map[string][]string))
|
||||||
|
buf, err := json.Marshal(cli.configFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
headers.Add("X-Registry-Auth", base64.URLEncoding.EncodeToString(buf))
|
||||||
|
|
||||||
if context != nil {
|
if context != nil {
|
||||||
headers.Set("Content-Type", "application/tar")
|
headers.Set("Content-Type", "application/tar")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1026,6 +1026,7 @@ Build an image from Dockerfile via stdin
|
||||||
:query q: suppress verbose build output
|
:query q: suppress verbose build output
|
||||||
:query nocache: do not use the cache when building the image
|
:query nocache: do not use the cache when building the image
|
||||||
:reqheader Content-type: should be set to ``"application/tar"``.
|
:reqheader Content-type: should be set to ``"application/tar"``.
|
||||||
|
:reqheader X-Registry-Auth: base64-encoded AuthConfig object
|
||||||
:statuscode 200: no error
|
:statuscode 200: no error
|
||||||
:statuscode 500: server error
|
:statuscode 500: server error
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue