2014-03-26 23:45:46 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module DockerProvider
|
|
|
|
module Action
|
2014-03-27 00:51:58 +00:00
|
|
|
# Include the built-in modules so we can use them as top-level things.
|
2014-03-27 00:14:25 +00:00
|
|
|
include Vagrant::Action::Builtin
|
2014-03-26 23:45:46 +00:00
|
|
|
|
|
|
|
# This action brings the "machine" up from nothing, including creating the
|
|
|
|
# container, configuring metadata, and booting.
|
|
|
|
def self.action_up
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use ConfigValidate
|
2014-04-18 00:11:00 +00:00
|
|
|
|
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use HandleBox
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-16 18:59:08 +00:00
|
|
|
b.use HostMachine
|
2014-04-18 00:11:00 +00:00
|
|
|
|
|
|
|
# Yeah, this is supposed to be here twice (once more above). This
|
|
|
|
# catches the case when the container was supposed to be created,
|
|
|
|
# but the host state was unknown, and now we know its not actually
|
|
|
|
# created.
|
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use HandleBox
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-18 00:02:09 +00:00
|
|
|
b.use action_start
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This action just runs the provisioners on the machine.
|
|
|
|
def self.action_provision
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use ConfigValidate
|
2014-03-27 00:51:58 +00:00
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
2014-03-27 00:21:40 +00:00
|
|
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
2014-03-26 23:45:46 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-03-27 00:51:58 +00:00
|
|
|
b2.use Call, IsState, :running do |env2, b3|
|
2014-03-26 23:45:46 +00:00
|
|
|
if !env2[:result]
|
2014-03-27 00:21:40 +00:00
|
|
|
b3.use Message, I18n.t("docker_provider.messages.not_running")
|
2014-03-26 23:45:46 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-04-18 00:05:10 +00:00
|
|
|
b3.use Call, HasSSH do |env3, b4|
|
|
|
|
if env3[:result]
|
|
|
|
b4.use Provision
|
|
|
|
else
|
|
|
|
b4.use Message,
|
|
|
|
I18n.t("docker_provider.messages.provision_no_ssh"),
|
|
|
|
post: true
|
|
|
|
end
|
|
|
|
end
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is the action that is primarily responsible for halting
|
|
|
|
# the virtual machine, gracefully or by force.
|
|
|
|
def self.action_halt
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
2014-04-11 01:26:19 +00:00
|
|
|
b.use Call, IsState, :host_state_unknown do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use HostMachine
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-27 00:51:58 +00:00
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
2014-03-26 23:45:46 +00:00
|
|
|
if env[:result]
|
2014-03-27 00:21:40 +00:00
|
|
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
2014-03-27 00:51:58 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-04-18 00:03:54 +00:00
|
|
|
b2.use Call, HasSSH do |env2, b3|
|
2014-03-27 00:51:58 +00:00
|
|
|
if !env2[:result]
|
|
|
|
b3.use Stop
|
2014-04-18 00:03:54 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b3.use Call, GracefulHalt, :stopped, :running do |env3, b4|
|
|
|
|
if !env3[:result]
|
|
|
|
b4.use Stop
|
|
|
|
end
|
2014-03-27 00:51:58 +00:00
|
|
|
end
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This action is responsible for reloading the machine, which
|
|
|
|
# brings it down, sucks in new configuration, and brings the
|
|
|
|
# machine back up with the new configuration.
|
|
|
|
def self.action_reload
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
2014-03-27 00:51:58 +00:00
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
2014-03-27 00:21:40 +00:00
|
|
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
2014-03-26 23:45:46 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-03-27 00:14:25 +00:00
|
|
|
b2.use ConfigValidate
|
2014-03-26 23:45:46 +00:00
|
|
|
b2.use action_halt
|
2014-04-18 23:29:56 +00:00
|
|
|
b2.use DestroyBuildImage
|
2014-04-18 22:53:12 +00:00
|
|
|
b2.use EnvSet, build_rebuild: true
|
2014-03-26 23:45:46 +00:00
|
|
|
b2.use action_start
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is the action that is primarily responsible for completely
|
|
|
|
# freeing the resources of the underlying virtual machine.
|
|
|
|
def self.action_destroy
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
2014-04-11 01:26:19 +00:00
|
|
|
b.use Call, IsState, :host_state_unknown do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use HostMachine
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-27 00:51:58 +00:00
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
2014-03-27 00:21:40 +00:00
|
|
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
2014-03-26 23:45:46 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2014-03-27 00:14:25 +00:00
|
|
|
b2.use Call, DestroyConfirm do |env2, b3|
|
2014-03-26 23:45:46 +00:00
|
|
|
if env2[:result]
|
2014-03-27 00:14:25 +00:00
|
|
|
b3.use ConfigValidate
|
|
|
|
b3.use EnvSet, :force_halt => true
|
2014-03-26 23:45:46 +00:00
|
|
|
b3.use action_halt
|
2014-04-16 21:46:37 +00:00
|
|
|
b3.use HostMachineSyncFoldersDisable
|
2014-04-18 23:29:56 +00:00
|
|
|
b3.use DestroyBuildImage
|
2014-03-26 23:45:46 +00:00
|
|
|
b3.use Destroy
|
2014-03-27 00:14:25 +00:00
|
|
|
b3.use ProvisionerCleanup
|
2014-03-26 23:45:46 +00:00
|
|
|
else
|
2014-03-27 00:21:40 +00:00
|
|
|
b3.use Message, I18n.t("docker_provider.messages.will_not_destroy")
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is the action that will exec into an SSH shell.
|
|
|
|
def self.action_ssh
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
2014-03-27 00:51:58 +00:00
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use Call, IsState, :running do |env2, b3|
|
|
|
|
if !env2[:result]
|
|
|
|
b3.use Message, I18n.t("docker_provider.messages.not_running")
|
|
|
|
next
|
|
|
|
end
|
2014-04-16 02:58:28 +00:00
|
|
|
|
|
|
|
b3.use PrepareSSH
|
2014-03-27 00:51:58 +00:00
|
|
|
b3.use SSHExec
|
|
|
|
end
|
|
|
|
end
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is the action that will run a single SSH command.
|
|
|
|
def self.action_ssh_run
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
2014-03-27 00:51:58 +00:00
|
|
|
b.use Call, IsState, :not_created do |env, b2|
|
|
|
|
if env[:result]
|
|
|
|
b2.use Message, I18n.t("docker_provider.messages.not_created")
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use Call, IsState, :running do |env2, b3|
|
|
|
|
if !env2[:result]
|
|
|
|
raise Vagrant::Errors::VMNotRunningError
|
|
|
|
end
|
|
|
|
|
|
|
|
b3.use SSHRun
|
|
|
|
end
|
|
|
|
end
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.action_start
|
2014-03-27 00:14:25 +00:00
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
2014-03-27 00:51:58 +00:00
|
|
|
b.use Call, IsState, :running do |env, b2|
|
2014-03-26 23:45:46 +00:00
|
|
|
# If the container is running, then our work here is done, exit
|
|
|
|
next if env[:result]
|
|
|
|
|
2014-04-18 00:02:09 +00:00
|
|
|
b2.use Call, HasSSH do |env2, b3|
|
|
|
|
if env2[:result]
|
|
|
|
b3.use Provision
|
|
|
|
else
|
|
|
|
b3.use Message,
|
|
|
|
I18n.t("docker_provider.messages.provision_no_ssh"),
|
|
|
|
post: true
|
|
|
|
end
|
|
|
|
end
|
2014-03-26 23:45:46 +00:00
|
|
|
|
2014-04-18 00:02:09 +00:00
|
|
|
b2.use Call, IsState, :not_created do |env2, b3|
|
|
|
|
if !env2[:result]
|
|
|
|
b3.use EnvSet, host_machine_sync_folders: false
|
|
|
|
end
|
|
|
|
end
|
2014-04-11 01:26:19 +00:00
|
|
|
|
2014-04-18 22:53:12 +00:00
|
|
|
b2.use HostMachineBuildDir
|
2014-04-18 00:02:09 +00:00
|
|
|
b2.use HostMachineSyncFolders
|
|
|
|
b2.use PrepareNFSValidIds
|
|
|
|
b2.use SyncedFolderCleanup
|
|
|
|
b2.use PrepareNFSSettings
|
2014-04-18 22:53:12 +00:00
|
|
|
b2.use Build
|
2014-04-18 00:02:09 +00:00
|
|
|
|
|
|
|
# If the VM is NOT created yet, then do some setup steps
|
|
|
|
# necessary for creating it.
|
|
|
|
b2.use Call, IsState, :not_created do |env2, b3|
|
|
|
|
if env2[:result]
|
|
|
|
b3.use EnvSet, port_collision_repair: true
|
|
|
|
b3.use HostMachinePortWarning
|
|
|
|
b3.use HostMachinePortChecker
|
|
|
|
b3.use HandleForwardedPortCollisions
|
2014-04-18 00:45:43 +00:00
|
|
|
b3.use SyncedFolders
|
2014-04-18 00:02:09 +00:00
|
|
|
b3.use Create
|
|
|
|
b3.use WaitForRunning
|
2014-04-18 00:45:43 +00:00
|
|
|
else
|
|
|
|
b3.use CompareSyncedFolders
|
2014-04-18 00:02:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
b2.use Start
|
|
|
|
b2.use WaitForRunning
|
|
|
|
|
|
|
|
b2.use Call, HasSSH do |env2, b3|
|
|
|
|
if env2[:result]
|
|
|
|
b3.use WaitForCommunicator
|
|
|
|
end
|
2014-04-11 01:26:19 +00:00
|
|
|
end
|
|
|
|
end
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# The autoload farm
|
|
|
|
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
2014-04-18 22:53:12 +00:00
|
|
|
autoload :Build, action_root.join("build")
|
2014-04-18 00:45:43 +00:00
|
|
|
autoload :CompareSyncedFolders, action_root.join("compare_synced_folders")
|
2014-03-26 23:45:46 +00:00
|
|
|
autoload :Create, action_root.join("create")
|
|
|
|
autoload :Destroy, action_root.join("destroy")
|
2014-04-18 23:29:56 +00:00
|
|
|
autoload :DestroyBuildImage, action_root.join("destroy_build_image")
|
2014-04-11 01:26:19 +00:00
|
|
|
autoload :HasSSH, action_root.join("has_ssh")
|
|
|
|
autoload :HostMachine, action_root.join("host_machine")
|
2014-04-18 22:53:12 +00:00
|
|
|
autoload :HostMachineBuildDir, action_root.join("host_machine_build_dir")
|
2014-04-17 22:05:50 +00:00
|
|
|
autoload :HostMachinePortChecker, action_root.join("host_machine_port_checker")
|
2014-04-17 22:35:04 +00:00
|
|
|
autoload :HostMachinePortWarning, action_root.join("host_machine_port_warning")
|
2014-04-17 21:22:41 +00:00
|
|
|
autoload :HostMachineRequired, action_root.join("host_machine_required")
|
2014-04-16 18:59:08 +00:00
|
|
|
autoload :HostMachineSyncFolders, action_root.join("host_machine_sync_folders")
|
2014-04-16 21:46:37 +00:00
|
|
|
autoload :HostMachineSyncFoldersDisable, action_root.join("host_machine_sync_folders_disable")
|
2014-04-16 02:58:28 +00:00
|
|
|
autoload :PrepareSSH, action_root.join("prepare_ssh")
|
2014-03-26 23:45:46 +00:00
|
|
|
autoload :Stop, action_root.join("stop")
|
|
|
|
autoload :PrepareNFSValidIds, action_root.join("prepare_nfs_valid_ids")
|
|
|
|
autoload :PrepareNFSSettings, action_root.join("prepare_nfs_settings")
|
|
|
|
autoload :Start, action_root.join("start")
|
2014-04-17 23:20:49 +00:00
|
|
|
autoload :WaitForRunning, action_root.join("wait_for_running")
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|