dip 7.0.1 → 7.1.3

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: 42ac21bbebf1b0ad111a5bc783a9a539ad9b27bf6ef46b6e64fb3a6109f87005
4
+ data.tar.gz: 8988eb2450aaa51ddfacc05749405fdc1879da5f622bc130fb8d4a64af0b7359
5
5
  SHA512:
6
- metadata.gz: 8a2d4acb5cac37f00a2dcb3132ca034fb9b8121c1d2d0b816a4b37a565b631afdc12b73a2701cd115389d56efb60d4241fe55253e5b59c122dce364b174b8a06
7
- data.tar.gz: ca168782f5af0500f4352631dd56237543b3c685b8b3d40819c240b58ec62c075ee01e5fd211c506855875e8c32e33c4afaf0df1f3131bbef2c98aa126fff518
6
+ metadata.gz: f9f6c9e006584fa20d7d42b4586b8b35a5908aa8f1587f4ca506cb42445b786db5a569033af8f466606db015c681458b6f961221afef360d0b7558cf941fa631
7
+ data.tar.gz: f77739aa2ffc4c245630732c88f2264a4c83421d1dc8b83807776d8c2eac507b991743aa3e482a117edcfc0424deb3e4a93785e69c9a46e47fb8d08db2fa28a9
data/README.md CHANGED
@@ -81,7 +81,7 @@ Also, you can check out examples at the top.
81
81
 
82
82
  ```yml
83
83
  # Required minimum dip version
84
- version: '7.0'
84
+ version: '7.1'
85
85
 
86
86
  environment:
87
87
  COMPOSE_EXT: development
@@ -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/*
@@ -292,8 +298,6 @@ Runs Nginx server container based on [bibendi/nginx-proxy](https://github.com/bi
292
298
  foo-project/docker-compose.yml
293
299
 
294
300
  ```yml
295
- version: '2'
296
-
297
301
  services:
298
302
  foo-web:
299
303
  image: company/foo_image
@@ -314,8 +318,6 @@ networks:
314
318
  baz-project/docker-compose.yml
315
319
 
316
320
  ```yml
317
- version: '2'
318
-
319
321
  services:
320
322
  baz-web:
321
323
  image: company/baz_image
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)
@@ -73,9 +78,17 @@ module Dip
73
78
 
74
79
  def get_args
75
80
  if argv.any?
76
- argv
81
+ if command[:shell]
82
+ [argv.shelljoin]
83
+ else
84
+ Array(argv)
85
+ end
77
86
  elsif !(default_args = command[:default_args]).empty?
78
- Array(default_args)
87
+ if command[:shell]
88
+ default_args.shellsplit
89
+ else
90
+ Array(default_args)
91
+ end
79
92
  else
80
93
  []
81
94
  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
data/lib/dip/config.rb CHANGED
@@ -62,10 +62,19 @@ module Dip
62
62
  def load_yaml(file_path = path)
63
63
  return {} unless File.exist?(file_path)
64
64
 
65
- YAML.safe_load(
66
- ERB.new(File.read(file_path)).result,
67
- [], [], true
68
- )&.deep_symbolize_keys! || {}
65
+ data = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("4.0.0")
66
+ YAML.safe_load(
67
+ ERB.new(File.read(file_path)).result,
68
+ aliases: true
69
+ )
70
+ else
71
+ YAML.safe_load(
72
+ ERB.new(File.read(file_path)).result,
73
+ [], [], true
74
+ )
75
+ end
76
+
77
+ data&.deep_symbolize_keys! || {}
69
78
  end
70
79
  end
71
80
 
@@ -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.3"
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - bibendi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-12 00:00:00.000000000 Z
11
+ date: 2021-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0.20'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '1.1'
22
+ version: '2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '0.20'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '1.1'
32
+ version: '2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -196,7 +196,7 @@ licenses:
196
196
  - MIT
197
197
  metadata:
198
198
  allowed_push_host: https://rubygems.org/
199
- post_install_message:
199
+ post_install_message:
200
200
  rdoc_options: []
201
201
  require_paths:
202
202
  - lib
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  version: '0'
213
213
  requirements: []
214
214
  rubygems_version: 3.1.2
215
- signing_key:
215
+ signing_key:
216
216
  specification_version: 4
217
217
  summary: Ruby gem CLI tool for better interacting docker-compose files.
218
218
  test_files: []