From 030c1ee4813344c1d368f0e4b90fe9b8dc83cdd2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 7 May 2014 18:41:24 -0700 Subject: [PATCH] providers/docker: build_args [GH-3684] --- CHANGELOG.md | 2 ++ plugins/providers/docker/action/build.rb | 5 ++++- plugins/providers/docker/config.rb | 8 ++++++++ plugins/providers/docker/driver.rb | 4 +++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfdd79229..0403d49f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ IMPROVEMENTS: - command/rdp: Args after "--" are passed directly through to the RDP client. [GH-3686] + - providers/docker: `build_args` config to specify extra args for + `docker build`. [GH-3684] ## 1.6.1 (May 7, 2014) diff --git a/plugins/providers/docker/action/build.rb b/plugins/providers/docker/action/build.rb index 87e27872c..61cbcb8a6 100644 --- a/plugins/providers/docker/action/build.rb +++ b/plugins/providers/docker/action/build.rb @@ -35,7 +35,10 @@ module VagrantPlugins if !image || env[:build_rebuild] # Build it machine.ui.output(I18n.t("docker_provider.building")) - image = machine.provider.driver.build(build_dir) + image = machine.provider.driver.build( + build_dir, + extra_args: machine.provider_config.build_args, + ) machine.ui.detail("Image: #{image}") # Store the image ID diff --git a/plugins/providers/docker/config.rb b/plugins/providers/docker/config.rb index 96ba3df53..f6ddedab4 100644 --- a/plugins/providers/docker/config.rb +++ b/plugins/providers/docker/config.rb @@ -5,6 +5,12 @@ module VagrantPlugins class Config < Vagrant.plugin("2", :config) attr_accessor :image, :cmd, :ports, :volumes, :privileged + # Additional arguments to pass to `docker build` when creating + # an image using the build dir setting. + # + # @return [Array] + attr_accessor :build_args + # The directory with a Dockerfile to build and use as the basis # for this container. If this is set, "image" should not be set. # @@ -73,6 +79,7 @@ module VagrantPlugins attr_accessor :vagrant_vagrantfile def initialize + @build_args = [] @build_dir = UNSET_VALUE @cmd = UNSET_VALUE @create_args = [] @@ -126,6 +133,7 @@ module VagrantPlugins end def finalize! + @build_args = [] if @build_args == UNSET_VALUE @build_dir = nil if @build_dir == UNSET_VALUE @cmd = [] if @cmd == UNSET_VALUE @create_args = [] if @create_args == UNSET_VALUE diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index 37d109d9b..546b06dfd 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -15,7 +15,9 @@ module VagrantPlugins end def build(dir, **opts) - result = execute('docker', 'build', dir) + args = Array(opts[:extra_args]) + args << dir + result = execute('docker', 'build', *args) regexp = /Successfully built (.+)$/i match = regexp.match(result) if !match