dip 5.0.0.rc1 → 7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -35
- data/exe/dip +7 -7
- data/lib/dip.rb +1 -1
- data/lib/dip/cli.rb +28 -23
- data/lib/dip/cli/console.rb +7 -7
- data/lib/dip/cli/dns.rb +31 -31
- data/lib/dip/cli/nginx.rb +25 -25
- data/lib/dip/cli/ssh.rb +25 -22
- data/lib/dip/command.rb +9 -7
- data/lib/dip/commands/compose.rb +14 -13
- data/lib/dip/commands/console.rb +5 -5
- data/lib/dip/commands/dns.rb +12 -12
- data/lib/dip/commands/list.rb +3 -3
- data/lib/dip/commands/nginx.rb +8 -8
- data/lib/dip/commands/provision.rb +1 -1
- data/lib/dip/commands/run.rb +31 -18
- data/lib/dip/commands/ssh.rb +19 -11
- data/lib/dip/config.rb +20 -6
- data/lib/dip/environment.rb +6 -6
- data/lib/dip/ext/hash.rb +1 -1
- data/lib/dip/interaction_tree.rb +3 -16
- data/lib/dip/version.rb +1 -1
- metadata +37 -10
data/lib/dip/cli/ssh.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "thor"
|
4
4
|
require_relative "./base"
|
5
5
|
require_relative "../commands/ssh"
|
6
6
|
|
@@ -8,25 +8,28 @@ module Dip
|
|
8
8
|
class CLI
|
9
9
|
class SSH < Base
|
10
10
|
desc "up", "Run ssh-agent container"
|
11
|
-
method_option :help, aliases:
|
12
|
-
desc:
|
13
|
-
method_option :key, aliases:
|
14
|
-
desc:
|
15
|
-
method_option :volume, aliases:
|
16
|
-
desc:
|
17
|
-
method_option :interactive, aliases:
|
18
|
-
desc:
|
11
|
+
method_option :help, aliases: "-h", type: :boolean,
|
12
|
+
desc: "Display usage information"
|
13
|
+
method_option :key, aliases: "-k", type: :string, default: "$HOME/.ssh/id_rsa",
|
14
|
+
desc: "Path to ssh key"
|
15
|
+
method_option :volume, aliases: "-v", type: :string, default: "$HOME",
|
16
|
+
desc: "Mounted docker volume"
|
17
|
+
method_option :interactive, aliases: "-t", type: :boolean, default: true,
|
18
|
+
desc: "Run in interactive mode"
|
19
|
+
method_option :user, aliases: "-u", type: :string,
|
20
|
+
desc: "UID for ssh-agent container"
|
19
21
|
# Backward compatibility
|
20
|
-
method_option :nonteractive, aliases:
|
21
|
-
desc:
|
22
|
+
method_option :nonteractive, aliases: "-T", type: :boolean,
|
23
|
+
desc: "Run in noninteractive mode"
|
22
24
|
def up
|
23
25
|
if options[:help]
|
24
|
-
invoke :help, [
|
26
|
+
invoke :help, ["up"]
|
25
27
|
else
|
26
28
|
Dip::Commands::SSH::Up.new(
|
27
29
|
key: options.fetch(:key),
|
28
30
|
volume: options.fetch(:volume),
|
29
|
-
interactive: options.nonteractive? ? false : options.interactive
|
31
|
+
interactive: options.nonteractive? ? false : options.interactive?,
|
32
|
+
user: options.user
|
30
33
|
).execute
|
31
34
|
end
|
32
35
|
end
|
@@ -34,22 +37,22 @@ module Dip
|
|
34
37
|
map add: :up
|
35
38
|
|
36
39
|
desc "down", "Stop ssh-agent container"
|
37
|
-
method_option :help, aliases:
|
38
|
-
desc:
|
40
|
+
method_option :help, aliases: "-h", type: :boolean,
|
41
|
+
desc: "Display usage information"
|
39
42
|
def down
|
40
43
|
if options[:help]
|
41
|
-
invoke :help, [
|
44
|
+
invoke :help, ["down"]
|
42
45
|
else
|
43
46
|
Dip::Commands::SSH::Down.new.execute
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
47
50
|
desc "restart", "Stop and start ssh-agent container"
|
48
|
-
method_option :help, aliases:
|
49
|
-
desc:
|
51
|
+
method_option :help, aliases: "-h", type: :boolean,
|
52
|
+
desc: "Display usage information"
|
50
53
|
def restart(*args)
|
51
54
|
if options[:help]
|
52
|
-
invoke :help, [
|
55
|
+
invoke :help, ["restart"]
|
53
56
|
else
|
54
57
|
Dip::CLI::SSH.start(["down"] + args)
|
55
58
|
sleep 1
|
@@ -58,11 +61,11 @@ module Dip
|
|
58
61
|
end
|
59
62
|
|
60
63
|
desc "status", "Show status of ssh-agent container"
|
61
|
-
method_option :help, aliases:
|
62
|
-
desc:
|
64
|
+
method_option :help, aliases: "-h", type: :boolean,
|
65
|
+
desc: "Display usage information"
|
63
66
|
def status
|
64
67
|
if options[:help]
|
65
|
-
invoke :help, [
|
68
|
+
invoke :help, ["status"]
|
66
69
|
else
|
67
70
|
Dip::Commands::SSH::Status.new.execute
|
68
71
|
end
|
data/lib/dip/command.rb
CHANGED
@@ -9,27 +9,29 @@ module Dip
|
|
9
9
|
def_delegators self, :shell, :subshell
|
10
10
|
|
11
11
|
class ExecRunner
|
12
|
-
def self.call(
|
13
|
-
::Process.exec(env,
|
12
|
+
def self.call(cmdline, env: {}, **options)
|
13
|
+
::Process.exec(env, cmdline, options)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
class SubshellRunner
|
18
|
-
def self.call(
|
19
|
-
return if ::Kernel.system(env,
|
20
|
-
raise Dip::Error, "Command '#{
|
18
|
+
def self.call(cmdline, env: {}, panic: true, **options)
|
19
|
+
return if ::Kernel.system(env, cmdline, options)
|
20
|
+
raise Dip::Error, "Command '#{cmdline}' executed with error." if panic
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
class << self
|
25
25
|
def shell(cmd, argv = [], subshell: false, **options)
|
26
26
|
cmd = Dip.env.interpolate(cmd)
|
27
|
+
argv = [argv] if argv.is_a?(String)
|
27
28
|
argv = argv.map { |arg| Dip.env.interpolate(arg) }
|
29
|
+
cmdline = [cmd, *argv].compact.join(" ").strip
|
28
30
|
|
29
|
-
puts [Dip.env.vars,
|
31
|
+
puts [Dip.env.vars, cmdline].inspect if Dip.debug?
|
30
32
|
|
31
33
|
runner = subshell ? SubshellRunner : ExecRunner
|
32
|
-
runner.call(
|
34
|
+
runner.call(cmdline, env: Dip.env.vars, **options)
|
33
35
|
end
|
34
36
|
|
35
37
|
def subshell(*args, **kwargs)
|
data/lib/dip/commands/compose.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "pathname"
|
4
4
|
|
5
|
-
require_relative
|
6
|
-
require_relative
|
5
|
+
require_relative "../command"
|
6
|
+
require_relative "dns"
|
7
7
|
|
8
8
|
module Dip
|
9
9
|
module Commands
|
@@ -20,7 +20,7 @@ module Dip
|
|
20
20
|
def execute
|
21
21
|
Dip.env["DIP_DNS"] ||= find_dns
|
22
22
|
|
23
|
-
compose_argv = Array(find_files) + Array(
|
23
|
+
compose_argv = Array(find_files) + Array(cli_options) + argv
|
24
24
|
|
25
25
|
shell("docker-compose", compose_argv)
|
26
26
|
end
|
@@ -43,13 +43,14 @@ module Dip
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
47
|
-
|
46
|
+
def cli_options
|
47
|
+
%i[project_name project_directory].flat_map do |name|
|
48
|
+
next unless (value = config[name])
|
49
|
+
next unless value.is_a?(String)
|
48
50
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
51
|
+
value = ::Dip.env.interpolate(value)
|
52
|
+
["--#{name.to_s.tr("_", "-")}", value]
|
53
|
+
end.compact
|
53
54
|
end
|
54
55
|
|
55
56
|
def find_dns
|
@@ -57,9 +58,9 @@ module Dip
|
|
57
58
|
net = Dip.env["FRONTEND_NETWORK"] || "frontend"
|
58
59
|
|
59
60
|
IO.pipe do |r, w|
|
60
|
-
Dip::Commands::DNS::IP
|
61
|
-
new(name: name, net: net)
|
62
|
-
execute(out: w, err: File::NULL, panic: false)
|
61
|
+
Dip::Commands::DNS::IP
|
62
|
+
.new(name: name, net: net)
|
63
|
+
.execute(out: w, err: File::NULL, panic: false)
|
63
64
|
|
64
65
|
w.close_write
|
65
66
|
ip = r.readlines[0].to_s.strip
|
data/lib/dip/commands/console.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../command"
|
4
4
|
|
5
5
|
module Dip
|
6
6
|
module Commands
|
@@ -13,9 +13,9 @@ module Dip
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def script
|
16
|
-
<<-SH.gsub(/^
|
16
|
+
<<-SH.gsub(/^ {12}/, "")
|
17
17
|
export DIP_SHELL=1
|
18
|
-
export DIP_EARLY_ENVS=#{ENV.keys.join(
|
18
|
+
export DIP_EARLY_ENVS=#{ENV.keys.join(",")}
|
19
19
|
export DIP_PROMPT_TEXT="ⅆ"
|
20
20
|
|
21
21
|
function dip_clear() {
|
@@ -88,7 +88,7 @@ module Dip
|
|
88
88
|
def execute
|
89
89
|
if Dip.config.exist?
|
90
90
|
add_aliases(*Dip.config.interaction.keys) if Dip.config.interaction
|
91
|
-
add_aliases("compose", "up", "stop", "down", "provision")
|
91
|
+
add_aliases("compose", "up", "stop", "down", "provision", "build")
|
92
92
|
end
|
93
93
|
|
94
94
|
clear_aliases
|
@@ -107,7 +107,7 @@ module Dip
|
|
107
107
|
|
108
108
|
def clear_aliases
|
109
109
|
out << "function dip_clear() { \n" \
|
110
|
-
"#{aliases.any? ? aliases.map { |a| " unset -f #{a}" }.join("\n") :
|
110
|
+
"#{aliases.any? ? aliases.map { |a| " unset -f #{a}" }.join("\n") : "true"} " \
|
111
111
|
"\n}"
|
112
112
|
end
|
113
113
|
end
|
data/lib/dip/commands/dns.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "shellwords"
|
4
|
-
require_relative
|
4
|
+
require_relative "../command"
|
5
5
|
|
6
6
|
module Dip
|
7
7
|
module Commands
|
@@ -17,20 +17,20 @@ module Dip
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def execute
|
20
|
-
subshell("docker", "network create #{@net}"
|
21
|
-
subshell("docker", "run #{container_args} #{@image} --domain=#{@domain}"
|
20
|
+
subshell("docker", "network create #{@net}", panic: false, err: File::NULL)
|
21
|
+
subshell("docker", "run #{container_args} #{@image} --domain=#{@domain}")
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def container_args
|
27
|
-
result = %w
|
27
|
+
result = %w[--detach]
|
28
28
|
result << "--volume #{@socket}:/var/run/docker.sock:ro"
|
29
29
|
result << "--restart always"
|
30
30
|
result << "--publish #{@publish}"
|
31
31
|
result << "--net #{@net}"
|
32
32
|
result << "--name #{@name}"
|
33
|
-
result.join(
|
33
|
+
result.join(" ")
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -40,8 +40,8 @@ module Dip
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def execute
|
43
|
-
subshell("docker", "stop #{@name}"
|
44
|
-
subshell("docker", "rm -v #{@name}"
|
43
|
+
subshell("docker", "stop #{@name}", panic: false, out: File::NULL, err: File::NULL)
|
44
|
+
subshell("docker", "rm -v #{@name}", panic: false, out: File::NULL, err: File::NULL)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -52,11 +52,11 @@ module Dip
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def execute(**options)
|
55
|
-
subshell(
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
subshell(
|
56
|
+
"docker",
|
57
|
+
"inspect --format '{{ .NetworkSettings.Networks.#{@net}.IPAddress }}' #{@name}",
|
58
|
+
**options
|
59
|
+
)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
data/lib/dip/commands/list.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
3
|
+
require_relative "../command"
|
4
|
+
require_relative "../interaction_tree"
|
5
5
|
|
6
6
|
module Dip
|
7
7
|
module Commands
|
@@ -12,7 +12,7 @@ module Dip
|
|
12
12
|
longest_name = tree.keys.map(&:size).max
|
13
13
|
|
14
14
|
tree.each do |name, command|
|
15
|
-
puts "#{name.ljust(longest_name)} ##{command[:description] ?
|
15
|
+
puts "#{name.ljust(longest_name)} ##{command[:description] ? " #{command[:description]}" : ""}"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/lib/dip/commands/nginx.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "shellwords"
|
4
|
-
require_relative
|
4
|
+
require_relative "../command"
|
5
5
|
|
6
6
|
module Dip
|
7
7
|
module Commands
|
@@ -18,22 +18,22 @@ module Dip
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def execute
|
21
|
-
subshell("docker", "network create #{@net}"
|
22
|
-
subshell("docker", "run #{container_args} #{@image}"
|
21
|
+
subshell("docker", "network create #{@net}", panic: false, err: File::NULL)
|
22
|
+
subshell("docker", "run #{container_args} #{@image}")
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def container_args
|
28
|
-
result = %w
|
28
|
+
result = %w[--detach]
|
29
29
|
result << "--volume #{@socket}:/tmp/docker.sock:ro"
|
30
30
|
result << "--volume #{@certs}:/etc/nginx/certs" unless @certs.to_s.empty?
|
31
31
|
result << "--restart always"
|
32
|
-
result << Array(@publish).map { |p| "--publish #{p}" }.join(
|
32
|
+
result << Array(@publish).map { |p| "--publish #{p}" }.join(" ")
|
33
33
|
result << "--net #{@net}"
|
34
34
|
result << "--name #{@name}"
|
35
35
|
result << "--label com.dnsdock.alias=#{@domain}"
|
36
|
-
result.join(
|
36
|
+
result.join(" ")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -43,8 +43,8 @@ module Dip
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def execute
|
46
|
-
subshell("docker", "stop #{@name}"
|
47
|
-
subshell("docker", "rm -v #{@name}"
|
46
|
+
subshell("docker", "stop #{@name}", panic: false, out: File::NULL, err: File::NULL)
|
47
|
+
subshell("docker", "rm -v #{@name}", panic: false, out: File::NULL, err: File::NULL)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/dip/commands/run.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
3
|
+
require "shellwords"
|
4
|
+
require_relative "../../../lib/dip/run_vars"
|
5
|
+
require_relative "../command"
|
6
|
+
require_relative "../interaction_tree"
|
7
|
+
require_relative "compose"
|
8
8
|
|
9
9
|
module Dip
|
10
10
|
module Commands
|
@@ -12,21 +12,24 @@ module Dip
|
|
12
12
|
def initialize(cmd, *argv, publish: nil)
|
13
13
|
@publish = publish
|
14
14
|
|
15
|
-
@command, @argv = InteractionTree
|
16
|
-
|
17
|
-
|
18
|
-
values_at(:command, :argv)
|
15
|
+
@command, @argv = InteractionTree
|
16
|
+
.new(Dip.config.interaction)
|
17
|
+
.find(cmd, *argv)&.values_at(:command, :argv)
|
19
18
|
|
20
|
-
raise Dip::Error, "Command `#{[cmd, *argv].join(
|
19
|
+
raise Dip::Error, "Command `#{[cmd, *argv].join(" ")}` not recognized!" unless command
|
21
20
|
|
22
21
|
Dip.env.merge(command[:environment])
|
23
22
|
end
|
24
23
|
|
25
24
|
def execute
|
26
|
-
|
27
|
-
command[:
|
28
|
-
|
29
|
-
|
25
|
+
if command[:service].nil?
|
26
|
+
shell(command[:command], get_args)
|
27
|
+
else
|
28
|
+
Dip::Commands::Compose.new(
|
29
|
+
command[:compose][:method],
|
30
|
+
*compose_arguments
|
31
|
+
).execute
|
32
|
+
end
|
30
33
|
end
|
31
34
|
|
32
35
|
private
|
@@ -44,11 +47,11 @@ module Dip
|
|
44
47
|
|
45
48
|
compose_argv << command.fetch(:service)
|
46
49
|
|
47
|
-
unless (cmd = command[:command]
|
48
|
-
compose_argv
|
50
|
+
unless (cmd = command[:command]).empty?
|
51
|
+
compose_argv << cmd
|
49
52
|
end
|
50
53
|
|
51
|
-
compose_argv.concat(
|
54
|
+
compose_argv.concat(get_args)
|
52
55
|
|
53
56
|
compose_argv
|
54
57
|
end
|
@@ -57,7 +60,7 @@ module Dip
|
|
57
60
|
run_vars = Dip::RunVars.env
|
58
61
|
return [] unless run_vars
|
59
62
|
|
60
|
-
run_vars.map { |k, v| ["-e", "#{k}=#{v}"] }.flatten
|
63
|
+
run_vars.map { |k, v| ["-e", "#{k}=#{Shellwords.escape(v)}"] }.flatten
|
61
64
|
end
|
62
65
|
|
63
66
|
def published_ports
|
@@ -67,6 +70,16 @@ module Dip
|
|
67
70
|
[]
|
68
71
|
end
|
69
72
|
end
|
73
|
+
|
74
|
+
def get_args
|
75
|
+
if argv.any?
|
76
|
+
argv
|
77
|
+
elsif !(default_args = command[:default_args]).empty?
|
78
|
+
Array(default_args)
|
79
|
+
else
|
80
|
+
[]
|
81
|
+
end
|
82
|
+
end
|
70
83
|
end
|
71
84
|
end
|
72
85
|
end
|