Supporting a named Dockerfile for Docker 1.5.0

This commit is contained in:
Adam Duro 2015-03-13 17:30:42 -07:00
parent a8dcf92f14
commit be81f09a60
3 changed files with 22 additions and 2 deletions

View File

@ -38,10 +38,22 @@ module VagrantPlugins
# If we have no image or we're rebuilding, we rebuild # If we have no image or we're rebuilding, we rebuild
if !image || env[:build_rebuild] if !image || env[:build_rebuild]
# Build it # 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( image = machine.provider.driver.build(
build_dir, 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 data = remove_ansi_escape_codes(data.chomp).chomp
env[:ui].detail(data) if data != "" env[:ui].detail(data) if data != ""
end end

View File

@ -17,6 +17,12 @@ module VagrantPlugins
# @return [String] # @return [String]
attr_accessor :build_dir 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 # Additional arguments to pass to `docker run` when creating
# the container for the first time. This is an array of args. # the container for the first time. This is an array of args.
# #

View File

@ -12,6 +12,8 @@ en:
Build image no longer exists. Rebuilding... Build image no longer exists. Rebuilding...
building: |- building: |-
Building the container from a Dockerfile... Building the container from a Dockerfile...
building_named_dockerfile: |-
Building the container from the named Dockerfile: %{file}...
creating: |- creating: |-
Creating the container... Creating the container...
created: |- created: |-