providers/docker: fix ordering of removing built images

This commit is contained in:
Mitchell Hashimoto 2014-04-18 17:19:31 -07:00
parent e50eb6c7a9
commit 67741ad902
3 changed files with 35 additions and 11 deletions

View File

@ -107,8 +107,14 @@ module VagrantPlugins
b2.use ConfigValidate
b2.use action_halt
b2.use DestroyBuildImage
b2.use EnvSet, build_rebuild: true
b2.use Call, IsBuild do |env2, b3|
if env2[:result]
b3.use Destroy
b3.use DestroyBuildImage
end
end
b2.use action_start
end
end
@ -136,8 +142,8 @@ module VagrantPlugins
b3.use EnvSet, :force_halt => true
b3.use action_halt
b3.use HostMachineSyncFoldersDisable
b3.use DestroyBuildImage
b3.use Destroy
b3.use DestroyBuildImage
b3.use ProvisionerCleanup
else
b3.use Message, I18n.t("docker_provider.messages.will_not_destroy")
@ -261,6 +267,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 :IsBuild, action_root.join("is_build")
autoload :PrepareSSH, action_root.join("prepare_ssh")
autoload :Stop, action_root.join("stop")
autoload :PrepareNFSValidIds, action_root.join("prepare_nfs_valid_ids")

View File

@ -12,10 +12,18 @@ module VagrantPlugins
machine = env[:machine]
driver = machine.provider.driver
# If we have a build image, store that
image_file = machine.data_dir.join("docker_build_image")
image = nil
if image_file.file?
image = image_file.read.chomp
end
env[:build_image] = image
driver.rm(machine.id)
machine.id = nil
@app.call env
@app.call(env)
end
end
end

View File

@ -11,16 +11,25 @@ module VagrantPlugins
def call(env)
machine = env[:machine]
image = env[:build_image]
image_file = nil
if !image
# Try to read the image ID from the cache file if we've
# already built it.
image_file = machine.data_dir.join("docker_build_image")
image = nil
if image_file.file?
image = image_file.read.chomp
end
end
if image
machine.ui.output(I18n.t("docker_provider.build_image_destroy"))
machine.provider.driver.rmi(image)
end
if image_file
image_file.delete
end