pero 0.4.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pero/cli.rb +33 -14
- data/lib/pero/docker.rb +26 -2
- 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: e8fc62fc16984c838f034444f6dc537009aaa019e460a5998bad1184411c8a5b
|
4
|
+
data.tar.gz: 02233a95f14a8a58e622cfc1cb23cdc55edb81b2ede70bd015872ad642788189
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88141e0b5932f838695df5fca5a558a1b9523a8486201d643bf866cbf019771f011d8dede89d363518fe70873b4d5fa86dd1746ba6bc16e2a3cafe6f4af729af
|
7
|
+
data.tar.gz: cc8ad0c0c15759f70a318121dcc4cf567138c35e1321e460820563112c132c65efcc1d853bfa69ba2612617436c13e8a338851dd0a29b49eb946ba6da09de1e9
|
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)
|
@@ -138,8 +139,26 @@ 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
|
+
|
152
|
+
legacy_signing = if Gem::Version.new("3.0.0") > Gem::Version.new(server_version)
|
153
|
+
"RUN echo 'LegacySigningMDs md5' >> /etc/pki/tls/legacy-settings"
|
154
|
+
else
|
155
|
+
''
|
156
|
+
end
|
157
|
+
|
141
158
|
<<-EOS
|
142
159
|
FROM #{from_image}
|
160
|
+
#{vault_repo}
|
161
|
+
#{legacy_signing}
|
143
162
|
RUN curl -L -k -O https://yum.puppetlabs.com/#{release_package} && \
|
144
163
|
rpm -ivh #{release_package}
|
145
164
|
RUN yum install -y #{package_name}-#{server_version}
|
@@ -149,7 +168,7 @@ RUN echo -e "#{puppet_config.split(/\n/).join("\\n")}" > #{conf_dir}/puppet.conf
|
|
149
168
|
end
|
150
169
|
|
151
170
|
def create_ca
|
152
|
-
|
171
|
+
if Gem::Version.new("5.0.0") > Gem::Version.new(server_version)
|
153
172
|
'puppet cert generate `hostname` --dns_alt_names localhost,127.0.0.1'
|
154
173
|
elsif Gem::Version.new("6.0.0") > Gem::Version.new(server_version)
|
155
174
|
'puppet cert generate `hostname` --dns_alt_names localhost,127.0.0.1'
|
@@ -159,7 +178,12 @@ RUN echo -e "#{puppet_config.split(/\n/).join("\\n")}" > #{conf_dir}/puppet.conf
|
|
159
178
|
end
|
160
179
|
|
161
180
|
def run_cmd
|
162
|
-
|
181
|
+
if Gem::Version.new("3.0.0") > Gem::Version.new(server_version)
|
182
|
+
# /var/puppet/run is created for the first time by running `puppet master`,
|
183
|
+
# but `puppet master` will fail because the permissions are wrong.
|
184
|
+
# So, let the `puppet master` fail once, fix the permission of /var/puppet/run, and execute `puppet master` again.
|
185
|
+
'puppet master --no-daemonize --verbose || (chown puppet: /var/puppet/run && puppet master --no-daemonize --verbose)'
|
186
|
+
elsif Gem::Version.new("5.0.0") > Gem::Version.new(server_version)
|
163
187
|
'puppet master --no-daemonize --verbose'
|
164
188
|
elsif Gem::Version.new("6.0.0") > Gem::Version.new(server_version)
|
165
189
|
'puppetserver foreground'
|
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.3
|
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-16 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.
|