Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: buildkit now honors daemon's DNS config #39329

Merged
merged 1 commit into from Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions builder/builder-next/builder.go
Expand Up @@ -75,6 +75,7 @@ type Opt struct {
BuilderConfig config.BuilderConfig
Rootless bool
IdentityMapping *idtools.IdentityMapping
DNSConfig config.DNSConfig
}

// Builder can build using BuildKit backend
Expand Down
4 changes: 3 additions & 1 deletion builder/builder-next/controller.go
Expand Up @@ -113,7 +113,9 @@ func newController(rt http.RoundTripper, opt Opt) (*control.Controller, error) {
return nil, err
}

exec, err := newExecutor(root, opt.DefaultCgroupParent, opt.NetworkController, opt.Rootless, opt.IdentityMapping)
dns := getDNSConfig(opt.DNSConfig)

exec, err := newExecutor(root, opt.DefaultCgroupParent, opt.NetworkController, dns, opt.Rootless, opt.IdentityMapping)
if err != nil {
return nil, err
}
Expand Down
16 changes: 15 additions & 1 deletion builder/builder-next/executor_unix.go
Expand Up @@ -8,9 +8,11 @@ import (
"strconv"
"sync"

"github.com/docker/docker/daemon/config"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/libnetwork"
"github.com/moby/buildkit/executor"
"github.com/moby/buildkit/executor/oci"
"github.com/moby/buildkit/executor/runcexecutor"
"github.com/moby/buildkit/identity"
"github.com/moby/buildkit/solver/pb"
Expand All @@ -21,7 +23,7 @@ import (

const networkName = "bridge"

func newExecutor(root, cgroupParent string, net libnetwork.NetworkController, rootless bool, idmap *idtools.IdentityMapping) (executor.Executor, error) {
func newExecutor(root, cgroupParent string, net libnetwork.NetworkController, dnsConfig *oci.DNSConfig, rootless bool, idmap *idtools.IdentityMapping) (executor.Executor, error) {
networkProviders := map[pb.NetMode]network.Provider{
pb.NetMode_UNSET: &bridgeProvider{NetworkController: net, Root: filepath.Join(root, "net")},
pb.NetMode_HOST: network.NewHostProvider(),
Expand All @@ -34,6 +36,7 @@ func newExecutor(root, cgroupParent string, net libnetwork.NetworkController, ro
Rootless: rootless,
NoPivot: os.Getenv("DOCKER_RAMDISK") != "",
IdentityMapping: idmap,
DNS: dnsConfig,
}, networkProviders)
}

Expand Down Expand Up @@ -117,3 +120,14 @@ func (iface *lnInterface) Close() error {
}
return iface.err
}

func getDNSConfig(cfg config.DNSConfig) *oci.DNSConfig {
if cfg.DNS != nil || cfg.DNSSearch != nil || cfg.DNSOptions != nil {
return &oci.DNSConfig{
Nameservers: cfg.DNS,
SearchDomains: cfg.DNSSearch,
Options: cfg.DNSOptions,
}
}
return nil
}
8 changes: 7 additions & 1 deletion builder/builder-next/executor_windows.go
Expand Up @@ -5,13 +5,15 @@ import (
"errors"
"io"

"github.com/docker/docker/daemon/config"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/libnetwork"
"github.com/moby/buildkit/cache"
"github.com/moby/buildkit/executor"
"github.com/moby/buildkit/executor/oci"
)

func newExecutor(_, _ string, _ libnetwork.NetworkController, _ bool, _ *idtools.IdentityMapping) (executor.Executor, error) {
func newExecutor(_, _ string, _ libnetwork.NetworkController, _ *oci.DNSConfig, _ bool, _ *idtools.IdentityMapping) (executor.Executor, error) {
return &winExecutor{}, nil
}

Expand All @@ -21,3 +23,7 @@ type winExecutor struct {
func (e *winExecutor) Exec(ctx context.Context, meta executor.Meta, rootfs cache.Mountable, mounts []executor.Mount, stdin io.ReadCloser, stdout, stderr io.WriteCloser) error {
return errors.New("buildkit executor not implemented for windows")
}

func getDNSConfig(config.DNSConfig) *oci.DNSConfig {
return nil
}
1 change: 1 addition & 0 deletions cmd/dockerd/daemon.go
Expand Up @@ -319,6 +319,7 @@ func newRouterOptions(config *config.Config, d *daemon.Daemon) (routerOptions, e
BuilderConfig: config.Builder,
Rootless: d.Rootless(),
IdentityMapping: d.IdentityMapping(),
DNSConfig: config.DNSConfig,
})
if err != nil {
return opts, err
Expand Down
11 changes: 8 additions & 3 deletions daemon/config/config.go
Expand Up @@ -109,6 +109,13 @@ type CommonTLSOptions struct {
KeyFile string `json:"tlskey,omitempty"`
}

// DNSConfig defines the DNS configurations.
type DNSConfig struct {
DNS []string `json:"dns,omitempty"`
DNSOptions []string `json:"dns-opts,omitempty"`
DNSSearch []string `json:"dns-search,omitempty"`
}

// CommonConfig defines the configuration of a docker daemon which is
// common across platforms.
// It includes json tags to deserialize configuration from a file
Expand All @@ -119,9 +126,6 @@ type CommonConfig struct {
AutoRestart bool `json:"-"`
Context map[string][]string `json:"-"`
DisableBridge bool `json:"-"`
DNS []string `json:"dns,omitempty"`
DNSOptions []string `json:"dns-opts,omitempty"`
DNSSearch []string `json:"dns-search,omitempty"`
ExecOptions []string `json:"exec-opts,omitempty"`
GraphDriver string `json:"storage-driver,omitempty"`
GraphOptions []string `json:"storage-opts,omitempty"`
Expand Down Expand Up @@ -200,6 +204,7 @@ type CommonConfig struct {

MetricsAddress string `json:"metrics-addr"`

DNSConfig
LogConfig
BridgeConfig // bridgeConfig holds bridge network specific configuration.
NetworkConfig
Expand Down
24 changes: 18 additions & 6 deletions daemon/config/config_test.go
Expand Up @@ -244,28 +244,36 @@ func TestValidateConfigurationErrors(t *testing.T) {
{
config: &Config{
CommonConfig: CommonConfig{
DNS: []string{"1.1.1.1o"},
DNSConfig: DNSConfig{
DNS: []string{"1.1.1.1o"},
},
},
},
},
{
config: &Config{
CommonConfig: CommonConfig{
DNS: []string{"2.2.2.2", "1.1.1.1o"},
DNSConfig: DNSConfig{
DNS: []string{"2.2.2.2", "1.1.1.1o"},
},
},
},
},
{
config: &Config{
CommonConfig: CommonConfig{
DNSSearch: []string{"123456"},
DNSConfig: DNSConfig{
DNSSearch: []string{"123456"},
},
},
},
},
{
config: &Config{
CommonConfig: CommonConfig{
DNSSearch: []string{"a.b.c", "123456"},
DNSConfig: DNSConfig{
DNSSearch: []string{"a.b.c", "123456"},
},
},
},
},
Expand Down Expand Up @@ -329,14 +337,18 @@ func TestValidateConfiguration(t *testing.T) {
{
config: &Config{
CommonConfig: CommonConfig{
DNS: []string{"1.1.1.1"},
DNSConfig: DNSConfig{
DNS: []string{"1.1.1.1"},
},
},
},
},
{
config: &Config{
CommonConfig: CommonConfig{
DNSSearch: []string{"a.b.c"},
DNSConfig: DNSConfig{
DNSSearch: []string{"a.b.c"},
},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion vendor.conf
Expand Up @@ -27,7 +27,7 @@ github.com/imdario/mergo 7c29201646fa3de8506f70121347
golang.org/x/sync e225da77a7e68af35c70ccbf71af2b83e6acac3c

# buildkit
github.com/moby/buildkit c24275065aca6605bd83c57c6735510f4ebeb6d9
github.com/moby/buildkit a258bd18b2c55aac4e8a10a3074757d66d45cef6
github.com/tonistiigi/fsutil 3bbb99cdbd76619ab717299830c60f6f2a533a6b
github.com/grpc-ecosystem/grpc-opentracing 8e809c8a86450a29b90dcc9efbf062d0fe6d9746
github.com/opentracing/opentracing-go 1361b9cd60be79c4c3a7fa9841b3c132e40066a7
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/moby/buildkit/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions vendor/github.com/moby/buildkit/cache/manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.