diff --git a/plugins/provisioners/docker/config.rb b/plugins/provisioners/docker/config.rb index 078804974..644b1f673 100644 --- a/plugins/provisioners/docker/config.rb +++ b/plugins/provisioners/docker/config.rb @@ -3,13 +3,14 @@ require 'set' module VagrantPlugins module Docker class Config < Vagrant.plugin("2", :config) - attr_reader :images, :containers + attr_reader :images, :containers, :build_options attr_accessor :version def initialize - @images = Set.new - @containers = Hash.new - @version = UNSET_VALUE + @images = Set.new + @containers = Hash.new + @version = UNSET_VALUE + @build_images = [] end def images=(images) @@ -20,6 +21,14 @@ module VagrantPlugins @images += images.map(&:to_s) end + def build_images(*images) + possible_options = @build_options.keys + + @build_images = images.map do |image| + image.values_at(:path, :args) + end + end + def run(name, **options) params = options.dup params[:image] ||= name diff --git a/plugins/provisioners/docker/docker_client.rb b/plugins/provisioners/docker/docker_client.rb index 7affc7c3a..3d82dbe2e 100644 --- a/plugins/provisioners/docker/docker_client.rb +++ b/plugins/provisioners/docker/docker_client.rb @@ -16,6 +16,16 @@ module VagrantPlugins end end + def build_images(images) + @machine.communicate.tap do |comm| + images.each do |image| + path = image[:path] + @machine.ui.info(I18n.t("vagrant.docker_building_single", path: path)) + comm.sudo("docker build #{image[:args]} #{path}") + end + end + end + def start_service if !daemon_running? && @machine.guest.capability?(:docker_start_service) @machine.guest.capability(:docker_start_service) diff --git a/plugins/provisioners/docker/provisioner.rb b/plugins/provisioners/docker/provisioner.rb index eac195b22..d4e8d99a9 100644 --- a/plugins/provisioners/docker/provisioner.rb +++ b/plugins/provisioners/docker/provisioner.rb @@ -33,6 +33,11 @@ module VagrantPlugins @client.pull_images(*config.images) end + if config.build_images.any? + @machine.ui.info(I18n.t("vagrant.docker_building_images")) + @client.build_images(config.build_images) + end + if config.containers.any? @machine.ui.info(I18n.t("vagrant.docker_starting_containers")) @client.run(config.containers) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 87bfcdc11..547d622b4 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -48,6 +48,8 @@ en: Pulling Docker images... docker_pulling_single: |- -- Image: %{name} + docker_building_single: |- + -- Path: %{path} docker_running: |- -- Container: %{name} docker_starting_containers: