From 635e393ae5221bb6e34505d177ca8e975b1508a0 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Wed, 17 Apr 2019 03:48:38 +0000 Subject: [PATCH] build: handle --network Signed-off-by: Tibor Vass --- build/build.go | 9 +++++++++ commands/build.go | 11 ++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/build/build.go b/build/build.go index 3c5f3ad9..1a838b0b 100644 --- a/build/build.go +++ b/build/build.go @@ -37,6 +37,7 @@ type Options struct { Pull bool ImageIDFile string ExtraHosts []string + NetworkMode string NoCache bool Target string @@ -228,6 +229,14 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, pw so.FrontendAttrs["platform"] = strings.Join(pp, ",") } + switch opt.NetworkMode { + case "host", "none": + so.FrontendAttrs["force-network-mode"] = opt.NetworkMode + case "", "default": + default: + return nil, errors.Errorf("network mode %q not supported by buildkit", opt.NetworkMode) + } + extraHosts, err := toBuildkitExtraHosts(opt.ExtraHosts) if err != nil { return nil, err diff --git a/commands/build.go b/commands/build.go index 8af1e0d7..7fbf9893 100644 --- a/commands/build.go +++ b/commands/build.go @@ -32,11 +32,11 @@ type buildOptions struct { outputs []string imageIDFile string extraHosts []string + networkMode string // unimplemented - squash bool - quiet bool - networkMode string + squash bool + quiet bool // hidden // untrusted bool @@ -68,9 +68,6 @@ func runBuild(dockerCli command.Cli, in buildOptions) error { if in.quiet { return errors.Errorf("quiet currently not implemented") } - if in.networkMode != "default" { - return errors.Errorf("network currently not implemented") - } ctx := appcontext.Context() @@ -88,6 +85,7 @@ func runBuild(dockerCli command.Cli, in buildOptions) error { Target: in.target, ImageIDFile: in.imageIDFile, ExtraHosts: in.extraHosts, + NetworkMode: in.networkMode, } platforms, err := build.ParsePlatformSpecs(in.platforms) @@ -166,7 +164,6 @@ func buildCmd(dockerCli command.Cli) *cobra.Command { flags.StringVar(&options.imageIDFile, "iidfile", "", "Write the image ID to the file") flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer") flags.MarkHidden("quiet") - flags.MarkHidden("network") flags.MarkHidden("squash") // hidden flags