percheron 0.7.11 → 0.7.12

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: 428285d6a914c5a406b8abb45fbd20c3fadcb343
4
- data.tar.gz: 2a60f876154c79d2fc83e1b6d5582a688e7fd5dd
3
+ metadata.gz: c3d3fe11591f768bc7d5867837dc546b679bbf85
4
+ data.tar.gz: ab113fd870d359c2ba383340feab044e42861b26
5
5
  SHA512:
6
- metadata.gz: dc1fb6039256e90aaa1ed5cc28341bab6f73522d7c5fb4734515ff60f25d7f356d5e302491bdfe5bb46fe12e8809b673c85d2a0f9b5cc566b77f01ec39ab39d5
7
- data.tar.gz: 8b0afb6b8a576b5ff668fe25b0071c6b675e6c7838b66786354047a9975b8f41edbebe43623556d9b3ee9258e22d6577c6b30ee8641b6f3e3aa496b797d1eaad
6
+ metadata.gz: d0b7b65daffc775d0606a6d11a5b55a26387c0d4362f4a75fcded15f4c9246ec35a732b992dc14f944a12d1521ce017665b5f762c81aba8b1cd99eab72c8f377
7
+ data.tar.gz: 3426521b489b6b91d5bbfad9b9fae2bae6c9e89bfaa3d3dfa2b75552571bbcbf5943c5d02d4cd992d0975be21c10ac071e6282c326c4bfe482c85d80e038b069
@@ -12,7 +12,10 @@ module Percheron
12
12
 
13
13
  def execute!
14
14
  results = []
15
- results << build! if unit.buildable?
15
+ if unit.buildable?
16
+ results << write_out_temp_dockerfile!
17
+ results << build!
18
+ end
16
19
  results.compact.empty? ? nil : unit
17
20
  end
18
21
 
@@ -23,13 +26,41 @@ module Percheron
23
26
 
24
27
  def options
25
28
  {
26
- 'dockerfile' => unit.dockerfile.basename.to_s,
29
+ 'dockerfile' => dockerfile,
27
30
  't' => unit.image_name,
28
31
  'forcerm' => true,
29
32
  'nocache' => nocache
30
33
  }
31
34
  end
32
35
 
36
+ def dockerfile
37
+ temp_dockerfile.basename.to_s
38
+ end
39
+
40
+ def temp_dockerfile
41
+ @temp_dockerfile ||= Pathname.new(temp_dockerfile_name)
42
+ end
43
+
44
+ def temp_dockerfile_name
45
+ @temp_dockerfile_name ||= begin
46
+ '%s/%s.%s' % [
47
+ unit.dockerfile.expand_path.dirname.to_s,
48
+ unit.dockerfile.basename.to_s,
49
+ SecureRandom.urlsafe_base64
50
+ ]
51
+ end
52
+ end
53
+
54
+ def write_out_temp_dockerfile!
55
+ options = { 'secrets' => Config.secrets }
56
+ content = Liquid::Template.parse(unit.dockerfile.read).render(options)
57
+ File.open(temp_dockerfile, 'w') { |f| f.write(content) }
58
+ end
59
+
60
+ def remove_temp_dockerfile!
61
+ temp_dockerfile.delete
62
+ end
63
+
33
64
  def build!
34
65
  in_working_directory(base_dir) do
35
66
  execute_pre_build_scripts!
@@ -38,6 +69,8 @@ module Percheron
38
69
  $logger.debug '%s' % [ out.strip ]
39
70
  end
40
71
  end
72
+ ensure
73
+ remove_temp_dockerfile!
41
74
  end
42
75
 
43
76
  def execute_pre_build_scripts!
@@ -37,7 +37,6 @@ module Percheron
37
37
  Stop.new(unit).execute! unless unit_running
38
38
  end
39
39
 
40
- # FIXME
41
40
  def commit_and_tag_new_image!
42
41
  new_image = unit.container.commit
43
42
  new_image.tag(repo: unit.image_repo, tag: unit.version.to_s, force: true)
@@ -2,8 +2,8 @@ module Percheron
2
2
  module Commands
3
3
  class Abstract < Clamp::Command
4
4
 
5
- option([ '-c', '--config_file' ], 'CONFIG', 'Config file',
6
- default: Config::DEFAULT_CONFIG_FILE)
5
+ option([ '-c', '--config_file' ], 'CONFIG', 'Config file', default:
6
+ ENV.fetch('PERCHERON_CONFIG', Config::DEFAULT_CONFIG_FILE))
7
7
 
8
8
  option('--version', :flag, 'show version') do
9
9
  puts Percheron::VERSION
@@ -22,10 +22,6 @@ module Percheron
22
22
  option('--start', :flag, 'Start unit', default: false)
23
23
  end
24
24
 
25
- def default_config_file
26
- ENV.fetch('PERCHERON_CONFIG', Config::DEFAULT_CONFIG_FILE)
27
- end
28
-
29
25
  def execute
30
26
  stack.valid?
31
27
  rescue => e
@@ -40,7 +36,7 @@ module Percheron
40
36
 
41
37
  def config
42
38
  @config ||= begin
43
- Percheron::Config.new(config_file).tap do |c|
39
+ Percheron::Config.load!(config_file).tap do |c|
44
40
  Percheron::Connection.load!(c)
45
41
  end
46
42
  end
@@ -7,7 +7,7 @@ module Percheron
7
7
  def execute
8
8
  super
9
9
  require 'pry-byebug'
10
- pry
10
+ pry Percheron
11
11
  end
12
12
 
13
13
  private
@@ -3,32 +3,72 @@ require 'yaml'
3
3
  module Percheron
4
4
  class Config
5
5
 
6
- extend Forwardable
6
+ include Singleton
7
7
 
8
8
  DEFAULT_CONFIG_FILE = '.percheron.yml'
9
9
 
10
- def_delegators :contents, :docker
10
+ # rubocop:disable Style/ClassVars
11
+ @@file = Pathname.new(DEFAULT_CONFIG_FILE).expand_path
12
+ # rubocop:enable Style/ClassVars
11
13
 
12
- def initialize(file = DEFAULT_CONFIG_FILE)
13
- @file = Pathname.new(file).expand_path
14
+ def self.load!(file)
15
+ instance.load!(file)
16
+ end
17
+
18
+ # rubocop:disable Style/ClassVars
19
+ def load!(file)
20
+ @@file = Pathname.new(file).expand_path
21
+ invalidate_memoised_values!
14
22
  self
15
23
  end
24
+ # rubocop:enable Style/ClassVars
25
+
26
+ def self.stacks
27
+ instance.stacks
28
+ end
16
29
 
17
30
  def stacks
18
31
  @stacks ||= process_stacks!
19
32
  end
20
33
 
34
+ def self.file_base_path
35
+ instance.file_base_path
36
+ end
37
+
21
38
  def file_base_path
22
39
  file.dirname
23
40
  end
24
41
 
25
- def valid?
26
- Validators::Config.new(file).valid?
42
+ def self.secrets
43
+ instance.secrets
44
+ end
45
+
46
+ def secrets
47
+ secrets_file ? Hashie::Mash.new(YAML.load_file(secrets_file)) : {}
48
+ end
49
+
50
+ def self.docker
51
+ instance.docker
52
+ end
53
+
54
+ def docker
55
+ contents.docker
27
56
  end
28
57
 
29
58
  private
30
59
 
31
- attr_reader :file
60
+ def file
61
+ @@file
62
+ end
63
+
64
+ def secrets_file
65
+ return unless yaml_contents.secrets_file
66
+ File.expand_path(yaml_contents.secrets_file, file_base_path)
67
+ end
68
+
69
+ def invalidate_memoised_values!
70
+ @stacks = @yaml_contents = @raw_contents = @contents = nil
71
+ end
32
72
 
33
73
  def process_stacks! # FIXME: bugs here :(
34
74
  stacks_by_name = contents.stacks.to_hash_by_key(:name)
@@ -91,29 +131,42 @@ module Percheron
91
131
  end
92
132
 
93
133
  def raw_contents
94
- @contents ||= Hashie::Mash.new(YAML.load_file(file))
134
+ @raw_contents ||= file.read
135
+ end
136
+
137
+ def yaml_contents
138
+ @yaml_contents ||= Hashie::Mash.new(YAML.load(raw_contents))
139
+ end
140
+
141
+ def templated_contents
142
+ Liquid::Template.parse(raw_contents).render('secrets' => secrets)
143
+ end
144
+
145
+ def parsed_contents
146
+ Hashie::Mash.new(YAML.load(templated_contents))
95
147
  end
96
148
 
97
149
  def contents
98
- raw_contents.tap do |c|
99
- c.docker ||= {}
100
- c.docker.host ||= env_docker_host
101
- c.docker.cert_path ||= env_cert_path
102
- c.docker.ssl_verify_peer ||= env_ssl_verify_peer
150
+ @contents ||= begin
151
+ parsed_contents.tap do |c|
152
+ c.docker ||= {}
153
+ c.docker.host ||= env_docker_host
154
+ c.docker.cert_path ||= env_cert_path
155
+ c.docker.ssl_verify_peer ||= env_ssl_verify_peer
156
+ end
103
157
  end
104
158
  end
105
159
 
106
160
  def env_docker_host
107
- @env_docker_host ||= ENV['DOCKER_HOST'] ||
108
- fail("Docker host not defined in '#{file}' or ENV['DOCKER_HOST']")
161
+ ENV['DOCKER_HOST'] || fail("Docker host not defined in '#{file}' or ENV['DOCKER_HOST']")
109
162
  end
110
163
 
111
164
  def env_cert_path
112
- @cert_path ||= ENV['DOCKER_CERT_PATH'] ? File.expand_path(ENV['DOCKER_CERT_PATH']) : nil
165
+ ENV['DOCKER_CERT_PATH'] ? File.expand_path(ENV['DOCKER_CERT_PATH']) : nil
113
166
  end
114
167
 
115
168
  def env_ssl_verify_peer
116
- @ssl_verify_peer ||= (ENV['DOCKER_TLS_VERIFY'] == 1) || true
169
+ (ENV['DOCKER_TLS_VERIFY'] == 1) || true
117
170
  end
118
171
  end
119
172
  end
@@ -1,4 +1,3 @@
1
- require 'singleton'
2
1
  require 'docker'
3
2
 
4
3
  module Percheron
@@ -14,12 +13,12 @@ module Percheron
14
13
  end
15
14
  # rubocop:enable Style/ClassVars
16
15
 
17
- def self.perform(klass, method, *args)
18
- instance.perform(klass, method, *args)
16
+ def self.perform(klass, method, *args, &blk)
17
+ instance.perform(klass, method, *args, &blk)
19
18
  end
20
19
 
21
20
  def perform(klass, method, *args)
22
- klass.public_send(method, *args)
21
+ klass.public_send(method, *args) { |out| yield(out) if block_given? }
23
22
  rescue => e
24
23
  $logger.debug '%s.%s(%s) - %s' % [ klass, method, args, e.inspect ]
25
24
  raise
@@ -23,8 +23,7 @@ module Percheron
23
23
  [
24
24
  :validate_config_file_defined,
25
25
  :validate_config_file_existence,
26
- :validate_config_file_not_empty,
27
- :validate_config_file_contents
26
+ :validate_config_file_not_empty
28
27
  ]
29
28
  end
30
29
 
@@ -44,10 +43,6 @@ module Percheron
44
43
  'Is empty' if config_file_contents.empty?
45
44
  end
46
45
 
47
- def validate_config_file_contents
48
- 'Is invalid' unless config_file_contents.docker
49
- end
50
-
51
46
  end
52
47
  end
53
48
  end
@@ -1,3 +1,3 @@
1
1
  module Percheron
2
- VERSION = '0.7.11'
2
+ VERSION = '0.7.12'
3
3
  end
data/lib/percheron.rb CHANGED
@@ -6,6 +6,7 @@ require 'naught'
6
6
  require 'semantic'
7
7
  require 'metastore'
8
8
  require 'liquid'
9
+ require 'singleton'
9
10
 
10
11
  require 'percheron/oh_dear'
11
12
  require 'percheron/core_extensions'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percheron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.11
4
+ version: 0.7.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ash McKenzie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-04 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp