dru 0.1.0 → 0.3.1

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: 452af962ffdb65caeb9f532ae055d0fc5980645f8705f2131da025797765dced
4
- data.tar.gz: 784dd5cdace3cd50a0695631473fc4d975be639dbe2828c2994aba6a0c6212f5
3
+ metadata.gz: ecaeff419166c955c4db31d00e6f8ec4af1a51d66d8b07adb4ef9a4313e489f4
4
+ data.tar.gz: d271501bff0d3d7f3d5acdb7af9d3640bd0ee49ab513453e5f47e6db77ac32c7
5
5
  SHA512:
6
- metadata.gz: 12517a5b8a94c16a61ba5e7084ce2c90cd6f5b5c1bfbb596309bcdbd3b829c964481f70c0b7ef22099ec9859cc1fb7c106a111842fbcf4d21b9ffd3b56fc3bd1
7
- data.tar.gz: 726ed77400c89bfb343b3460c4ec99aafdfb8598eff1dd8386ff15e234b643f23d5674167108e81a8c17182daaad86b3d6e5e74a0be57fe47da3ebd3cf90616d
6
+ metadata.gz: 841e2324220cdce42b0670ef357dc8d17e3a1392f43bc5ea55fd14fa7589ed79d6708859f5dd90c7400c71204f70c70b4901001b1caf267f9766c2df6800bd6b
7
+ data.tar.gz: d2fbe9d4e1678fd0fb31a59263e364a119672fce16b9505d0b87f5d23e39596b06ea51fefdbd8cc9df5458b0418ddbcf7bb1f12833090549570c95c921fe037b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dru (0.1.0)
4
+ dru (0.3.1)
5
5
  pastel (~> 0.7.2)
6
6
  thor (~> 0.20.0)
7
7
  tty-color (~> 0.4.2)
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
- command(options).run(DOCKER_COMPOSE_COMMAND, *docker_compose_paths, *args)
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
@@ -7,7 +7,7 @@ module Dru
7
7
  class Up < Dru::Command
8
8
  DOCKER_ATTACH_COMMAND = 'docker attach --detach-keys="ctrl-d"'.freeze
9
9
 
10
- def initialize(options)
10
+ def initialize(options:)
11
11
  @options = options
12
12
  end
13
13
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Dru
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.0
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