root: add --registry-mirror flag
Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
		
							parent
							
								
									cbf4de8108
								
							
						
					
					
						commit
						3873aa05e3
					
				|  | @ -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().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.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().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
 | // addHiddenFlags marks certain flags as hidden from the executor help text
 | ||||||
|  |  | ||||||
|  | @ -51,6 +51,7 @@ type KanikoOptions struct { | ||||||
| 	Cleanup                 bool | 	Cleanup                 bool | ||||||
| 	InsecureRegistries      multiArg | 	InsecureRegistries      multiArg | ||||||
| 	SkipTLSVerifyRegistries multiArg | 	SkipTLSVerifyRegistries multiArg | ||||||
|  | 	RegistryMirror          string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // WarmerOptions are options that are set by command line arguments to the cache warmer.
 | // WarmerOptions are options that are set by command line arguments to the cache warmer.
 | ||||||
|  |  | ||||||
|  | @ -101,11 +101,25 @@ func remoteImage(image string, opts *config.KanikoOptions) (v1.Image, error) { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	registryName := ref.Context().RegistryStr() | 	registryName := ref.Context().RegistryStr() | ||||||
| 	if opts.InsecurePull || opts.InsecureRegistries.Contains(registryName) { | 	var newReg name.Registry | ||||||
| 		newReg, err := name.NewRegistry(registryName, name.WeakValidation, name.Insecure) | 
 | ||||||
|  | 	if opts.RegistryMirror != "" && registryName == name.DefaultRegistry { | ||||||
|  | 		registryName = opts.RegistryMirror | ||||||
|  | 
 | ||||||
|  | 		newReg, err = name.NewRegistry(opts.RegistryMirror, name.StrictValidation) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, err | 			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 { | 		if tag, ok := ref.(name.Tag); ok { | ||||||
| 			tag.Repository.Registry = newReg | 			tag.Repository.Registry = newReg | ||||||
| 			ref = tag | 			ref = tag | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue