diff --git a/dup.rb b/dup.rb index 0cad562..7a53f18 100755 --- a/dup.rb +++ b/dup.rb @@ -31,6 +31,7 @@ def get_sample(name="container") restart: always command: "/bin/bash" build: "/data/dir" + pull: false ports: - "1234:1234" @@ -81,6 +82,7 @@ def action_help puts "-n, --dry-run Don't execute any commands." puts "-s, --sample Outputs a sample 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 end @@ -147,6 +149,9 @@ def action_run(container, file) 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(cmd.compact.join(" ")) @@ -157,12 +162,14 @@ end action = :run container = nil $dry_run = false +$pull = false opts = GetoptLong.new( [ '--sample', '-s', GetoptLong::NO_ARGUMENT ], [ '--create', '-c', 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| @@ -176,6 +183,8 @@ opts.each do |opt, arg| when '--dry-run' puts "Dry-run. Not going to execute any command." $dry_run = true + when '--pull' + $pull = true end end