From be81f09a6093fcf87716cb720aa456040057c2b5 Mon Sep 17 00:00:00 2001 From: Adam Duro Date: Fri, 13 Mar 2015 17:30:42 -0700 Subject: [PATCH] Supporting a named Dockerfile for Docker 1.5.0 --- plugins/providers/docker/action/build.rb | 16 ++++++++++++++-- plugins/providers/docker/config.rb | 6 ++++++ templates/locales/providers_docker.yml | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/plugins/providers/docker/action/build.rb b/plugins/providers/docker/action/build.rb index ddc96084c..90453119e 100644 --- a/plugins/providers/docker/action/build.rb +++ b/plugins/providers/docker/action/build.rb @@ -38,10 +38,22 @@ module VagrantPlugins # If we have no image or we're rebuilding, we rebuild if !image || env[:build_rebuild] # Build it - machine.ui.output(I18n.t("docker_provider.building")) + args = machine.provider_config.build_args.clone + if (machine.provider_config.dockerfile) + dockerfile = machine.provider_config.dockerfile + dockerfile_path = File.join(build_dir, dockerfile) + + args.push "--file=\"#{dockerfile_path}\"" + machine.ui.output( + I18n.t("docker_provider.building_named_dockerfile", + file: machine.provider_config.dockerfile)) + else + machine.ui.output(I18n.t("docker_provider.building")) + end + image = machine.provider.driver.build( build_dir, - extra_args: machine.provider_config.build_args) do |type, data| + extra_args: args) do |type, data| data = remove_ansi_escape_codes(data.chomp).chomp env[:ui].detail(data) if data != "" end diff --git a/plugins/providers/docker/config.rb b/plugins/providers/docker/config.rb index 7b36ab70c..9339f6e79 100644 --- a/plugins/providers/docker/config.rb +++ b/plugins/providers/docker/config.rb @@ -17,6 +17,12 @@ module VagrantPlugins # @return [String] attr_accessor :build_dir + # An optional file name of a Dockerfile to be used when building + # the image. This requires Docker >1.5.0. + # + # @return [String] + attr_accessor :dockerfile + # Additional arguments to pass to `docker run` when creating # the container for the first time. This is an array of args. # diff --git a/templates/locales/providers_docker.yml b/templates/locales/providers_docker.yml index c04248a95..5e2df1480 100644 --- a/templates/locales/providers_docker.yml +++ b/templates/locales/providers_docker.yml @@ -12,6 +12,8 @@ en: Build image no longer exists. Rebuilding... building: |- Building the container from a Dockerfile... + building_named_dockerfile: |- + Building the container from the named Dockerfile: %{file}... creating: |- Creating the container... created: |-