./share/scripts/toolchain in docker-utils-0.1.25 vs ./share/scripts/toolchain in docker-utils-0.1.26
- old
+ new
@@ -1,9 +1,18 @@
#!/usr/bin/env ruby
EXPUNGE_ENV_KEYS = [
- 'TMPDIR'
+ 'TMPDIR',
+ 'DOCKER_HOST',
+ 'LOGNAME',
+ 'LANG',
+ 'PWD',
+ 'OLDPWD',
+ 'PS1',
+ 'SHELL',
+ 'USER',
+ '_'
]
require 'optparse'
require 'pathname'
@@ -49,12 +58,18 @@
guest_repo_root = Pathname.new('/src')
guest_cwd = guest_repo_root + rel_cwd
toolchain_docker_args.concat([
'-v', "#{host_repo_root}:#{guest_repo_root}",
- '-w', guest_cwd.to_s
+ '-w', '/build'
])
+
+ data_container_name = host_repo_root.basename.to_s + "-build"
+
+ toolchain_docker_args.concat([
+ "--volumes-from=#{data_container_name}"
+ ])
end
# interactivity options
if $stdin.tty? and $stdout.tty?
toolchain_docker_args.concat(['-i', '-t'])
@@ -63,17 +78,49 @@
# environment options
exposed_env_keys = ENV.keys - EXPUNGE_ENV_KEYS
container_env_keys = `docker inspect -f '{{.Config.Env}}' #{toolchain_image}`.chomp[1..-2].split(' ').map{ |pair| pair.split('=').first }
toolchain_docker_args.concat((exposed_env_keys - container_env_keys).map{ |k| ['-e', k] }.flatten)
+toolchain_docker_args.concat([
+ '-v', "#{ENV['HOME']}/.ssh:/root/.ssh"
+])
+
# network options
if options[:bind_net]
toolchain_docker_args.push '--net=host'
end
docker_bin_path = `which docker`.chomp
-Kernel.exec docker_bin_path, 'run', '--rm',
- *toolchain_docker_args,
- toolchain_image,
- *toolchain_subcommand_args
+toolchain = lambda do |*subcommand|
+ Kernel.system docker_bin_path, 'run', '--rm',
+ *toolchain_docker_args,
+ toolchain_image,
+ *subcommand
+end
+
+if data_container_name
+ data_container_image = 'tianon/true:latest'
+ data_container_image_available = system docker_bin_path, 'inspect', '-f', '{{.Id}}', data_container_image, out: '/dev/null', err: '/dev/null'
+ unless data_container_image_available or system(docker_bin_path, 'pull', data_container_image)
+ $stderr.puts "could not locate data-container image '#{data_container_image}'; aborting"
+ Kernel.exit 1
+ end
+
+ data_container_exists = system docker_bin_path, 'inspect', '-f', '{{.Id}}', data_container_name, out: '/dev/null', err: '/dev/null'
+
+ #toolchain.call 'find', '/build', '-mindepth', '1', '-maxdepth', '1', '-type', 'l', '-exec', 'rm', '{}', ';'
+ unless data_container_exists
+ Kernel.system(
+ docker_bin_path, 'run',
+ "--name=#{data_container_name}",
+ '-v', '/build',
+ data_container_image
+ )
+
+ toolchain.call 'find', '/src', '-mindepth', '1', '-maxdepth', '1', '-exec', 'ln', '-sF', '{}', ';'
+ end
+end
+
+
+toolchain.call *toolchain_subcommand_args