dip 7.0.1 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6effe7d3575e71e95f9e4ec3d61fe016cf55691c1adaa96a0e75ab1e04e894f
4
- data.tar.gz: 7f4f7ca8bded48c8b7abb7979148b9deb77d8f2e2b15493c8cc8831a4600c49f
3
+ metadata.gz: b07d037c5f420807fbe56f174c208211fa2d5f1dcee9d6bf8bb9cf86d3f97af5
4
+ data.tar.gz: 2354f68ddc596c5f1e87076a5cb7fd1f0cc37b69f0354d092db1b389a773e709
5
5
  SHA512:
6
- metadata.gz: 8a2d4acb5cac37f00a2dcb3132ca034fb9b8121c1d2d0b816a4b37a565b631afdc12b73a2701cd115389d56efb60d4241fe55253e5b59c122dce364b174b8a06
7
- data.tar.gz: ca168782f5af0500f4352631dd56237543b3c685b8b3d40819c240b58ec62c075ee01e5fd211c506855875e8c32e33c4afaf0df1f3131bbef2c98aa126fff518
6
+ metadata.gz: 1c1210a158918c0bbefa63efe5f8f42cecd2ae87a532fc1b9c98667cf8304c0bedcf5cbc1f7b1aef6e0a49704420aaf45fcb99874beb33b112ff8f6c0083d163
7
+ data.tar.gz: 24e5113b9c1b96799a0fff2f9c63b9e6182c44ca21fc9a5241c8421de4442c0633d28196ee6f10f474361e6c2730ed8e5bbe2739ca66683fa1eb6b0108d11fbc
data/README.md CHANGED
@@ -142,6 +142,12 @@ interaction:
142
142
  default_args: db_dev
143
143
  command: psql -h pg -U postgres
144
144
 
145
+ setup_key:
146
+ description: Copy key
147
+ service: app
148
+ command: cp `pwd`/config/key.pem /root/keys/
149
+ shell: false # you can disable shell interpolations on the host machine and send the command as is
150
+
145
151
  clean_cache:
146
152
  description: Delete cache files on the host machine
147
153
  command: rm -rf $(pwd)/tmp/cache/*
data/lib/dip/cli.rb CHANGED
@@ -111,7 +111,7 @@ module Dip
111
111
  subcommand :nginx, Dip::CLI::Nginx
112
112
 
113
113
  require_relative "cli/console"
114
- desc "console", "Integrate Dip commands into shell (only ZSH and Bash is supported)"
114
+ desc "console", "Integrate Dip commands into shell (only ZSH and Bash are supported)"
115
115
  subcommand :console, Dip::CLI::Console
116
116
  end
117
117
  end
data/lib/dip/command.rb CHANGED
@@ -6,38 +6,47 @@ module Dip
6
6
  class Command
7
7
  extend Forwardable
8
8
 
9
- def_delegators self, :shell, :subshell
9
+ def_delegators self, :exec_program, :exec_subprocess
10
10
 
11
- class ExecRunner
11
+ class ProgramRunner
12
12
  def self.call(cmdline, env: {}, **options)
13
- ::Process.exec(env, cmdline, options)
13
+ if cmdline.is_a?(Array)
14
+ ::Kernel.exec(env, cmdline[0], *cmdline[1..-1], **options)
15
+ else
16
+ ::Kernel.exec(env, cmdline, **options)
17
+ end
14
18
  end
15
19
  end
16
20
 
17
- class SubshellRunner
21
+ class SubprocessRunner
18
22
  def self.call(cmdline, env: {}, panic: true, **options)
19
- return if ::Kernel.system(env, cmdline, options)
23
+ return if ::Kernel.system(env, cmdline, **options)
20
24
  raise Dip::Error, "Command '#{cmdline}' executed with error." if panic
21
25
  end
22
26
  end
23
27
 
24
28
  class << self
25
- def shell(cmd, argv = [], subshell: false, **options)
29
+ def exec_program(*args, **kwargs)
30
+ run(ProgramRunner, *args, **kwargs)
31
+ end
32
+
33
+ def exec_subprocess(*args, **kwargs)
34
+ run(SubprocessRunner, *args, **kwargs)
35
+ end
36
+
37
+ private
38
+
39
+ def run(runner, cmd, argv = [], shell: true, **options)
26
40
  cmd = Dip.env.interpolate(cmd)
27
41
  argv = [argv] if argv.is_a?(String)
28
42
  argv = argv.map { |arg| Dip.env.interpolate(arg) }
29
- cmdline = [cmd, *argv].compact.join(" ").strip
43
+ cmdline = [cmd, *argv].compact
44
+ cmdline = cmdline.join(" ").strip if shell
30
45
 
31
46
  puts [Dip.env.vars, cmdline].inspect if Dip.debug?
32
47
 
33
- runner = subshell ? SubshellRunner : ExecRunner
34
48
  runner.call(cmdline, env: Dip.env.vars, **options)
35
49
  end
36
-
37
- def subshell(*args, **kwargs)
38
- kwargs[:subshell] = true
39
- shell(*args, **kwargs)
40
- end
41
50
  end
42
51
  end
43
52
  end
@@ -10,10 +10,11 @@ module Dip
10
10
  class Compose < Dip::Command
11
11
  DOCKER_EMBEDDED_DNS = "127.0.0.11"
12
12
 
13
- attr_reader :argv, :config
13
+ attr_reader :argv, :config, :shell
14
14
 
15
- def initialize(*argv)
15
+ def initialize(*argv, shell: true)
16
16
  @argv = argv
17
+ @shell = shell
17
18
  @config = ::Dip.config.compose || {}
18
19
  end
19
20
 
@@ -22,7 +23,7 @@ module Dip
22
23
 
23
24
  compose_argv = Array(find_files) + Array(cli_options) + argv
24
25
 
25
- shell("docker-compose", compose_argv)
26
+ exec_program("docker-compose", compose_argv, shell: shell)
26
27
  end
27
28
 
28
29
  private
@@ -17,8 +17,8 @@ module Dip
17
17
  end
18
18
 
19
19
  def execute
20
- subshell("docker", "network create #{@net}", panic: false, err: File::NULL)
21
- subshell("docker", "run #{container_args} #{@image} --domain=#{@domain}")
20
+ exec_subprocess("docker", "network create #{@net}", panic: false, err: File::NULL)
21
+ exec_subprocess("docker", "run #{container_args} #{@image} --domain=#{@domain}")
22
22
  end
23
23
 
24
24
  private
@@ -40,8 +40,8 @@ module Dip
40
40
  end
41
41
 
42
42
  def execute
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)
43
+ exec_subprocess("docker", "stop #{@name}", panic: false, out: File::NULL, err: File::NULL)
44
+ exec_subprocess("docker", "rm -v #{@name}", panic: false, out: File::NULL, err: File::NULL)
45
45
  end
46
46
  end
47
47
 
@@ -52,7 +52,7 @@ module Dip
52
52
  end
53
53
 
54
54
  def execute(**options)
55
- subshell(
55
+ exec_subprocess(
56
56
  "docker",
57
57
  "inspect --format '{{ .NetworkSettings.Networks.#{@net}.IPAddress }}' #{@name}",
58
58
  **options
@@ -18,8 +18,8 @@ module Dip
18
18
  end
19
19
 
20
20
  def execute
21
- subshell("docker", "network create #{@net}", panic: false, err: File::NULL)
22
- subshell("docker", "run #{container_args} #{@image}")
21
+ exec_subprocess("docker", "network create #{@net}", panic: false, err: File::NULL)
22
+ exec_subprocess("docker", "run #{container_args} #{@image}")
23
23
  end
24
24
 
25
25
  private
@@ -43,8 +43,8 @@ module Dip
43
43
  end
44
44
 
45
45
  def execute
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)
46
+ exec_subprocess("docker", "stop #{@name}", panic: false, out: File::NULL, err: File::NULL)
47
+ exec_subprocess("docker", "rm -v #{@name}", panic: false, out: File::NULL, err: File::NULL)
48
48
  end
49
49
  end
50
50
  end
@@ -7,7 +7,7 @@ module Dip
7
7
  class Provision < Dip::Command
8
8
  def execute
9
9
  Dip.config.provision.each do |command|
10
- subshell(command)
10
+ exec_subprocess(command)
11
11
  end
12
12
  end
13
13
  end
@@ -23,11 +23,12 @@ module Dip
23
23
 
24
24
  def execute
25
25
  if command[:service].nil?
26
- shell(command[:command], get_args)
26
+ exec_program(command[:command], get_args, shell: command[:shell])
27
27
  else
28
28
  Dip::Commands::Compose.new(
29
29
  command[:compose][:method],
30
- *compose_arguments
30
+ *compose_arguments,
31
+ shell: command[:shell]
31
32
  ).execute
32
33
  end
33
34
  end
@@ -48,7 +49,11 @@ module Dip
48
49
  compose_argv << command.fetch(:service)
49
50
 
50
51
  unless (cmd = command[:command]).empty?
51
- compose_argv << cmd
52
+ if command[:shell]
53
+ compose_argv << cmd
54
+ else
55
+ compose_argv.concat(cmd.shellsplit)
56
+ end
52
57
  end
53
58
 
54
59
  compose_argv.concat(get_args)
@@ -75,7 +80,11 @@ module Dip
75
80
  if argv.any?
76
81
  argv
77
82
  elsif !(default_args = command[:default_args]).empty?
78
- Array(default_args)
83
+ if command[:shell]
84
+ default_args.shellsplit
85
+ else
86
+ Array(default_args)
87
+ end
79
88
  else
80
89
  []
81
90
  end
@@ -15,15 +15,15 @@ module Dip
15
15
  end
16
16
 
17
17
  def execute
18
- subshell("docker", "volume create --name ssh_data", out: File::NULL, err: File::NULL)
18
+ exec_subprocess("docker", "volume create --name ssh_data", out: File::NULL, err: File::NULL)
19
19
 
20
- subshell(
20
+ exec_subprocess(
21
21
  "docker",
22
22
  "run #{user_args}--detach --volume ssh_data:/ssh --name=ssh-agent whilp/ssh-agent"
23
23
  )
24
24
 
25
25
  key = Dip.env.interpolate(@key)
26
- subshell("docker", "run #{container_args} whilp/ssh-agent ssh-add #{key}")
26
+ exec_subprocess("docker", "run #{container_args} whilp/ssh-agent ssh-add #{key}")
27
27
  end
28
28
 
29
29
  private
@@ -44,15 +44,15 @@ module Dip
44
44
 
45
45
  class Down < Dip::Command
46
46
  def execute
47
- subshell("docker", "stop ssh-agent", panic: false, out: File::NULL, err: File::NULL)
48
- subshell("docker", "rm -v ssh-agent", panic: false, out: File::NULL, err: File::NULL)
49
- subshell("docker", "volume rm ssh_data", panic: false, out: File::NULL, err: File::NULL)
47
+ exec_subprocess("docker", "stop ssh-agent", panic: false, out: File::NULL, err: File::NULL)
48
+ exec_subprocess("docker", "rm -v ssh-agent", panic: false, out: File::NULL, err: File::NULL)
49
+ exec_subprocess("docker", "volume rm ssh_data", panic: false, out: File::NULL, err: File::NULL)
50
50
  end
51
51
  end
52
52
 
53
53
  class Status < Dip::Command
54
54
  def execute
55
- subshell("docker", "inspect --format '{{.State.Status}}' ssh-agent")
55
+ exec_subprocess("docker", "inspect --format '{{.State.Status}}' ssh-agent")
56
56
  end
57
57
  end
58
58
  end
@@ -60,6 +60,7 @@ module Dip
60
60
  description: entry[:description],
61
61
  service: entry[:service],
62
62
  command: entry[:command].to_s.strip,
63
+ shell: entry.fetch(:shell, true),
63
64
  default_args: entry[:default_args].to_s.strip,
64
65
  environment: entry[:environment] || {},
65
66
  compose: {
data/lib/dip/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dip
4
- VERSION = "7.0.1"
4
+ VERSION = "7.1.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dip
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.1
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bibendi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-12 00:00:00.000000000 Z
11
+ date: 2021-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor