2013-11-26 21:48:51 +00:00
|
|
|
require 'set'
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Docker
|
|
|
|
class Config < Vagrant.plugin("2", :config)
|
2014-01-14 17:22:55 +00:00
|
|
|
attr_reader :build_images, :images, :containers, :build_options
|
2013-11-26 21:48:51 +00:00
|
|
|
attr_accessor :version
|
|
|
|
|
|
|
|
def initialize
|
2013-12-09 22:52:45 +00:00
|
|
|
@images = Set.new
|
|
|
|
@containers = Hash.new
|
|
|
|
@version = UNSET_VALUE
|
|
|
|
@build_images = []
|
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)
|
|
|
|
@build_images << [path, opts]
|
|
|
|
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)
|
|
|
|
params = options.dup
|
2013-12-06 00:12:44 +00:00
|
|
|
params[:image] ||= name
|
2013-11-26 21:48:51 +00:00
|
|
|
|
|
|
|
# TODO: Validate provided parameters before assignment
|
2013-12-03 22:33:13 +00:00
|
|
|
@containers[name.to_s] = params
|
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
|
|
|
|
end
|
|
|
|
|
2013-11-26 21:48:51 +00:00
|
|
|
def merge(other)
|
|
|
|
super.tap do |result|
|
2013-12-03 22:18:30 +00:00
|
|
|
result.pull_images(*(other.images + self.images))
|
2013-11-26 21:48:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|