dru 0.1.0 → 0.3.1
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/Gemfile.lock +1 -1
- data/lib/dru/cli.rb +34 -1
- data/lib/dru/command.rb +11 -1
- data/lib/dru/commands/exec.rb +13 -0
- data/lib/dru/commands/runner.rb +19 -0
- data/lib/dru/commands/up.rb +1 -1
- data/lib/dru/container_command.rb +24 -0
- data/lib/dru/templates/exec/.gitkeep +1 -0
- data/lib/dru/templates/runner/.gitkeep +1 -0
- data/lib/dru/version.rb +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecaeff419166c955c4db31d00e6f8ec4af1a51d66d8b07adb4ef9a4313e489f4
|
4
|
+
data.tar.gz: d271501bff0d3d7f3d5acdb7af9d3640bd0ee49ab513453e5f47e6db77ac32c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 841e2324220cdce42b0670ef357dc8d17e3a1392f43bc5ea55fd14fa7589ed79d6708859f5dd90c7400c71204f70c70b4901001b1caf267f9766c2df6800bd6b
|
7
|
+
data.tar.gz: d2fbe9d4e1678fd0fb31a59263e364a119672fce16b9505d0b87f5d23e39596b06ea51fefdbd8cc9df5458b0418ddbcf7bb1f12833090549570c95c921fe037b
|
data/Gemfile.lock
CHANGED
data/lib/dru/cli.rb
CHANGED
@@ -18,6 +18,22 @@ module Dru
|
|
18
18
|
end
|
19
19
|
map %w(--version -v) => :version
|
20
20
|
|
21
|
+
desc 'exec', 'Execute a command in a running container.'
|
22
|
+
method_option :help, aliases: '-h', type: :boolean,
|
23
|
+
desc: 'Display usage information'
|
24
|
+
method_option :container, aliases: '-c', type: :string, default: 'app',
|
25
|
+
desc: 'Container name'
|
26
|
+
method_option :environment, aliases: '-e', type: :string,
|
27
|
+
desc: 'Environment'
|
28
|
+
def exec(*command)
|
29
|
+
if options[:help]
|
30
|
+
invoke :help, ['exec']
|
31
|
+
else
|
32
|
+
require_relative 'commands/exec'
|
33
|
+
Dru::Commands::Exec.new(command: command, options: options).execute
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
21
37
|
desc 'up', 'Build, (re)create, start, and attach to default container'
|
22
38
|
method_option :help, aliases: '-h', type: :boolean,
|
23
39
|
desc: 'Display usage information'
|
@@ -28,8 +44,25 @@ module Dru
|
|
28
44
|
invoke :help, ['up']
|
29
45
|
else
|
30
46
|
require_relative 'commands/up'
|
31
|
-
Dru::Commands::Up.new(options).execute
|
47
|
+
Dru::Commands::Up.new(options: options).execute
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'run', 'Command description...'
|
52
|
+
method_option :help, aliases: '-h', type: :boolean,
|
53
|
+
desc: 'Display usage information'
|
54
|
+
method_option :container, aliases: '-c', type: :string, default: 'app',
|
55
|
+
desc: 'Container name'
|
56
|
+
method_option :environment, aliases: '-e', type: :string,
|
57
|
+
desc: 'Environment'
|
58
|
+
def runner(*command)
|
59
|
+
if options[:help]
|
60
|
+
invoke :help, ['runner']
|
61
|
+
else
|
62
|
+
require_relative 'commands/runner'
|
63
|
+
Dru::Commands::Runner.new(command: command, options: options).execute
|
32
64
|
end
|
33
65
|
end
|
66
|
+
map %w(run) => :runner
|
34
67
|
end
|
35
68
|
end
|
data/lib/dru/command.rb
CHANGED
@@ -6,6 +6,12 @@ module Dru
|
|
6
6
|
class Command
|
7
7
|
extend Forwardable
|
8
8
|
|
9
|
+
class MissingContainerError < StandardError
|
10
|
+
def initialize(msg = 'Missing container')
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
9
15
|
DOCKER_COMPOSE_COMMAND = 'docker-compose'.freeze
|
10
16
|
|
11
17
|
attr_accessor :options
|
@@ -149,7 +155,11 @@ module Dru
|
|
149
155
|
end
|
150
156
|
|
151
157
|
def run_docker_compose_command(*args, **options)
|
152
|
-
|
158
|
+
if options[:tty]
|
159
|
+
system(DOCKER_COMPOSE_COMMAND, *docker_compose_paths, *args)
|
160
|
+
else
|
161
|
+
command(options).run(DOCKER_COMPOSE_COMMAND, *docker_compose_paths, *args)
|
162
|
+
end
|
153
163
|
end
|
154
164
|
|
155
165
|
def container_name_to_id(container_name = 'app')
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../container_command'
|
4
|
+
|
5
|
+
module Dru
|
6
|
+
module Commands
|
7
|
+
class Exec < Dru::ContainerCommand
|
8
|
+
def execute(input: $stdin, output: $stdout)
|
9
|
+
run_docker_compose_command('exec', container, *@command, tty: true)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../container_command'
|
4
|
+
|
5
|
+
module Dru
|
6
|
+
module Commands
|
7
|
+
class Runner < Dru::ContainerCommand
|
8
|
+
def execute(input: $stdin, output: $stdout)
|
9
|
+
run_docker_compose_command('run', '--rm', '--entrypoint', 'sh -c', container, command, tty: true)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def command
|
15
|
+
@command.join(' ')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/dru/commands/up.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './command'
|
4
|
+
|
5
|
+
module Dru
|
6
|
+
class ContainerCommand < Command
|
7
|
+
def initialize(command:, options:)
|
8
|
+
raise MissingContainerError unless options[:container]
|
9
|
+
|
10
|
+
@options = options
|
11
|
+
@command = command || []
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute(input: $stdin, output: $stdout)
|
15
|
+
raise NotImplementedError
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def container
|
21
|
+
options[:container]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
data/lib/dru/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Rimondi
|
@@ -364,9 +364,14 @@ files:
|
|
364
364
|
- lib/dru/cli.rb
|
365
365
|
- lib/dru/command.rb
|
366
366
|
- lib/dru/commands/.gitkeep
|
367
|
+
- lib/dru/commands/exec.rb
|
368
|
+
- lib/dru/commands/runner.rb
|
367
369
|
- lib/dru/commands/up.rb
|
368
370
|
- lib/dru/config.rb
|
371
|
+
- lib/dru/container_command.rb
|
369
372
|
- lib/dru/templates/.gitkeep
|
373
|
+
- lib/dru/templates/exec/.gitkeep
|
374
|
+
- lib/dru/templates/runner/.gitkeep
|
370
375
|
- lib/dru/templates/up/.gitkeep
|
371
376
|
- lib/dru/version.rb
|
372
377
|
homepage: https://github.com/nebulab/dru
|