Add option to Docker provisioner to build local images

This commit is contained in:
Jacques Fuentes 2013-12-09 17:52:45 -05:00
parent 25b0018759
commit 1738f9dccf
4 changed files with 30 additions and 4 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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: