pero 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pero/docker.rb +106 -102
  3. data/lib/pero/version.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c70b7eacb6c850afd1cdd014f357204cf34face7354aeb5056cf3869172794e
4
- data.tar.gz: 83d9dd8fedd249340337914d5635725b9f2cd189fac0d8bc189c7e9a3a74874f
3
+ metadata.gz: ecfeedf1f5589503f81308e4df7f4e8ce6735d17ea53aa146b9a6ff4749b65c6
4
+ data.tar.gz: 6ae0544b2f34d3d8f26ef8c1d10338528091215cf4ae3e7620c0d86829a6ed2d
5
5
  SHA512:
6
- metadata.gz: bb72ebfec2140ef2bde35127614ed05240e73b41ebd7442d9cf8ab8bcc9b2bbed3c98198c6caef0932481066477246661332741b7a44d3fcfeb7667509709741
7
- data.tar.gz: 4a9288d537cc01061b725552f9dd01ce71f48112cf9f49a5b180bba9cb5274521d95b7d673e3f9121d518158ae3596cba1e100e4a1f6c62d8acdcf2509fd1862
6
+ metadata.gz: fc3aad015bc517fbedcb5aa30ea824cbc08819c63054e09491d389ff2383119ab3449b895a5d8caf17450271dc7398d474159050006c590bfb6a71130f8c5d43
7
+ data.tar.gz: 06ea7ee5a816e62bb257636c53c863709e3217e7d6fe218bec9efdb51ccee4821d4ff3013c79528ce2813f693c081e090d295393c8b68fc35d504083e6d2b461
data/lib/pero/docker.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  require 'docker'
2
2
  require 'digest/md5'
3
- require "retryable"
3
+ require 'retryable'
4
4
  require 'net/https'
5
5
  module Pero
6
6
  class Docker
7
7
  attr_reader :server_version, :image_name, :volumes
8
+
8
9
  def initialize(version, image_name, environment, volumes)
9
10
  @server_version = version
10
11
  @image_name = image_name
@@ -13,20 +14,25 @@ module Pero
13
14
  end
14
15
 
15
16
  def build
16
- Pero.log.info "start build container"
17
+ Pero.log.info 'start build container'
17
18
  ::Docker.options[:read_timeout] = 300
18
19
  begin
19
20
  image = if image_name
20
21
  ::Docker::Image.create('fromImage' => image_name)
21
22
  else
22
- ::Docker::Image.build(docker_file)
23
+ ::Docker::Image.build(
24
+ docker_file,
25
+ {
26
+ 'platform' => ENV['DOCKER_DEFAULT_PLATFORM'] || 'linux/amd64'
27
+ }
28
+ )
23
29
  end
24
- rescue => e
30
+ rescue StandardError => e
25
31
  Pero.log.debug docker_file
26
32
  Pero.log.error "failed build container #{e.inspect}"
27
33
  raise e
28
34
  end
29
- Pero.log.info "success build container"
35
+ Pero.log.info 'success build container'
30
36
  image
31
37
  end
32
38
 
@@ -35,19 +41,19 @@ module Pero
35
41
  end
36
42
 
37
43
  def find
38
- ::Docker::Container.all(:all => true).find do |c|
39
- c.info["Names"].first == "/#{container_name}"
44
+ ::Docker::Container.all(all: true).find do |c|
45
+ c.info['Names'].first == "/#{container_name}"
40
46
  end
41
47
  end
42
48
 
43
49
  def alerady_run?
44
50
  c = find
45
- c && c.info["State"] == "running" && c
51
+ c && c.info['State'] == 'running' && c
46
52
  end
47
53
 
48
54
  def run
49
- ::Docker::Container.all(:all => true).each do |c|
50
- c.delete(:force => true) if c.info["Names"].first == "/#{container_name}"
55
+ ::Docker::Container.all(all: true).each do |c|
56
+ c.delete(force: true) if c.info['Names'].first == "/#{container_name}"
51
57
  end
52
58
 
53
59
  vols = volumes || []
@@ -55,124 +61,122 @@ module Pero
55
61
  vols << "#{Dir.pwd}/keys:/etc/puppetlabs/puppet/eyaml/"
56
62
 
57
63
  container = ::Docker::Container.create({
58
- 'name' => container_name,
59
- 'Hostname' => 'puppet',
60
- 'Image' => build.id,
61
- 'ExposedPorts' => { '8140/tcp' => {} },
62
- 'HostConfig' => {
63
- 'Binds' => vols,
64
- 'PortBindings' => {
65
- '8140/tcp' => [{ 'HostPort' => "0" }],
66
- },
67
- },
68
- 'Cmd' => ["bash", "-c", "rm -rf #{conf_dir}/ssl/* && #{create_ca} && #{run_cmd}"]
69
- })
70
-
71
- Pero.log.info "start puppet master container"
64
+ 'name' => container_name,
65
+ 'Hostname' => 'puppet',
66
+ 'Image' => build.id,
67
+ 'ExposedPorts' => { '8140/tcp' => {} },
68
+ 'HostConfig' => {
69
+ 'Binds' => vols,
70
+ 'PortBindings' => {
71
+ '8140/tcp' => [{ 'HostPort' => '0' }]
72
+ }
73
+ },
74
+ 'platform' => ENV['DOCKER_DEFAULT_PLATFORM'] || 'linux/amd64',
75
+ 'Cmd' => ['bash', '-c', "rm -rf #{conf_dir}/ssl/* && #{create_ca} && #{run_cmd}"]
76
+ })
77
+
78
+ Pero.log.info 'start puppet master container'
72
79
  container.start
73
80
 
74
81
  container = find
75
82
  raise "can't start container" unless container
83
+
76
84
  begin
77
85
  Retryable.retryable(tries: 20, sleep: 5) do
78
- begin
79
- https = Net::HTTP.new('localhost', container.info["Ports"].first["PublicPort"])
80
- https.use_ssl = true
81
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
82
- Pero.log.debug "start server health check"
83
- https.start {
84
- response = https.get('/')
85
- Pero.log.debug "puppet http response #{response}"
86
- }
87
- rescue => e
88
- Pero.log.debug e.inspect
89
- raise e
86
+ https = Net::HTTP.new('localhost', container.info['Ports'].first['PublicPort'])
87
+ https.use_ssl = true
88
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
89
+ Pero.log.debug 'start server health check'
90
+ https.start do
91
+ response = https.get('/')
92
+ Pero.log.debug "puppet http response #{response}"
90
93
  end
94
+ rescue StandardError => e
95
+ Pero.log.debug e.inspect
96
+ raise e
91
97
  end
92
- rescue
93
- Pero.log.error "can't start container.please check [ docker logs #{container.info["id"]} ]"
98
+ rescue StandardError
99
+ Pero.log.error "can't start container.please check [ docker logs #{container.info['id']} ]"
94
100
  container = find
95
- container.kill if container && container.info["State"] != "exited"
101
+ container.kill if container && container.info['State'] != 'exited'
96
102
  raise "can't start puppet server"
97
103
  end
98
104
  container
99
105
  end
100
106
 
101
107
  def puppet_config
102
- <<-EOS
103
- [master]
104
- vardir = /var/puppet
105
- certname = puppet
106
- dns_alt_names = puppet,localhost
107
- autosign = true
108
- environment_timeout = unlimited
109
- codedir = /etc/puppetlabs/code
110
-
111
- [main]
112
- server = puppet
113
- #{@environment && @environment != "" ? "environment = #{@environment}" : nil}
114
- EOS
115
-
116
-
108
+ <<~EOS
109
+ [master]
110
+ vardir = /var/puppet
111
+ certname = puppet
112
+ dns_alt_names = puppet,localhost
113
+ autosign = true
114
+ environment_timeout = unlimited
115
+ codedir = /etc/puppetlabs/code
116
+
117
+ [main]
118
+ server = puppet
119
+ #{@environment && @environment != '' ? "environment = #{@environment}" : nil}
120
+ EOS
117
121
  end
118
122
 
119
123
  def conf_dir
120
- if Gem::Version.new("4.0.0") > Gem::Version.new(server_version)
121
- "/etc/puppet"
122
- elsif Gem::Version.new("5.0.0") > Gem::Version.new(server_version) && Gem::Version.new("4.0.0") <= Gem::Version.new(server_version)
123
- "/etc/puppetlabs/puppet/"
124
- elsif Gem::Version.new("6.0.0") > Gem::Version.new(server_version)&& Gem::Version.new("5.0.0") <= Gem::Version.new(server_version)
125
- "/etc/puppetlabs/puppet/"
124
+ if Gem::Version.new('4.0.0') > Gem::Version.new(server_version)
125
+ '/etc/puppet'
126
+ elsif Gem::Version.new('5.0.0') > Gem::Version.new(server_version) && Gem::Version.new('4.0.0') <= Gem::Version.new(server_version)
127
+ '/etc/puppetlabs/puppet/'
128
+ elsif Gem::Version.new('6.0.0') > Gem::Version.new(server_version) && Gem::Version.new('5.0.0') <= Gem::Version.new(server_version)
129
+ '/etc/puppetlabs/puppet/'
126
130
  else
127
- "/etc/puppetlabs/puppet/"
131
+ '/etc/puppetlabs/puppet/'
128
132
  end
129
133
  end
130
134
 
131
135
  def docker_file
132
- release_package,package_name = if Gem::Version.new("4.0.0") > Gem::Version.new(server_version)
133
- ["puppetlabs-release-el-#{el}.noarch.rpm", "puppet-server"]
134
- elsif Gem::Version.new("5.0.0") > Gem::Version.new(server_version) && Gem::Version.new("4.0.0") <= Gem::Version.new(server_version)
135
- ["puppetlabs-release-pc1-el-#{el}.noarch.rpm", "puppetserver"]
136
- elsif Gem::Version.new("6.0.0") > Gem::Version.new(server_version)&& Gem::Version.new("5.0.0") <= Gem::Version.new(server_version)
137
- ["puppet5-release-el-#{el}.noarch.rpm", "puppetserver"]
138
- elsif Gem::Version.new("7.0.0") > Gem::Version.new(server_version)&& Gem::Version.new("6.0.0") <= Gem::Version.new(server_version)
139
- ["puppet6-release-el-#{el}.noarch.rpm", "puppetserver"]
140
- else
141
- ["puppet7-release-el-#{el}.noarch.rpm", "puppetserver"]
142
- end
136
+ release_package, package_name = if Gem::Version.new('4.0.0') > Gem::Version.new(server_version)
137
+ ["puppetlabs-release-el-#{el}.noarch.rpm", 'puppet-server']
138
+ elsif Gem::Version.new('5.0.0') > Gem::Version.new(server_version) && Gem::Version.new('4.0.0') <= Gem::Version.new(server_version)
139
+ ["puppetlabs-release-pc1-el-#{el}.noarch.rpm", 'puppetserver']
140
+ elsif Gem::Version.new('6.0.0') > Gem::Version.new(server_version) && Gem::Version.new('5.0.0') <= Gem::Version.new(server_version)
141
+ ["puppet5-release-el-#{el}.noarch.rpm", 'puppetserver']
142
+ elsif Gem::Version.new('7.0.0') > Gem::Version.new(server_version) && Gem::Version.new('6.0.0') <= Gem::Version.new(server_version)
143
+ ["puppet6-release-el-#{el}.noarch.rpm", 'puppetserver']
144
+ else
145
+ ["puppet7-release-el-#{el}.noarch.rpm", 'puppetserver']
146
+ end
143
147
 
144
148
  vault_repo = if el == 6
145
- <<-EOS
146
- RUN sed -i "s|#baseurl=|baseurl=|g" /etc/yum.repos.d/CentOS-Base.repo \
147
- && sed -i "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-Base.repo \
148
- && sed -i "s|http://mirror\.centos\.org/|http://vault\.centos\.org/|g" /etc/yum.repos.d/CentOS-Base.repo
149
- EOS
150
- else
151
- ''
152
- end
153
-
154
- legacy_signing = if Gem::Version.new("3.0.0") > Gem::Version.new(server_version)
155
- "RUN echo 'LegacySigningMDs md5' >> /etc/pki/tls/legacy-settings"
156
- else
157
- ''
158
- end
159
-
160
- <<-EOS
161
- FROM #{from_image}
162
- #{vault_repo}
163
- #{legacy_signing}
164
- RUN curl -L -k -O https://yum.puppetlabs.com/#{release_package} && \
165
- rpm -ivh #{release_package}
166
- RUN yum install -y #{package_name}-#{server_version}
167
- ENV PATH $PATH:/opt/puppetlabs/bin
168
- RUN echo -e "#{puppet_config.split(/\n/).join("\\n")}" > #{conf_dir}/puppet.conf
149
+ <<~EOS
150
+ RUN sed -i "s|#baseurl=|baseurl=|g" /etc/yum.repos.d/CentOS-Base.repo \
151
+ && sed -i "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-Base.repo \
152
+ && sed -i "s|http://mirror\.centos\.org/|http://vault\.centos\.org/|g" /etc/yum.repos.d/CentOS-Base.repo
153
+ EOS
154
+ else
155
+ ''
156
+ end
157
+
158
+ legacy_signing = if Gem::Version.new('3.0.0') > Gem::Version.new(server_version)
159
+ "RUN echo 'LegacySigningMDs md5' >> /etc/pki/tls/legacy-settings"
160
+ else
161
+ ''
162
+ end
163
+
164
+ <<~EOS
165
+ FROM #{from_image}
166
+ #{vault_repo}
167
+ #{legacy_signing}
168
+ RUN curl -L -k -O https://yum.puppetlabs.com/#{release_package} && \
169
+ rpm -ivh #{release_package}
170
+ RUN yum install -y #{package_name}-#{server_version}
171
+ ENV PATH $PATH:/opt/puppetlabs/bin
172
+ RUN echo -e "#{puppet_config.split(/\n/).join('\\n')}" > #{conf_dir}/puppet.conf
169
173
  EOS
170
174
  end
171
175
 
172
176
  def create_ca
173
- if Gem::Version.new("5.0.0") > Gem::Version.new(server_version)
177
+ if Gem::Version.new('5.0.0') > Gem::Version.new(server_version)
174
178
  'puppet cert generate `hostname` --dns_alt_names localhost,127.0.0.1'
175
- elsif Gem::Version.new("6.0.0") > Gem::Version.new(server_version)
179
+ elsif Gem::Version.new('6.0.0') > Gem::Version.new(server_version)
176
180
  'puppet cert generate `hostname` --dns_alt_names localhost,127.0.0.1'
177
181
  else
178
182
  'puppetserver ca setup --ca-name `hostname` --subject-alt-names DNS:localhost'
@@ -180,14 +184,14 @@ RUN echo -e "#{puppet_config.split(/\n/).join("\\n")}" > #{conf_dir}/puppet.conf
180
184
  end
181
185
 
182
186
  def run_cmd
183
- if Gem::Version.new("3.0.0") > Gem::Version.new(server_version)
187
+ if Gem::Version.new('3.0.0') > Gem::Version.new(server_version)
184
188
  # /var/puppet/run is created for the first time by running `puppet master`,
185
189
  # but `puppet master` will fail because the permissions are wrong.
186
190
  # So, let the `puppet master` fail once, fix the permission of /var/puppet/run, and execute `puppet master` again.
187
191
  'puppet master --no-daemonize --verbose || (chown puppet: /var/puppet/run && puppet master --no-daemonize --verbose)'
188
- elsif Gem::Version.new("5.0.0") > Gem::Version.new(server_version)
192
+ elsif Gem::Version.new('5.0.0') > Gem::Version.new(server_version)
189
193
  'puppet master --no-daemonize --verbose'
190
- elsif Gem::Version.new("6.0.0") > Gem::Version.new(server_version)
194
+ elsif Gem::Version.new('6.0.0') > Gem::Version.new(server_version)
191
195
  'puppetserver foreground'
192
196
  else
193
197
  'puppetserver foreground'
@@ -195,7 +199,7 @@ RUN echo -e "#{puppet_config.split(/\n/).join("\\n")}" > #{conf_dir}/puppet.conf
195
199
  end
196
200
 
197
201
  def el
198
- if Gem::Version.new("3.5.1") > Gem::Version.new(server_version)
202
+ if Gem::Version.new('3.5.1') > Gem::Version.new(server_version)
199
203
  6
200
204
  else
201
205
  7
data/lib/pero/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pero
2
- VERSION = "0.5.4"
2
+ VERSION = '0.5.5'
3
3
  end
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.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyama86
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-31 00:00:00.000000000 Z
11
+ date: 2023-12-07 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.3.26
202
+ rubygems_version: 3.4.10
203
203
  signing_key:
204
204
  specification_version: 4
205
205
  summary: tool for puppet apply from our desktop.