pero 0.4.1 → 0.5.2
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/lib/pero/cli.rb +33 -14
- data/lib/pero/docker.rb +13 -1
- data/lib/pero/history.rb +1 -0
- data/lib/pero/puppet.rb +17 -10
- data/lib/pero/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c887b6e9b5f504590d3a89b77630d76fa1bc39823e25b74e0bece76ff74a94b7
|
4
|
+
data.tar.gz: 1147b48bbaf1cdc375ce946c312f14010fc75ba89c4fd610d3c1f6c4a001cfcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0acb6080d4ecfb1499f12628667ad952346bf4a16d97d777b9492bfcf798a86d03ba7d95788a8c84be47c811cf4880de4d03e6d7dedcec298b494fb83a53ed20
|
7
|
+
data.tar.gz: 25ffa99fc93c113cff3e29daa77c369daee6972c4ed1752bd6fa55ea14cf723beca64cbaea9a7b032da5100c7b2aa9d7a04536fbbf45e6ef4031d86efe05a168
|
data/lib/pero/cli.rb
CHANGED
@@ -55,24 +55,31 @@ module Pero
|
|
55
55
|
return
|
56
56
|
end
|
57
57
|
|
58
|
+
prepare
|
59
|
+
nodes = Pero::History.search(name_regexp)
|
60
|
+
return unless nodes
|
61
|
+
m = Mutex.new
|
62
|
+
|
58
63
|
begin
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
Parallel.each(nodes, in_process: options["concurrent"]) do |n|
|
63
|
-
opt = n["last_options"].merge(options)
|
64
|
-
opt["environment"] = "production" if opt["environment"].nil? || opt["environment"].empty?
|
65
|
-
if options["image-name"]
|
66
|
-
opt.delete("server-version")
|
67
|
-
else
|
68
|
-
opt.delete("image-name")
|
69
|
-
end
|
70
|
-
puppet = Pero::Puppet.new(opt["host"], opt)
|
64
|
+
Parallel.each(nodes, in_threads: options["concurrent"]) do |n|
|
65
|
+
opt = merge_options(n, options)
|
66
|
+
puppet = Pero::Puppet.new(opt["host"], opt, m)
|
71
67
|
puppet.apply
|
72
68
|
end
|
73
69
|
rescue => e
|
74
70
|
Pero.log.error e.backtrace.join("\n")
|
75
71
|
Pero.log.error e.inspect
|
72
|
+
|
73
|
+
ensure
|
74
|
+
if options["one-shot"]
|
75
|
+
Pero.log.info "stop puppet master container"
|
76
|
+
Parallel.each(nodes, in_threads: options["concurrent"]) do |n|
|
77
|
+
opt = merge_options(n, options)
|
78
|
+
Pero::Puppet.new(opt["host"], opt, m).stop_master
|
79
|
+
end
|
80
|
+
else
|
81
|
+
Pero.log.info "puppet master container keep running"
|
82
|
+
end
|
76
83
|
end
|
77
84
|
end
|
78
85
|
|
@@ -83,9 +90,10 @@ module Pero
|
|
83
90
|
def bootstrap(*hosts)
|
84
91
|
begin
|
85
92
|
options["environment"] = "production" if options["environment"].nil? || options["environment"].empty?
|
86
|
-
|
93
|
+
m = Mutex.new
|
94
|
+
Parallel.each(hosts, in_threads: options["concurrent"]) do |host|
|
87
95
|
raise "unknown option #{host}" if host =~ /^-/
|
88
|
-
puppet = Pero::Puppet.new(host, options)
|
96
|
+
puppet = Pero::Puppet.new(host, options, m)
|
89
97
|
|
90
98
|
Pero.log.info "bootstrap pero #{host}"
|
91
99
|
puppet.install
|
@@ -97,6 +105,17 @@ module Pero
|
|
97
105
|
end
|
98
106
|
|
99
107
|
no_commands do
|
108
|
+
def merge_options(node, options)
|
109
|
+
opt = node["last_options"].merge(options)
|
110
|
+
opt["environment"] = "production" if opt["environment"].nil? || opt["environment"].empty?
|
111
|
+
if options["image-name"]
|
112
|
+
opt.delete("server-version")
|
113
|
+
else
|
114
|
+
opt.delete("image-name")
|
115
|
+
end
|
116
|
+
opt
|
117
|
+
end
|
118
|
+
|
100
119
|
def prepare
|
101
120
|
`bundle install` if File.exists?("Gemfile")
|
102
121
|
`bundle exec librarian-puppet install` if File.exists?("Puppetfile")
|
data/lib/pero/docker.rb
CHANGED
@@ -14,6 +14,7 @@ module Pero
|
|
14
14
|
|
15
15
|
def build
|
16
16
|
Pero.log.info "start build container"
|
17
|
+
::Docker.options[:read_timeout] = 300
|
17
18
|
begin
|
18
19
|
image = if image_name
|
19
20
|
::Docker::Image.create('fromImage' => image_name)
|
@@ -41,7 +42,7 @@ module Pero
|
|
41
42
|
|
42
43
|
def alerady_run?
|
43
44
|
c = find
|
44
|
-
c && c.info["State"] == "running" && c
|
45
|
+
c && c.info["State"] == "running" && c
|
45
46
|
end
|
46
47
|
|
47
48
|
def run
|
@@ -138,8 +139,19 @@ EOS
|
|
138
139
|
["puppet6-release-el-#{el}.noarch.rpm", "puppetserver"]
|
139
140
|
end
|
140
141
|
|
142
|
+
vault_repo = if el == 6
|
143
|
+
<<-EOS
|
144
|
+
RUN sed -i "s|#baseurl=|baseurl=|g" /etc/yum.repos.d/CentOS-Base.repo \
|
145
|
+
&& sed -i "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-Base.repo \
|
146
|
+
&& sed -i "s|http://mirror\.centos\.org/|http://vault\.centos\.org/|g" /etc/yum.repos.d/CentOS-Base.repo
|
147
|
+
EOS
|
148
|
+
else
|
149
|
+
''
|
150
|
+
end
|
151
|
+
|
141
152
|
<<-EOS
|
142
153
|
FROM #{from_image}
|
154
|
+
#{vault_repo}
|
143
155
|
RUN curl -L -k -O https://yum.puppetlabs.com/#{release_package} && \
|
144
156
|
rpm -ivh #{release_package}
|
145
157
|
RUN yum install -y #{package_name}-#{server_version}
|
data/lib/pero/history.rb
CHANGED
data/lib/pero/puppet.rb
CHANGED
@@ -23,8 +23,9 @@ module Pero
|
|
23
23
|
class Puppet
|
24
24
|
extend Pero::SshExecutable
|
25
25
|
attr_reader :specinfra
|
26
|
-
def initialize(host, options)
|
26
|
+
def initialize(host, options, mutex)
|
27
27
|
@options = options.dup
|
28
|
+
@mutex = mutex
|
28
29
|
|
29
30
|
@options[:host] = host
|
30
31
|
so = ssh_options
|
@@ -90,6 +91,10 @@ module Pero
|
|
90
91
|
Pero::History::Attribute.new(specinfra, @options).save
|
91
92
|
end
|
92
93
|
|
94
|
+
def stop_master
|
95
|
+
run_container.kill if docker.alerady_run?
|
96
|
+
end
|
97
|
+
|
93
98
|
def serve_master
|
94
99
|
container = run_container
|
95
100
|
begin
|
@@ -97,19 +102,20 @@ module Pero
|
|
97
102
|
rescue => e
|
98
103
|
Pero.log.error e.inspect
|
99
104
|
raise e
|
100
|
-
ensure
|
101
|
-
if @options["one-shot"]
|
102
|
-
Pero.log.info "stop puppet master container"
|
103
|
-
container.kill
|
104
|
-
else
|
105
|
-
Pero.log.info "puppet master container keep running"
|
106
|
-
end
|
107
105
|
end
|
108
106
|
end
|
109
107
|
|
108
|
+
def docker
|
109
|
+
Pero::Docker.new(@options["server-version"], @options["image-name"], @options["environment"], @options["volumes"])
|
110
|
+
end
|
111
|
+
|
110
112
|
def run_container
|
111
|
-
|
112
|
-
|
113
|
+
begin
|
114
|
+
@mutex.lock
|
115
|
+
docker.alerady_run? || docker.run
|
116
|
+
ensure
|
117
|
+
@mutex.unlock
|
118
|
+
end
|
113
119
|
end
|
114
120
|
|
115
121
|
def apply
|
@@ -172,6 +178,7 @@ module Pero
|
|
172
178
|
ret << " --#{n}" if options[n]
|
173
179
|
end
|
174
180
|
ret << " --tags #{options["tags"].join(",")}" if options["tags"]
|
181
|
+
ret << " --environment #{options["environment"]}" if options["environment"]
|
175
182
|
ret
|
176
183
|
end
|
177
184
|
|
data/lib/pero/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pyama86
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: '0'
|
201
201
|
requirements: []
|
202
|
-
rubygems_version: 3.1.
|
202
|
+
rubygems_version: 3.1.4
|
203
203
|
signing_key:
|
204
204
|
specification_version: 4
|
205
205
|
summary: tool for puppet apply from our desktop.
|