Skip to content

Commit

Permalink
image: fix registry mirror setup
Browse files Browse the repository at this point in the history
Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
  • Loading branch information
greut committed Feb 16, 2020
1 parent edc4eb3 commit 474fdcf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions integration/dockerfiles/Dockerfile_registry_mirror
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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...)
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion pkg/util/image_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -116,16 +117,20 @@ 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) {
newReg, err = name.NewRegistry(registryName, name.WeakValidation, name.Insecure)
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
Expand Down

0 comments on commit 474fdcf

Please sign in to comment.