2014-04-18 22:53:12 +00:00
|
|
|
require "digest/md5"
|
|
|
|
|
|
|
|
require "log4r"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module DockerProvider
|
|
|
|
module Action
|
|
|
|
class HostMachineBuildDir
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
@logger = Log4r::Logger.new("vagrant::docker::hostmachinebuilddir")
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
machine = env[:machine]
|
|
|
|
build_dir = machine.provider_config.build_dir
|
|
|
|
|
|
|
|
# If we're not building a Dockerfile, ignore
|
|
|
|
return @app.call(env) if !build_dir
|
|
|
|
|
|
|
|
# If we're building a docker file, expand the directory
|
|
|
|
build_dir = File.expand_path(build_dir, env[:machine].env.root_path)
|
|
|
|
env[:build_dir] = build_dir
|
|
|
|
|
|
|
|
# If we're not on a host VM, we're done
|
|
|
|
return @app.call(env) if !machine.provider.host_vm?
|
|
|
|
|
|
|
|
# We're on a host VM, so we need to move our build dir to
|
|
|
|
# that machine. We do this by putting the synced folder on
|
|
|
|
# ourself and letting HostMachineSyncFolders handle it.
|
2015-02-07 23:33:55 +00:00
|
|
|
new_build_dir = "/var/lib/docker/docker_build_#{Digest::MD5.hexdigest(build_dir)}"
|
2014-04-18 22:53:12 +00:00
|
|
|
options = {
|
|
|
|
docker__ignore: true,
|
|
|
|
docker__exact: true,
|
2014-05-09 01:46:03 +00:00
|
|
|
}.merge(machine.provider_config.host_vm_build_dir_options || {})
|
2014-04-18 22:53:12 +00:00
|
|
|
machine.config.vm.synced_folder(build_dir, new_build_dir, options)
|
|
|
|
|
|
|
|
# Set the build dir to be the correct one
|
|
|
|
env[:build_dir] = new_build_dir
|
|
|
|
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|