Skip to content

Commit

Permalink
move RegistryConfig to resolver package
Browse files Browse the repository at this point in the history
This allows using the resolver package without having to import
the buildkit daemon configuration.

Aliasses were added in the config package for backward compatibility,
and to allow for the config package to diverge / extend the internal
type if needed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Jun 5, 2021
1 parent 8e88c5d commit 097cbab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
22 changes: 7 additions & 15 deletions cmd/buildkitd/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

import "github.com/BurntSushi/toml"
import (
"github.com/BurntSushi/toml"
"github.com/moby/buildkit/util/resolver"
)

// Config provides containerd configuration data for the server
type Config struct {
Expand All @@ -9,7 +12,7 @@ type Config struct {
// Root is the path to a directory where buildkit will store persistent data
Root string `toml:"root"`

//Entitlements e.g. security.insecure, network.host
// Entitlements e.g. security.insecure, network.host
Entitlements []string `toml:"insecure-entitlements"`
// GRPC configuration settings
GRPC GRPCConfig `toml:"grpc"`
Expand All @@ -35,19 +38,8 @@ type GRPCConfig struct {
// MaxSendMsgSize int `toml:"max_send_message_size"`
}

type RegistryConfig struct {
Mirrors []string `toml:"mirrors"`
PlainHTTP *bool `toml:"http"`
Insecure *bool `toml:"insecure"`
RootCAs []string `toml:"ca"`
KeyPairs []TLSKeyPair `toml:"keypair"`
TLSConfigDir []string `toml:"tlsconfigdir"`
}

type TLSKeyPair struct {
Key string `toml:"key"`
Certificate string `toml:"cert"`
}
type RegistryConfig = resolver.RegistryConfig
type TLSKeyPair = resolver.TLSKeyPair

type TLSConfig struct {
Cert string `toml:"cert"`
Expand Down
23 changes: 18 additions & 5 deletions util/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import (
"time"

"github.com/containerd/containerd/remotes/docker"
"github.com/moby/buildkit/cmd/buildkitd/config"
"github.com/moby/buildkit/util/tracing"
"github.com/pkg/errors"
)

func fillInsecureOpts(host string, c config.RegistryConfig, h docker.RegistryHost) ([]docker.RegistryHost, error) {
func fillInsecureOpts(host string, c RegistryConfig, h docker.RegistryHost) ([]docker.RegistryHost, error) {
var hosts []docker.RegistryHost

tc, err := loadTLSConfig(c)
Expand Down Expand Up @@ -65,7 +64,7 @@ func fillInsecureOpts(host string, c config.RegistryConfig, h docker.RegistryHos
return hosts, nil
}

func loadTLSConfig(c config.RegistryConfig) (*tls.Config, error) {
func loadTLSConfig(c RegistryConfig) (*tls.Config, error) {
for _, d := range c.TLSConfigDir {
fs, err := ioutil.ReadDir(d)
if err != nil && !errors.Is(err, os.ErrNotExist) && !errors.Is(err, os.ErrPermission) {
Expand All @@ -76,7 +75,7 @@ func loadTLSConfig(c config.RegistryConfig) (*tls.Config, error) {
c.RootCAs = append(c.RootCAs, filepath.Join(d, f.Name()))
}
if strings.HasSuffix(f.Name(), ".cert") {
c.KeyPairs = append(c.KeyPairs, config.TLSKeyPair{
c.KeyPairs = append(c.KeyPairs, TLSKeyPair{
Certificate: filepath.Join(d, f.Name()),
Key: filepath.Join(d, strings.TrimSuffix(f.Name(), ".cert")+".key"),
})
Expand Down Expand Up @@ -115,8 +114,22 @@ func loadTLSConfig(c config.RegistryConfig) (*tls.Config, error) {
return tc, nil
}

type RegistryConfig struct {
Mirrors []string `toml:"mirrors"`
PlainHTTP *bool `toml:"http"`
Insecure *bool `toml:"insecure"`
RootCAs []string `toml:"ca"`
KeyPairs []TLSKeyPair `toml:"keypair"`
TLSConfigDir []string `toml:"tlsconfigdir"`
}

type TLSKeyPair struct {
Key string `toml:"key"`
Certificate string `toml:"cert"`
}

// NewRegistryConfig converts registry config to docker.RegistryHosts callback
func NewRegistryConfig(m map[string]config.RegistryConfig) docker.RegistryHosts {
func NewRegistryConfig(m map[string]RegistryConfig) docker.RegistryHosts {
return docker.Registries(
func(host string) ([]docker.RegistryHost, error) {
c, ok := m[host]
Expand Down

0 comments on commit 097cbab

Please sign in to comment.