2014-03-26 23:45:46 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module DockerProvider
|
|
|
|
class Config < Vagrant.plugin("2", :config)
|
|
|
|
attr_accessor :image, :cmd, :ports, :volumes, :privileged
|
|
|
|
|
2014-04-18 22:53:12 +00:00
|
|
|
# The directory with a Dockerfile to build and use as the basis
|
|
|
|
# for this container. If this is set, "image" should not be set.
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :build_dir
|
|
|
|
|
2014-04-11 01:26:19 +00:00
|
|
|
# Additional arguments to pass to `docker run` when creating
|
|
|
|
# the container for the first time. This is an array of args.
|
|
|
|
#
|
|
|
|
# @return [Array<String>]
|
|
|
|
attr_accessor :create_args
|
|
|
|
|
2014-04-18 01:07:57 +00:00
|
|
|
# Environmental variables to set in the container.
|
|
|
|
#
|
|
|
|
# @return [Hash]
|
|
|
|
attr_accessor :env
|
|
|
|
|
2014-04-11 01:26:19 +00:00
|
|
|
# True if the Docker container exposes SSH access. If this is true,
|
|
|
|
# then Vagrant can do a bunch more things like setting the hostname,
|
|
|
|
# provisioning, etc.
|
|
|
|
attr_accessor :has_ssh
|
|
|
|
|
2014-04-18 01:40:04 +00:00
|
|
|
# The name for the container. This must be unique for all containers
|
|
|
|
# on the proxy machine if it is made.
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :name
|
|
|
|
|
2014-04-17 23:20:49 +00:00
|
|
|
# True if the docker container is meant to stay in the "running"
|
|
|
|
# state (is a long running process). By default this is true.
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
attr_accessor :remains_running
|
|
|
|
|
2014-04-11 01:26:19 +00:00
|
|
|
# The name of the machine in the Vagrantfile set with
|
|
|
|
# "vagrant_vagrantfile" that will be the docker host. Defaults
|
|
|
|
# to "default"
|
|
|
|
#
|
|
|
|
# See the "vagrant_vagrantfile" docs for more info.
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :vagrant_machine
|
|
|
|
|
|
|
|
# The path to the Vagrantfile that contains a VM that will be
|
|
|
|
# started as the Docker host if needed (Windows, OS X, Linux
|
|
|
|
# without container support).
|
|
|
|
#
|
|
|
|
# Defaults to a built-in Vagrantfile that will load boot2docker.
|
|
|
|
#
|
|
|
|
# NOTE: This only has an effect if Vagrant needs a Docker host.
|
|
|
|
# Vagrant determines this automatically based on the environment
|
|
|
|
# it is running in.
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :vagrant_vagrantfile
|
|
|
|
|
2014-03-26 23:45:46 +00:00
|
|
|
def initialize
|
2014-04-18 22:53:12 +00:00
|
|
|
@build_dir = UNSET_VALUE
|
2014-03-26 23:45:46 +00:00
|
|
|
@cmd = UNSET_VALUE
|
2014-04-11 01:26:19 +00:00
|
|
|
@create_args = []
|
2014-04-18 01:07:57 +00:00
|
|
|
@env = {}
|
2014-04-11 01:26:19 +00:00
|
|
|
@has_ssh = UNSET_VALUE
|
2014-04-10 15:50:14 +00:00
|
|
|
@image = UNSET_VALUE
|
2014-04-18 01:40:04 +00:00
|
|
|
@name = UNSET_VALUE
|
2014-04-18 01:33:46 +00:00
|
|
|
@links = []
|
2014-03-26 23:45:46 +00:00
|
|
|
@ports = []
|
|
|
|
@privileged = UNSET_VALUE
|
2014-04-17 23:20:49 +00:00
|
|
|
@remains_running = UNSET_VALUE
|
2014-03-26 23:45:46 +00:00
|
|
|
@volumes = []
|
2014-04-11 01:26:19 +00:00
|
|
|
@vagrant_machine = UNSET_VALUE
|
|
|
|
@vagrant_vagrantfile = UNSET_VALUE
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
|
2014-04-18 01:33:46 +00:00
|
|
|
def link(name)
|
|
|
|
@links << name
|
|
|
|
end
|
|
|
|
|
2014-04-18 01:07:57 +00:00
|
|
|
def merge(other)
|
|
|
|
super.tap do |result|
|
|
|
|
env = {}
|
|
|
|
env.merge!(@env) if @env
|
|
|
|
env.merge!(other.env) if other.env
|
|
|
|
result.env = env
|
2014-04-18 01:33:46 +00:00
|
|
|
|
|
|
|
links = _links.dup
|
|
|
|
links += other._links
|
|
|
|
result.instance_variable_set(:@links, links)
|
2014-04-18 01:07:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-26 23:45:46 +00:00
|
|
|
def finalize!
|
2014-04-18 22:53:12 +00:00
|
|
|
@build_dir = nil if @build_dir == UNSET_VALUE
|
2014-03-26 23:45:46 +00:00
|
|
|
@cmd = [] if @cmd == UNSET_VALUE
|
2014-04-11 01:26:19 +00:00
|
|
|
@create_args = [] if @create_args == UNSET_VALUE
|
2014-04-18 01:07:57 +00:00
|
|
|
@env ||= {}
|
2014-04-11 01:26:19 +00:00
|
|
|
@has_ssh = false if @has_ssh == UNSET_VALUE
|
2014-04-10 15:50:14 +00:00
|
|
|
@image = nil if @image == UNSET_VALUE
|
2014-04-18 01:40:04 +00:00
|
|
|
@name = nil if @name == UNSET_VALUE
|
2014-03-26 23:45:46 +00:00
|
|
|
@privileged = false if @privileged == UNSET_VALUE
|
2014-04-17 23:20:49 +00:00
|
|
|
@remains_running = true if @remains_running == UNSET_VALUE
|
2014-04-11 01:26:19 +00:00
|
|
|
@vagrant_machine = nil if @vagrant_machine == UNSET_VALUE
|
|
|
|
@vagrant_vagrantfile = nil if @vagrant_vagrantfile == UNSET_VALUE
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def validate(machine)
|
|
|
|
errors = _detected_errors
|
|
|
|
|
2014-04-18 01:33:46 +00:00
|
|
|
@links.each do |link|
|
|
|
|
parts = link.split(":")
|
|
|
|
if parts.length != 2 || parts[0] == "" || parts[1] == ""
|
|
|
|
errors << I18n.t(
|
|
|
|
"docker_provider.errors.config.invalid_link", link: link)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-26 23:45:46 +00:00
|
|
|
# TODO: Detect if base image has a CMD / ENTRYPOINT set before erroring out
|
2014-04-11 01:26:19 +00:00
|
|
|
errors << I18n.t("docker_provider.errors.config.cmd_not_set") if @cmd == UNSET_VALUE
|
2014-03-26 23:45:46 +00:00
|
|
|
|
2014-04-10 15:50:14 +00:00
|
|
|
{ "docker provider" => errors }
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
2014-04-18 01:33:46 +00:00
|
|
|
|
|
|
|
#--------------------------------------------------------------
|
|
|
|
# Functions below should not be called by config files
|
|
|
|
#--------------------------------------------------------------
|
|
|
|
|
|
|
|
def _links
|
|
|
|
@links
|
|
|
|
end
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|