mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #14139 from jlhawn/fix_build_with_auth
[api, builder] Fix build auth config
This commit is contained in:
commit
dd408891ba
4 changed files with 24 additions and 24 deletions
|
@ -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 {
|
func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||||
var (
|
var (
|
||||||
authConfig = &cliconfig.AuthConfig{}
|
authConfigs = map[string]cliconfig.AuthConfig{}
|
||||||
configFileEncoded = r.Header.Get("X-Registry-Config")
|
authConfigsEncoded = r.Header.Get("X-Registry-Config")
|
||||||
configFile = &cliconfig.ConfigFile{}
|
buildConfig = builder.NewBuildConfig()
|
||||||
buildConfig = builder.NewBuildConfig()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if configFileEncoded != "" {
|
if authConfigsEncoded != "" {
|
||||||
configFileJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(configFileEncoded))
|
authConfigsJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authConfigsEncoded))
|
||||||
if err := json.NewDecoder(configFileJson).Decode(configFile); err != nil {
|
if err := json.NewDecoder(authConfigsJSON).Decode(&authConfigs); 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
|
||||||
configFile = &cliconfig.ConfigFile{}
|
// 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.SuppressOutput = boolValue(r, "q")
|
||||||
buildConfig.NoCache = boolValue(r, "nocache")
|
buildConfig.NoCache = boolValue(r, "nocache")
|
||||||
buildConfig.ForceRemove = boolValue(r, "forcerm")
|
buildConfig.ForceRemove = boolValue(r, "forcerm")
|
||||||
buildConfig.AuthConfig = authConfig
|
buildConfig.AuthConfigs = authConfigs
|
||||||
buildConfig.ConfigFile = configFile
|
|
||||||
buildConfig.MemorySwap = int64ValueOrZero(r, "memswap")
|
buildConfig.MemorySwap = int64ValueOrZero(r, "memswap")
|
||||||
buildConfig.Memory = int64ValueOrZero(r, "memory")
|
buildConfig.Memory = int64ValueOrZero(r, "memory")
|
||||||
buildConfig.CpuShares = int64ValueOrZero(r, "cpushares")
|
buildConfig.CpuShares = int64ValueOrZero(r, "cpushares")
|
||||||
|
|
|
@ -98,8 +98,8 @@ type Builder struct {
|
||||||
// the final configs of the Dockerfile but dont want the layers
|
// the final configs of the Dockerfile but dont want the layers
|
||||||
disableCommit bool
|
disableCommit bool
|
||||||
|
|
||||||
AuthConfig *cliconfig.AuthConfig
|
// Registry server auth configs used to pull images when handling `FROM`.
|
||||||
ConfigFile *cliconfig.ConfigFile
|
AuthConfigs map[string]cliconfig.AuthConfig
|
||||||
|
|
||||||
// Deprecated, original writer used for ImagePull. To be removed.
|
// Deprecated, original writer used for ImagePull. To be removed.
|
||||||
OutOld io.Writer
|
OutOld io.Writer
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/builder/parser"
|
"github.com/docker/docker/builder/parser"
|
||||||
|
"github.com/docker/docker/cliconfig"
|
||||||
"github.com/docker/docker/daemon"
|
"github.com/docker/docker/daemon"
|
||||||
"github.com/docker/docker/graph"
|
"github.com/docker/docker/graph"
|
||||||
imagepkg "github.com/docker/docker/image"
|
imagepkg "github.com/docker/docker/image"
|
||||||
|
@ -454,15 +455,19 @@ func (b *Builder) pullImage(name string) (*imagepkg.Image, error) {
|
||||||
tag = "latest"
|
tag = "latest"
|
||||||
}
|
}
|
||||||
|
|
||||||
pullRegistryAuth := b.AuthConfig
|
pullRegistryAuth := &cliconfig.AuthConfig{}
|
||||||
if len(b.ConfigFile.AuthConfigs) > 0 {
|
if len(b.AuthConfigs) > 0 {
|
||||||
// The request came with a full auth config file, we prefer to use that
|
// The request came with a full auth config file, we prefer to use that
|
||||||
repoInfo, err := b.Daemon.RegistryService.ResolveRepository(remote)
|
repoInfo, err := b.Daemon.RegistryService.ResolveRepository(remote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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{
|
imagePullConfig := &graph.ImagePullConfig{
|
||||||
|
|
|
@ -59,8 +59,7 @@ type Config struct {
|
||||||
CpuSetCpus string
|
CpuSetCpus string
|
||||||
CpuSetMems string
|
CpuSetMems string
|
||||||
CgroupParent string
|
CgroupParent string
|
||||||
AuthConfig *cliconfig.AuthConfig
|
AuthConfigs map[string]cliconfig.AuthConfig
|
||||||
ConfigFile *cliconfig.ConfigFile
|
|
||||||
|
|
||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
Context io.ReadCloser
|
Context io.ReadCloser
|
||||||
|
@ -85,9 +84,8 @@ func (b *Config) WaitCancelled() <-chan struct{} {
|
||||||
|
|
||||||
func NewBuildConfig() *Config {
|
func NewBuildConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
AuthConfig: &cliconfig.AuthConfig{},
|
AuthConfigs: map[string]cliconfig.AuthConfig{},
|
||||||
ConfigFile: &cliconfig.ConfigFile{},
|
cancelled: make(chan struct{}),
|
||||||
cancelled: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,8 +188,7 @@ func Build(d *daemon.Daemon, buildConfig *Config) error {
|
||||||
Pull: buildConfig.Pull,
|
Pull: buildConfig.Pull,
|
||||||
OutOld: buildConfig.Stdout,
|
OutOld: buildConfig.Stdout,
|
||||||
StreamFormatter: sf,
|
StreamFormatter: sf,
|
||||||
AuthConfig: buildConfig.AuthConfig,
|
AuthConfigs: buildConfig.AuthConfigs,
|
||||||
ConfigFile: buildConfig.ConfigFile,
|
|
||||||
dockerfileName: buildConfig.DockerfileName,
|
dockerfileName: buildConfig.DockerfileName,
|
||||||
cpuShares: buildConfig.CpuShares,
|
cpuShares: buildConfig.CpuShares,
|
||||||
cpuPeriod: buildConfig.CpuPeriod,
|
cpuPeriod: buildConfig.CpuPeriod,
|
||||||
|
|
Loading…
Reference in a new issue