ops_build 1.0.4 → 1.0.5
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/README.md +4 -0
- data/lib/ops_build/packer.rb +35 -6
- data/lib/ops_build/version.rb +1 -1
- data/lib/ops_build.rb +19 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebb6c7d7517a303c66a1586cb9077cb5289f00a2
|
4
|
+
data.tar.gz: fb09cb2c9664a09100c0e9bb88114dcde69c24ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccdf2f57d92241ba93d55247b98e82953bdb34ef66ee34836b0e7810da8e604bbf4c1258b97cec9e66ccda68f69f12de5dc56bb54ccdd1647c468ff2fb5629ce
|
7
|
+
data.tar.gz: e1f04a63944e6ba6c7f18bcaa4a747729c953bd2ec2edd476561fd89abe5fd4f86016086c72b460a67325c36f1485a41bb789f2bf2726f6e0292dfcce9846dc7
|
data/README.md
CHANGED
data/lib/ops_build/packer.rb
CHANGED
@@ -6,7 +6,7 @@ module OpsBuild
|
|
6
6
|
require 'tempfile'
|
7
7
|
|
8
8
|
class PackerSupport
|
9
|
-
attr_accessor :user_vars, :user_var_file
|
9
|
+
attr_accessor :user_vars, :user_var_file, :packer_log
|
10
10
|
|
11
11
|
def initialize()
|
12
12
|
@user_vars = {}
|
@@ -17,6 +17,8 @@ module OpsBuild
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
#
|
21
|
+
# Add name/value pair to users_vars hash which is going to be used later for packer var-file
|
20
22
|
def packer_add_user_variable(name, value)
|
21
23
|
unless name.nil? and value.nil?
|
22
24
|
@user_vars[name] = value
|
@@ -31,11 +33,27 @@ module OpsBuild
|
|
31
33
|
packer_create_var_file()
|
32
34
|
|
33
35
|
unless @user_var_file.nil?
|
34
|
-
puts(">>>>
|
35
|
-
packer_options = "-var-file #{@user_var_file.path}"
|
36
|
+
puts(">>>> Changing packer build with variables file from: #{@user_var_file.path} ")
|
37
|
+
packer_options = "-machine-readable -var-file #{@user_var_file.path}"
|
38
|
+
end
|
39
|
+
|
40
|
+
if @packer_log.nil?
|
41
|
+
packer_create_log_file()
|
42
|
+
puts(">>>> Using file #{@packer_log.path} as log file.")
|
43
|
+
end
|
44
|
+
|
45
|
+
unless system("packer build #{packer_options} #{packer_config} | tee -a #{@packer_log.path}")
|
46
|
+
puts(">>>> Packer build failed.")
|
47
|
+
raise
|
36
48
|
end
|
49
|
+
puts(">>>>> packer run exit $?")
|
50
|
+
end
|
51
|
+
|
52
|
+
def packer_get_ami_id()
|
53
|
+
# Get AMI id by greping log for given string and then getting last value
|
54
|
+
ami = File.foreach(@packer_log.path).grep(/amazon-ebs,artifact.*,id/).first.chomp.split(':').last
|
37
55
|
|
38
|
-
|
56
|
+
puts(">>>> Packer built ami: #{ami}")
|
39
57
|
end
|
40
58
|
|
41
59
|
#
|
@@ -46,7 +64,7 @@ module OpsBuild
|
|
46
64
|
packer_create_var_file()
|
47
65
|
|
48
66
|
unless @user_var_file.nil?
|
49
|
-
puts(">>>>
|
67
|
+
puts(">>>> Customizing packer build with variable file from: #{@user_var_file.path} ")
|
50
68
|
packer_options = "-var-file #{@user_var_file.path}"
|
51
69
|
end
|
52
70
|
|
@@ -57,15 +75,26 @@ module OpsBuild
|
|
57
75
|
end
|
58
76
|
|
59
77
|
#
|
60
|
-
# Clean user_var-file from system
|
78
|
+
# Clean user_var-file/packer_log from system
|
61
79
|
def packer_cleanup()
|
62
80
|
unless @user_var_file.nil?
|
63
81
|
@user_var_file.unlink
|
64
82
|
@user_var_file.close
|
65
83
|
end
|
84
|
+
|
85
|
+
unless @packer_log.nil?
|
86
|
+
@packer_log.unlink
|
87
|
+
@packer_log.close
|
88
|
+
end
|
66
89
|
end
|
67
90
|
|
68
91
|
private
|
92
|
+
def packer_create_log_file()
|
93
|
+
if @packer_log.nil?
|
94
|
+
@packer_log = Tempfile.new('packer-log-file')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
69
98
|
def packer_create_var_file()
|
70
99
|
if @user_var_file.nil?
|
71
100
|
@user_var_file = Tempfile.new('packer-var-file')
|
data/lib/ops_build/version.rb
CHANGED
data/lib/ops_build.rb
CHANGED
@@ -19,6 +19,8 @@ lib = File.expand_path('.', __FILE__)
|
|
19
19
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
20
20
|
|
21
21
|
class OpsBuilder < Thor
|
22
|
+
class_option :verbose, :type => :boolean
|
23
|
+
|
22
24
|
desc 'validate template', 'validate packer template'
|
23
25
|
def validate_packer(template)
|
24
26
|
packer = OpsBuild::PackerSupport.new
|
@@ -26,6 +28,10 @@ class OpsBuilder < Thor
|
|
26
28
|
end
|
27
29
|
|
28
30
|
desc 'build template', 'build packer template'
|
31
|
+
option :ec2_region, :type => :string, :aliases => 'R', :desc => 'AWS EC2 region'
|
32
|
+
option :aws_access, :type => :string, :aliases => 'A', :desc => 'AWS Access key'
|
33
|
+
option :aws_secret, :type => :string, :aliases => 'S', :desc => 'AWS Secret key'
|
34
|
+
option :berk_dir, :type => :string, :aliases => 'b', :desc => 'Berkshelf cookbook directory path'
|
29
35
|
def build_packer(template)
|
30
36
|
packer = OpsBuild::PackerSupport.new
|
31
37
|
berkshelf = OpsBuild::BerkshelfSupport.new
|
@@ -34,10 +40,9 @@ class OpsBuilder < Thor
|
|
34
40
|
puts ">> Building VM using packer from template #{template}"
|
35
41
|
|
36
42
|
# Add some config variables
|
37
|
-
packer.packer_add_user_variable(:
|
38
|
-
packer.packer_add_user_variable(:
|
39
|
-
packer.packer_add_user_variable(:
|
40
|
-
packer.packer_add_user_variable(:aws_region, aws.aws_get_ec2_region)
|
43
|
+
packer.packer_add_user_variable(:aws_access_key, options[:aws_access].nil? ? aws.aws_get_access_key : options[:aws_access])
|
44
|
+
packer.packer_add_user_variable(:aws_secret_key, options[:aws_secret].nil? ? aws.aws_get_secret_key : options[:aws_secret])
|
45
|
+
packer.packer_add_user_variable(:aws_region, options[:ec2_region].nil? ? aws.aws_get_ec2_region : options[:ec2_region])
|
41
46
|
packer.packer_add_user_variable(:cookbook_path, berkshelf.berkshelf_dir)
|
42
47
|
|
43
48
|
# Install missing cookbooks
|
@@ -56,8 +61,16 @@ class OpsBuilder < Thor
|
|
56
61
|
end
|
57
62
|
puts ">>>> Vendoring cookbooks with berks to #{berkshelf.berkshelf_dir}"
|
58
63
|
|
59
|
-
|
60
|
-
|
64
|
+
begin
|
65
|
+
# Run packer
|
66
|
+
packer.packer_build(template)
|
67
|
+
rescue
|
68
|
+
berkshelf.berks_cleanup()
|
69
|
+
packer.packer_cleanup()
|
70
|
+
exit(1)
|
71
|
+
end
|
72
|
+
|
73
|
+
packer.packer_get_ami_id()
|
61
74
|
|
62
75
|
puts ">>>> Cleaning up cookbooks/packer files from system."
|
63
76
|
berkshelf.berks_cleanup()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ops_build
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HAMSIK Adam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|