diff --git a/api/server/server.go b/api/server/server.go index 036f1dc34b..ea93916c83 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -1221,18 +1221,17 @@ func (s *Server) getImagesByName(version version.Version, w http.ResponseWriter, func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error { var ( - authConfig = &cliconfig.AuthConfig{} - configFileEncoded = r.Header.Get("X-Registry-Config") - configFile = &cliconfig.ConfigFile{} - buildConfig = builder.NewBuildConfig() + authConfigs = map[string]cliconfig.AuthConfig{} + authConfigsEncoded = r.Header.Get("X-Registry-Config") + buildConfig = builder.NewBuildConfig() ) - if configFileEncoded != "" { - configFileJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(configFileEncoded)) - if err := json.NewDecoder(configFileJson).Decode(configFile); err != nil { + if authConfigsEncoded != "" { + authConfigsJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authConfigsEncoded)) + if err := json.NewDecoder(authConfigsJSON).Decode(&authConfigs); 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 - configFile = &cliconfig.ConfigFile{} + // to increase compatibility with the existing api it is defaulting + // to be empty. } } @@ -1259,8 +1258,7 @@ func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *ht buildConfig.SuppressOutput = boolValue(r, "q") buildConfig.NoCache = boolValue(r, "nocache") buildConfig.ForceRemove = boolValue(r, "forcerm") - buildConfig.AuthConfig = authConfig - buildConfig.ConfigFile = configFile + buildConfig.AuthConfigs = authConfigs buildConfig.MemorySwap = int64ValueOrZero(r, "memswap") buildConfig.Memory = int64ValueOrZero(r, "memory") buildConfig.CpuShares = int64ValueOrZero(r, "cpushares") diff --git a/builder/evaluator.go b/builder/evaluator.go index 62f86bb889..24f15c77ec 100644 --- a/builder/evaluator.go +++ b/builder/evaluator.go @@ -98,8 +98,8 @@ type Builder struct { // the final configs of the Dockerfile but dont want the layers disableCommit bool - AuthConfig *cliconfig.AuthConfig - ConfigFile *cliconfig.ConfigFile + // Registry server auth configs used to pull images when handling `FROM`. + AuthConfigs map[string]cliconfig.AuthConfig // Deprecated, original writer used for ImagePull. To be removed. OutOld io.Writer diff --git a/builder/internals.go b/builder/internals.go index 54f9f2cb57..9fbde2914f 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -21,6 +21,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/docker/docker/builder/parser" + "github.com/docker/docker/cliconfig" "github.com/docker/docker/daemon" "github.com/docker/docker/graph" imagepkg "github.com/docker/docker/image" @@ -454,15 +455,19 @@ func (b *Builder) pullImage(name string) (*imagepkg.Image, error) { tag = "latest" } - pullRegistryAuth := b.AuthConfig - if len(b.ConfigFile.AuthConfigs) > 0 { + pullRegistryAuth := &cliconfig.AuthConfig{} + if len(b.AuthConfigs) > 0 { // The request came with a full auth config file, we prefer to use that repoInfo, err := b.Daemon.RegistryService.ResolveRepository(remote) if err != nil { return nil, err } - resolvedAuth := registry.ResolveAuthConfig(b.ConfigFile, repoInfo.Index) - pullRegistryAuth = &resolvedAuth + + resolvedConfig := registry.ResolveAuthConfig( + &cliconfig.ConfigFile{AuthConfigs: b.AuthConfigs}, + repoInfo.Index, + ) + pullRegistryAuth = &resolvedConfig } imagePullConfig := &graph.ImagePullConfig{ diff --git a/builder/job.go b/builder/job.go index 6668fa947a..26b37b6ccc 100644 --- a/builder/job.go +++ b/builder/job.go @@ -59,8 +59,7 @@ type Config struct { CpuSetCpus string CpuSetMems string CgroupParent string - AuthConfig *cliconfig.AuthConfig - ConfigFile *cliconfig.ConfigFile + AuthConfigs map[string]cliconfig.AuthConfig Stdout io.Writer Context io.ReadCloser @@ -85,9 +84,8 @@ func (b *Config) WaitCancelled() <-chan struct{} { func NewBuildConfig() *Config { return &Config{ - AuthConfig: &cliconfig.AuthConfig{}, - ConfigFile: &cliconfig.ConfigFile{}, - cancelled: make(chan struct{}), + AuthConfigs: map[string]cliconfig.AuthConfig{}, + cancelled: make(chan struct{}), } } @@ -190,8 +188,7 @@ func Build(d *daemon.Daemon, buildConfig *Config) error { Pull: buildConfig.Pull, OutOld: buildConfig.Stdout, StreamFormatter: sf, - AuthConfig: buildConfig.AuthConfig, - ConfigFile: buildConfig.ConfigFile, + AuthConfigs: buildConfig.AuthConfigs, dockerfileName: buildConfig.DockerfileName, cpuShares: buildConfig.CpuShares, cpuPeriod: buildConfig.CpuPeriod,