dockly 1.8.0 → 1.9.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.
data/README.md CHANGED
@@ -281,7 +281,7 @@ In addition to the above attributes, `deb` has the following references:
281
281
  - required: `false`
282
282
  - default: `nil`
283
283
  - class: `Dockly::Foreman`
284
- - description: any Foreman scripts used in the deb
284
+ - description: any Foreman scripts used in the deb.
285
285
 
286
286
  `rpm`
287
287
  -----
@@ -9,7 +9,7 @@ class Dockly::BuildCache::Base
9
9
  dsl_attribute :s3_bucket, :s3_object_prefix, :use_latest,
10
10
  :hash_command, :build_command, :parameter_commands,
11
11
  :base_dir, :command_dir, :output_dir, :tmp_dir,
12
- :keep_old_files
12
+ :keep_old_files, :safe_push_cache
13
13
 
14
14
  default_value :use_latest, false
15
15
  default_value :parameter_commands, {}
@@ -17,6 +17,7 @@ class Dockly::BuildCache::Base
17
17
  default_value :output_dir, '.'
18
18
  default_value :tmp_dir, Dir.tmpdir
19
19
  default_value :keep_old_files, false
20
+ default_value :safe_push_cache, false
20
21
 
21
22
  def execute!
22
23
  debug "Looking for cache for hash: #{hash_output}"
@@ -1,10 +1,6 @@
1
1
  class Dockly::BuildCache::Docker < Dockly::BuildCache::Base
2
2
  attr_accessor :image
3
3
 
4
- def wait_time
5
- 300 # max 5 minutes
6
- end
7
-
8
4
  def execute!
9
5
  ensure_present! :image
10
6
  super
@@ -29,25 +25,11 @@ class Dockly::BuildCache::Docker < Dockly::BuildCache::Base
29
25
  ensure_present! :output_dir
30
26
  if cache = pull_from_s3(version)
31
27
  debug "inserting to #{output_directory}"
32
- path = File.expand_path(cache.path)
33
- path_parent = File.dirname(path)
34
- tar_flags = keep_old_files ? '-xkf' : 'xf'
35
- container = ::Docker::Container.create(
36
- 'Image' => image.id,
37
- 'Cmd' => ['/bin/bash', '-c', [
38
- "mkdir -p #{File.dirname(output_directory)}",
39
- '&&',
40
- "tar #{tar_flags} #{File.join('/', 'host', path)} -C #{File.dirname(output_directory)}"
41
- ].join(' ')
42
- ],
43
- 'Volumes' => {
44
- File.join('/', 'host', path_parent) => { path_parent => 'rw' }
45
- }
46
- )
47
- container.start('Binds' => ["#{path_parent}:#{File.join('/', 'host', path_parent)}"])
48
- result = container.wait['StatusCode']
49
- raise "Got bad status code when copying build cache: #{result}" unless result.zero?
50
- self.image = container.commit
28
+ if safe_push_cache
29
+ push_cache_safe(cache)
30
+ else
31
+ push_cache_with_volumes(cache)
32
+ end
51
33
  debug "inserted cache into #{output_directory}"
52
34
  cache.close
53
35
  else
@@ -55,6 +37,37 @@ class Dockly::BuildCache::Docker < Dockly::BuildCache::Base
55
37
  end
56
38
  end
57
39
 
40
+ def push_cache_safe(cache)
41
+ container = image.run("mkdir -p #{File.dirname(output_directory)}")
42
+ image_with_dir = container.tap(&:wait).commit
43
+ self.image = image_with_dir.insert_local(
44
+ 'localPath' => cache.path,
45
+ 'outputPath' => File.dirname(output_directory)
46
+ )
47
+ end
48
+
49
+ def push_cache_with_volumes(cache)
50
+ path = File.expand_path(cache.path)
51
+ path_parent = File.dirname(path)
52
+ tar_flags = keep_old_files ? '-xkf' : 'xf'
53
+ container = ::Docker::Container.create(
54
+ 'Image' => image.id,
55
+ 'Cmd' => ['/bin/bash', '-c', [
56
+ "mkdir -p #{File.dirname(output_directory)}",
57
+ '&&',
58
+ "tar #{tar_flags} #{File.join('/', 'host', path)} -C #{File.dirname(output_directory)}"
59
+ ].join(' ')
60
+ ],
61
+ 'Volumes' => {
62
+ File.join('/', 'host', path_parent) => { path_parent => 'rw' }
63
+ }
64
+ )
65
+ container.start('Binds' => ["#{path_parent}:#{File.join('/', 'host', path_parent)}"])
66
+ result = container.wait['StatusCode']
67
+ raise "Got bad status code when copying build cache: #{result}" unless result.zero?
68
+ self.image = container.commit
69
+ end
70
+
58
71
  def copy_output_dir(container)
59
72
  ensure_present! :output_dir
60
73
  file_path = File.join(tmp_dir,s3_object(hash_output))
@@ -92,7 +105,7 @@ class Dockly::BuildCache::Docker < Dockly::BuildCache::Base
92
105
  debug "running command `#{command}` on image #{image.id}"
93
106
  container = image.run(["/bin/bash", "-c", "cd #{command_directory} && #{command}"])
94
107
  debug "command running in container #{container.id}"
95
- status = container.wait(wait_time)['StatusCode']
108
+ status = container.wait(docker.timeout)['StatusCode']
96
109
  resp = container.streaming_logs(stdout: true, stderr: true)
97
110
  debug "`#{command}` returned the following output:"
98
111
  debug resp.strip
@@ -10,7 +10,7 @@ class Dockly::Deb
10
10
  :post_uninstall, :s3_bucket, :files, :app_user, :vendor
11
11
 
12
12
  dsl_class_attribute :docker, Dockly::Docker
13
- dsl_class_attribute :foreman, Dockly::Foreman
13
+ dsl_class_attribute :foreman, Dockly::Foreman, type: Array
14
14
 
15
15
  default_value :version, '0.0'
16
16
  default_value :release, '0'
@@ -127,14 +127,14 @@ private
127
127
  end
128
128
 
129
129
  def add_foreman(package)
130
- return if foreman.nil?
131
- info "adding foreman export"
132
- foreman.create!
133
- package.attributes[:prefix] = foreman.init_dir
134
- Dir.chdir(foreman.build_dir) do
135
- package.input('.')
130
+ return if (foreman || []).empty?
131
+ foreman.each do |fore|
132
+ info "adding foreman export '#{fore.name}'"
133
+ fore.create!
134
+ package.attributes[:prefix] = fore.init_dir
135
+ Dir.chdir(fore.build_dir) { package.input('.') }
136
+ package.attributes[:prefix] = nil
136
137
  end
137
- package.attributes[:prefix] = nil
138
138
  end
139
139
 
140
140
  def add_files(package)
@@ -1,3 +1,3 @@
1
1
  module Dockly
2
- VERSION = '1.8.0'
2
+ VERSION = '1.9.0'
3
3
  end
@@ -25,23 +25,36 @@ describe Dockly::Deb do
25
25
  end
26
26
  end
27
27
 
28
- context 'when it has a foreman export' do
28
+ context 'when it has foreman exports' do
29
+ let(:contents) { `dpkg --contents #{filename}` }
30
+
29
31
  before do
30
32
  subject.foreman do
31
- name 'foreman'
32
- init_dir '/etc/systemd/system'
33
+ name 'systemd-foreman'
33
34
  build_dir 'build/foreman'
35
+ init_dir '/etc/systemd/system'
34
36
  procfile File.join(File.dirname(__FILE__), '..', 'fixtures', 'Procfile')
35
37
  user 'root'
36
38
  type 'systemd'
37
39
  prefix '/bin/sh'
38
40
  end
39
- end
40
41
 
41
- it 'export the foreman to the deb' do
42
+ subject.foreman do
43
+ name 'upstart-foreman'
44
+ build_dir 'build/foreman'
45
+ init_dir '/etc/systemd/system'
46
+ procfile File.join(File.dirname(__FILE__), '..', 'fixtures', 'Procfile')
47
+ user 'root'
48
+ type 'upstart'
49
+ prefix '/bin/sh'
50
+ end
51
+
42
52
  subject.create_package!
43
- `dpkg --contents #{filename}`
44
- .lines.grep(/foreman/).should_not be_empty
53
+ end
54
+
55
+ it 'exports the foreman to the deb', :cur do
56
+ expect(contents).to match(/upstart-foreman/)
57
+ expect(contents).to match(/systemd-foreman/)
45
58
  end
46
59
  end
47
60
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dockly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.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-05-12 00:00:00.000000000 Z
12
+ date: 2015-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clamp
@@ -362,3 +362,4 @@ test_files:
362
362
  - spec/fixtures/test-3.tar
363
363
  - spec/spec_helper.rb
364
364
  - spec/support/vcr.rb
365
+ has_rdoc: