percheron 0.6.3 → 0.6.4

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: febfd28281497bcdac84631381e348032bdf5308
4
- data.tar.gz: 3dce8fa1c163bc54d369463b239f9198d3233d74
3
+ metadata.gz: 61e4d66006bf086c797d921852dae42438f8abca
4
+ data.tar.gz: b91b6698c444e51757bee46fa5f290b67211670b
5
5
  SHA512:
6
- metadata.gz: b1ec93761eae6aec601ffb80c6072182f956f240610d9b3277ec561360efa8c5360f61a841f0cfc1c6d857e0ed22d96683c176726f8591d307363232a5a435e4
7
- data.tar.gz: 8019b9377222d367f8a4f3a0316860456829a503c0678e5b72e8928c35d9f3b347fffd6e4666971698f267ff73cbbd33bba5c785fd90b9696b5e050417a48a32
6
+ metadata.gz: 9a136f407d6823d6983723a36ea9056f56e440411e56df65e2101348fbb4dcd957027f570a9af29b21f9e5c273698ca9a460a05666fa79353577413c00e8892e
7
+ data.tar.gz: b87043f174f595bd1aed913e087089575d7ee602d5a46a5810d01c98aebd38d4816aa1a45145f2b7b685fb443bb1fd4d10c29a3e7ed0dc8396048a0299bbb97c
@@ -36,11 +36,11 @@ module Percheron
36
36
  end
37
37
  end
38
38
 
39
- def start_containers!(containers)
39
+ def start_containers!(containers, exec_scripts: true)
40
40
  exec_on_containers!(containers) do |container|
41
41
  unless container.running?
42
42
  $logger.debug "Starting '#{container.name}' container"
43
- Start.new(container, container.dependant_containers.values).execute!
43
+ Start.new(container, dependant_containers: container.dependant_containers.values, exec_scripts: exec_scripts).execute!
44
44
  end
45
45
  end
46
46
  end
@@ -10,8 +10,9 @@ module Percheron
10
10
  end
11
11
 
12
12
  def execute!
13
- build!
14
- container
13
+ results = []
14
+ results << build!
15
+ results.compact.empty? ? nil : container
15
16
  end
16
17
 
17
18
  private
@@ -30,7 +31,7 @@ module Percheron
30
31
  def build!
31
32
  in_working_directory(base_dir) do
32
33
  execute_pre_build_scripts! unless container.pre_build_scripts.empty?
33
- $logger.info "Building '#{container.image_name}'"
34
+ $logger.info "Building '#{container.image_name}' image"
34
35
  Docker::Image.build_from_dir(base_dir, build_opts) do |out|
35
36
  $logger.debug '%s' % [ out.strip ]
36
37
  end
@@ -10,12 +10,13 @@ module Percheron
10
10
  end
11
11
 
12
12
  def execute!(opts={})
13
+ results = []
13
14
  if recreate? || !container.exists?
14
- create!(opts)
15
- container
15
+ results << create!(opts)
16
16
  else
17
17
  $logger.debug "Container '#{container.name}' already exists"
18
18
  end
19
+ results.compact.empty? ? nil : container
19
20
  end
20
21
 
21
22
  private
@@ -60,8 +61,7 @@ module Percheron
60
61
  end
61
62
 
62
63
  def create!(opts)
63
- $logger.debug "Container '#{container.name}' does not exist, creating"
64
- build_image!
64
+ build_image! unless container.image_exists?
65
65
  insert_scripts!
66
66
  create_container!(opts.fetch(:create, {}))
67
67
  execute_post_create_scripts! unless container.post_create_scripts.empty?
@@ -69,41 +69,29 @@ module Percheron
69
69
  end
70
70
 
71
71
  def build_image!
72
- unless container.image_exists?
73
- $logger.info "Creating '#{container.image_name}' image"
74
- Build.new(container).execute!
75
- end
72
+ Build.new(container).execute!
76
73
  end
77
74
 
78
- def set_dockerfile_md5!
79
- $logger.info "Setting MD5 for '#{container.name}' container to #{container.current_dockerfile_md5}"
80
- $metastore.set("#{container.metastore_key}.dockerfile_md5", container.current_dockerfile_md5)
75
+ def insert_scripts!
76
+ insert_files!(container.post_create_scripts)
77
+ insert_files!(container.post_start_scripts)
81
78
  end
82
79
 
83
80
  def create_container!(opts)
84
81
  options = base_options.merge(host_config_options).merge(opts)
85
-
86
82
  $logger.info "Creating '%s' container" % options['name']
87
83
  Docker::Container.create(options)
88
84
  end
89
85
 
90
- def insert_scripts!
91
- insert_post_create_scripts!
92
- insert_post_start_scripts!
93
- end
94
-
95
- def insert_post_create_scripts!
96
- insert_files!(container.post_create_scripts)
97
- end
98
-
99
- def insert_post_start_scripts!
100
- insert_files!(container.post_start_scripts)
101
- end
102
-
103
86
  def execute_post_create_scripts!
104
87
  Exec.new(container, container.dependant_containers.values, container.post_create_scripts, 'POST create').execute!
105
88
  end
106
89
 
90
+ def set_dockerfile_md5!
91
+ $logger.info "Setting MD5 for '#{container.name}' container to #{container.current_dockerfile_md5}"
92
+ $metastore.set("#{container.metastore_key}.dockerfile_md5", container.current_dockerfile_md5)
93
+ end
94
+
107
95
  end
108
96
  end
109
97
  end
@@ -12,11 +12,12 @@ module Percheron
12
12
  end
13
13
 
14
14
  def execute!
15
+ results = []
15
16
  $logger.debug "Executing #{description} scripts '#{scripts.inspect}' on '#{container.name}'"
16
17
  started_dependant_containers = start_containers!(dependant_containers)
17
- execute_scripts_on_running_container!
18
- stop_containers!(started_dependant_containers)
19
- container
18
+ results << execute_scripts_on_running_container!
19
+ results << stop_containers!(started_dependant_containers)
20
+ results.compact.empty? ? nil : container
20
21
  end
21
22
 
22
23
  private
@@ -25,7 +26,7 @@ module Percheron
25
26
 
26
27
  def execute_scripts_on_running_container!
27
28
  container_running = container.running?
28
- Start.new(container).execute! unless container_running
29
+ Start.new(container, exec_scripts: false).execute! unless container_running
29
30
  execute_scripts!
30
31
  Stop.new(container).execute! unless container_running
31
32
  end
@@ -13,8 +13,9 @@ module Percheron
13
13
  end
14
14
 
15
15
  def execute!
16
- $logger.debug "Executing #{description} scripts '#{scripts.inspect}' locally"
17
- execute_scripts!
16
+ results = []
17
+ results << execute_scripts!
18
+ results.compact.empty? ? nil : container
18
19
  end
19
20
 
20
21
  private
@@ -22,6 +23,7 @@ module Percheron
22
23
  attr_reader :container, :scripts, :description
23
24
 
24
25
  def execute_scripts!
26
+ $logger.debug "Executing #{description} scripts '#{scripts.inspect}' locally"
25
27
  scripts.each do |script|
26
28
  in_working_directory(base_dir) do
27
29
  execute_command!('/bin/bash -x %s 2>&1' % Pathname.new(File.expand_path(script)))
@@ -9,10 +9,11 @@ module Percheron
9
9
  end
10
10
 
11
11
  def execute!
12
- stop!
13
- delete_container! if container.exists?
14
- delete_image! if container.image_exists?
15
- container
12
+ results = []
13
+ results << stop!
14
+ results << delete_container! if container.exists?
15
+ results << delete_image! if container.image_exists?
16
+ results.compact.empty? ? nil : container
16
17
  end
17
18
 
18
19
  private
@@ -11,9 +11,9 @@ module Percheron
11
11
  end
12
12
 
13
13
  def execute!
14
+ results = []
14
15
  if recreate?
15
- recreate!
16
- container
16
+ results << recreate!
17
17
  else
18
18
  unless dockerfile_md5s_match?
19
19
  $logger.warn "Container '#{container.name}' MD5's do not match, consider recreating (bump the version!)"
@@ -21,6 +21,7 @@ module Percheron
21
21
  $logger.info "Container '#{container.name}' does not need to be recreated"
22
22
  end
23
23
  end
24
+ results.compact.empty? ? nil : container
24
25
  end
25
26
 
26
27
  private
@@ -11,8 +11,9 @@ module Percheron
11
11
  end
12
12
 
13
13
  def execute!
14
- rename!
15
- container
14
+ results = []
15
+ results << rename!
16
+ results.compact.empty? ? nil : container
16
17
  end
17
18
 
18
19
  private
@@ -9,9 +9,10 @@ module Percheron
9
9
  end
10
10
 
11
11
  def execute!
12
- stop!
13
- start!
14
- container
12
+ results = []
13
+ results << stop!
14
+ results << start!
15
+ results.compact.empty? ? nil : container
15
16
  end
16
17
 
17
18
  private
@@ -23,7 +24,7 @@ module Percheron
23
24
  end
24
25
 
25
26
  def start!
26
- Start.new(container, container.dependant_containers.values).execute!
27
+ Start.new(container, dependant_containers: container.dependant_containers.values).execute!
27
28
  end
28
29
 
29
30
  end
@@ -4,25 +4,32 @@ module Percheron
4
4
 
5
5
  include Base
6
6
 
7
- def initialize(container, dependant_containers=[])
7
+ def initialize(container, dependant_containers: [], exec_scripts: true)
8
8
  @container = container
9
9
  @dependant_containers = dependant_containers
10
+ @exec_scripts = exec_scripts
10
11
  end
11
12
 
12
13
  def execute!
13
- create! unless container.exists?
14
+ results = []
15
+ results << create! unless container.exists?
14
16
  unless container.running?
15
- start!
16
- execute_post_start_scripts! unless container.post_start_scripts.empty?
17
+ results << start!
18
+ results << execute_post_start_scripts! if exec_scripts?
17
19
  end
18
- container
20
+ results.compact.empty? ? nil : container
19
21
  end
20
22
 
21
23
  private
22
24
 
23
- attr_reader :container, :dependant_containers
25
+ attr_reader :container, :dependant_containers, :exec_scripts
26
+
27
+ def exec_scripts?
28
+ !container.post_start_scripts.empty? && exec_scripts
29
+ end
24
30
 
25
31
  def create!
32
+ $logger.info "Creating '#{container.name}' container as it doesn't exist"
26
33
  Create.new(container).execute!
27
34
  end
28
35
 
@@ -9,8 +9,9 @@ module Percheron
9
9
  end
10
10
 
11
11
  def execute!
12
- stop! if container.running?
13
- container
12
+ results = []
13
+ results << stop! if container.running?
14
+ results.compact.empty? ? nil : container
14
15
  end
15
16
 
16
17
  private
@@ -18,6 +18,10 @@ module Percheron
18
18
  end
19
19
  end
20
20
 
21
+ def stack
22
+ Percheron::Stack.new(config, stack_name)
23
+ end
24
+
21
25
  def default_config_file
22
26
  ENV.fetch('PERCHERON_CONFIG', DEFAULT_CONFIG_FILE)
23
27
  end
@@ -6,7 +6,7 @@ module Percheron
6
6
 
7
7
  def execute
8
8
  opts = { container_names: container_names }
9
- Percheron::Stack.new(config, stack_name).create!(opts)
9
+ stack.create!(opts)
10
10
  end
11
11
  end
12
12
  end
@@ -2,10 +2,11 @@ module Percheron
2
2
  module Commands
3
3
  class Purge < Abstract
4
4
 
5
- parameter('STACK_NAME', 'stack name', required: false)
5
+ default_parameters!
6
6
 
7
7
  def execute
8
- Percheron::Stack.new(config, stack_name).purge!
8
+ opts = { container_names: container_names }
9
+ stack.purge!(opts)
9
10
  end
10
11
  end
11
12
  end
@@ -14,7 +14,7 @@ module Percheron
14
14
  delete: delete?
15
15
  }
16
16
 
17
- Percheron::Stack.new(config, stack_name).recreate!(opts)
17
+ stack.recreate!(opts)
18
18
  end
19
19
  end
20
20
  end
@@ -6,7 +6,7 @@ module Percheron
6
6
 
7
7
  def execute
8
8
  opts = { container_names: container_names }
9
- Percheron::Stack.new(config, stack_name).restart!(opts)
9
+ stack.restart!(opts)
10
10
  end
11
11
  end
12
12
  end
@@ -6,7 +6,7 @@ module Percheron
6
6
 
7
7
  def execute
8
8
  opts = { container_names: container_names }
9
- Percheron::Stack.new(config, stack_name).start!(opts)
9
+ stack.start!(opts)
10
10
  end
11
11
  end
12
12
  end
@@ -6,7 +6,7 @@ module Percheron
6
6
 
7
7
  def execute
8
8
  opts = { container_names: container_names }
9
- Percheron::Stack.new(config, stack_name).stop!(opts)
9
+ stack.stop!(opts)
10
10
  end
11
11
  end
12
12
  end
@@ -46,8 +46,7 @@ module Percheron
46
46
 
47
47
  def start!(container_names: [])
48
48
  container_names = dependant_containers_for(container_names)
49
- exec_on_dependant_containers_for(container_names) { |container| Actions::Start.new(container, container.dependant_containers.values).execute! }
50
-
49
+ exec_on_dependant_containers_for(container_names) { |container| Actions::Start.new(container, dependant_containers: container.dependant_containers.values).execute! }
51
50
  end
52
51
 
53
52
  def restart!(container_names: [])
@@ -73,11 +72,9 @@ module Percheron
73
72
  exec_on_dependant_containers_for(container_names_final.uniq) { |container| Actions::Recreate.new(container, force_recreate: force_recreate, delete: delete).execute! }
74
73
  end
75
74
 
76
- def purge!
77
- serial_processor(filter_container_names) do |container|
78
- Actions::Purge.new(container).execute!
79
- $logger.info ''
80
- end
75
+ def purge!(container_names: [])
76
+ container_names = filter_container_names(container_names)
77
+ exec_on_dependant_containers_for(container_names) { |container| Actions::Purge.new(container).execute! }
81
78
  end
82
79
 
83
80
  def valid?
@@ -106,8 +103,7 @@ module Percheron
106
103
 
107
104
  def exec_on_dependant_containers_for(container_names)
108
105
  serial_processor(container_names) do |container|
109
- yield(container)
110
- $logger.info ''
106
+ $logger.info '' if yield(container)
111
107
  end
112
108
  end
113
109
 
@@ -1,3 +1,3 @@
1
1
  module Percheron
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
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.6.3
4
+ version: 0.6.4
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-03-14 00:00:00.000000000 Z
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp