pero 0.1.9 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cc26e00bd55e4f440b1093cb50d648c692431e242aaad76ee5a75b4861a569e
4
- data.tar.gz: 993f4b79e420e78cfdebc1f124fa066b70f2b562b4948affa768819eb212ee5c
3
+ metadata.gz: d2cd510f50571a49f36a9d83b33b6ec102c2ec31dce18ee08223b96d9767a867
4
+ data.tar.gz: a576229ec962f9359956f787591b3c14b7d6a779fae2224d06181f4508adb573
5
5
  SHA512:
6
- metadata.gz: b84c3ad2efb6a369fd8d3edf4a80076d107dd9270a41840e5ff41ca15549aeb360ba2318d2568237f279bfb941b6b97963bbace51e15771584c38dc67dc20d7d
7
- data.tar.gz: ac0092e216b422dd99afdede3175063d267c92e09a10cdcfa207d7a3e514a5d4412ba57900c6bf1efbcb049c139ddbc345ab640cd113f93866820dfa95603466
6
+ metadata.gz: de370da8d84760e9c441630e123ecce5af27fb52af670b9edc16ba62b14b4bdc4b156b343c0ba8f764dc3203cfa3eb5b6ffc9a0d6b17efaa5982e31f68e42e22
7
+ data.tar.gz: 743fc365959f454d404d11faf1dda6d4c89242e2e4b054d137c5887befc7fb027c5c56345f6bfc164db4c19e8081d27563e8b19bdcd117d6e1a0ea070940da88
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pero (0.1.8)
4
+ pero (0.1.9)
5
5
  docker-api
6
6
  logger
7
7
  net-ssh
data/Rakefile CHANGED
@@ -4,3 +4,8 @@ require "rspec/core/rake_task"
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :default => :spec
7
+
8
+ task :build_docker do
9
+ puts `docker build -f ./misc/Dockerfile -t pyama/puppet:3.0.1 .`
10
+ puts `docker push pyama/puppet:3.0.1`
11
+ end
@@ -20,8 +20,9 @@ module Pero
20
20
  option :user, type: :string, aliases: ['-x'], desc: "ssh user"
21
21
  option :key, type: :string, aliases: ['-i'], desc: "ssh private key"
22
22
  option :port, type: :numeric, aliases: ['-p'], desc: "ssh port"
23
+ option "timeout", default: 10, type: :numeric, desc: "ssh connect timeout"
23
24
  option :ssh_config, type: :string, desc: "ssh config path"
24
- option :environment, type: :string, desc: "puppet environment"
25
+ option :environment, type: :string, desc: "puppet environment", default: "production"
25
26
  option :ask_password, type: :boolean, default: false, desc: "ask ssh or sudo password"
26
27
  option :vagrant, type: :boolean, default: false, desc: "use vagrarant"
27
28
  option :sudo, type: :boolean, default: true, desc: "use sudo"
@@ -39,18 +40,32 @@ module Pero
39
40
 
40
41
  desc "apply", "puppet apply"
41
42
  shared_options
42
- option "server-version", type: :string, default: "6.12.0"
43
+ option "server-version", type: :string
44
+ option "image-name", type: :string
43
45
  option :noop, aliases: '-n', default: false, type: :boolean
46
+ option :test, aliases: '-t', default: false, type: :boolean
44
47
  option :verbose, aliases: '-v', default: true, type: :boolean
45
48
  option :tags, default: nil, type: :array
49
+ option :volumes, default: nil, type: :array
46
50
  option "one-shot", default: false, type: :boolean, desc: "stop puppet server after run"
47
51
  def apply(name_regexp)
52
+
53
+ if !options["image-name"] && !options["server-version"]
54
+ Pero.log.error "image-name or server-version are required"
55
+ return
56
+ end
57
+
48
58
  begin
49
59
  prepare
50
60
  nodes = Pero::History.search(name_regexp)
51
61
  return unless nodes
52
62
  Parallel.each(nodes, in_process: options["concurrent"]) do |n|
53
63
  opt = n["last_options"].merge(options)
64
+ if options["image-name"]
65
+ opt.delete("server-version")
66
+ else
67
+ opt.delete("image-name")
68
+ end
54
69
  puppet = Pero::Puppet.new(opt["host"], opt)
55
70
  puppet.apply
56
71
  end
@@ -66,8 +81,10 @@ module Pero
66
81
  def bootstrap(*hosts)
67
82
  begin
68
83
  Parallel.each(hosts, in_process: options["concurrent"]) do |host|
69
- next if host =~ /^-/
84
+ raise "unknown option #{host}" if host =~ /^-/
70
85
  puppet = Pero::Puppet.new(host, options)
86
+
87
+ Pero.log.info "bootstrap pero #{host}"
71
88
  puppet.install
72
89
  end
73
90
  rescue => e
@@ -4,16 +4,22 @@ require "retryable"
4
4
  require 'net/https'
5
5
  module Pero
6
6
  class Docker
7
- attr_reader :server_version
8
- def initialize(version, environment)
7
+ attr_reader :server_version, :image_name, :volumes
8
+ def initialize(version, image_name, environment, volumes)
9
9
  @server_version = version
10
+ @image_name = image_name
10
11
  @environment = environment
12
+ @volumes = volumes
11
13
  end
12
14
 
13
15
  def build
14
16
  Pero.log.info "start build container"
15
17
  begin
16
- image = ::Docker::Image.build(docker_file)
18
+ image = if image_name
19
+ ::Docker::Image.create('fromImage' => image_name)
20
+ else
21
+ ::Docker::Image.build(docker_file)
22
+ end
17
23
  rescue => e
18
24
  Pero.log.debug docker_file
19
25
  Pero.log.error "failed build container #{e.inspect}"
@@ -24,7 +30,7 @@ module Pero
24
30
  end
25
31
 
26
32
  def container_name
27
- "pero-#{server_version}-#{Digest::MD5.hexdigest(Dir.pwd)[0..5]}-#{@environment}"
33
+ "pero-#{Digest::MD5.hexdigest(Dir.pwd)[0..5]}-#{@environment}"
28
34
  end
29
35
 
30
36
  def find
@@ -51,11 +57,11 @@ module Pero
51
57
  })
52
58
 
53
59
  Pero.log.info "start puppet master container"
60
+ vols = volumes || []
61
+ vols << "#{Dir.pwd}:/etc/puppetlabs/code/environments/#{@environment}"
62
+ vols << "#{Dir.pwd}/keys:/etc/puppetlabs/puppet/eyaml/"
54
63
  container.start(
55
- 'Binds' => [
56
- "#{Dir.pwd}:/etc/puppetlabs/code/environments/#{@environment}",
57
- "#{Dir.pwd}/keys:/etc/puppetlabs/puppet/eyaml/",
58
- ],
64
+ 'Binds' => vols,
59
65
  'PortBindings' => {
60
66
  '8140/tcp' => [{ 'HostPort' => "0" }],
61
67
  },
@@ -27,6 +27,7 @@ module Pero
27
27
  options["node-name"]
28
28
  end
29
29
  options.delete("noop")
30
+ options.delete("tags")
30
31
  @h = {
31
32
  name: name,
32
33
  last_options: options
@@ -53,6 +53,7 @@ module Pero
53
53
  opts[:password] = @options["password"] if @options["password"]
54
54
  opts[:keys] = [@options["key"]] if @options["key"]
55
55
  opts[:port] = @options["port"] if @options["port"]
56
+ opts[:timeout] = @options["timeout"] if @options["timeout"]
56
57
 
57
58
  if @options["vagrant"]
58
59
  config = Tempfile.new('', Dir.tmpdir)
@@ -78,7 +79,6 @@ module Pero
78
79
  end
79
80
 
80
81
  def install
81
- Pero.log.info "bootstrap pero"
82
82
  osi = specinfra.os_info
83
83
  os = case osi[:family]
84
84
  when "redhat"
@@ -108,7 +108,7 @@ module Pero
108
108
  end
109
109
 
110
110
  def run_container
111
- docker = Pero::Docker.new(@options["server-version"], @options["environment"])
111
+ docker = Pero::Docker.new(@options["server-version"], @options["image-name"], @options["environment"], @options["volumes"])
112
112
  docker.alerady_run? || docker.run
113
113
  end
114
114
 
@@ -123,11 +123,13 @@ module Pero
123
123
  mkdir -p `puppet config print ssldir` && mount --bind /tmp/puppet/#{tmpdir} `puppet config print ssldir` && \
124
124
  #{puppet_cmd}'"
125
125
  Pero.log.debug "run cmd:#{cmd}"
126
- ssh.exec!(specinfra.build_command(cmd)) do |channel, stream, data|
127
- Pero.log.info "#{host}:#{data.chomp}" if stream == :stdout && data.chomp != ""
128
- Pero.log.warn "#{host}:#{data.chomp}" if stream == :stderr && data.chomp != ""
129
- end
130
- ssh.exec!(specinfra.build_command("rm -rf /tmp/puppet/#{tmpdir}")) if @options["one-shot"]
126
+ ssh_exec(ssh, host, cmd)
127
+
128
+ if @options["one-shot"]
129
+ cmd = "/bin/rm -rf /tmp/puppet/#{tmpdir}"
130
+ ssh_exec(ssh, host, cmd)
131
+ end
132
+
131
133
  ssh.loop {true} if ENV['PERO_DEBUG']
132
134
  end
133
135
  rescue => e
@@ -138,17 +140,35 @@ module Pero
138
140
  Pero::History::Attribute.new(specinfra, @options).save
139
141
  end
140
142
 
143
+ def ssh_exec(ssh, host, cmd)
144
+ ssh.open_channel do |ch|
145
+ ch.request_pty
146
+ ch.on_data do |ch,data|
147
+ Pero.log.info "#{host}:#{data.chomp}"
148
+ end
149
+
150
+ ch.on_extended_data do |c,type,data|
151
+ Pero.log.error "#{host}:#{data.chomp}"
152
+ end
153
+
154
+ ch.exec specinfra.build_command(cmd) do |ch, success|
155
+ raise "could not execute #{cmd}" unless success
156
+ end
157
+ end
158
+ ssh.loop
159
+ end
160
+
141
161
  def puppet_cmd
142
162
  if Gem::Version.new("5.0.0") > Gem::Version.new(@options["agent-version"])
143
- "puppet agent --no-daemonize --onetime #{parse_puppet_option(@options)} --server localhost"
163
+ "puppet agent --no-daemonize --onetime #{parse_puppet_option(@options)} --ca_port 8140 --ca_server localhost --masterport 8140 --server localhost"
144
164
  else
145
- "/opt/puppetlabs/bin/puppet agent --no-daemonize --onetime #{parse_puppet_option(@options)} --server localhost"
165
+ "/opt/puppetlabs/bin/puppet agent --no-daemonize --onetime #{parse_puppet_option(@options)} --ca_server localhost --masterport 8140 --server localhost"
146
166
  end
147
167
  end
148
168
 
149
169
  def parse_puppet_option(options)
150
170
  ret = ""
151
- %w(noop verbose).each do |n|
171
+ %w(noop verbose test).each do |n|
152
172
  ret << " --#{n}" if options[n]
153
173
  end
154
174
  ret << " --tags #{options["tags"].join(",")}" if options["tags"]
@@ -1,3 +1,3 @@
1
1
  module Pero
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,11 @@
1
+ FROM centos:6
2
+ RUN yum -y install curl epel-release
3
+ RUN rpm -ivh https://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-12.noarch.rpm
4
+ RUN curl -O http://software.exogeni.net/repo/puppet/6/products/x86_64/puppet-server-3.0.1-1.el6.noarch.rpm && \
5
+ curl -O http://software.exogeni.net/repo/puppet/6/products/x86_64/puppet-3.0.1-1.el6.noarch.rpm && \
6
+ yum -y install puppet-3.0.1-1.el6.noarch.rpm puppet-server-3.0.1-1.el6.noarch.rpm
7
+ RUN mkdir -p /etc/puppetlabs/code/environments/production
8
+
9
+ RUN echo -e "[master]\nvardir= /var/puppet\nmanifestdir = /var/puppet/data/manifests\n templatedir = /var/puppet/data/templates\n modulepath = /var/puppet/data/modules:/var/puppet/data/roles:/var/puppet/data/vendor/modules\nlogdir = /var/log/puppet\n rundir = /var/run/puppet\n ssldir = /var/puppet/ssl\n" > /etc/puppet/puppet.conf
10
+
11
+ CMD bash -c "rm -rf /etc/puppet/ssl/* && puppet cert generate `hostname` --dns_alt_names localhost,127.0.0.1 && echo '*' > /etc/puppet/autosign.conf && puppet master --no-daemonize --verbose"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pyama86
@@ -179,6 +179,7 @@ files:
179
179
  - lib/pero/puppet/redhat.rb
180
180
  - lib/pero/ssh_executable.rb
181
181
  - lib/pero/version.rb
182
+ - misc/Dockerfile
182
183
  - pero.gemspec
183
184
  homepage: https://github.com/pyama86/pero
184
185
  licenses: