sidedock 1.0.1 → 1.0.2

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
  SHA1:
3
- metadata.gz: 92788013f2d5b7639cfc7019d1a31ca8ae3530cf
4
- data.tar.gz: e8a6675dac27fb06acca0fb3cd7e8815e62d1094
3
+ metadata.gz: 1547b9506277f91d09403b7711efa3c74fcdf5df
4
+ data.tar.gz: 9336b1ac9f4dda4a8d9f33eadf2266123ae7ed4f
5
5
  SHA512:
6
- metadata.gz: 928fd851e3813ca8548783e60ea911c85966541ddde878e3a5ef19ead5a2e4b91534f22e15877d6aaa8596142b866b3fa664c6ccaa47211ea5863fafe094b89b
7
- data.tar.gz: 4f8ccc2cfe822ff9e7464ec1a04efa0f0b46232656d791fd8c02d8656f36dcb165d0e971d67adc9b912d49d1899d1b48e6e8207ce0b8d0b375d0b9c8382ad535
6
+ metadata.gz: 3ced41b69bc14f0f387ef69a63f308cd21f5805961eb8d5c277c5d2348dd8c7899952a58a2cb72d5e34539ca262664b23435741097bce3224deaeb05e7444b2e
7
+ data.tar.gz: 0fcf42814c428f75a2cde390e7f648011af4fd1bd4235c55c1108b640395b7668d12f19a9b1f56440d4d5502e55fb77fd579d2f95b1d0fd8f601fe8984972d8b
data/lib/sidedock/cli.rb CHANGED
@@ -6,15 +6,31 @@ module Sidedock
6
6
 
7
7
  def initialize(default_options = '')
8
8
  @default_options = default_options
9
- @cmd = TTY::Command.new
10
9
  end
11
10
 
11
+
12
12
  def execute(command)
13
13
  full_command = "#{program} #{@default_options} #{command}"
14
- stdout, stderr = @cmd.run full_command
14
+ stdout, stderr = command_runner.run full_command
15
15
  raise "`#{command}` failed" if stderr.present?
16
16
  stdout.strip
17
17
  end
18
+
19
+ def command_runner
20
+ if Sidedock.configuration.debug
21
+ debug_command_runner
22
+ else
23
+ quiet_command_runner
24
+ end
25
+ end
26
+
27
+ def debug_command_runner
28
+ @debug_command_runner ||= TTY::Command.new
29
+ end
30
+
31
+ def quiet_command_runner
32
+ @quiet_command_runner ||= TTY::Command.new printer: :null
33
+ end
18
34
  end
19
35
  end
20
36
 
@@ -0,0 +1,25 @@
1
+ # Allow gem users to do:
2
+ #
3
+ # Sidedock.configure do |config|
4
+ # config.debug = true
5
+ # end
6
+
7
+ module Sidedock
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ def self.configure
13
+ self.configuration ||= Configuration.new
14
+ yield configuration
15
+ end
16
+
17
+ class Configuration
18
+ attr_accessor :debug
19
+
20
+ def initialize
21
+ @debug = false
22
+ end
23
+ end
24
+ end
25
+
@@ -2,7 +2,7 @@ module Sidedock
2
2
  class Container < Base
3
3
  attr_accessor :ports, :id
4
4
 
5
- def initialize(id, port_mapping: {})
5
+ def initialize(id, port_mapping: {}, **options)
6
6
  @id = id
7
7
  @port_mapping = port_mapping
8
8
  end
@@ -28,7 +28,7 @@ module Sidedock
28
28
  end
29
29
 
30
30
  def ports
31
- Ports.new(@id, @port_mapping) if @port_mapping.present?
31
+ @ports ||= Ports.new @id, @port_mapping
32
32
  end
33
33
 
34
34
  def running?
@@ -17,7 +17,6 @@ module Sidedock
17
17
 
18
18
  def self.build(dockerfile_path)
19
19
  built_id = machine.execute "build -q #{dockerfile_path}"
20
- Rails.logger.info "Built #{dockerfile_path}, image ID: #{built_id}"
21
20
  new built_id
22
21
  end
23
22
  end
@@ -15,10 +15,6 @@ module Sidedock
15
15
  raise "Could not start docker machine #{@name}" unless running?
16
16
  end
17
17
 
18
- def running?
19
- docker_machine("ls -q --filter state=Running").include? @name
20
- end
21
-
22
18
  def start
23
19
  docker_machine "start #{@name}"
24
20
  end
@@ -28,8 +24,18 @@ module Sidedock
28
24
  docker_machine "create -d virtualbox #{@name}"
29
25
  end
30
26
 
27
+ def running?
28
+ return true if @running
29
+ if docker_machine("ls -q --filter state=Running").include? @name
30
+ @running = true
31
+ end
32
+ end
33
+
31
34
  def exists?
32
- docker_machine("ls -q").include? @name
35
+ return true if @exists
36
+ if docker_machine("ls -q").include? @name
37
+ @exists = true
38
+ end
33
39
  end
34
40
 
35
41
  def ip
data/lib/sidedock.rb CHANGED
@@ -1,4 +1,4 @@
1
- %w( cli machine base image container ports port_configuration
1
+ %w( configuration cli machine base image container ports port_configuration
2
2
  ).each { |file| require "sidedock/#{file}" }
3
3
 
4
4
  module Sidedock
@@ -8,7 +8,7 @@ module Sidedock
8
8
  container.start
9
9
  yield container
10
10
  container.stop
11
- container.remove
11
+ container.remove unless options[:keep_image]
12
12
  end
13
13
 
14
14
  def with_dockerfile(name, options = {}, &block)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidedock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Raasveld
@@ -35,6 +35,7 @@ files:
35
35
  - lib/sidedock/cli.rb
36
36
  - lib/sidedock/cli/docker_cli.rb
37
37
  - lib/sidedock/cli/machine_cli.rb
38
+ - lib/sidedock/configuration.rb
38
39
  - lib/sidedock/container.rb
39
40
  - lib/sidedock/image.rb
40
41
  - lib/sidedock/machine.rb