construi 0.40.0 → 0.41.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.
@@ -93,9 +93,19 @@ module Construi
93
93
  end
94
94
  end
95
95
 
96
+ module Volumes
97
+ def volumes
98
+ with_parent([], &:volumes).concat get(:volumes, [])
99
+ end
100
+
101
+ def volumes_from
102
+ with_parent([], &:volumes_from).concat get(:volumes_from, [])
103
+ end
104
+ end
105
+
96
106
  module Options
97
107
  def options
98
- { env: env, privileged: privileged? }
108
+ { env: env, privileged: privileged?, volumes: volumes }
99
109
  end
100
110
  end
101
111
 
@@ -105,6 +115,7 @@ module Construi
105
115
  include Image
106
116
  include Files
107
117
  include EnvironmentVariables
118
+ include Volumes
108
119
  include Options
109
120
 
110
121
  attr_reader :yaml
@@ -130,6 +141,7 @@ module Construi
130
141
  include Image
131
142
  include Files
132
143
  include EnvironmentVariables
144
+ include Volumes
133
145
  include Links
134
146
  end
135
147
 
@@ -1,3 +1,4 @@
1
+ require 'construi/options'
1
2
 
2
3
  module Construi
3
4
  module Console
@@ -11,6 +12,10 @@ module Construi
11
12
  puts msg.green
12
13
  end
13
14
 
15
+ def self.verbose(msg)
16
+ puts msg if Options.enabled?(:verbose)
17
+ end
18
+
14
19
  def self.progress(msg)
15
20
  puts
16
21
  info msg
@@ -22,6 +27,25 @@ module Construi
22
27
  end
23
28
  end
24
29
 
30
+ def self.logger(name)
31
+ Logger.new name
32
+ end
33
+
34
+ class Logger
35
+ attr_reader :name
36
+
37
+ def initialize(name)
38
+ @name = name
39
+ end
40
+
41
+ def debug?
42
+ true
43
+ end
44
+
45
+ def debug(msg)
46
+ Console.verbose "#{name}: #{msg}"
47
+ end
48
+ end
25
49
  end
26
50
  end
27
51
 
@@ -69,11 +69,14 @@ module Construi
69
69
  env = options[:env] || []
70
70
  privileged = options[:privileged] || false
71
71
  links = options[:links] || []
72
+ volumes = options[:volumes] || []
73
+ volumes_from = options[:volumes_from] || []
72
74
 
73
75
  host_config = {
74
- 'Binds' => ["#{Dir.pwd}:/var/workspace"],
76
+ 'Binds' => ["#{Dir.pwd}:/var/workspace"].concat(volumes),
75
77
  'Privileged' => privileged,
76
- 'Links' => links
78
+ 'Links' => links,
79
+ 'VolumesFrom' => volumes_from
77
80
  }
78
81
 
79
82
  create_options = {
@@ -0,0 +1,17 @@
1
+ module Construi
2
+ module Options
3
+ @features = []
4
+
5
+ class << self
6
+ attr_accessor :features
7
+
8
+ def enable(feature)
9
+ features << feature
10
+ end
11
+
12
+ def enabled?(feature)
13
+ features.include? feature
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,4 +1,5 @@
1
1
 
2
+ require 'construi/console'
2
3
  require 'construi/container'
3
4
  require 'construi/image'
4
5
  require 'construi/target'
@@ -7,6 +8,7 @@ require 'construi/version'
7
8
 
8
9
  require 'colorize'
9
10
  require 'docker'
11
+ require 'optparse'
10
12
 
11
13
  module Construi
12
14
  DOCKER_TIMEOUT = 60
@@ -21,7 +23,9 @@ module Construi
21
23
  docker_host = ENV['DOCKER_HOST']
22
24
  Docker.url = docker_host if docker_host
23
25
 
24
- puts "Docker url: #{Docker.url}"
26
+ Console.verbose "Docker url: #{Docker.url}"
27
+
28
+ Docker.logger = Console.logger 'Docker'
25
29
 
26
30
  Excon.defaults[:ssl_verify_peer] = false
27
31
 
@@ -34,11 +38,15 @@ module Construi
34
38
  end
35
39
 
36
40
  def run(targets)
37
- puts "Construi version: #{Construi::VERSION}"
41
+ OptionParser.new do |opts|
42
+ opts.on '-v', '--[no-]verbose' do |v|
43
+ Options.enable(:verbose) if v
44
+ end
45
+ end.parse!
38
46
 
39
- setup_docker
47
+ Console.verbose "Construi version: #{Construi::VERSION}"
40
48
 
41
- puts "Current directory: #{Dir.pwd}"
49
+ setup_docker
42
50
 
43
51
  targets.map { |t| Target.new t, @config.target(t) } .each(&:run)
44
52
  end
@@ -22,11 +22,13 @@ module Construi
22
22
  final_image = IntermediateImage.seed(create_initial_image).reduce(commands) do |image, command|
23
23
  Console.progress " > #{command}"
24
24
 
25
- link_option = links.each_with_object([]) do |l, o|
26
- o << "#{l.id}:#{l.name}"
27
- end
25
+ options = config.options.merge(
26
+ links: link_option(links),
27
+ volumes_from: volumes_from_option(config, links),
28
+ name: name
29
+ )
28
30
 
29
- image.run command, @config.options.merge(links: link_option, name: name)
31
+ image.run command, options
30
32
  end
31
33
 
32
34
  final_image.delete
@@ -43,7 +45,26 @@ module Construi
43
45
 
44
46
  def start_linked_images
45
47
  @config.links.map do |(name, config)|
46
- Image.from(config).start(config.options.merge name: name, log_lifecycle: true)
48
+ options = config.options.merge(
49
+ name: name,
50
+ log_lifecycle: true
51
+ )
52
+
53
+ Image.from(config).start options
54
+ end
55
+ end
56
+
57
+ def link_option(links)
58
+ links.each_with_object([]) do |l, o|
59
+ o << "#{l.id}:#{l.name}"
60
+ end
61
+ end
62
+
63
+ def volumes_from_option(config, links)
64
+ config.volumes_from.each_with_object([]) do |v, o|
65
+ volume_from = links.detect { |l| l.name == v }
66
+
67
+ o << (volume_from.nil? ? v : volume_from.id)
47
68
  end
48
69
  end
49
70
  end
@@ -1,3 +1,3 @@
1
1
  module Construi
2
- VERSION = "0.40.0"
2
+ VERSION = "0.41.0"
3
3
  end
@@ -92,7 +92,8 @@ RSpec.describe Construi::Container do
92
92
  'HostConfig' => {
93
93
  'Binds' => ["#{pwd}:/var/workspace"],
94
94
  'Privileged' => true,
95
- 'Links' => []
95
+ 'Links' => [],
96
+ 'VolumesFrom' => []
96
97
  }
97
98
  } )
98
99
  end
@@ -9,6 +9,9 @@ RSpec.describe Construi::Runner do
9
9
 
10
10
  before { allow(image_class).to receive(:from).and_return image }
11
11
 
12
+ let(:option_parser) { instance_double(OptionParser).as_null_object }
13
+ before { allow(OptionParser).to receive(:new).and_return option_parser }
14
+
12
15
  subject(:runner) { Construi::Runner.new(config) }
13
16
 
14
17
  describe '#run' do
@@ -32,7 +35,16 @@ RSpec.describe Construi::Runner do
32
35
  subject! { runner.run(targets) }
33
36
 
34
37
  it { expect(docker).to have_received(:validate_version!) }
35
- it { expect(image).to have_received(:run).with('cmd1', env: [], privileged: false, links: [], name: 'target1') }
38
+ it do
39
+ expect(image).to have_received(:run)
40
+ .with('cmd1',
41
+ env: [],
42
+ privileged: false,
43
+ volumes: [],
44
+ volumes_from: [],
45
+ links: [],
46
+ name: 'target1')
47
+ end
36
48
  it { expect(image).to have_received(:delete) }
37
49
 
38
50
  it { expect($stdout.string).to include('Running target1...'.green) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: construi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.40.0
4
+ version: 0.41.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-24 00:00:00.000000000 Z
12
+ date: 2015-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: docker-api
@@ -246,6 +246,7 @@ files:
246
246
  - lib/construi/console.rb
247
247
  - lib/construi/container.rb
248
248
  - lib/construi/image.rb
249
+ - lib/construi/options.rb
249
250
  - lib/construi/runner.rb
250
251
  - lib/construi/target.rb
251
252
  - lib/construi/version.rb
@@ -282,7 +283,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
283
  version: '0'
283
284
  segments:
284
285
  - 0
285
- hash: 2884457678396287104
286
+ hash: 4041224697425592295
286
287
  requirements: []
287
288
  rubyforge_project:
288
289
  rubygems_version: 1.8.23.2