providers/docker: set preparing set to avoid data dir clear [GH-3873]

This commit is contained in:
Mitchell Hashimoto 2014-10-22 20:52:08 -07:00
parent 62fa97f334
commit 1e6259dd00
5 changed files with 34 additions and 4 deletions

View File

@ -12,6 +12,7 @@ BUG FIXES:
- core: Fix cases where sometimes SSH connection would hang.
- commands/box: `--cert` flag works properly. [GH-4691]
- command/docker-logs: Won't crash if container is removed. [GH-3990]
- command/docker-run: Synced folders will be attached properly. [GH-3873]
- command/rsync: Sync to Docker containers properly. [GH-4066]
- providers/docker: Create args works. [GH-4526]
- providers/docker: Nicer error if package is called. [GH-4595]

View File

@ -215,7 +215,7 @@ module VagrantPlugins
def self.action_start
Vagrant::Action::Builder.new.tap do |b|
b.use Call, IsState, :running do |env, b2|
# If the container is running and we're doing a run, we're done
# If the container is running and we're not doing a run, we're done
next if env[:result] && env[:machine_action] != :run_command
if env[:machine_action] != :run_command
@ -231,7 +231,10 @@ module VagrantPlugins
end
b2.use Call, IsState, :not_created do |env2, b3|
if !env2[:result]
if env2[:result]
# First time making this thing, set to the "preparing" state
b3.use InitState
else
b3.use EnvSet, host_machine_sync_folders: false
end
end
@ -247,7 +250,7 @@ module VagrantPlugins
if env[:machine_action] != :run_command
# If the container is NOT created yet, then do some setup steps
# necessary for creating it.
b2.use Call, IsState, :not_created do |env2, b3|
b2.use Call, IsState, :preparing do |env2, b3|
if env2[:result]
b3.use EnvSet, port_collision_repair: true
b3.use HostMachinePortWarning
@ -271,6 +274,7 @@ module VagrantPlugins
end
end
else
# We're in a run command, so we do things a bit differently.
b2.use SyncedFolders
b2.use Create
end
@ -294,6 +298,7 @@ module VagrantPlugins
autoload :HostMachineRequired, action_root.join("host_machine_required")
autoload :HostMachineSyncFolders, action_root.join("host_machine_sync_folders")
autoload :HostMachineSyncFoldersDisable, action_root.join("host_machine_sync_folders_disable")
autoload :InitState, action_root.join("init_state")
autoload :IsBuild, action_root.join("is_build")
autoload :IsHostMachineCreated, action_root.join("is_host_machine_created")
autoload :Login, action_root.join("login")

View File

@ -46,7 +46,6 @@ module VagrantPlugins
def setup_synced_folders(host_machine, env)
# Write the host machine SFID if we have one
id_path = env[:machine].data_dir.join("host_machine_sfid")
host_sfid = nil
if !id_path.file?
host_sfid = SecureRandom.uuid
id_path.open("w") do |f|

View File

@ -0,0 +1,20 @@
module VagrantPlugins
module DockerProvider
module Action
class InitState
def initialize(app, env)
@app = app
end
def call(env)
# We set the ID of the machine to "preparing" so that we can use
# the data dir without it being deleted with the not_created state.
env[:machine].id = nil
env[:machine].id = "preparing"
@app.call(env)
end
end
end
end
end

View File

@ -156,6 +156,11 @@ module VagrantPlugins
state_id = driver.state(@machine.id) if @machine.id && !state_id
state_id = :unknown if !state_id
# This is a special pseudo-state so that we don't set the
# NOT_CREATED_ID while we're setting up the machine. This avoids
# clearing the data dir.
state_id = :preparing if @machine.id == "preparing"
short = state_id.to_s.gsub("_", " ")
long = I18n.t("docker_provider.status.#{state_id}")