mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #5158 from vieux/refactor_build_only_configFile
refactor build job to know only configFile
This commit is contained in:
commit
e5ad715e59
4 changed files with 26 additions and 30 deletions
|
@ -829,8 +829,6 @@ func postBuild(eng *engine.Engine, version version.Version, w http.ResponseWrite
|
||||||
return fmt.Errorf("Multipart upload for build is no longer supported. Please upgrade your docker client.")
|
return fmt.Errorf("Multipart upload for build is no longer supported. Please upgrade your docker client.")
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
authEncoded = r.Header.Get("X-Registry-Auth")
|
|
||||||
authConfig = ®istry.AuthConfig{}
|
|
||||||
configFileEncoded = r.Header.Get("X-Registry-Config")
|
configFileEncoded = r.Header.Get("X-Registry-Config")
|
||||||
configFile = ®istry.ConfigFile{}
|
configFile = ®istry.ConfigFile{}
|
||||||
job = eng.Job("build")
|
job = eng.Job("build")
|
||||||
|
@ -840,12 +838,18 @@ func postBuild(eng *engine.Engine, version version.Version, w http.ResponseWrite
|
||||||
// Both headers will be parsed and sent along to the daemon, but if a non-empty
|
// Both headers will be parsed and sent along to the daemon, but if a non-empty
|
||||||
// ConfigFile is present, any value provided as an AuthConfig directly will
|
// ConfigFile is present, any value provided as an AuthConfig directly will
|
||||||
// be overridden. See BuildFile::CmdFrom for details.
|
// be overridden. See BuildFile::CmdFrom for details.
|
||||||
|
var (
|
||||||
|
authEncoded = r.Header.Get("X-Registry-Auth")
|
||||||
|
authConfig = ®istry.AuthConfig{}
|
||||||
|
)
|
||||||
if version.LessThan("1.9") && authEncoded != "" {
|
if version.LessThan("1.9") && authEncoded != "" {
|
||||||
authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
|
authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
|
||||||
if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
|
if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
|
||||||
// for a pull it is not an error if no auth was given
|
// 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
|
// to increase compatibility with the existing api it is defaulting to be empty
|
||||||
authConfig = ®istry.AuthConfig{}
|
authConfig = ®istry.AuthConfig{}
|
||||||
|
} else {
|
||||||
|
configFile.Configs[authConfig.ServerAddress] = *authConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -870,8 +874,7 @@ func postBuild(eng *engine.Engine, version version.Version, w http.ResponseWrite
|
||||||
job.Setenv("q", r.FormValue("q"))
|
job.Setenv("q", r.FormValue("q"))
|
||||||
job.Setenv("nocache", r.FormValue("nocache"))
|
job.Setenv("nocache", r.FormValue("nocache"))
|
||||||
job.Setenv("rm", r.FormValue("rm"))
|
job.Setenv("rm", r.FormValue("rm"))
|
||||||
job.SetenvJson("authConfig", authConfig)
|
job.SetenvJson("auth", configFile)
|
||||||
job.SetenvJson("configFile", configFile)
|
|
||||||
|
|
||||||
if err := job.Run(); err != nil {
|
if err := job.Run(); err != nil {
|
||||||
if !job.Stdout.Used() {
|
if !job.Stdout.Used() {
|
||||||
|
|
|
@ -394,7 +394,7 @@ func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, u
|
||||||
}
|
}
|
||||||
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
||||||
|
|
||||||
buildfile := server.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, useCache, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
|
buildfile := server.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, useCache, false, ioutil.Discard, utils.NewStreamFormatter(false), nil)
|
||||||
id, err := buildfile.Build(context.Archive(dockerfile, t))
|
id, err := buildfile.Build(context.Archive(dockerfile, t))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -828,7 +828,7 @@ func TestForbiddenContextPath(t *testing.T) {
|
||||||
}
|
}
|
||||||
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
||||||
|
|
||||||
buildfile := server.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
|
buildfile := server.NewBuildFile(srv, ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false), nil)
|
||||||
_, err = buildfile.Build(context.Archive(dockerfile, t))
|
_, err = buildfile.Build(context.Archive(dockerfile, t))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -874,7 +874,7 @@ func TestBuildADDFileNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
||||||
|
|
||||||
buildfile := server.NewBuildFile(mkServerFromEngine(eng, t), ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false), nil, nil)
|
buildfile := server.NewBuildFile(mkServerFromEngine(eng, t), ioutil.Discard, ioutil.Discard, false, true, false, ioutil.Discard, utils.NewStreamFormatter(false), nil)
|
||||||
_, err = buildfile.Build(context.Archive(dockerfile, t))
|
_, err = buildfile.Build(context.Archive(dockerfile, t))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
@ -49,7 +49,6 @@ type buildFile struct {
|
||||||
utilizeCache bool
|
utilizeCache bool
|
||||||
rm bool
|
rm bool
|
||||||
|
|
||||||
authConfig *registry.AuthConfig
|
|
||||||
configFile *registry.ConfigFile
|
configFile *registry.ConfigFile
|
||||||
|
|
||||||
tmpContainers map[string]struct{}
|
tmpContainers map[string]struct{}
|
||||||
|
@ -80,20 +79,10 @@ 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)
|
||||||
pullRegistryAuth := b.authConfig
|
|
||||||
if len(b.configFile.Configs) > 0 {
|
|
||||||
// The request came with a full auth config file, we prefer to use that
|
|
||||||
endpoint, _, err := registry.ResolveRepositoryName(remote)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
resolvedAuth := b.configFile.ResolveAuthConfig(endpoint)
|
|
||||||
pullRegistryAuth = &resolvedAuth
|
|
||||||
}
|
|
||||||
job := b.srv.Eng.Job("pull", remote, tag)
|
job := b.srv.Eng.Job("pull", remote, tag)
|
||||||
job.SetenvBool("json", b.sf.Json())
|
job.SetenvBool("json", b.sf.Json())
|
||||||
job.SetenvBool("parallel", true)
|
job.SetenvBool("parallel", true)
|
||||||
job.SetenvJson("authConfig", pullRegistryAuth)
|
job.SetenvJson("auth", b.configFile)
|
||||||
job.Stdout.Add(b.outOld)
|
job.Stdout.Add(b.outOld)
|
||||||
if err := job.Run(); err != nil {
|
if err := job.Run(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -832,7 +821,7 @@ func stripComments(raw []byte) string {
|
||||||
return strings.Join(out, "\n")
|
return strings.Join(out, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBuildFile(srv *Server, outStream, errStream io.Writer, verbose, utilizeCache, rm bool, outOld io.Writer, sf *utils.StreamFormatter, auth *registry.AuthConfig, authConfigFile *registry.ConfigFile) BuildFile {
|
func NewBuildFile(srv *Server, outStream, errStream io.Writer, verbose, utilizeCache, rm bool, outOld io.Writer, sf *utils.StreamFormatter, configFile *registry.ConfigFile) BuildFile {
|
||||||
return &buildFile{
|
return &buildFile{
|
||||||
runtime: srv.runtime,
|
runtime: srv.runtime,
|
||||||
srv: srv,
|
srv: srv,
|
||||||
|
@ -845,8 +834,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,
|
configFile: configFile,
|
||||||
configFile: authConfigFile,
|
|
||||||
outOld: outOld,
|
outOld: outOld,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,13 +448,11 @@ func (srv *Server) Build(job *engine.Job) engine.Status {
|
||||||
suppressOutput = job.GetenvBool("q")
|
suppressOutput = job.GetenvBool("q")
|
||||||
noCache = job.GetenvBool("nocache")
|
noCache = job.GetenvBool("nocache")
|
||||||
rm = job.GetenvBool("rm")
|
rm = job.GetenvBool("rm")
|
||||||
authConfig = ®istry.AuthConfig{}
|
|
||||||
configFile = ®istry.ConfigFile{}
|
configFile = ®istry.ConfigFile{}
|
||||||
tag string
|
tag string
|
||||||
context io.ReadCloser
|
context io.ReadCloser
|
||||||
)
|
)
|
||||||
job.GetenvJson("authConfig", authConfig)
|
job.GetenvJson("auth", configFile)
|
||||||
job.GetenvJson("configFile", configFile)
|
|
||||||
repoName, tag = utils.ParseRepositoryTag(repoName)
|
repoName, tag = utils.ParseRepositoryTag(repoName)
|
||||||
|
|
||||||
if remoteURL == "" {
|
if remoteURL == "" {
|
||||||
|
@ -506,7 +504,7 @@ func (srv *Server) Build(job *engine.Job) engine.Status {
|
||||||
Writer: job.Stdout,
|
Writer: job.Stdout,
|
||||||
StreamFormatter: sf,
|
StreamFormatter: sf,
|
||||||
},
|
},
|
||||||
!suppressOutput, !noCache, rm, job.Stdout, sf, authConfig, configFile)
|
!suppressOutput, !noCache, rm, job.Stdout, sf, configFile)
|
||||||
id, err := b.Build(context)
|
id, err := b.Build(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
|
@ -1386,16 +1384,23 @@ func (srv *Server) ImagePull(job *engine.Job) engine.Status {
|
||||||
localName = job.Args[0]
|
localName = job.Args[0]
|
||||||
tag string
|
tag string
|
||||||
sf = utils.NewStreamFormatter(job.GetenvBool("json"))
|
sf = utils.NewStreamFormatter(job.GetenvBool("json"))
|
||||||
authConfig = ®istry.AuthConfig{}
|
authConfig registry.AuthConfig
|
||||||
|
configFile = ®istry.ConfigFile{}
|
||||||
metaHeaders map[string][]string
|
metaHeaders map[string][]string
|
||||||
)
|
)
|
||||||
if len(job.Args) > 1 {
|
if len(job.Args) > 1 {
|
||||||
tag = job.Args[1]
|
tag = job.Args[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
job.GetenvJson("authConfig", authConfig)
|
job.GetenvJson("auth", configFile)
|
||||||
job.GetenvJson("metaHeaders", metaHeaders)
|
job.GetenvJson("metaHeaders", metaHeaders)
|
||||||
|
|
||||||
|
endpoint, _, err := registry.ResolveRepositoryName(localName)
|
||||||
|
if err != nil {
|
||||||
|
return job.Error(err)
|
||||||
|
}
|
||||||
|
authConfig = configFile.ResolveAuthConfig(endpoint)
|
||||||
|
|
||||||
c, err := srv.poolAdd("pull", localName+":"+tag)
|
c, err := srv.poolAdd("pull", localName+":"+tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if c != nil {
|
if c != nil {
|
||||||
|
@ -1414,12 +1419,12 @@ func (srv *Server) ImagePull(job *engine.Job) engine.Status {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint, err := registry.ExpandAndVerifyRegistryUrl(hostname)
|
endpoint, err = registry.ExpandAndVerifyRegistryUrl(hostname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := registry.NewRegistry(authConfig, srv.HTTPRequestFactory(metaHeaders), endpoint)
|
r, err := registry.NewRegistry(&authConfig, srv.HTTPRequestFactory(metaHeaders), endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return job.Error(err)
|
return job.Error(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue