From 3d604da2b8850b5bf076395573bc954c28b43dac Mon Sep 17 00:00:00 2001 From: Vladimir Yarotsky Date: Thu, 23 Jun 2022 09:33:58 -0700 Subject: [PATCH] Add support for insecure registries Signed-off-by: Vladimir Yarotsky --- buildkitd.go | 14 +++++++++++--- buildkitd_config.go | 4 ++-- buildkitd_test.go | 7 ++++--- testdata/buildkitd-config/cfg.toml | 8 ++++++++ testdata/buildkitd-config/mirrors.toml | 3 --- types.go | 3 ++- 6 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 testdata/buildkitd-config/cfg.toml delete mode 100644 testdata/buildkitd-config/mirrors.toml diff --git a/buildkitd.go b/buildkitd.go index a2e65cc..87fad18 100644 --- a/buildkitd.go +++ b/buildkitd.go @@ -148,16 +148,24 @@ func (buildkitd *Buildkitd) Cleanup() error { func generateConfig(req Request, configPath string) error { var config BuildkitdConfig + var registryConfigs map[string]RegistryConfig + registryConfigs = make(map[string]RegistryConfig) + if len(req.Config.RegistryMirrors) > 0 { - var registryConfigs map[string]RegistryConfig - registryConfigs = make(map[string]RegistryConfig) registryConfigs["docker.io"] = RegistryConfig{ Mirrors: req.Config.RegistryMirrors, } + } - config.Registries = registryConfigs + for _, r := range req.Config.InsecureRegistries { + registryConfigs[r] = RegistryConfig{ + Insecure: true, + PlainHTTP: true, + } } + config.Registries = registryConfigs + err := os.MkdirAll(filepath.Dir(configPath), 0700) if err != nil { return err diff --git a/buildkitd_config.go b/buildkitd_config.go index 0c5c65e..8730280 100644 --- a/buildkitd_config.go +++ b/buildkitd_config.go @@ -6,8 +6,8 @@ type BuildkitdConfig struct { type RegistryConfig struct { Mirrors []string `toml:"mirrors"` - PlainHTTP *bool `toml:"http"` - Insecure *bool `toml:"insecure"` + PlainHTTP bool `toml:"http"` + Insecure bool `toml:"insecure"` RootCAs []string `toml:"ca"` KeyPairs []TLSKeyPair `toml:"keypair"` TLSConfigDir []string `toml:"tlsconfigdir"` diff --git a/buildkitd_test.go b/buildkitd_test.go index 0d78f6c..52074e0 100644 --- a/buildkitd_test.go +++ b/buildkitd_test.go @@ -58,16 +58,17 @@ func (s *BuildkitdSuite) TestGenerateConfig() { var err error s.req.Config.RegistryMirrors = []string{"hub.docker.io"} + s.req.Config.InsecureRegistries = []string{"my-registry:5000"} s.buildkitd, err = task.SpawnBuildkitd(s.req, &task.BuildkitdOpts{ - ConfigPath: s.configPath("mirrors.toml"), + ConfigPath: s.configPath("cfg.toml"), }) s.NoError(err) - configContent, err := ioutil.ReadFile(s.configPath("mirrors.toml")) + configContent, err := ioutil.ReadFile(s.configPath("cfg.toml")) s.NoError(err) - expectedContent, err := ioutil.ReadFile("testdata/buildkitd-config/mirrors.toml") + expectedContent, err := ioutil.ReadFile("testdata/buildkitd-config/cfg.toml") s.NoError(err) s.Equal(expectedContent, configContent) diff --git a/testdata/buildkitd-config/cfg.toml b/testdata/buildkitd-config/cfg.toml new file mode 100644 index 0000000..d039704 --- /dev/null +++ b/testdata/buildkitd-config/cfg.toml @@ -0,0 +1,8 @@ +[registry] + [registry."docker.io"] + mirrors = ["hub.docker.io"] + http = false + insecure = false + [registry."my-registry:5000"] + http = true + insecure = true diff --git a/testdata/buildkitd-config/mirrors.toml b/testdata/buildkitd-config/mirrors.toml deleted file mode 100644 index 71eb79b..0000000 --- a/testdata/buildkitd-config/mirrors.toml +++ /dev/null @@ -1,3 +0,0 @@ -[registry] - [registry."docker.io"] - mirrors = ["hub.docker.io"] diff --git a/types.go b/types.go index 1249e2a..ddc5a9b 100644 --- a/types.go +++ b/types.go @@ -80,7 +80,8 @@ type Config struct { ImagePlatform string `json:"image_platform" envconfig:"optional"` - RegistryCache string `json:"registry_cache" envconfig:"optional"` + RegistryCache string `json:"registry_cache" envconfig:"optional"` + InsecureRegistries []string `json:"insecure_registries" envconfig:"optional"` } // ImageMetadata is the schema written to manifest.json when producing the