2014-03-26 23:45:46 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module DockerProvider
|
|
|
|
module Action
|
|
|
|
class Destroy
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
machine = env[:machine]
|
|
|
|
|
2014-05-06 04:35:08 +00:00
|
|
|
# If the container actually exists, destroy it
|
|
|
|
if machine.state.id != :not_created
|
|
|
|
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
|
|
|
|
|
|
|
|
env[:ui].info I18n.t("docker_provider.messages.destroying")
|
|
|
|
driver.rm(machine.id)
|
2014-04-19 00:19:31 +00:00
|
|
|
end
|
|
|
|
|
2014-05-06 04:35:08 +00:00
|
|
|
# Otherwise, always make sure we remove the ID
|
2014-03-26 23:45:46 +00:00
|
|
|
machine.id = nil
|
|
|
|
|
2014-04-19 00:19:31 +00:00
|
|
|
@app.call(env)
|
2014-03-26 23:45:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|