2013-11-26 21:48:51 +00:00
|
|
|
require 'set'
|
|
|
|
|
|
|
|
module VagrantPlugins
|
2014-03-26 23:32:31 +00:00
|
|
|
module DockerProvisioner
|
2013-11-26 21:48:51 +00:00
|
|
|
class Config < Vagrant.plugin("2", :config)
|
2014-02-03 21:23:26 +00:00
|
|
|
attr_reader :images
|
2013-11-26 21:48:51 +00:00
|
|
|
attr_accessor :version
|
|
|
|
|
|
|
|
def initialize
|
2013-12-09 22:52:45 +00:00
|
|
|
@images = Set.new
|
|
|
|
@version = UNSET_VALUE
|
2014-02-03 21:23:26 +00:00
|
|
|
|
|
|
|
@__build_images = []
|
|
|
|
@__containers = Hash.new { |h, k| h[k] = {} }
|
|
|
|
end
|
|
|
|
|
|
|
|
# Accessor for internal state.
|
|
|
|
def build_images
|
|
|
|
@__build_images
|
|
|
|
end
|
|
|
|
|
|
|
|
# Accessor for the internal state.
|
|
|
|
def containers
|
|
|
|
@__containers
|
2013-11-26 21:48:51 +00:00
|
|
|
end
|
|
|
|
|
2014-01-14 17:22:55 +00:00
|
|
|
# Defines an image to build using `docker build` within the machine.
|
|
|
|
#
|
|
|
|
# @param [String] path Path to the Dockerfile to pass to
|
|
|
|
# `docker build`.
|
|
|
|
def build_image(path, **opts)
|
2014-02-03 21:23:26 +00:00
|
|
|
@__build_images << [path, opts]
|
2014-01-14 17:22:55 +00:00
|
|
|
end
|
|
|
|
|
2013-12-03 22:25:20 +00:00
|
|
|
def images=(images)
|
|
|
|
@images = Set.new(images)
|
|
|
|
end
|
|
|
|
|
2013-11-26 21:48:51 +00:00
|
|
|
def pull_images(*images)
|
|
|
|
@images += images.map(&:to_s)
|
|
|
|
end
|
|
|
|
|
2013-12-03 22:33:13 +00:00
|
|
|
def run(name, **options)
|
2014-02-03 21:23:26 +00:00
|
|
|
@__containers[name.to_s] = options.dup
|
|
|
|
end
|
2013-11-26 21:48:51 +00:00
|
|
|
|
2014-02-03 21:23:26 +00:00
|
|
|
def merge(other)
|
|
|
|
super.tap do |result|
|
|
|
|
result.pull_images(*(other.images + self.images))
|
|
|
|
|
|
|
|
build_images = @__build_images.dup
|
|
|
|
build_images += other.build_images
|
|
|
|
result.instance_variable_set(:@__build_images, build_images)
|
|
|
|
|
|
|
|
containers = {}
|
|
|
|
@__containers.each do |name, params|
|
|
|
|
containers[name] = params.dup
|
|
|
|
end
|
|
|
|
other.containers.each do |name, params|
|
|
|
|
containers[name] = @__containers[name].merge(params)
|
|
|
|
end
|
|
|
|
|
|
|
|
result.instance_variable_set(:@__containers, containers)
|
|
|
|
end
|
2013-11-26 21:48:51 +00:00
|
|
|
end
|
|
|
|
|
2013-12-03 22:18:30 +00:00
|
|
|
def finalize!
|
2013-12-04 00:19:08 +00:00
|
|
|
@version = "latest" if @version == UNSET_VALUE
|
2013-12-03 22:18:30 +00:00
|
|
|
@version = @version.to_sym
|
|
|
|
|
2014-02-03 21:23:26 +00:00
|
|
|
@__containers.each do |name, params|
|
|
|
|
params[:image] ||= name
|
2015-01-05 23:29:01 +00:00
|
|
|
params[:auto_assign_name] = true if !params.key?(:auto_assign_name)
|
|
|
|
params[:daemonize] = true if !params.key?(:daemonize)
|
2013-11-26 21:48:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|