move RegistryConfig to resolver package
This allows using the resolver package without having to import the buildkit daemon configuration. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>v0.9
parent
67953d67c0
commit
12c9920fb5
|
@ -1,6 +1,9 @@
|
||||||
package config
|
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
|
// Config provides containerd configuration data for the server
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -19,7 +22,7 @@ type Config struct {
|
||||||
Containerd ContainerdConfig `toml:"containerd"`
|
Containerd ContainerdConfig `toml:"containerd"`
|
||||||
} `toml:"worker"`
|
} `toml:"worker"`
|
||||||
|
|
||||||
Registries map[string]RegistryConfig `toml:"registry"`
|
Registries map[string]resolver.RegistryConfig `toml:"registry"`
|
||||||
|
|
||||||
DNS *DNSConfig `toml:"dns"`
|
DNS *DNSConfig `toml:"dns"`
|
||||||
}
|
}
|
||||||
|
@ -35,20 +38,6 @@ type GRPCConfig struct {
|
||||||
// MaxSendMsgSize int `toml:"max_send_message_size"`
|
// 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 TLSConfig struct {
|
type TLSConfig struct {
|
||||||
Cert string `toml:"cert"`
|
Cert string `toml:"cert"`
|
||||||
Key string `toml:"key"`
|
Key string `toml:"key"`
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"github.com/containerd/containerd/remotes"
|
"github.com/containerd/containerd/remotes"
|
||||||
"github.com/containerd/containerd/remotes/docker"
|
"github.com/containerd/containerd/remotes/docker"
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
"github.com/moby/buildkit/cmd/buildkitd/config"
|
|
||||||
"github.com/moby/buildkit/session"
|
"github.com/moby/buildkit/session"
|
||||||
"github.com/moby/buildkit/util/flightcontrol"
|
"github.com/moby/buildkit/util/flightcontrol"
|
||||||
"github.com/moby/buildkit/util/imageutil"
|
"github.com/moby/buildkit/util/imageutil"
|
||||||
|
@ -55,7 +54,7 @@ func Push(ctx context.Context, sm *session.Manager, sid string, provider content
|
||||||
if insecure {
|
if insecure {
|
||||||
insecureTrue := true
|
insecureTrue := true
|
||||||
httpTrue := true
|
httpTrue := true
|
||||||
hosts = resolver.NewRegistryConfig(map[string]config.RegistryConfig{
|
hosts = resolver.NewRegistryConfig(map[string]resolver.RegistryConfig{
|
||||||
reference.Domain(parsed): {
|
reference.Domain(parsed): {
|
||||||
Insecure: &insecureTrue,
|
Insecure: &insecureTrue,
|
||||||
PlainHTTP: &httpTrue,
|
PlainHTTP: &httpTrue,
|
||||||
|
|
|
@ -13,12 +13,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd/remotes/docker"
|
"github.com/containerd/containerd/remotes/docker"
|
||||||
"github.com/moby/buildkit/cmd/buildkitd/config"
|
|
||||||
"github.com/moby/buildkit/util/tracing"
|
"github.com/moby/buildkit/util/tracing"
|
||||||
"github.com/pkg/errors"
|
"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
|
var hosts []docker.RegistryHost
|
||||||
|
|
||||||
tc, err := loadTLSConfig(c)
|
tc, err := loadTLSConfig(c)
|
||||||
|
@ -65,7 +64,7 @@ func fillInsecureOpts(host string, c config.RegistryConfig, h docker.RegistryHos
|
||||||
return hosts, nil
|
return hosts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadTLSConfig(c config.RegistryConfig) (*tls.Config, error) {
|
func loadTLSConfig(c RegistryConfig) (*tls.Config, error) {
|
||||||
for _, d := range c.TLSConfigDir {
|
for _, d := range c.TLSConfigDir {
|
||||||
fs, err := ioutil.ReadDir(d)
|
fs, err := ioutil.ReadDir(d)
|
||||||
if err != nil && !errors.Is(err, os.ErrNotExist) && !errors.Is(err, os.ErrPermission) {
|
if err != nil && !errors.Is(err, os.ErrNotExist) && !errors.Is(err, os.ErrPermission) {
|
||||||
|
@ -76,7 +75,7 @@ func loadTLSConfig(c config.RegistryConfig) (*tls.Config, error) {
|
||||||
c.RootCAs = append(c.RootCAs, filepath.Join(d, f.Name()))
|
c.RootCAs = append(c.RootCAs, filepath.Join(d, f.Name()))
|
||||||
}
|
}
|
||||||
if strings.HasSuffix(f.Name(), ".cert") {
|
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()),
|
Certificate: filepath.Join(d, f.Name()),
|
||||||
Key: filepath.Join(d, strings.TrimSuffix(f.Name(), ".cert")+".key"),
|
Key: filepath.Join(d, strings.TrimSuffix(f.Name(), ".cert")+".key"),
|
||||||
})
|
})
|
||||||
|
@ -115,8 +114,22 @@ func loadTLSConfig(c config.RegistryConfig) (*tls.Config, error) {
|
||||||
return tc, nil
|
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
|
// 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(
|
return docker.Registries(
|
||||||
func(host string) ([]docker.RegistryHost, error) {
|
func(host string) ([]docker.RegistryHost, error) {
|
||||||
c, ok := m[host]
|
c, ok := m[host]
|
||||||
|
|
Loading…
Reference in New Issue