packer-config 1.6.0 → 1.6.1
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/.rubocop.yml +23 -0
- data/.rubocop_todo.yml +0 -125
- data/README.md +12 -12
- data/RELEASENOTES.md +4 -0
- data/lib/packer-config.rb +4 -4
- data/lib/packer/builder.rb +2 -0
- data/lib/packer/dataobject.rb +8 -15
- data/lib/packer/envvar.rb +6 -0
- data/lib/packer/macro.rb +6 -0
- data/lib/packer/postprocessor.rb +4 -3
- data/lib/packer/provisioner.rb +7 -6
- data/lib/packer/runner.rb +3 -2
- data/lib/packer/version.rb +1 -1
- data/packer-config.gemspec +1 -1
- data/spec/integration/centos_vagrant_spec.rb +12 -12
- data/spec/integration/scripts/kickstart/{centos-6.6-ks.cfg → centos-6.8-ks.cfg} +0 -0
- data/spec/packer/envvar_spec.rb +2 -2
- data/spec/packer/macro_spec.rb +2 -2
- data/spec/packer/provisioners/ansible_spec.rb +1 -1
- data/spec/packer/provisioners/chef/client_spec.rb +1 -1
- data/spec/packer/provisioners/puppet/masterless_spec.rb +1 -1
- data/spec/packer/provisioners/salt_spec.rb +1 -1
- data/spec/packer/runner_spec.rb +2 -2
- data/spec/packer_config_spec.rb +8 -8
- data/tasks/clean.rake +2 -2
- data/tasks/rspec.rake +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e83b6084bc9fc5e7f733b5cd914555e1f5ec5b21
|
|
4
|
+
data.tar.gz: 58691f783c9828674fa806d3c14ca589f4b01269
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 485f6738bda938b9ca79e9f594df1e0daab586380a0cd51a8b3747ccf1338784d1751d92a02c9229608614f892528964f68146ebc8aaa2af64659d782333896f
|
|
7
|
+
data.tar.gz: aa530dfdd9d9ce3024c2498c0d64ecfafc38467ff9ab8bf1a1f2946a6046d74b7d4ee1f901551a21982d3b9908a9fbcbc89e21890041fba010d6e05d2b1d4f6c
|
data/.rubocop.yml
CHANGED
|
@@ -38,10 +38,21 @@ Lint/EndAlignment:
|
|
|
38
38
|
Lint/Loop:
|
|
39
39
|
Enabled: false
|
|
40
40
|
|
|
41
|
+
Lint/UnusedMethodArgument:
|
|
42
|
+
Exclude:
|
|
43
|
+
- 'lib/packer/dataobject.rb'
|
|
44
|
+
- 'lib/packer/envvar.rb'
|
|
45
|
+
- 'lib/packer/macro.rb'
|
|
46
|
+
- 'lib/packer/provisioners/powershell.rb'
|
|
47
|
+
|
|
41
48
|
Lint/Void:
|
|
42
49
|
Exclude:
|
|
43
50
|
- dashboard/spec/**/*
|
|
44
51
|
|
|
52
|
+
Style/FileName:
|
|
53
|
+
Exclude:
|
|
54
|
+
- 'lib/packer-config.rb'
|
|
55
|
+
|
|
45
56
|
Style/AccessModifierIndentation:
|
|
46
57
|
Enabled: false
|
|
47
58
|
|
|
@@ -60,6 +71,15 @@ Style/AlignParameters:
|
|
|
60
71
|
Metrics/BlockNesting:
|
|
61
72
|
Enabled: false
|
|
62
73
|
|
|
74
|
+
Metrics/AbcSize:
|
|
75
|
+
Max: 30
|
|
76
|
+
|
|
77
|
+
Metrics/ClassLength:
|
|
78
|
+
Max: 150
|
|
79
|
+
|
|
80
|
+
Metrics/MethodLength:
|
|
81
|
+
Max: 27
|
|
82
|
+
|
|
63
83
|
Style/BracesAroundHashParameters:
|
|
64
84
|
Enabled: false
|
|
65
85
|
|
|
@@ -171,6 +191,9 @@ Style/WhileUntilDo:
|
|
|
171
191
|
Style/WhileUntilModifier:
|
|
172
192
|
Enabled: false
|
|
173
193
|
|
|
194
|
+
Style/IndentHash:
|
|
195
|
+
Enabled: false
|
|
196
|
+
|
|
174
197
|
# As of rubocop 0.21, it thinks kwargs are useless assignments
|
|
175
198
|
UselessAssignment:
|
|
176
199
|
Enabled: false
|
data/.rubocop_todo.yml
CHANGED
|
@@ -6,84 +6,6 @@
|
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
|
8
8
|
|
|
9
|
-
# Offense count: 3
|
|
10
|
-
Lint/IneffectiveAccessModifier:
|
|
11
|
-
Exclude:
|
|
12
|
-
- 'lib/packer/builder.rb'
|
|
13
|
-
- 'lib/packer/postprocessor.rb'
|
|
14
|
-
- 'lib/packer/provisioner.rb'
|
|
15
|
-
|
|
16
|
-
# Offense count: 1
|
|
17
|
-
# Cop supports --auto-correct.
|
|
18
|
-
# Configuration parameters: IgnoreEmptyBlocks.
|
|
19
|
-
Lint/UnusedBlockArgument:
|
|
20
|
-
Exclude:
|
|
21
|
-
- 'lib/packer/runner.rb'
|
|
22
|
-
|
|
23
|
-
# Offense count: 8
|
|
24
|
-
# Cop supports --auto-correct.
|
|
25
|
-
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
|
|
26
|
-
Lint/UnusedMethodArgument:
|
|
27
|
-
Exclude:
|
|
28
|
-
- 'lib/packer/dataobject.rb'
|
|
29
|
-
- 'lib/packer/envvar.rb'
|
|
30
|
-
- 'lib/packer/macro.rb'
|
|
31
|
-
- 'lib/packer/provisioners/powershell.rb'
|
|
32
|
-
|
|
33
|
-
# Offense count: 2
|
|
34
|
-
Lint/UselessAccessModifier:
|
|
35
|
-
Exclude:
|
|
36
|
-
- 'lib/packer/postprocessor.rb'
|
|
37
|
-
- 'lib/packer/provisioner.rb'
|
|
38
|
-
|
|
39
|
-
# Offense count: 8
|
|
40
|
-
Metrics/AbcSize:
|
|
41
|
-
Max: 30
|
|
42
|
-
|
|
43
|
-
# Offense count: 4
|
|
44
|
-
# Configuration parameters: CountComments.
|
|
45
|
-
Metrics/ClassLength:
|
|
46
|
-
Max: 150
|
|
47
|
-
|
|
48
|
-
# Offense count: 7
|
|
49
|
-
# Configuration parameters: CountComments.
|
|
50
|
-
Metrics/MethodLength:
|
|
51
|
-
Max: 27
|
|
52
|
-
|
|
53
|
-
# Offense count: 1
|
|
54
|
-
# Cop supports --auto-correct.
|
|
55
|
-
# Configuration parameters: SingleLineConditionsOnly.
|
|
56
|
-
Style/ConditionalAssignment:
|
|
57
|
-
Exclude:
|
|
58
|
-
- 'lib/packer/dataobject.rb'
|
|
59
|
-
|
|
60
|
-
# Offense count: 9
|
|
61
|
-
# Cop supports --auto-correct.
|
|
62
|
-
Style/DeprecatedHashMethods:
|
|
63
|
-
Exclude:
|
|
64
|
-
- 'lib/packer-config.rb'
|
|
65
|
-
- 'lib/packer/dataobject.rb'
|
|
66
|
-
- 'lib/packer/postprocessor.rb'
|
|
67
|
-
- 'lib/packer/provisioner.rb'
|
|
68
|
-
|
|
69
|
-
# Offense count: 1
|
|
70
|
-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
|
|
71
|
-
Style/FileName:
|
|
72
|
-
Exclude:
|
|
73
|
-
- 'lib/packer-config.rb'
|
|
74
|
-
|
|
75
|
-
# Offense count: 1
|
|
76
|
-
Style/IfInsideElse:
|
|
77
|
-
Exclude:
|
|
78
|
-
- 'lib/packer/dataobject.rb'
|
|
79
|
-
|
|
80
|
-
# Offense count: 6
|
|
81
|
-
# Cop supports --auto-correct.
|
|
82
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
|
|
83
|
-
# SupportedStyles: special_inside_parentheses, consistent, align_braces
|
|
84
|
-
Style/IndentHash:
|
|
85
|
-
Enabled: false
|
|
86
|
-
|
|
87
9
|
# Offense count: 31
|
|
88
10
|
# Cop supports --auto-correct.
|
|
89
11
|
Style/MutableConstant:
|
|
@@ -97,55 +19,8 @@ Style/MutableConstant:
|
|
|
97
19
|
- 'spec/packer/postprocessor_spec.rb'
|
|
98
20
|
- 'spec/packer/provisioner_spec.rb'
|
|
99
21
|
|
|
100
|
-
# Offense count: 2
|
|
101
|
-
# Cop supports --auto-correct.
|
|
102
|
-
Style/NegatedIf:
|
|
103
|
-
Exclude:
|
|
104
|
-
- 'lib/packer/dataobject.rb'
|
|
105
|
-
|
|
106
|
-
# Offense count: 9
|
|
107
|
-
Style/NestedParenthesizedCalls:
|
|
108
|
-
Exclude:
|
|
109
|
-
- 'spec/packer/envvar_spec.rb'
|
|
110
|
-
- 'spec/packer/macro_spec.rb'
|
|
111
|
-
- 'spec/packer/runner_spec.rb'
|
|
112
|
-
- 'spec/packer_config_spec.rb'
|
|
113
|
-
|
|
114
|
-
# Offense count: 1
|
|
115
|
-
# Cop supports --auto-correct.
|
|
116
|
-
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
|
|
117
|
-
# SupportedStyles: skip_modifier_ifs, always
|
|
118
|
-
Style/Next:
|
|
119
|
-
Exclude:
|
|
120
|
-
- 'lib/packer/dataobject.rb'
|
|
121
|
-
|
|
122
|
-
# Offense count: 1
|
|
123
|
-
# Cop supports --auto-correct.
|
|
124
|
-
Style/NumericLiterals:
|
|
125
|
-
MinDigits: 6
|
|
126
|
-
|
|
127
22
|
# Offense count: 34
|
|
128
23
|
# Cop supports --auto-correct.
|
|
129
24
|
# Configuration parameters: PreferredDelimiters.
|
|
130
25
|
Style/PercentLiteralDelimiters:
|
|
131
26
|
Enabled: false
|
|
132
|
-
|
|
133
|
-
# Offense count: 6
|
|
134
|
-
# Cop supports --auto-correct.
|
|
135
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
136
|
-
# SupportedStyles: space, no_space
|
|
137
|
-
Style/SpaceBeforeBlockBraces:
|
|
138
|
-
Enabled: false
|
|
139
|
-
|
|
140
|
-
# Offense count: 5
|
|
141
|
-
# Cop supports --auto-correct.
|
|
142
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
|
143
|
-
# SupportedStyles: space, no_space
|
|
144
|
-
Style/SpaceInsideBlockBraces:
|
|
145
|
-
Enabled: false
|
|
146
|
-
|
|
147
|
-
# Offense count: 1
|
|
148
|
-
# Cop supports --auto-correct.
|
|
149
|
-
Style/UnneededInterpolation:
|
|
150
|
-
Exclude:
|
|
151
|
-
- 'lib/packer/runner.rb'
|
data/README.md
CHANGED
|
@@ -69,27 +69,27 @@ The following [Packer post-processors](http://www.packer.io/docs/templates/post-
|
|
|
69
69
|
|
|
70
70
|
### Packing a Vagrant Basebox from a CentOS ISO Using VirtualBox
|
|
71
71
|
|
|
72
|
-
This example is based on the integration test [spec/integration/centos_vagrant_spec.rb](spec/integration/centos_vagrant_spec.rb). It produces a Vagrant Basebox that's provisionable with [Chef](http://www.getchef.com/) and the packer config and provisioning is
|
|
72
|
+
This example is based on the integration test [spec/integration/centos_vagrant_spec.rb](spec/integration/centos_vagrant_spec.rb). It produces a Vagrant Basebox that's provisionable with [Chef](http://www.getchef.com/) and the packer config and provisioning is based on work done in the [Bento](https://github.com/opscode/bento) project from the OpsCode crew.
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
CENTOS_VERSION = '6.8'
|
|
75
75
|
|
|
76
|
-
pconfig = Packer::Config.new "
|
|
77
|
-
pconfig.description "#{
|
|
76
|
+
pconfig = Packer::Config.new "centos-#{CENTOS_VERSION}-vagrant.json"
|
|
77
|
+
pconfig.description "CentOS #{CENTOS_VERSION} VirtualBox Vagrant"
|
|
78
78
|
pconfig.add_variable 'mirror', 'http://mirrors.sonic.net/centos/'
|
|
79
79
|
pconfig.add_variable 'my_version', '0.0.1'
|
|
80
80
|
pconfig.add_variable 'chef_version', 'latest'
|
|
81
81
|
|
|
82
82
|
builder = pconfig.add_builder Packer::Builder::VIRTUALBOX_ISO
|
|
83
|
-
builder.boot_command ["<tab> text ks=http://#{pconfig.macro.HTTPIP}:#{pconfig.macro.HTTPPort}
|
|
83
|
+
builder.boot_command ["<tab> text ks=http://#{pconfig.macro.HTTPIP}:#{pconfig.macro.HTTPPort}/centos-#{CENTOS_VERSION}-ks.cfg<enter><wait>"]
|
|
84
84
|
builder.boot_wait '10s'
|
|
85
|
-
builder.disk_size
|
|
85
|
+
builder.disk_size 40_960
|
|
86
86
|
builder.guest_additions_path "VBoxGuestAdditions_#{pconfig.macro.Version}.iso"
|
|
87
87
|
builder.guest_os_type "RedHat_64"
|
|
88
88
|
builder.http_directory "scripts/kickstart"
|
|
89
|
-
builder.iso_checksum '
|
|
89
|
+
builder.iso_checksum 'afab3a588cda94cd768826e77ad4db2b5ee7c485'
|
|
90
90
|
builder.iso_checksum_type 'sha1'
|
|
91
|
-
builder.iso_url "#{pconfig.variable 'mirror'}/6
|
|
92
|
-
builder.output_directory "
|
|
91
|
+
builder.iso_url "#{pconfig.variable 'mirror'}/6/isos/x86_64/CentOS-#{CENTOS_VERSION}-x86_64-bin-DVD1.iso"
|
|
92
|
+
builder.output_directory "centos-#{CENTOS_VERSION}-x86_64-virtualbox"
|
|
93
93
|
builder.shutdown_command "echo 'vagrant'|sudo -S /sbin/halt -h -p"
|
|
94
94
|
builder.communicator "ssh"
|
|
95
95
|
builder.ssh_password "vagrant"
|
|
@@ -111,7 +111,7 @@ This example is based on the integration test [spec/integration/centos_vagrant_s
|
|
|
111
111
|
]
|
|
112
112
|
]
|
|
113
113
|
builder.virtualbox_version_file ".vbox_version"
|
|
114
|
-
builder.vm_name "packer-#{
|
|
114
|
+
builder.vm_name "packer-centos-#{CENTOS_VERSION}-x86_64"
|
|
115
115
|
|
|
116
116
|
provisioner = pconfig.add_provisioner Packer::Provisioner::FILE
|
|
117
117
|
provisioner.source 'scripts/hello.sh'
|
|
@@ -129,12 +129,12 @@ This example is based on the integration test [spec/integration/centos_vagrant_s
|
|
|
129
129
|
]
|
|
130
130
|
provisioner.environment_vars [
|
|
131
131
|
"CHEF_VERSION=#{pconfig.variable 'chef_version'}",
|
|
132
|
-
"
|
|
132
|
+
"MY_CENTOS_VERSION=#{pconfig.variable 'my_version'}"
|
|
133
133
|
]
|
|
134
134
|
provisioner.execute_command "echo 'vagrant' | #{pconfig.macro.Vars} sudo -S -E bash '#{pconfig.macro.Path}'"
|
|
135
135
|
|
|
136
136
|
postprocessor = pconfig.add_postprocessor Packer::PostProcessor::VAGRANT
|
|
137
|
-
postprocessor.output File.join('builds', pconfig.macro.Provider, "
|
|
137
|
+
postprocessor.output File.join('builds', pconfig.macro.Provider, "centos-#{CENTOS_VERSION}-x86_64-#{pconfig.variable 'my_version'}.box")
|
|
138
138
|
|
|
139
139
|
pconfig.validate
|
|
140
140
|
pconfig.build
|
data/RELEASENOTES.md
CHANGED
data/lib/packer-config.rb
CHANGED
|
@@ -36,8 +36,8 @@ module Packer
|
|
|
36
36
|
self.envvar = EnvVar.new
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
def validate
|
|
40
|
-
super
|
|
39
|
+
def validate(verbose: false)
|
|
40
|
+
super()
|
|
41
41
|
verify_packer_version
|
|
42
42
|
if self.builders.empty?
|
|
43
43
|
raise DataValidationError.new("At least one builder is required")
|
|
@@ -49,7 +49,7 @@ module Packer
|
|
|
49
49
|
stdout = nil
|
|
50
50
|
Dir.chdir(File.dirname(self.output_file)) do
|
|
51
51
|
begin
|
|
52
|
-
stdout = Packer::Runner.run! self.packer, 'validate', File.basename(self.output_file), quiet:
|
|
52
|
+
stdout = Packer::Runner.run! self.packer, 'validate', File.basename(self.output_file), quiet: !verbose
|
|
53
53
|
rescue Packer::Runner::CommandExecutionError => e
|
|
54
54
|
raise PackerBuildError.new(e.to_s)
|
|
55
55
|
end
|
|
@@ -153,7 +153,7 @@ module Packer
|
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
def variable(name)
|
|
156
|
-
unless self.variables.
|
|
156
|
+
unless self.variables.key? name
|
|
157
157
|
raise UndefinedVariableError.new("No variable named #{name} has been defined -- did you forget to call add_variable?")
|
|
158
158
|
end
|
|
159
159
|
"{{user `#{name}`}}"
|
data/lib/packer/builder.rb
CHANGED
data/lib/packer/dataobject.rb
CHANGED
|
@@ -25,26 +25,23 @@ module Packer
|
|
|
25
25
|
def validate_required
|
|
26
26
|
self.required.each do |r|
|
|
27
27
|
if (r.is_a? Array) && !r.empty?
|
|
28
|
-
if r.length - (r - self.data.keys).length
|
|
28
|
+
if (r.length - (r - self.data.keys).length).zero?
|
|
29
29
|
raise DataValidationError.new("Missing one required setting from the set #{r}")
|
|
30
30
|
end
|
|
31
31
|
if r.length - (r - self.data.keys).length > 1
|
|
32
32
|
raise DataValidationError.new("Found more than one exclusive setting in data from set #{r}")
|
|
33
33
|
end
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
raise DataValidationError.new("Missing required setting #{r}")
|
|
37
|
-
end
|
|
34
|
+
elsif ! self.data.keys.include? r
|
|
35
|
+
raise DataValidationError.new("Missing required setting #{r}")
|
|
38
36
|
end
|
|
39
37
|
end
|
|
40
38
|
end
|
|
41
39
|
|
|
42
40
|
def validate_key_dependencies
|
|
43
41
|
self.data.keys.each do |data_key|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
end
|
|
42
|
+
next unless self.key_dependencies.key? data_key
|
|
43
|
+
unless (self.key_dependencies[data_key] - self.data.keys).empty?
|
|
44
|
+
raise DataValidationError.new("Key #{data_key} requires that keys be defined: #{self.key_dependencies[data_key]}")
|
|
48
45
|
end
|
|
49
46
|
end
|
|
50
47
|
end
|
|
@@ -68,7 +65,7 @@ module Packer
|
|
|
68
65
|
|
|
69
66
|
def __exclusive_key_error(key, exclusives)
|
|
70
67
|
exclusives.each do |e|
|
|
71
|
-
if self.data.
|
|
68
|
+
if self.data.key? e
|
|
72
69
|
raise ExclusiveKeyError.new("Only one of #{exclusives} can be used at a time")
|
|
73
70
|
end
|
|
74
71
|
end
|
|
@@ -123,11 +120,7 @@ module Packer
|
|
|
123
120
|
|
|
124
121
|
def __add_boolean(key, bool, exclusives = [])
|
|
125
122
|
self.__exclusive_key_error(key, exclusives)
|
|
126
|
-
|
|
127
|
-
self.data[key.to_s] = true
|
|
128
|
-
else
|
|
129
|
-
self.data[key.to_s] = false
|
|
130
|
-
end
|
|
123
|
+
self.data[key.to_s] = bool ? true : false
|
|
131
124
|
end
|
|
132
125
|
|
|
133
126
|
def __add_hash(key, data, exclusives = [])
|
data/lib/packer/envvar.rb
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
# Encoding: utf-8
|
|
2
|
+
# rubocop:disable Style/MethodMissing
|
|
3
|
+
|
|
2
4
|
module Packer
|
|
3
5
|
class EnvVar
|
|
4
6
|
def method_missing(method_name, *args)
|
|
5
7
|
"{{env `#{method_name}`}}"
|
|
6
8
|
end
|
|
7
9
|
|
|
10
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
11
|
+
true
|
|
12
|
+
end
|
|
13
|
+
|
|
8
14
|
def respond_to?(symbol, include_private=false)
|
|
9
15
|
# We literally respond to everything...
|
|
10
16
|
true
|
data/lib/packer/macro.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
# Encoding: utf-8
|
|
2
|
+
# rubocop:disable Style/MethodMissing
|
|
3
|
+
|
|
2
4
|
module Packer
|
|
3
5
|
class Macro
|
|
4
6
|
def method_missing(method_name, *args)
|
|
@@ -6,6 +8,10 @@ module Packer
|
|
|
6
8
|
"{{ .#{name} }}"
|
|
7
9
|
end
|
|
8
10
|
|
|
11
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
12
|
+
true
|
|
13
|
+
end
|
|
14
|
+
|
|
9
15
|
def respond_to?(symbol, include_private=false)
|
|
10
16
|
# We literally respond to everything...
|
|
11
17
|
true
|
data/lib/packer/postprocessor.rb
CHANGED
|
@@ -44,14 +44,14 @@ module Packer
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def only(buildname)
|
|
47
|
-
unless self.data.
|
|
47
|
+
unless self.data.key? 'only'
|
|
48
48
|
self.data['only'] = []
|
|
49
49
|
end
|
|
50
50
|
self.data['only'] << buildname.to_s
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def except(buildname)
|
|
54
|
-
unless self.data.
|
|
54
|
+
unless self.data.key? 'except'
|
|
55
55
|
self.data['except'] = []
|
|
56
56
|
end
|
|
57
57
|
self.data['except'] << buildname.to_s
|
|
@@ -61,9 +61,10 @@ module Packer
|
|
|
61
61
|
self.__add_boolean('keep_input_artifact', bool)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
private
|
|
65
64
|
def self.validate_type(type)
|
|
66
65
|
VALID_POST_PROCESSOR_TYPES.include? type
|
|
67
66
|
end
|
|
67
|
+
|
|
68
|
+
private_class_method :validate_type
|
|
68
69
|
end
|
|
69
70
|
end
|
data/lib/packer/provisioner.rb
CHANGED
|
@@ -62,14 +62,14 @@ module Packer
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def only(buildname)
|
|
65
|
-
unless self.data.
|
|
65
|
+
unless self.data.key? 'only'
|
|
66
66
|
self.data['only'] = []
|
|
67
67
|
end
|
|
68
68
|
self.data['only'] << buildname.to_s
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def except(buildname)
|
|
72
|
-
unless self.data.
|
|
72
|
+
unless self.data.key? 'except'
|
|
73
73
|
self.data['except'] = []
|
|
74
74
|
end
|
|
75
75
|
self.data['except'] << buildname.to_s
|
|
@@ -81,19 +81,20 @@ module Packer
|
|
|
81
81
|
|
|
82
82
|
def override(builddefinition, values)
|
|
83
83
|
raise TypeError.new() unless values.is_a?(Hash)
|
|
84
|
-
unless self.data.
|
|
84
|
+
unless self.data.key? 'override'
|
|
85
85
|
self.data['override'] = {}
|
|
86
86
|
end
|
|
87
|
-
if self.data.
|
|
87
|
+
if self.data.key? @data['override'][builddefinition]
|
|
88
88
|
self.data['override'][builddefinition].merge! values
|
|
89
89
|
else
|
|
90
90
|
self.data['override'][builddefinition] = values
|
|
91
91
|
end
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
private
|
|
95
94
|
def self.validate_type(type)
|
|
96
95
|
VALID_PROVISIONER_TYPES.include? type
|
|
97
96
|
end
|
|
97
|
+
|
|
98
|
+
private_class_method :validate_type
|
|
98
99
|
end
|
|
99
|
-
end
|
|
100
|
+
end
|
data/lib/packer/runner.rb
CHANGED
|
@@ -17,12 +17,12 @@ module Packer
|
|
|
17
17
|
else
|
|
18
18
|
# Run but stream as well as capture stdout to the screen
|
|
19
19
|
# see: http://stackoverflow.com/a/1162850/83386
|
|
20
|
-
Open3.popen3(cmd) do |
|
|
20
|
+
Open3.popen3(cmd) do |_std_in, std_out, std_err, thread|
|
|
21
21
|
# read each stream from a new thread
|
|
22
22
|
Thread.new do
|
|
23
23
|
until (raw = std_out.getc).nil? do
|
|
24
24
|
stdout << raw
|
|
25
|
-
$stdout.write
|
|
25
|
+
$stdout.write raw.to_s
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
Thread.new do
|
|
@@ -35,6 +35,7 @@ module Packer
|
|
|
35
35
|
status = thread.value
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
|
+
# rubocop:disable Style/NumericPredicate
|
|
38
39
|
raise CommandExecutionError.new(stderr) unless status == 0
|
|
39
40
|
stdout
|
|
40
41
|
end
|
data/lib/packer/version.rb
CHANGED
data/packer-config.gemspec
CHANGED
|
@@ -18,7 +18,7 @@ correct JSON format. It also saved me having to remember the esoteric Packer
|
|
|
18
18
|
syntax for referencing variables and whatnot in the JSON.
|
|
19
19
|
END
|
|
20
20
|
spec.homepage = 'https://github.com/ianchesal/packer-config'
|
|
21
|
-
spec.license = 'Apache
|
|
21
|
+
spec.license = 'Apache-2.0'
|
|
22
22
|
spec.required_ruby_version = '>= 2.0.0'
|
|
23
23
|
|
|
24
24
|
spec.files = `git ls-files -z`.split("\x0")
|
|
@@ -2,26 +2,26 @@
|
|
|
2
2
|
require 'spec_helper'
|
|
3
3
|
|
|
4
4
|
RSpec.describe Packer::Config do
|
|
5
|
-
it 'can build a centos-6.
|
|
6
|
-
|
|
5
|
+
it 'can build a centos-6.7 Vagrant base box' do
|
|
6
|
+
CENTOS_VERSION = '6.8'
|
|
7
7
|
|
|
8
|
-
pconfig = Packer::Config.new "
|
|
9
|
-
pconfig.description "#{
|
|
8
|
+
pconfig = Packer::Config.new "centos-#{CENTOS_VERSION}-vagrant.json"
|
|
9
|
+
pconfig.description "CentOS #{CENTOS_VERSION} VirtualBox Vagrant"
|
|
10
10
|
pconfig.add_variable 'mirror', 'http://mirrors.sonic.net/centos/'
|
|
11
11
|
pconfig.add_variable 'my_version', '0.0.1'
|
|
12
12
|
pconfig.add_variable 'chef_version', 'latest'
|
|
13
13
|
|
|
14
14
|
builder = pconfig.add_builder Packer::Builder::VIRTUALBOX_ISO
|
|
15
|
-
builder.boot_command ["<tab> text ks=http://#{pconfig.macro.HTTPIP}:#{pconfig.macro.HTTPPort}
|
|
15
|
+
builder.boot_command ["<tab> text ks=http://#{pconfig.macro.HTTPIP}:#{pconfig.macro.HTTPPort}/centos-#{CENTOS_VERSION}-ks.cfg<enter><wait>"]
|
|
16
16
|
builder.boot_wait '10s'
|
|
17
|
-
builder.disk_size
|
|
17
|
+
builder.disk_size 40_960
|
|
18
18
|
builder.guest_additions_path "VBoxGuestAdditions_#{pconfig.macro.Version}.iso"
|
|
19
19
|
builder.guest_os_type "RedHat_64"
|
|
20
20
|
builder.http_directory "scripts/kickstart"
|
|
21
|
-
builder.iso_checksum '
|
|
21
|
+
builder.iso_checksum 'afab3a588cda94cd768826e77ad4db2b5ee7c485'
|
|
22
22
|
builder.iso_checksum_type 'sha1'
|
|
23
|
-
builder.iso_url "#{pconfig.variable 'mirror'}/6
|
|
24
|
-
builder.output_directory "
|
|
23
|
+
builder.iso_url "#{pconfig.variable 'mirror'}/6/isos/x86_64/CentOS-#{CENTOS_VERSION}-x86_64-bin-DVD1.iso"
|
|
24
|
+
builder.output_directory "centos-#{CENTOS_VERSION}-x86_64-virtualbox"
|
|
25
25
|
builder.shutdown_command "echo 'vagrant'|sudo -S /sbin/halt -h -p"
|
|
26
26
|
builder.communicator "ssh"
|
|
27
27
|
builder.ssh_password "vagrant"
|
|
@@ -43,7 +43,7 @@ RSpec.describe Packer::Config do
|
|
|
43
43
|
]
|
|
44
44
|
]
|
|
45
45
|
builder.virtualbox_version_file ".vbox_version"
|
|
46
|
-
builder.vm_name "packer-#{
|
|
46
|
+
builder.vm_name "packer-centos-#{CENTOS_VERSION}-x86_64"
|
|
47
47
|
|
|
48
48
|
provisioner = pconfig.add_provisioner Packer::Provisioner::FILE
|
|
49
49
|
provisioner.source 'scripts/hello.sh'
|
|
@@ -61,12 +61,12 @@ RSpec.describe Packer::Config do
|
|
|
61
61
|
]
|
|
62
62
|
provisioner.environment_vars [
|
|
63
63
|
"CHEF_VERSION=#{pconfig.variable 'chef_version'}",
|
|
64
|
-
"
|
|
64
|
+
"MY_CENTOS_VERSION=#{pconfig.variable 'my_version'}"
|
|
65
65
|
]
|
|
66
66
|
provisioner.execute_command "echo 'vagrant' | #{pconfig.macro.Vars} sudo -S -E bash '#{pconfig.macro.Path}'"
|
|
67
67
|
|
|
68
68
|
postprocessor = pconfig.add_postprocessor Packer::PostProcessor::VAGRANT
|
|
69
|
-
postprocessor.output File.join('builds', pconfig.macro.Provider, "
|
|
69
|
+
postprocessor.output File.join('builds', pconfig.macro.Provider, "centos-#{CENTOS_VERSION}-x86_64-#{pconfig.variable 'my_version'}.box")
|
|
70
70
|
|
|
71
71
|
Dir.chdir('spec/integration')
|
|
72
72
|
expect(pconfig.validate).to be_truthy
|
|
File without changes
|
data/spec/packer/envvar_spec.rb
CHANGED
|
@@ -19,7 +19,7 @@ RSpec.describe Packer::EnvVar do
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it 'responds to anything' do
|
|
22
|
-
expect(envvar.respond_to?
|
|
23
|
-
expect(envvar.respond_to?
|
|
22
|
+
expect(envvar.respond_to?('anything')).to be_truthy
|
|
23
|
+
expect(envvar.respond_to?('anything_else')).to be_truthy
|
|
24
24
|
end
|
|
25
25
|
end
|
data/spec/packer/macro_spec.rb
CHANGED
|
@@ -19,7 +19,7 @@ RSpec.describe Packer::Macro do
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it 'responds to anything' do
|
|
22
|
-
expect(macro.respond_to?
|
|
23
|
-
expect(macro.respond_to?
|
|
22
|
+
expect(macro.respond_to?('anything')).to be_truthy
|
|
23
|
+
expect(macro.respond_to?('anything_else')).to be_truthy
|
|
24
24
|
end
|
|
25
25
|
end
|
data/spec/packer/runner_spec.rb
CHANGED
|
@@ -7,13 +7,13 @@ RSpec.describe Packer::Runner do
|
|
|
7
7
|
it 'returns stdout on success' do
|
|
8
8
|
open3 = class_double("Open3").as_stubbed_const(:transfer_nested_constants => true)
|
|
9
9
|
expect(open3).to receive(:capture3).and_return(['output', 'error', 0])
|
|
10
|
-
expect(described_class.run!
|
|
10
|
+
expect(described_class.run!('true', quiet: true)).to eq('output')
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
it 'raises an error on failure' do
|
|
14
14
|
open3 = class_double("Open3").as_stubbed_const(:transfer_nested_constants => true)
|
|
15
15
|
expect(open3).to receive(:capture3).and_return(['output', 'error', 1])
|
|
16
|
-
expect{ described_class.run!
|
|
16
|
+
expect { described_class.run!('false', quiet: true) }.to raise_error
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
data/spec/packer_config_spec.rb
CHANGED
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
|
3
3
|
require 'fakefs/spec_helpers'
|
|
4
4
|
|
|
5
5
|
RSpec.describe Packer::Config do
|
|
6
|
-
let(:config_file) { 'config.json'}
|
|
6
|
+
let(:config_file) { 'config.json' }
|
|
7
7
|
let(:packer) { Packer::Config.new(config_file) }
|
|
8
8
|
let(:builder_type) { Packer::Builder::VIRTUALBOX_ISO }
|
|
9
9
|
let(:provisioner_type) { Packer::Provisioner::FILE }
|
|
@@ -97,33 +97,33 @@ RSpec.describe Packer::Config do
|
|
|
97
97
|
|
|
98
98
|
describe "#add_builder" do
|
|
99
99
|
it 'returns a builder for a valid type' do
|
|
100
|
-
expect(packer.add_builder
|
|
100
|
+
expect(packer.add_builder(builder_type)).to be_a_kind_of(Packer::Builder)
|
|
101
101
|
expect(packer.builders.length).to eq(1)
|
|
102
102
|
packer.builders = []
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
it 'raises an error for an invalid type' do
|
|
106
|
-
expect { packer.add_builder
|
|
106
|
+
expect { packer.add_builder('invalid') }.to raise_error
|
|
107
107
|
expect(packer.builders.length).to eq(0)
|
|
108
108
|
end
|
|
109
109
|
end
|
|
110
110
|
|
|
111
111
|
describe "#add_provisioner" do
|
|
112
112
|
it 'returns a provisioner for a valid type' do
|
|
113
|
-
expect(packer.add_provisioner
|
|
113
|
+
expect(packer.add_provisioner(provisioner_type)).to be_a_kind_of(Packer::Provisioner)
|
|
114
114
|
expect(packer.provisioners.length).to eq(1)
|
|
115
115
|
packer.provisioners = []
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it 'raises an error for an invalid type' do
|
|
119
|
-
expect { packer.add_provisioner
|
|
119
|
+
expect { packer.add_provisioner('invalid') }.to raise_error
|
|
120
120
|
expect(packer.provisioners.length).to eq(0)
|
|
121
121
|
end
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
describe "#add_postprocessor" do
|
|
125
125
|
it 'returns a post-processor for a valid type' do
|
|
126
|
-
expect(packer.add_postprocessor
|
|
126
|
+
expect(packer.add_postprocessor(postprocessor_type)).to be_a_kind_of(Packer::PostProcessor)
|
|
127
127
|
expect(packer.postprocessors.length).to eq(1)
|
|
128
128
|
packer.postprocessors = []
|
|
129
129
|
end
|
|
@@ -149,7 +149,7 @@ RSpec.describe Packer::Config do
|
|
|
149
149
|
it 'creates a packer reference to a variable in the configuration' do
|
|
150
150
|
expect(packer.variables).to eq({})
|
|
151
151
|
packer.add_variable('key1', 'value1')
|
|
152
|
-
expect(packer.variable
|
|
152
|
+
expect(packer.variable('key1')).to eq('{{user `key1`}}')
|
|
153
153
|
packer.data['variables'] = {}
|
|
154
154
|
end
|
|
155
155
|
|
|
@@ -180,7 +180,7 @@ RSpec.describe Packer::Config do
|
|
|
180
180
|
|
|
181
181
|
it 'raises an error if the version of Packer is not high enough' do
|
|
182
182
|
expect(Packer::Runner).to receive(:run!).and_return('Packer v0.0.1')
|
|
183
|
-
expect{ packer.verify_packer_version }.to raise_error
|
|
183
|
+
expect { packer.verify_packer_version }.to raise_error
|
|
184
184
|
end
|
|
185
185
|
end
|
|
186
186
|
end
|
data/tasks/clean.rake
CHANGED
|
@@ -6,10 +6,10 @@ task :clean do
|
|
|
6
6
|
FileList['spec/integration/packer_cache/*'].each do |f|
|
|
7
7
|
FileUtils.rm_f(f)
|
|
8
8
|
end
|
|
9
|
-
Dir.glob('spec/integration/builds/*').select {|f| File.directory? f}.each do |d|
|
|
9
|
+
Dir.glob('spec/integration/builds/*').select { |f| File.directory? f }.each do |d|
|
|
10
10
|
FileUtils.rm_rf(d)
|
|
11
11
|
end
|
|
12
|
-
Dir.glob('spec/integration/*.json').select {|f| File.file? f}.each do |d|
|
|
12
|
+
Dir.glob('spec/integration/*.json').select { |f| File.file? f }.each do |d|
|
|
13
13
|
FileUtils.rm_f(d)
|
|
14
14
|
end
|
|
15
15
|
end
|
data/tasks/rspec.rake
CHANGED
|
@@ -2,7 +2,7 @@ require 'rspec/core/rake_task'
|
|
|
2
2
|
|
|
3
3
|
namespace :test do
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
5
|
-
t.pattern = Dir['spec/**/*_spec.rb'].reject{ |f| f['/integration'] }
|
|
5
|
+
t.pattern = Dir['spec/**/*_spec.rb'].reject { |f| f['/integration'] }
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
RSpec::Core::RakeTask.new(:integration) do |t|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: packer-config
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.6.
|
|
4
|
+
version: 1.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ian Chesal
|
|
@@ -13,7 +13,7 @@ authors:
|
|
|
13
13
|
autorequire:
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
|
-
date: 2016-
|
|
16
|
+
date: 2016-09-15 00:00:00.000000000 Z
|
|
17
17
|
dependencies: []
|
|
18
18
|
description: |
|
|
19
19
|
Building the Packer JSON configurations in raw JSON can be quite an adventure.
|
|
@@ -79,7 +79,7 @@ files:
|
|
|
79
79
|
- spec/integration/scripts/cleanup.sh
|
|
80
80
|
- spec/integration/scripts/fix-slow-dns.sh
|
|
81
81
|
- spec/integration/scripts/hello.sh
|
|
82
|
-
- spec/integration/scripts/kickstart/centos-6.
|
|
82
|
+
- spec/integration/scripts/kickstart/centos-6.8-ks.cfg
|
|
83
83
|
- spec/integration/scripts/minimize.sh
|
|
84
84
|
- spec/integration/scripts/sshd.sh
|
|
85
85
|
- spec/integration/scripts/vagrant.sh
|
|
@@ -122,7 +122,7 @@ files:
|
|
|
122
122
|
- tasks/rubygems.rake
|
|
123
123
|
homepage: https://github.com/ianchesal/packer-config
|
|
124
124
|
licenses:
|
|
125
|
-
- Apache
|
|
125
|
+
- Apache-2.0
|
|
126
126
|
metadata: {}
|
|
127
127
|
post_install_message:
|
|
128
128
|
rdoc_options: []
|
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
140
140
|
version: '0'
|
|
141
141
|
requirements: []
|
|
142
142
|
rubyforge_project:
|
|
143
|
-
rubygems_version: 2.
|
|
143
|
+
rubygems_version: 2.5.1
|
|
144
144
|
signing_key:
|
|
145
145
|
specification_version: 4
|
|
146
146
|
summary: An object model to build packer.io configurations in Ruby.
|
|
@@ -153,7 +153,7 @@ test_files:
|
|
|
153
153
|
- spec/integration/scripts/cleanup.sh
|
|
154
154
|
- spec/integration/scripts/fix-slow-dns.sh
|
|
155
155
|
- spec/integration/scripts/hello.sh
|
|
156
|
-
- spec/integration/scripts/kickstart/centos-6.
|
|
156
|
+
- spec/integration/scripts/kickstart/centos-6.8-ks.cfg
|
|
157
157
|
- spec/integration/scripts/minimize.sh
|
|
158
158
|
- spec/integration/scripts/sshd.sh
|
|
159
159
|
- spec/integration/scripts/vagrant.sh
|