From 345ee70d797fe34480771f5bedee16b340fd9b40 Mon Sep 17 00:00:00 2001 From: jw910731 Date: Tue, 26 Mar 2024 09:11:09 +0000 Subject: [PATCH 1/4] feat: add registry mirror environment variable option The KANIKO_REGISTRY_MIRROR environment variable can set to mirror of docker hub. Useful when rate limited by docker hub. --- envbuilder.go | 1 + 1 file changed, 1 insertion(+) diff --git a/envbuilder.go b/envbuilder.go index 7607a3ee..eaf7bf60 100644 --- a/envbuilder.go +++ b/envbuilder.go @@ -656,6 +656,7 @@ func Run(ctx context.Context, options Options) error { Insecure: options.Insecure, InsecurePull: options.Insecure, SkipTLSVerify: options.Insecure, + RegistryMirrors: strings.Split(os.Getenv("KANIKO_REGISTRY_MIRROR"), ";"), }, SrcContext: buildParams.BuildContext, }) From 2637085378baf43898e33eb742b12570909b5c5b Mon Sep 17 00:00:00 2001 From: jw910731 Date: Tue, 26 Mar 2024 15:30:39 +0000 Subject: [PATCH 2/4] doc: add comments to reference kaniko document and PR --- envbuilder.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/envbuilder.go b/envbuilder.go index eaf7bf60..a1345f5e 100644 --- a/envbuilder.go +++ b/envbuilder.go @@ -656,7 +656,11 @@ func Run(ctx context.Context, options Options) error { Insecure: options.Insecure, InsecurePull: options.Insecure, SkipTLSVerify: options.Insecure, - RegistryMirrors: strings.Split(os.Getenv("KANIKO_REGISTRY_MIRROR"), ";"), + // Enables registry mirror features in Kaniko, see more in link below + // https://github.com/GoogleContainerTools/kaniko?tab=readme-ov-file#flag---registry-mirror + // Related to PR #114 + // https://github.com/coder/envbuilder/pull/114 + RegistryMirrors: strings.Split(os.Getenv("·"), ";"), }, SrcContext: buildParams.BuildContext, }) From 52b9f76879556a6a6ba1896e36dbdc13ff1e906b Mon Sep 17 00:00:00 2001 From: jw910731 Date: Tue, 26 Mar 2024 15:48:02 +0000 Subject: [PATCH 3/4] fix: fix typo and improve robustness Deals with thet case when the KANIKO_REGISTRY_MIRROR is not set. --- envbuilder.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/envbuilder.go b/envbuilder.go index a1345f5e..8dbbaa7c 100644 --- a/envbuilder.go +++ b/envbuilder.go @@ -625,6 +625,10 @@ func Run(ctx context.Context, options Options) error { endStage := startStage("🏗️ Building image...") // At this point we have all the context, we can now build! + var registry_mirror []string = nil + if val, ok := os.LookupEnv("KANIKO_REGISTRY_MIRROR"); ok { + registry_mirror = strings.Split(val, ";") + } image, err := executor.DoBuild(&config.KanikoOptions{ // Boilerplate! CustomPlatform: platforms.Format(platforms.Normalize(platforms.DefaultSpec())), @@ -660,7 +664,7 @@ func Run(ctx context.Context, options Options) error { // https://github.com/GoogleContainerTools/kaniko?tab=readme-ov-file#flag---registry-mirror // Related to PR #114 // https://github.com/coder/envbuilder/pull/114 - RegistryMirrors: strings.Split(os.Getenv("·"), ";"), + RegistryMirrors: registry_mirror, }, SrcContext: buildParams.BuildContext, }) From 23972c2df8e12f8d31371cb892c07db182c3dee6 Mon Sep 17 00:00:00 2001 From: jw910731 Date: Tue, 26 Mar 2024 15:53:58 +0000 Subject: [PATCH 4/4] fix: fix coding style --- envbuilder.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/envbuilder.go b/envbuilder.go index 8dbbaa7c..160ca3fe 100644 --- a/envbuilder.go +++ b/envbuilder.go @@ -625,9 +625,9 @@ func Run(ctx context.Context, options Options) error { endStage := startStage("🏗️ Building image...") // At this point we have all the context, we can now build! - var registry_mirror []string = nil + registryMirror := []string{} if val, ok := os.LookupEnv("KANIKO_REGISTRY_MIRROR"); ok { - registry_mirror = strings.Split(val, ";") + registryMirror = strings.Split(val, ";") } image, err := executor.DoBuild(&config.KanikoOptions{ // Boilerplate! @@ -664,7 +664,7 @@ func Run(ctx context.Context, options Options) error { // https://github.com/GoogleContainerTools/kaniko?tab=readme-ov-file#flag---registry-mirror // Related to PR #114 // https://github.com/coder/envbuilder/pull/114 - RegistryMirrors: registry_mirror, + RegistryMirrors: registryMirror, }, SrcContext: buildParams.BuildContext, })