image: fix registry mirror setup

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
Yoan Blanc 2020-02-16 10:47:07 +01:00
parent edc4eb33f4
commit 474fdcf68d
No known key found for this signature in database
GPG Key ID: 6058CF4574298812
4 changed files with 12 additions and 7 deletions

View File

@ -15,6 +15,6 @@
# Test to make sure the executor builds an image correctly
# when no files are changed
FROM google-appengine/debian9@sha256:1d6a9a6d106bd795098f60f4abb7083626354fa6735e81743c7f8cfca11259f0
RUN echo "hey"
FROM library/debian:latest
RUN echo "hey"
MAINTAINER kaniko

View File

@ -229,7 +229,7 @@ func getGitRepo() string {
} else {
branch = os.Getenv("TRAVIS_BRANCH")
repoSlug = os.Getenv("TRAVIS_REPO_SLUG")
log.Printf("Travis CI pepo: %s branch: %s\n", repoSlug, branch)
log.Printf("Travis CI repo: %s branch: %s\n", repoSlug, branch)
}
return "github.com/" + repoSlug + "#refs/heads/" + branch
}
@ -303,7 +303,7 @@ func TestBuildViaRegistryMirror(t *testing.T) {
dockerRunFlags = append(dockerRunFlags, ExecutorImage,
"-f", dockerfile,
"-d", kanikoImage,
"--registry-mirror", "gcr.io",
"--registry-mirror", "us-mirror.gcr.io",
"-c", fmt.Sprintf("git://%s", repo))
kanikoCmd := exec.Command("docker", dockerRunFlags...)

View File

@ -40,10 +40,10 @@ type KanikoOptions struct {
ImageNameDigestFile string
OCILayoutPath string
RegistryMirror string
InsecureRegistries multiArg
SkipTLSVerifyRegistries multiArg
Destinations multiArg
BuildArgs multiArg
InsecureRegistries multiArg
SkipTLSVerifyRegistries multiArg
Insecure bool
SkipTLSVerify bool
InsecurePull bool

View File

@ -108,6 +108,7 @@ func remoteImage(image string, opts *config.KanikoOptions) (v1.Image, error) {
registryName := ref.Context().RegistryStr()
var newReg name.Registry
toSet := false
if opts.RegistryMirror != "" && registryName == name.DefaultRegistry {
registryName = opts.RegistryMirror
@ -116,6 +117,8 @@ func remoteImage(image string, opts *config.KanikoOptions) (v1.Image, error) {
if err != nil {
return nil, err
}
toSet = true
}
if opts.InsecurePull || opts.InsecureRegistries.Contains(registryName) {
@ -123,9 +126,11 @@ func remoteImage(image string, opts *config.KanikoOptions) (v1.Image, error) {
if err != nil {
return nil, err
}
toSet = true
}
if newReg != ref.Context().Registry {
if toSet {
if tag, ok := ref.(name.Tag); ok {
tag.Repository.Registry = newReg
ref = tag