ops_build 1.1.2 → 1.1.3
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/TODO +4 -1
- data/lib/ops_build/box_indexer.rb +69 -0
- data/lib/ops_build/commands/build.rb +34 -19
- data/lib/ops_build/commands/generate.rb +22 -0
- data/lib/ops_build/commands/validate.rb +1 -1
- data/lib/ops_build/packer.rb +2 -2
- data/lib/ops_build/runner.rb +11 -1
- data/lib/ops_build/utils.rb +6 -3
- data/lib/ops_build/version.rb +1 -1
- data/lib/ops_build.rb +4 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8edb28512aa51341dcc8555e8f79ad53f05c76c0
|
4
|
+
data.tar.gz: ec0c1e7f1575e04a0b5b8fae56ed5f3110a878e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 608bcea2efb907015fd8549f04c19f16f352f14f5038454a05eceafb83cc554a47d16f06e7093a19f61a6c09b5294f0fc198a3d79441c54bb0630d6b262b2309
|
7
|
+
data.tar.gz: cf15e5624e52360b17ba668578059b27828d2180b50db50c030fbf7e2affca3f3c357abee37b65d02fb34a356bb9c097141c02dd96622cac251da85d86703952
|
data/TODO
CHANGED
@@ -1 +1,4 @@
|
|
1
|
-
- process manager? (when opsbuild is interrupted, packer build process continues ... )
|
1
|
+
- process manager? (when opsbuild is interrupted, packer build process continues ... )
|
2
|
+
- .ovf file
|
3
|
+
- https://www.packer.io/intro/getting-started/vagrant.html
|
4
|
+
- http://pretengineer.com/post/packer-vagrant-infra/
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module OpsBuild
|
2
|
+
class BoxIndexer
|
3
|
+
def initialize(dir:, out:, name:, desc:, root_url:, checksum_type: :sha1)
|
4
|
+
@dir = File.expand_path(dir)
|
5
|
+
@out = out
|
6
|
+
@name = name
|
7
|
+
@desc = desc
|
8
|
+
@root_url = root_url
|
9
|
+
@checksum_type = checksum_type
|
10
|
+
|
11
|
+
check_dir!
|
12
|
+
check_checksum_type!
|
13
|
+
end
|
14
|
+
|
15
|
+
def index
|
16
|
+
OpsBuild.logger.debug("Indexing directory '#{@dir}'")
|
17
|
+
out = {
|
18
|
+
name: @name,
|
19
|
+
description: @desc,
|
20
|
+
versions: []
|
21
|
+
}
|
22
|
+
|
23
|
+
Dir.glob("#{@dir}/*.box").each do |path|
|
24
|
+
filename = File.basename(path)
|
25
|
+
m = /^#{@name}_(?<version>[0-9]+\.[0-9]+\.[0-9]+)\.box$/.match(filename)
|
26
|
+
next if m.nil?
|
27
|
+
|
28
|
+
OpsBuild.logger.debug("Found box '#{filename}'")
|
29
|
+
|
30
|
+
out[:versions] << box_info(File.expand_path(path), m[:version])
|
31
|
+
end
|
32
|
+
|
33
|
+
out
|
34
|
+
end
|
35
|
+
|
36
|
+
def index!
|
37
|
+
write(index)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def check_dir!
|
42
|
+
raise "Folder '#{@dir}' does not exist!" unless Dir.exists?(@dir)
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_checksum_type!
|
46
|
+
raise "Unknown checksum type '#{@checksum_type}'!" unless %w(sha1 sha2 md5 rmd160).include?(@checksum_type.to_s.downcase)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def write(hash)
|
51
|
+
File.open(@out, 'w+') { |f| f.write(JSON.pretty_generate(hash)) }
|
52
|
+
end
|
53
|
+
def box_info(path, version)
|
54
|
+
{
|
55
|
+
version: version,
|
56
|
+
providers: [{
|
57
|
+
name: 'virtualbox',
|
58
|
+
url: File.join(@root_url, File.basename(path)),
|
59
|
+
checksum_type: @checksum_type.to_s,
|
60
|
+
checksum: checksum(path)
|
61
|
+
}]
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def checksum(path)
|
66
|
+
Digest.const_get(@checksum_type.upcase).file(path).hexdigest
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -10,29 +10,23 @@ module OpsBuild
|
|
10
10
|
|
11
11
|
desc 'packer TEMPLATE', 'build packer template'
|
12
12
|
shared_options
|
13
|
-
option :berk_dir,
|
13
|
+
option :berk_dir, type: :string, aliases: '-b', desc: 'Berkshelf cookbook directory path'
|
14
14
|
def packer(template)
|
15
15
|
packer = Packer.new
|
16
16
|
berkshelf = Berkshelf.new(dir: options[:berk_dir], silent: false)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
params = if options[:params]
|
18
|
+
raise "JSON #{options[:params]} not found!" unless File.exists?(options[:params])
|
19
|
+
JSON.parse(File.read(options[:params]), symbolize_names: true)
|
20
|
+
else
|
21
|
+
{}
|
22
|
+
end
|
21
23
|
|
22
24
|
OpsBuild.logger.info("Building VM using packer from template #{template}")
|
23
25
|
|
24
|
-
# aws_access_key = options[:aws_access] || aws.aws_get_access_key
|
25
|
-
# aws_secret_key = options[:aws_secret] || aws.aws_get_secret_key
|
26
|
-
# aws_region = options[:ec2_region] || aws.aws_get_ec2_region
|
27
|
-
|
28
26
|
aws_access_key = options[:aws_access] || ENV['AWS_ACCESS_KEY']
|
29
27
|
aws_secret_key = options[:aws_secret] || ENV['AWS_SECRET_KEY']
|
30
28
|
aws_region = options[:ec2_region] || ENV['AWS_EC2_REGION']
|
31
29
|
|
32
|
-
# Validations::not_empty!(aws_access_key, :aws_access)
|
33
|
-
# Validations::not_empty!(aws_secret_key, :aws_secret)
|
34
|
-
# Validations::not_empty!(aws_region, :ec2_region)
|
35
|
-
|
36
30
|
# Add some config variables
|
37
31
|
packer.add_user_variable(:aws_access_key, aws_access_key) if aws_access_key
|
38
32
|
packer.add_user_variable(:aws_secret_key, aws_secret_key) if aws_secret_key
|
@@ -52,8 +46,6 @@ module OpsBuild
|
|
52
46
|
|
53
47
|
# Run packer
|
54
48
|
packer.build(template)
|
55
|
-
|
56
|
-
packer.get_ami_id
|
57
49
|
rescue => e
|
58
50
|
OpsBuild.logger.error(e.message)
|
59
51
|
exit(1)
|
@@ -64,11 +56,34 @@ module OpsBuild
|
|
64
56
|
end
|
65
57
|
end
|
66
58
|
|
67
|
-
desc 'vagrant
|
59
|
+
desc 'vagrant VAGRANTFILE', 'build vagrant box'
|
68
60
|
shared_options
|
69
|
-
|
70
|
-
|
61
|
+
option :only, type: :string, aliases: '-l', desc: 'Do not create all boxes, just the one passed as argument'
|
62
|
+
option :output, type: :string, aliases: '-o', desc: 'Name of the output (box)', default: 'package.box'
|
63
|
+
def vagrant(path)
|
64
|
+
path = File.expand_path(path)
|
65
|
+
raise "Vagrantfile #{path} not found!" unless File.exists?(path)
|
66
|
+
|
67
|
+
env = { 'VAGRANT_CWD' => File.dirname(path) }
|
68
|
+
if options[:params]
|
69
|
+
raise "JSON #{options[:params]} not found!" unless File.exists?(options[:params])
|
70
|
+
JSON.parse(File.read(options[:params])).each do |k, v|
|
71
|
+
env[k.to_s.upcase] = v
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
OpsBuild.logger.info('Running vagrant up')
|
76
|
+
Utils::execute(
|
77
|
+
"vagrant up #{options[:only]}", # still correct even if --only not provided, because nil.to_s == ""
|
78
|
+
log_prefix: 'vagrant:',
|
79
|
+
env: env)
|
80
|
+
|
81
|
+
OpsBuild.logger.info('Running vagrant package')
|
82
|
+
Utils::execute(
|
83
|
+
"vagrant package #{options[:only]} --output #{options[:output]}",
|
84
|
+
log_prefix: 'vagrant:',
|
85
|
+
env: env)
|
71
86
|
end
|
72
87
|
end
|
73
88
|
end
|
74
|
-
end
|
89
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module OpsBuild
|
2
|
+
module Commands
|
3
|
+
class Generate < Thor
|
4
|
+
desc 'box-index', ' vagrant box folder and write json'
|
5
|
+
option :directory, type: :string, aliases: '-d', required: true, desc: 'Directory to search vagrant boxes in, e.g. \'/var/www/centos65/boxes\''
|
6
|
+
option :json_path, type: :string, aliases: '-j', required: true, desc: 'Path to output json, e.g. \'/var/www/centos65/centos.json\''
|
7
|
+
option :name, type: :string, aliases: '-n', required: true, desc: 'Box name, e.g. \'centos65\''
|
8
|
+
option :desc, type: :string, aliases: '-e', required: true, desc: 'Description of box collection, e.g. \'This box contains CentOS 6.5 build XYZ 64-bit\''
|
9
|
+
option :root_url, type: :string, aliases: '-r', required: true, desc: 'Root URL of boxes, e.g. \'http://example.com/centos65/boxes\''
|
10
|
+
def box_index
|
11
|
+
BoxIndexer.new(dir: options[:directory],
|
12
|
+
out: options[:json_path],
|
13
|
+
name: options[:name],
|
14
|
+
desc: options[:desc],
|
15
|
+
root_url: options[:root_url]).index!
|
16
|
+
rescue => e
|
17
|
+
OpsBuild.logger.error(e.message)
|
18
|
+
exit(1)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/ops_build/packer.rb
CHANGED
@@ -30,7 +30,7 @@ module OpsBuild
|
|
30
30
|
options = " -var-file #{@user_var_file.path}"
|
31
31
|
end
|
32
32
|
|
33
|
-
Utils::execute("packer build -color=false -machine-readable #{options} #{config}")
|
33
|
+
Utils::execute("packer build -color=false -machine-readable #{options} #{config}", log_prefix: 'packer:')
|
34
34
|
end
|
35
35
|
|
36
36
|
#
|
@@ -45,7 +45,7 @@ module OpsBuild
|
|
45
45
|
options = "-var-file #{@user_var_file.path}"
|
46
46
|
end
|
47
47
|
|
48
|
-
Utils::execute("packer validate #{options} #{config}")
|
48
|
+
Utils::execute("packer validate #{options} #{config}", log_prefix: 'packer:')
|
49
49
|
end
|
50
50
|
|
51
51
|
#
|
data/lib/ops_build/runner.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
module OpsBuild
|
2
2
|
class Runner < Thor
|
3
|
-
class_option :verbose, :
|
3
|
+
class_option :verbose, type: :boolean, default: false
|
4
|
+
|
5
|
+
#
|
6
|
+
# Adjust global options
|
7
|
+
def initialize(*args, &block)
|
8
|
+
super(*args, &block)
|
9
|
+
OpsBuild.logger.level = Logger::DEBUG if options[:verbose]
|
10
|
+
end
|
4
11
|
|
5
12
|
desc 'build SUBCOMMAND ...ARGS', 'build'
|
6
13
|
subcommand 'build', Commands::Build
|
@@ -10,5 +17,8 @@ module OpsBuild
|
|
10
17
|
|
11
18
|
desc 'kitchen SUBCOMMAND ...ARGS', 'kitchen'
|
12
19
|
subcommand 'kitchen', Commands::Kitchen
|
20
|
+
|
21
|
+
desc 'generate SUBCOMMAND ...ARGS', 'generate'
|
22
|
+
subcommand 'generate', Commands::Generate
|
13
23
|
end
|
14
24
|
end
|
data/lib/ops_build/utils.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
module OpsBuild
|
2
2
|
class Utils
|
3
|
-
def self.execute(cmd, log_level: :debug, log_prefix: '', raise_on_failure: true)
|
3
|
+
def self.execute(cmd, log_level: :debug, log_prefix: '', raise_on_failure: true, env: nil)
|
4
|
+
log_prefix << " " unless log_prefix.end_with?(" ")
|
4
5
|
OpsBuild.logger.debug("Running command '#{cmd}'")
|
5
|
-
|
6
|
+
args = [cmd]
|
7
|
+
args.unshift(env) if env
|
8
|
+
_, out, wait_thr = Open3.popen2e(*args)
|
6
9
|
|
7
10
|
while line = out.gets
|
8
|
-
OpsBuild.logger.__send__(log_level, "#{log_prefix}
|
11
|
+
OpsBuild.logger.__send__(log_level, "#{log_prefix}#{line}")
|
9
12
|
end
|
10
13
|
|
11
14
|
code = wait_thr.value.exitstatus # #value is blocking call
|
data/lib/ops_build/version.rb
CHANGED
data/lib/ops_build.rb
CHANGED
@@ -8,13 +8,16 @@ require 'thor'
|
|
8
8
|
require 'open3'
|
9
9
|
require 'yaml'
|
10
10
|
require 'logger'
|
11
|
+
require 'digest'
|
11
12
|
|
12
13
|
lib = File.expand_path('..', __FILE__)
|
13
14
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
14
15
|
|
15
16
|
require 'ops_build/commands/build'
|
17
|
+
require 'ops_build/commands/generate'
|
16
18
|
require 'ops_build/commands/kitchen'
|
17
19
|
require 'ops_build/commands/validate'
|
20
|
+
require 'ops_build/box_indexer'
|
18
21
|
require 'ops_build/runner'
|
19
22
|
require 'ops_build/version'
|
20
23
|
require 'ops_build/aws'
|
@@ -33,6 +36,7 @@ module OpsBuild
|
|
33
36
|
@logger.formatter = proc do |severity, datetime, progname, msg|
|
34
37
|
"[#{severity}] [#{datetime.strftime('%Y-%m-%d %H:%M:%S')}] #{msg.strip}\n"
|
35
38
|
end
|
39
|
+
@logger.level = Logger::INFO
|
36
40
|
end
|
37
41
|
|
38
42
|
@logger
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ops_build
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HAMSIK Adam
|
@@ -56,8 +56,10 @@ files:
|
|
56
56
|
- lib/ops_build.rb
|
57
57
|
- lib/ops_build/aws.rb
|
58
58
|
- lib/ops_build/berkshelf.rb
|
59
|
+
- lib/ops_build/box_indexer.rb
|
59
60
|
- lib/ops_build/chefspec.rb
|
60
61
|
- lib/ops_build/commands/build.rb
|
62
|
+
- lib/ops_build/commands/generate.rb
|
61
63
|
- lib/ops_build/commands/kitchen.rb
|
62
64
|
- lib/ops_build/commands/validate.rb
|
63
65
|
- lib/ops_build/kitchen.rb
|
@@ -88,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
90
|
version: '0'
|
89
91
|
requirements: []
|
90
92
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
93
|
+
rubygems_version: 2.4.5
|
92
94
|
signing_key:
|
93
95
|
specification_version: 4
|
94
96
|
summary: RSD Devops related build tool to run packer, berkshelf
|