Class: CIDE::Runner
Instance Method Summary collapse
- #cleanup!(output: $stderr) ⇒ Object
- #export!(guest_dir: nil, host_dir: nil) ⇒ Object
-
#initialize(command: [], env: {}, links: [], tag: nil, user: nil) ⇒ Runner
constructor
A new instance of Runner.
-
#run!(interactive: false) ⇒ Object
!!!! Don’t call run twice !!!!.
Methods included from Docker
#docker, #docker_image_ids, id
Constructor Details
#initialize(command: [], env: {}, links: [], tag: nil, user: nil) ⇒ Runner
Returns a new instance of Runner.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cide/runner.rb', line 9 def initialize( command: [], env: {}, links: [], tag: nil, user: nil ) raise ArgumentError, 'tag missing' unless tag @containers = [] @id = SecureRandom.hex @tag = tag @env = env @links = links @command = command @user = user end |
Instance Method Details
#cleanup!(output: $stderr) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/cide/runner.rb', line 69 def cleanup!(output: $stderr) return if @containers.empty? begin report_containers!(output) ensure # Shutdown old containers docker :rm, '--force', '--volumes', *@containers.reverse, capture: true end end |
#export!(guest_dir: nil, host_dir: nil) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cide/runner.rb', line 56 def export!(guest_dir: nil, host_dir: nil) raise ArgumentError, 'guest export_dir missing' unless guest_dir raise ArgumentError, 'host export_dir missing' unless host_dir # FIXME: strip trailing slashes ? guest_dir = File.(guest_dir, CIDE_SRC_DIR) host_dir = File.(host_dir, Dir.pwd) FileUtils.mkdir_p(File.dirname(host_dir)) docker :cp, [@id, guest_dir].join(':'), host_dir end |
#run!(interactive: false) ⇒ Object
!!!! Don’t call run twice !!!!
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cide/runner.rb', line 29 def run!(interactive: false) start_links! = ['--detach'] @env.each_pair do |key, value| .push '--env', [key, value].join('=') end @links.each do |link| .push '--link', [link.id, link.name].join(':') end .push '--name', @id .push '--user', @user if @user .push('--interactive', '--tty') if interactive .push @tag .push(*@command) id = docker(:run, *, capture: true).strip @containers << id docker(:attach, id) end |