percheron 0.3.2 → 0.4.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/percheron/cli/recreate_command.rb +3 -1
- data/lib/percheron/config.rb +1 -4
- data/lib/percheron/container/actions/build.rb +33 -4
- data/lib/percheron/container/main.rb +18 -5
- data/lib/percheron/core_extensions.rb +11 -2
- data/lib/percheron/stack.rb +3 -6
- data/lib/percheron/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddfc86ead3b58968ec07cccf692a841643a45060
|
4
|
+
data.tar.gz: a09225865990c275d6812e26ab9dd2496d1171f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8a42293482b1d1ac38891aa44a2dbb1dd7d1d1000a1e2879ee78e07230e3af1d8f0747d8d8e9ab945f4534338362d561e6f2dfc53df2100311139c9934fb726
|
7
|
+
data.tar.gz: c153bc4ca7252f604143e96d55a6e5d8f0fe7684cf14e893657e00ab150fd227d4e78ccbe88169a85832325492a57d958d185f40b5198ae6b1389c6f724c2a04
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
[](https://codeclimate.com/github/ashmckenzie/percheron)
|
7
7
|
[](https://gemnasium.com/ashmckenzie/percheron)
|
8
8
|
|
9
|
-

|
10
10
|
|
11
11
|
Organise your Docker containers with muscle and intelligence.
|
12
12
|
|
@@ -4,8 +4,10 @@ module Percheron
|
|
4
4
|
|
5
5
|
parameter 'STACK_NAME', 'stack name'
|
6
6
|
|
7
|
+
option "--force", :flag, 'Force recreation', default: false
|
8
|
+
|
7
9
|
def execute
|
8
|
-
Percheron::Stack.new(config, stack_name).recreate!(
|
10
|
+
Percheron::Stack.new(config, stack_name).recreate!(force_recreate: force?, force_auto_recreate: true)
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
data/lib/percheron/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
1
3
|
module Percheron
|
2
4
|
module Container
|
3
5
|
module Actions
|
@@ -9,10 +11,12 @@ module Percheron
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def execute!
|
12
|
-
base_dir
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
in_working_directory(base_dir) do
|
15
|
+
execute_pre_build_scripts!
|
16
|
+
$logger.debug "Building '#{container.image}'"
|
17
|
+
Docker::Image.build_from_dir(base_dir, build_opts) do |out|
|
18
|
+
$logger.debug '%s' % [ out.strip ]
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
@@ -29,6 +33,31 @@ module Percheron
|
|
29
33
|
}
|
30
34
|
end
|
31
35
|
|
36
|
+
def base_dir
|
37
|
+
container.dockerfile.dirname.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def in_working_directory(new_dir)
|
41
|
+
old_dir = Dir.pwd
|
42
|
+
Dir.chdir(new_dir)
|
43
|
+
yield
|
44
|
+
Dir.chdir(old_dir)
|
45
|
+
end
|
46
|
+
|
47
|
+
def execute_pre_build_scripts!
|
48
|
+
container.pre_build_scripts.each do |script|
|
49
|
+
in_working_directory(base_dir) do
|
50
|
+
command = '/bin/bash -x %s 2>&1' % Pathname.new(File.expand_path(script))
|
51
|
+
$logger.debug "Executing '#{command}' for '#{container.name}' container"
|
52
|
+
Open3.popen2e(command) do |stdin, stdout_err, wait_thr|
|
53
|
+
while line = stdout_err.gets
|
54
|
+
$logger.debug line.strip
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
32
61
|
end
|
33
62
|
end
|
34
63
|
end
|
@@ -8,7 +8,7 @@ module Percheron
|
|
8
8
|
def_delegators :container_config, :name
|
9
9
|
|
10
10
|
def_config_item_with_default :container_config, false, :auto_recreate
|
11
|
-
def_config_item_with_default :container_config, [], :env, :ports, :volumes, :dependant_container_names
|
11
|
+
def_config_item_with_default :container_config, [], :env, :ports, :volumes, :dependant_container_names, :pre_build_scripts
|
12
12
|
|
13
13
|
alias_method :auto_recreate?, :auto_recreate
|
14
14
|
|
@@ -66,6 +66,7 @@ module Percheron
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def start!
|
69
|
+
start_dependant_containers!
|
69
70
|
create!
|
70
71
|
recreate!
|
71
72
|
Container::Actions::Start.new(self).execute!
|
@@ -86,9 +87,9 @@ module Percheron
|
|
86
87
|
end
|
87
88
|
end
|
88
89
|
|
89
|
-
def recreate!(
|
90
|
+
def recreate!(force_recreate: false, force_auto_recreate: false)
|
90
91
|
if exists?
|
91
|
-
if recreate?(
|
92
|
+
if recreate?(force_recreate: force_recreate, force_auto_recreate: force_auto_recreate)
|
92
93
|
$logger.warn "Container '#{name}' exists and will be recreated"
|
93
94
|
Container::Actions::Recreate.new(self).execute!
|
94
95
|
set_dockerfile_md5!
|
@@ -108,8 +109,8 @@ module Percheron
|
|
108
109
|
!dockerfile_md5s_match?
|
109
110
|
end
|
110
111
|
|
111
|
-
def recreate?(
|
112
|
-
recreatable? && versions_mismatch? && (
|
112
|
+
def recreate?(force_recreate: false, force_auto_recreate: false)
|
113
|
+
(force_recreate || (recreatable? && versions_mismatch?)) && (force_auto_recreate || auto_recreate?)
|
113
114
|
end
|
114
115
|
|
115
116
|
def running?
|
@@ -169,6 +170,18 @@ module Percheron
|
|
169
170
|
@container_config ||= stack.container_configs[container_name] || Hashie::Mash.new({})
|
170
171
|
end
|
171
172
|
|
173
|
+
def dependant_containers
|
174
|
+
dependant_container_names.map { |container_name| stack.containers[container_name] }
|
175
|
+
end
|
176
|
+
|
177
|
+
def start_dependant_containers!
|
178
|
+
dependant_containers.each do |container|
|
179
|
+
next if container.running?
|
180
|
+
$logger.debug "Container '#{container.name}' being started as it's a dependancy"
|
181
|
+
container.start!
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
172
185
|
end
|
173
186
|
end
|
174
187
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Percheron
|
2
2
|
module CoreExtensions
|
3
3
|
module Array
|
4
|
-
module
|
4
|
+
module Extras
|
5
|
+
|
5
6
|
def return
|
6
7
|
result = nil
|
7
8
|
each do |x|
|
@@ -13,9 +14,17 @@ module Percheron
|
|
13
14
|
end
|
14
15
|
result
|
15
16
|
end
|
17
|
+
|
18
|
+
def to_hash_by_key(key_attr)
|
19
|
+
inject({}) do |all, e|
|
20
|
+
all[e.send(key_attr)] = e unless all[e.send(key_attr)]
|
21
|
+
all
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
16
25
|
end
|
17
26
|
end
|
18
27
|
end
|
19
28
|
end
|
20
29
|
|
21
|
-
Array.include(Percheron::CoreExtensions::Array::
|
30
|
+
Array.include(Percheron::CoreExtensions::Array::Extras)
|
data/lib/percheron/stack.rb
CHANGED
@@ -30,10 +30,7 @@ module Percheron
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def container_configs
|
33
|
-
stack_config.containers.
|
34
|
-
all[container.name] = container unless all[container.name]
|
35
|
-
all
|
36
|
-
end
|
33
|
+
stack_config.containers.to_hash_by_key(:name)
|
37
34
|
end
|
38
35
|
|
39
36
|
def containers
|
@@ -61,8 +58,8 @@ module Percheron
|
|
61
58
|
exec_on_containers { |container| container.create! }
|
62
59
|
end
|
63
60
|
|
64
|
-
def recreate!(
|
65
|
-
exec_on_containers { |container| container.recreate!(
|
61
|
+
def recreate!(force_recreate: false, force_auto_recreate: false)
|
62
|
+
exec_on_containers { |container| container.recreate!(force_recreate: force_recreate, force_auto_recreate: force_auto_recreate) }
|
66
63
|
end
|
67
64
|
|
68
65
|
def valid?
|
data/lib/percheron/version.rb
CHANGED