dip 7.4.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +40 -5
- data/lib/dip/cli.rb +13 -3
- data/lib/dip/commands/kubectl.rb +34 -0
- data/lib/dip/commands/run.rb +20 -66
- data/lib/dip/commands/runners/base.rb +41 -0
- data/lib/dip/commands/runners/docker_compose_runner.rb +63 -0
- data/lib/dip/commands/runners/kubectl_runner.rb +34 -0
- data/lib/dip/commands/runners/local_runner.rb +20 -0
- data/lib/dip/config.rb +2 -1
- data/lib/dip/interaction_tree.rb +3 -0
- data/lib/dip/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: be7ef96533ac533734f04b61b49864b8db104269813c5dd00d8192d968c0c1dd
|
|
4
|
+
data.tar.gz: 74d31efceda6300bd5f93023f5a108c3a9972d2b4416d0e4433e98f7ec76f61e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aafe6a31332d687c065c29e34d3c8fdc69bdc6c0507aa4a4c1d3fc1c68d5ded516c4f52e2b7092b34cf585a3ceb9f69ad4a6b764a41863ea090323d5b0a5b2c2
|
|
7
|
+
data.tar.gz: 6d801682b927567b84f07a0f7df75535d35ac1f11a953f286cc9785a8d415d55d5940b72a68365d2cafaa13e02b9aafa01f6f58282a41e2c37546274553fbf74
|
data/README.md
CHANGED
|
@@ -38,8 +38,7 @@ After that we can type commands without `dip` prefix. For example:
|
|
|
38
38
|
<run-command> *any-args
|
|
39
39
|
compose *any-compose-arg
|
|
40
40
|
up <service>
|
|
41
|
-
|
|
42
|
-
down
|
|
41
|
+
ktl *any-kubectl-arg
|
|
43
42
|
provision
|
|
44
43
|
```
|
|
45
44
|
|
|
@@ -81,10 +80,11 @@ Also, you can check out examples at the top.
|
|
|
81
80
|
|
|
82
81
|
```yml
|
|
83
82
|
# Required minimum dip version
|
|
84
|
-
version: '7.
|
|
83
|
+
version: '7.5'
|
|
85
84
|
|
|
86
85
|
environment:
|
|
87
86
|
COMPOSE_EXT: development
|
|
87
|
+
STAGE: "staging"
|
|
88
88
|
|
|
89
89
|
compose:
|
|
90
90
|
files:
|
|
@@ -93,6 +93,9 @@ compose:
|
|
|
93
93
|
- docker/docker-compose.$DIP_OS.yml
|
|
94
94
|
project_name: bear
|
|
95
95
|
|
|
96
|
+
kubectl:
|
|
97
|
+
namespace: rocket-$STAGE
|
|
98
|
+
|
|
96
99
|
interaction:
|
|
97
100
|
shell:
|
|
98
101
|
description: Open the Bash shell in app's container
|
|
@@ -142,6 +145,22 @@ interaction:
|
|
|
142
145
|
default_args: db_dev
|
|
143
146
|
command: psql -h pg -U postgres
|
|
144
147
|
|
|
148
|
+
k:
|
|
149
|
+
description: Run commands in Kubernetes cluster
|
|
150
|
+
pod: svc/rocket-app:app-container
|
|
151
|
+
entrypoint: /env-entrypoint
|
|
152
|
+
subcommands:
|
|
153
|
+
bash:
|
|
154
|
+
description: Get a shell to the running container
|
|
155
|
+
command: /bin/bash
|
|
156
|
+
rails:
|
|
157
|
+
description: Run Rails commands
|
|
158
|
+
command: bundle exec rails
|
|
159
|
+
kafka-topics:
|
|
160
|
+
description: Manage Kafka topics
|
|
161
|
+
pod: svc/rocket-kafka
|
|
162
|
+
command: kafka-topics.sh --zookeeper zookeeper:2181
|
|
163
|
+
|
|
145
164
|
setup_key:
|
|
146
165
|
description: Copy key
|
|
147
166
|
service: app
|
|
@@ -201,7 +220,13 @@ returned is `/app/sub-project-dir`.
|
|
|
201
220
|
|
|
202
221
|
Run commands defined within the `interaction` section of dip.yml
|
|
203
222
|
|
|
204
|
-
|
|
223
|
+
A command will be executed by specified runner. Dip has three types of them:
|
|
224
|
+
|
|
225
|
+
- `docker-compose` runner — used when the `service` option is defined.
|
|
226
|
+
- `kubectl` runner — used when the `pod` option is defined.
|
|
227
|
+
- `local` runner — used when the previous ones are not defined.
|
|
228
|
+
|
|
229
|
+
If you are still using `docker-compose` binary (i.e., prior to Compose V2 changes), a command would be run through it. You can disable using of Compose V2 by passing an environment variable `DIP_COMPOSE_V2=false dip run`.
|
|
205
230
|
|
|
206
231
|
```sh
|
|
207
232
|
dip run rails c
|
|
@@ -254,7 +279,7 @@ Run commands each by each from `provision` section of dip.yml
|
|
|
254
279
|
|
|
255
280
|
### dip compose
|
|
256
281
|
|
|
257
|
-
Run docker-compose commands that are configured according to the application's dip.yml
|
|
282
|
+
Run docker-compose commands that are configured according to the application's dip.yml:
|
|
258
283
|
|
|
259
284
|
```sh
|
|
260
285
|
dip compose COMMAND [OPTIONS]
|
|
@@ -262,6 +287,16 @@ dip compose COMMAND [OPTIONS]
|
|
|
262
287
|
dip compose up -d redis
|
|
263
288
|
```
|
|
264
289
|
|
|
290
|
+
### dip ktl
|
|
291
|
+
|
|
292
|
+
Run kubectl commands that are configured according to the application's dip.yml:
|
|
293
|
+
|
|
294
|
+
```sh
|
|
295
|
+
dip ktl COMMAND [OPTIONS]
|
|
296
|
+
|
|
297
|
+
STAGE=some dip ktl get pods
|
|
298
|
+
```
|
|
299
|
+
|
|
265
300
|
### dip ssh
|
|
266
301
|
|
|
267
302
|
Runs ssh-agent container based on https://github.com/whilp/ssh-agent with your ~/.ssh/id_rsa.
|
data/lib/dip/cli.rb
CHANGED
|
@@ -32,7 +32,7 @@ module Dip
|
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
stop_on_unknown_option! :run
|
|
35
|
+
stop_on_unknown_option! :run, :ktl
|
|
36
36
|
|
|
37
37
|
desc "version", "dip version"
|
|
38
38
|
def version
|
|
@@ -82,7 +82,13 @@ module Dip
|
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
desc "
|
|
85
|
+
desc "ktl CMD [OPTIONS]", "Run kubectl commands"
|
|
86
|
+
def ktl(*argv)
|
|
87
|
+
require_relative "commands/kubectl"
|
|
88
|
+
Dip::Commands::Kubectl.new(*argv).execute
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
desc "run [OPTIONS] CMD [ARGS]", "Run configured command (`run` prefix may be omitted)"
|
|
86
92
|
method_option :publish, aliases: "-p", type: :string, repeatable: true,
|
|
87
93
|
desc: "Publish a container's port(s) to the host"
|
|
88
94
|
method_option :help, aliases: "-h", type: :boolean, desc: "Display usage information"
|
|
@@ -91,7 +97,11 @@ module Dip
|
|
|
91
97
|
invoke :help, ["run"]
|
|
92
98
|
else
|
|
93
99
|
require_relative "commands/run"
|
|
94
|
-
|
|
100
|
+
|
|
101
|
+
Dip::Commands::Run.new(
|
|
102
|
+
*argv,
|
|
103
|
+
**options.to_h.transform_keys!(&:to_sym)
|
|
104
|
+
).execute
|
|
95
105
|
end
|
|
96
106
|
end
|
|
97
107
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../command"
|
|
4
|
+
|
|
5
|
+
module Dip
|
|
6
|
+
module Commands
|
|
7
|
+
class Kubectl < Dip::Command
|
|
8
|
+
attr_reader :argv, :config
|
|
9
|
+
|
|
10
|
+
def initialize(*argv)
|
|
11
|
+
@argv = argv
|
|
12
|
+
@config = ::Dip.config.kubectl || {}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def execute
|
|
16
|
+
k_argv = cli_options + argv
|
|
17
|
+
|
|
18
|
+
exec_program("kubectl", k_argv)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def cli_options
|
|
24
|
+
%i[namespace].flat_map do |name|
|
|
25
|
+
next unless (value = config[name])
|
|
26
|
+
next unless value.is_a?(String)
|
|
27
|
+
|
|
28
|
+
value = ::Dip.env.interpolate(value).delete_suffix("-")
|
|
29
|
+
["--#{name.to_s.tr("_", "-")}", value]
|
|
30
|
+
end.compact
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/dip/commands/run.rb
CHANGED
|
@@ -4,13 +4,17 @@ require "shellwords"
|
|
|
4
4
|
require_relative "../../../lib/dip/run_vars"
|
|
5
5
|
require_relative "../command"
|
|
6
6
|
require_relative "../interaction_tree"
|
|
7
|
-
require_relative "
|
|
7
|
+
require_relative "runners/local_runner"
|
|
8
|
+
require_relative "runners/docker_compose_runner"
|
|
9
|
+
require_relative "runners/kubectl_runner"
|
|
10
|
+
|
|
11
|
+
require_relative "kubectl"
|
|
8
12
|
|
|
9
13
|
module Dip
|
|
10
14
|
module Commands
|
|
11
15
|
class Run < Dip::Command
|
|
12
|
-
def initialize(cmd, *argv,
|
|
13
|
-
@
|
|
16
|
+
def initialize(cmd, *argv, **options)
|
|
17
|
+
@options = options
|
|
14
18
|
|
|
15
19
|
@command, @argv = InteractionTree
|
|
16
20
|
.new(Dip.config.interaction)
|
|
@@ -22,75 +26,25 @@ module Dip
|
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def execute
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Dip::Commands::Compose.new(
|
|
29
|
-
command[:compose][:method],
|
|
30
|
-
*compose_arguments,
|
|
31
|
-
shell: command[:shell]
|
|
32
|
-
).execute
|
|
33
|
-
end
|
|
29
|
+
lookup_runner
|
|
30
|
+
.new(command, argv, **options)
|
|
31
|
+
.execute
|
|
34
32
|
end
|
|
35
33
|
|
|
36
34
|
private
|
|
37
35
|
|
|
38
|
-
attr_reader :command, :argv, :
|
|
39
|
-
|
|
40
|
-
def compose_arguments
|
|
41
|
-
compose_argv = command[:compose][:run_options].dup
|
|
42
|
-
|
|
43
|
-
if command[:compose][:method] == "run"
|
|
44
|
-
compose_argv.concat(run_vars)
|
|
45
|
-
compose_argv.concat(published_ports)
|
|
46
|
-
compose_argv << "--rm"
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
compose_argv << command.fetch(:service)
|
|
50
|
-
|
|
51
|
-
unless (cmd = command[:command]).empty?
|
|
52
|
-
if command[:shell]
|
|
53
|
-
compose_argv << cmd
|
|
54
|
-
else
|
|
55
|
-
compose_argv.concat(cmd.shellsplit)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
compose_argv.concat(get_args)
|
|
60
|
-
|
|
61
|
-
compose_argv
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def run_vars
|
|
65
|
-
run_vars = Dip::RunVars.env
|
|
66
|
-
return [] unless run_vars
|
|
67
|
-
|
|
68
|
-
run_vars.map { |k, v| ["-e", "#{k}=#{Shellwords.escape(v)}"] }.flatten
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def published_ports
|
|
72
|
-
if publish.respond_to?(:each)
|
|
73
|
-
publish.map { |p| "--publish=#{p}" }
|
|
74
|
-
else
|
|
75
|
-
[]
|
|
76
|
-
end
|
|
77
|
-
end
|
|
36
|
+
attr_reader :command, :argv, :options
|
|
78
37
|
|
|
79
|
-
def
|
|
80
|
-
if
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if command[:shell]
|
|
88
|
-
default_args.shellsplit
|
|
89
|
-
else
|
|
90
|
-
Array(default_args)
|
|
91
|
-
end
|
|
38
|
+
def lookup_runner
|
|
39
|
+
if (runner = command[:runner])
|
|
40
|
+
camelized_runner = runner.split("_").collect(&:capitalize).join
|
|
41
|
+
Runners.const_get("#{camelized_runner}Runner")
|
|
42
|
+
elsif command[:service]
|
|
43
|
+
Runners::DockerComposeRunner
|
|
44
|
+
elsif command[:pod]
|
|
45
|
+
Runners::KubectlRunner
|
|
92
46
|
else
|
|
93
|
-
|
|
47
|
+
Runners::LocalRunner
|
|
94
48
|
end
|
|
95
49
|
end
|
|
96
50
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dip
|
|
4
|
+
module Commands
|
|
5
|
+
module Runners
|
|
6
|
+
class Base
|
|
7
|
+
def initialize(command, argv, **options)
|
|
8
|
+
@command = command
|
|
9
|
+
@argv = argv
|
|
10
|
+
@options = options
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def execute
|
|
14
|
+
raise NotImplementedError
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
attr_reader :command, :argv, :options
|
|
20
|
+
|
|
21
|
+
def command_args
|
|
22
|
+
if argv.any?
|
|
23
|
+
if command[:shell]
|
|
24
|
+
[argv.shelljoin]
|
|
25
|
+
else
|
|
26
|
+
Array(argv)
|
|
27
|
+
end
|
|
28
|
+
elsif !(default_args = command[:default_args]).empty?
|
|
29
|
+
if command[:shell]
|
|
30
|
+
default_args.shellsplit
|
|
31
|
+
else
|
|
32
|
+
Array(default_args)
|
|
33
|
+
end
|
|
34
|
+
else
|
|
35
|
+
[]
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
require_relative "../compose"
|
|
5
|
+
|
|
6
|
+
module Dip
|
|
7
|
+
module Commands
|
|
8
|
+
module Runners
|
|
9
|
+
class DockerComposeRunner < Base
|
|
10
|
+
def execute
|
|
11
|
+
Commands::Compose.new(
|
|
12
|
+
command[:compose][:method],
|
|
13
|
+
*compose_arguments,
|
|
14
|
+
shell: command[:shell]
|
|
15
|
+
).execute
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def compose_arguments
|
|
21
|
+
compose_argv = command[:compose][:run_options].dup
|
|
22
|
+
|
|
23
|
+
if command[:compose][:method] == "run"
|
|
24
|
+
compose_argv.concat(run_vars)
|
|
25
|
+
compose_argv.concat(published_ports)
|
|
26
|
+
compose_argv << "--rm"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
compose_argv << command.fetch(:service)
|
|
30
|
+
|
|
31
|
+
unless (cmd = command[:command]).empty?
|
|
32
|
+
if command[:shell]
|
|
33
|
+
compose_argv << cmd
|
|
34
|
+
else
|
|
35
|
+
compose_argv.concat(cmd.shellsplit)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
compose_argv.concat(command_args)
|
|
40
|
+
|
|
41
|
+
compose_argv
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def run_vars
|
|
45
|
+
run_vars = Dip::RunVars.env
|
|
46
|
+
return [] unless run_vars
|
|
47
|
+
|
|
48
|
+
run_vars.map { |k, v| ["-e", "#{k}=#{Shellwords.escape(v)}"] }.flatten
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def published_ports
|
|
52
|
+
publish = options[:publish]
|
|
53
|
+
|
|
54
|
+
if publish.respond_to?(:each)
|
|
55
|
+
publish.map { |p| "--publish=#{p}" }
|
|
56
|
+
else
|
|
57
|
+
[]
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
require_relative "../kubectl"
|
|
5
|
+
|
|
6
|
+
module Dip
|
|
7
|
+
module Commands
|
|
8
|
+
module Runners
|
|
9
|
+
class KubectlRunner < Base
|
|
10
|
+
def execute
|
|
11
|
+
Commands::Kubectl.new(*kubectl_arguments).execute
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def kubectl_arguments
|
|
17
|
+
argv = ["exec", "--tty", "--stdin"]
|
|
18
|
+
|
|
19
|
+
pod, container = command.fetch(:pod).split(":")
|
|
20
|
+
argv.push("--container", container) unless container.nil?
|
|
21
|
+
argv.push(pod, "--")
|
|
22
|
+
|
|
23
|
+
unless (entrypoint = command[:entrypoint]).nil?
|
|
24
|
+
argv << entrypoint
|
|
25
|
+
end
|
|
26
|
+
argv << command.fetch(:command)
|
|
27
|
+
argv.concat(command_args)
|
|
28
|
+
|
|
29
|
+
argv
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
require_relative "../../command"
|
|
5
|
+
|
|
6
|
+
module Dip
|
|
7
|
+
module Commands
|
|
8
|
+
module Runners
|
|
9
|
+
class LocalRunner < Base
|
|
10
|
+
def execute
|
|
11
|
+
Dip::Command.exec_program(
|
|
12
|
+
command[:command],
|
|
13
|
+
command_args,
|
|
14
|
+
shell: command[:shell]
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/dip/config.rb
CHANGED
|
@@ -16,6 +16,7 @@ module Dip
|
|
|
16
16
|
CONFIG_DEFAULTS = {
|
|
17
17
|
environment: {},
|
|
18
18
|
compose: {},
|
|
19
|
+
kubectl: {},
|
|
19
20
|
interation: {},
|
|
20
21
|
provision: []
|
|
21
22
|
}.freeze
|
|
@@ -94,7 +95,7 @@ module Dip
|
|
|
94
95
|
config
|
|
95
96
|
end
|
|
96
97
|
|
|
97
|
-
%i[environment compose interaction provision].each do |key|
|
|
98
|
+
%i[environment compose kubectl interaction provision].each do |key|
|
|
98
99
|
define_method(key) do
|
|
99
100
|
config[key] || (raise config_missing_error(key))
|
|
100
101
|
end
|
data/lib/dip/interaction_tree.rb
CHANGED
|
@@ -58,7 +58,10 @@ module Dip
|
|
|
58
58
|
def build_command(entry)
|
|
59
59
|
{
|
|
60
60
|
description: entry[:description],
|
|
61
|
+
runner: entry[:runner],
|
|
61
62
|
service: entry[:service],
|
|
63
|
+
pod: entry[:pod],
|
|
64
|
+
entrypoint: entry[:entrypoint],
|
|
62
65
|
command: entry[:command].to_s.strip,
|
|
63
66
|
shell: entry.fetch(:shell, true),
|
|
64
67
|
default_args: entry[:default_args].to_s.strip,
|
data/lib/dip/version.rb
CHANGED
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.
|
|
4
|
+
version: 7.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- bibendi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-11-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|
|
@@ -180,10 +180,15 @@ files:
|
|
|
180
180
|
- lib/dip/commands/console.rb
|
|
181
181
|
- lib/dip/commands/dns.rb
|
|
182
182
|
- lib/dip/commands/down_all.rb
|
|
183
|
+
- lib/dip/commands/kubectl.rb
|
|
183
184
|
- lib/dip/commands/list.rb
|
|
184
185
|
- lib/dip/commands/nginx.rb
|
|
185
186
|
- lib/dip/commands/provision.rb
|
|
186
187
|
- lib/dip/commands/run.rb
|
|
188
|
+
- lib/dip/commands/runners/base.rb
|
|
189
|
+
- lib/dip/commands/runners/docker_compose_runner.rb
|
|
190
|
+
- lib/dip/commands/runners/kubectl_runner.rb
|
|
191
|
+
- lib/dip/commands/runners/local_runner.rb
|
|
187
192
|
- lib/dip/commands/ssh.rb
|
|
188
193
|
- lib/dip/config.rb
|
|
189
194
|
- lib/dip/environment.rb
|