Added support for pulling new images before starting the container.

This commit is contained in:
Fabian Schlenz 2017-09-25 09:25:09 +02:00
parent 12c16cf9c3
commit e8bea498d8
1 changed files with 10 additions and 1 deletions

11
dup.rb
View File

@ -31,6 +31,7 @@ def get_sample(name="container")
restart: always restart: always
command: "/bin/bash" command: "/bin/bash"
build: "/data/dir" build: "/data/dir"
pull: false
ports: ports:
- "1234:1234" - "1234:1234"
@ -81,6 +82,7 @@ def action_help
puts "-n, --dry-run Don't execute any commands." puts "-n, --dry-run Don't execute any commands."
puts "-s, --sample Outputs a sample yml file." puts "-s, --sample Outputs a sample yml file."
puts "-c, --create Create a new container yml file." puts "-c, --create Create a new container yml file."
puts "-p, --pull (Try to) Pull the image(s) before starting the container."
exit 1 exit 1
end end
@ -147,6 +149,9 @@ def action_run(container, file)
end end
end end
if data["pull"] || $pull
run("docker pull #{data["image"].shellescape}", true)
end
run("docker rm -f #{(data["container_name"] || key).shellescape}", true) run("docker rm -f #{(data["container_name"] || key).shellescape}", true)
run(cmd.compact.join(" ")) run(cmd.compact.join(" "))
@ -157,12 +162,14 @@ end
action = :run action = :run
container = nil container = nil
$dry_run = false $dry_run = false
$pull = false
opts = GetoptLong.new( opts = GetoptLong.new(
[ '--sample', '-s', GetoptLong::NO_ARGUMENT ], [ '--sample', '-s', GetoptLong::NO_ARGUMENT ],
[ '--create', '-c', GetoptLong::NO_ARGUMENT ], [ '--create', '-c', GetoptLong::NO_ARGUMENT ],
[ '--help', '-h', GetoptLong::NO_ARGUMENT ], [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--dry-run', '-n', GetoptLong::NO_ARGUMENT ] [ '--dry-run', '-n', GetoptLong::NO_ARGUMENT ],
[ '--pull', '-p', GetoptLong::NO_ARGUMENT ]
) )
opts.each do |opt, arg| opts.each do |opt, arg|
@ -176,6 +183,8 @@ opts.each do |opt, arg|
when '--dry-run' when '--dry-run'
puts "Dry-run. Not going to execute any command." puts "Dry-run. Not going to execute any command."
$dry_run = true $dry_run = true
when '--pull'
$pull = true
end end
end end