root: add --registry-mirror flag

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
Yoan Blanc 2019-10-25 11:34:49 +02:00
parent cbf4de8108
commit 3873aa05e3
No known key found for this signature in database
GPG Key ID: 6058CF4574298812
3 changed files with 18 additions and 2 deletions

View File

@ -140,6 +140,7 @@ func addKanikoOptionsFlags(cmd *cobra.Command) {
RootCmd.PersistentFlags().DurationVarP(&opts.CacheTTL, "cache-ttl", "", time.Hour*336, "Cache timeout in hours. Defaults to two weeks.")
RootCmd.PersistentFlags().VarP(&opts.InsecureRegistries, "insecure-registry", "", "Insecure registry using plain HTTP to push and pull. Set it repeatedly for multiple registries.")
RootCmd.PersistentFlags().VarP(&opts.SkipTLSVerifyRegistries, "skip-tls-verify-registry", "", "Insecure registry ignoring TLS verify to push and pull. Set it repeatedly for multiple registries.")
RootCmd.PersistentFlags().StringVarP(&opts.RegistryMirror, "registry-mirror", "", "", "Registry mirror to use has pull-through cache instead of docker.io.")
}
// addHiddenFlags marks certain flags as hidden from the executor help text

View File

@ -51,6 +51,7 @@ type KanikoOptions struct {
Cleanup bool
InsecureRegistries multiArg
SkipTLSVerifyRegistries multiArg
RegistryMirror string
}
// WarmerOptions are options that are set by command line arguments to the cache warmer.

View File

@ -101,11 +101,25 @@ func remoteImage(image string, opts *config.KanikoOptions) (v1.Image, error) {
}
registryName := ref.Context().RegistryStr()
if opts.InsecurePull || opts.InsecureRegistries.Contains(registryName) {
newReg, err := name.NewRegistry(registryName, name.WeakValidation, name.Insecure)
var newReg name.Registry
if opts.RegistryMirror != "" && registryName == name.DefaultRegistry {
registryName = opts.RegistryMirror
newReg, err = name.NewRegistry(opts.RegistryMirror, name.StrictValidation)
if err != nil {
return nil, err
}
}
if opts.InsecurePull || opts.InsecureRegistries.Contains(registryName) {
newReg, err = name.NewRegistry(registryName, name.WeakValidation, name.Insecure)
if err != nil {
return nil, err
}
}
if newReg != ref.Context().Registry {
if tag, ok := ref.(name.Tag); ok {
tag.Repository.Registry = newReg
ref = tag