Add option to Docker provisioner to build local images
This commit is contained in:
parent
25b0018759
commit
1738f9dccf
|
@ -3,13 +3,14 @@ require 'set'
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module Docker
|
module Docker
|
||||||
class Config < Vagrant.plugin("2", :config)
|
class Config < Vagrant.plugin("2", :config)
|
||||||
attr_reader :images, :containers
|
attr_reader :images, :containers, :build_options
|
||||||
attr_accessor :version
|
attr_accessor :version
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@images = Set.new
|
@images = Set.new
|
||||||
@containers = Hash.new
|
@containers = Hash.new
|
||||||
@version = UNSET_VALUE
|
@version = UNSET_VALUE
|
||||||
|
@build_images = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def images=(images)
|
def images=(images)
|
||||||
|
@ -20,6 +21,14 @@ module VagrantPlugins
|
||||||
@images += images.map(&:to_s)
|
@images += images.map(&:to_s)
|
||||||
end
|
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)
|
def run(name, **options)
|
||||||
params = options.dup
|
params = options.dup
|
||||||
params[:image] ||= name
|
params[:image] ||= name
|
||||||
|
|
|
@ -16,6 +16,16 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
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
|
def start_service
|
||||||
if !daemon_running? && @machine.guest.capability?(:docker_start_service)
|
if !daemon_running? && @machine.guest.capability?(:docker_start_service)
|
||||||
@machine.guest.capability(:docker_start_service)
|
@machine.guest.capability(:docker_start_service)
|
||||||
|
|
|
@ -33,6 +33,11 @@ module VagrantPlugins
|
||||||
@client.pull_images(*config.images)
|
@client.pull_images(*config.images)
|
||||||
end
|
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?
|
if config.containers.any?
|
||||||
@machine.ui.info(I18n.t("vagrant.docker_starting_containers"))
|
@machine.ui.info(I18n.t("vagrant.docker_starting_containers"))
|
||||||
@client.run(config.containers)
|
@client.run(config.containers)
|
||||||
|
|
|
@ -48,6 +48,8 @@ en:
|
||||||
Pulling Docker images...
|
Pulling Docker images...
|
||||||
docker_pulling_single: |-
|
docker_pulling_single: |-
|
||||||
-- Image: %{name}
|
-- Image: %{name}
|
||||||
|
docker_building_single: |-
|
||||||
|
-- Path: %{path}
|
||||||
docker_running: |-
|
docker_running: |-
|
||||||
-- Container: %{name}
|
-- Container: %{name}
|
||||||
docker_starting_containers:
|
docker_starting_containers:
|
||||||
|
|
Loading…
Reference in New Issue