fix registry auth (#4146)

Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
Avi Deitcher 2025-07-15 14:07:20 +03:00 committed by GitHub
parent 33ee27971d
commit bc44cb899c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View File

@ -101,6 +101,6 @@ func pkgCmd() *cobra.Command {
cmd.PersistentFlags().BoolVar(&dirty, "force-dirty", false, "Force the pkg(s) to be considered dirty")
cmd.PersistentFlags().BoolVar(&devMode, "dev", false, "Force org and hash to $USER and \"dev\" respectively")
cmd.PersistentFlags().StringSliceVar(&registryCreds, "registry-creds", nil, "Registry auths to use for building images, format is <registry>=<username>:<password> OR <registry>=<registry-token>. If no username is provided, it is treated as a registry token. <registry> must be a URL, e.g. 'https://index.docker.io/'. May be provided as many times as desired. Will override anything in your default.")
cmd.PersistentFlags().StringSliceVar(&registryCreds, "registry-creds", nil, "Registry auths to use for building images, format is <registry>=<username>:<password> OR <registry>=<registry-token-base64>; do NOT forget to base64 encode it. If no username is provided, it is treated as a registry token. <registry> must be a URL, e.g. 'https://index.docker.io/'. May be provided as many times as desired. Will override anything in your default.")
return cmd
}

View File

@ -593,10 +593,13 @@ func (dr *dockerRunnerImpl) build(ctx context.Context, tag, pkg, dockerContext,
cf = configfile.New("custom")
// merge imageBuildOpts.RegistryAuths into dockercfg
for registry, auth := range imageBuildOpts.RegistryAuths {
bareRegistry := strings.TrimPrefix(registry, "https://")
bareRegistry = strings.TrimPrefix(bareRegistry, "http://")
cf.AuthConfigs[bareRegistry] = dockerconfigtypes.AuthConfig{
ServerAddress: bareRegistry,
// special case for docker.io
registryWithoutScheme := strings.TrimPrefix(registry, "https://")
registryWithoutScheme = strings.TrimPrefix(registryWithoutScheme, "http://")
if registryWithoutScheme == "docker.io" || registryWithoutScheme == "index.docker.io" || registryWithoutScheme == "registry-1.docker.io" {
registry = "https://index.docker.io/v1/"
}
cf.AuthConfigs[registry] = dockerconfigtypes.AuthConfig{
Username: auth.Username,
Password: auth.Password,
RegistryToken: auth.RegistryToken,