dockly 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -146,7 +146,7 @@ In addition to the above attributes, `docker` has the following references:
146
146
  - allows multiple
147
147
  - class: `Dockly::BuildCache`
148
148
  - description: a caching system to stop rebuilding/compiling the same files every time
149
- - `build_cache`
149
+ - `registry`
150
150
  - required: `false`
151
151
  - allows one
152
152
  - class: `Dockly::Docker::Registry`
data/lib/dockly/deb.rb CHANGED
@@ -7,7 +7,8 @@ class Dockly::Deb
7
7
  logger_prefix '[dockly deb]'
8
8
  dsl_attribute :package_name, :version, :release, :arch, :build_dir,
9
9
  :pre_install, :post_install, :pre_uninstall, :post_uninstall,
10
- :s3_bucket, :files
10
+ :s3_bucket, :files, :app_user
11
+
11
12
  dsl_class_attribute :docker, Dockly::Docker
12
13
  dsl_class_attribute :foreman, Dockly::Foreman
13
14
 
@@ -16,6 +17,7 @@ class Dockly::Deb
16
17
  default_value :arch, 'x86_64'
17
18
  default_value :build_dir, 'build/deb'
18
19
  default_value :files, []
20
+ default_value :app_user, 'nobody'
19
21
 
20
22
  def file(source, destination)
21
23
  @files << { :source => source, :destination => destination }
@@ -88,11 +90,12 @@ private
88
90
  add_docker(@dir_package)
89
91
  add_foreman(@dir_package)
90
92
  add_files(@dir_package)
93
+ add_docker_auth_config(@dir_package)
91
94
 
92
95
  debug "converting to deb"
93
96
  @deb_package = @dir_package.convert(FPM::Package::Deb)
94
97
 
95
- @deb_package.scripts[:before_install] = compile_pre_install
98
+ @deb_package.scripts[:before_install] = pre_install
96
99
  @deb_package.scripts[:after_install] = post_install
97
100
  @deb_package.scripts[:before_remove] = pre_uninstall
98
101
  @deb_package.scripts[:after_remove] = post_uninstall
@@ -140,19 +143,15 @@ private
140
143
  end
141
144
  end
142
145
 
143
- def compile_pre_install
144
- registry = !docker.nil? && docker.registry
145
- if registry
146
- login_str = if registry.authentication_required?
147
- "docker login -e '#{registry.email}' -p '$DOCKER_REGISTRY_PASSWORD' -u '#{registry.username}'"
148
- end
149
- [
150
- pre_install,
151
- login_str,
152
- "docker pull #{docker.repo}"
153
- ].compact.join("\n")
154
- else
155
- pre_install
146
+ def add_docker_auth_config(package)
147
+ return if docker.nil? || (registry = docker.registry).nil? || !registry.authentication_required?
148
+ info "adding docker config file"
149
+ registry.generate_config_file!
150
+
151
+ package.attributes[:prefix] = docker.auth_config_file || "~#{app_user}/.dockercfg"
152
+ Dir.chdir(File.dirname(registry.config_file)) do
153
+ package.input(File.basename(registry.config_file))
156
154
  end
155
+ package.attributes[:prefix] = nil
157
156
  end
158
157
  end
data/lib/dockly/docker.rb CHANGED
@@ -17,7 +17,7 @@ class Dockly::Docker
17
17
  dsl_class_attribute :registry, Dockly::Docker::Registry
18
18
 
19
19
  dsl_attribute :name, :import, :git_archive, :build, :tag, :build_dir, :package_dir,
20
- :timeout, :cleanup_images, :registry_import
20
+ :timeout, :cleanup_images, :registry_import, :auth_config_file
21
21
 
22
22
  default_value :tag, nil
23
23
  default_value :build_dir, 'build/docker'
@@ -31,6 +31,26 @@ class Dockly::Docker::Registry
31
31
  server_address == DEFAULT_SERVER_ADDRESS
32
32
  end
33
33
 
34
+ def config_file
35
+ @config_file ||= File.join('build', 'docker', 'registry', '.dockercfg')
36
+ end
37
+
38
+ def generate_config_file!
39
+ return unless authentication_required?
40
+ @password ||= ENV['DOCKER_REGISTRY_PASSWORD']
41
+ ensure_present! :username, :password, :email, :server_address
42
+
43
+ auth = {
44
+ server_address => {
45
+ :auth => Base64.encode64("#{username}:#{password}"),
46
+ :email => email.to_s
47
+ }
48
+ }.to_json
49
+
50
+ FileUtils.mkdir_p(File.dirname(config_file))
51
+ File.open(config_file, 'w') { |file| file.write(auth) }
52
+ end
53
+
34
54
  def to_h
35
55
  {
36
56
  'serveraddress' => server_address,
@@ -1,3 +1,3 @@
1
1
  module Dockly
2
- VERSION = '1.4.2'
2
+ VERSION = '1.4.3'
3
3
  end
@@ -63,6 +63,30 @@ describe Dockly::Deb do
63
63
  end
64
64
  end
65
65
 
66
+ context 'when it has a docker with registry', :docker do
67
+ before do
68
+ subject.docker do
69
+ name 'deb_test'
70
+ import 'https://s3.amazonaws.com/swipely-pub/docker-export-ubuntu-latest.tgz'
71
+ git_archive '.'
72
+ build 'touch /deb_worked'
73
+ build_dir 'build/docker'
74
+ auth_config_file '/etc/docker/.dockercfg'
75
+
76
+ registry :test_docker_registry do
77
+ username 'nahiluhmot'
78
+ email 'hulihan.tom159@gmail.com'
79
+ end
80
+ end
81
+ end
82
+
83
+ it 'builds the docker image and adds it to the deb' do
84
+ subject.create_package!
85
+ `dpkg --contents #{filename}`
86
+ .lines.grep(/.dockercfg/).should_not be_empty
87
+ end
88
+ end
89
+
66
90
  context 'when it has files' do
67
91
  let(:file1) { Tempfile.new('files') }
68
92
  let(:file2) { Tempfile.new('files') }
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.4.2
4
+ version: 1.4.3
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: 2014-02-19 00:00:00.000000000 Z
12
+ date: 2014-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clamp