-
Notifications
You must be signed in to change notification settings - Fork 42
/
docker_compose_runner.rb
63 lines (50 loc) · 1.41 KB
/
docker_compose_runner.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true
require_relative "base"
require_relative "../compose"
module Dip
module Commands
module Runners
class DockerComposeRunner < Base
def execute
Commands::Compose.new(
command[:compose][:method],
*compose_arguments,
shell: command[:shell]
).execute
end
private
def compose_arguments
compose_argv = command[:compose][:run_options].dup
if command[:compose][:method] == "run"
compose_argv.concat(run_vars)
compose_argv.concat(published_ports)
compose_argv << "--rm"
end
compose_argv << command.fetch(:service)
unless (cmd = command[:command]).empty?
if command[:shell]
compose_argv << cmd
else
compose_argv.concat(cmd.shellsplit)
end
end
compose_argv.concat(command_args)
compose_argv
end
def run_vars
run_vars = Dip::RunVars.env
return [] unless run_vars
run_vars.map { |k, v| ["-e", "#{k}=#{Shellwords.escape(v)}"] }.flatten
end
def published_ports
publish = options[:publish]
if publish.respond_to?(:each)
publish.map { |p| "--publish=#{p}" }
else
[]
end
end
end
end
end
end