packer-config 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: a8d09aa2bf43904d51a9b8b86374a20ae71fd6fd
4
- data.tar.gz: a84431fb5cbe4c2d2fd0dde6a694402af91cf153
3
+ metadata.gz: e45c5e454faed8c47d2303a5b62ccf57ab41ce80
4
+ data.tar.gz: 9bf6e3f2cdbbb446c7fad85caaaefe4be976a4a4
5
5
  SHA512:
6
- metadata.gz: df285e99eeb101df9a5020399f53fc45edbb9f288c99b9cd50d62826e45be6a5c20f925a6c916960acd5923f4c876d615a1399916dfcd697df68d7ac9c39ebbb
7
- data.tar.gz: e818223bcf70f201073a711ea7102e7b96a15f197b860a7c9b355b66e758fb0a1bea977391126f53c9d711a40448253a38c8c60301b986e4c3d9b50dacaf7644
6
+ metadata.gz: b4f75659bb9f8847b8952320d22032e51727b5fca6adb7df66c864034c6aa4ac271da2d7b2e5ac1eedaf58d27bf7d2a0871ebe16575ab01d36e2302f5bf5fd5e
7
+ data.tar.gz: 7bb2f90741d18c236262e9586c591e9c016b036ac572f0f67c782f9f79a371eef287903dea5f8d53ba69d2d5f5a8f1b1da602b1e0af31f450befad34b4e28185
data/.rubocop.yml CHANGED
@@ -178,7 +178,7 @@ Style/AlignHash:
178
178
  Style/AlignParameters:
179
179
  Enabled: false
180
180
 
181
- Style/BlockNesting:
181
+ Metrics/BlockNesting:
182
182
  Enabled: false
183
183
 
184
184
  Style/BracesAroundHashParameters:
@@ -214,9 +214,6 @@ Style/EmptyLines:
214
214
  Style/EmptyLinesAroundAccessModifier:
215
215
  Enabled: false
216
216
 
217
- Style/EmptyLinesAroundBody:
218
- Enabled: false
219
-
220
217
  Style/GuardClause:
221
218
  Enabled: false
222
219
 
@@ -304,14 +301,17 @@ Style/Next:
304
301
  Style/NumericLiterals:
305
302
  Enabled: false
306
303
 
307
- Style/ParameterLists:
304
+ Metrics/ParameterLists:
308
305
  Enabled: false
309
306
 
310
307
  Style/TrailingComma:
311
308
  # EnforcedStyleForMultiline: comma
312
309
  Enabled: false
313
310
 
314
- Style/CyclomaticComplexity:
311
+ Metrics/CyclomaticComplexity:
312
+ Enabled: false
313
+
314
+ Metrics/AbcSize:
315
315
  Enabled: false
316
316
 
317
317
  ####
@@ -337,4 +337,4 @@ UselessAssignment:
337
337
  Enabled: false
338
338
 
339
339
  WordArray:
340
- Enabled: false
340
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1.1
6
- - ruby-head
5
+ - ruby-head
data/README.md CHANGED
@@ -15,6 +15,32 @@ Bonus: you can really go to town with templates when it's all done it Ruby.
15
15
 
16
16
  gem install packer-config
17
17
 
18
+ ## Use
19
+
20
+ ### Builders
21
+
22
+ The following [Packer builders](http://www.packer.io/docs/templates/builders.html) are currently implemented:
23
+
24
+ * [amazon-ebs](http://www.packer.io/docs/builders/amazon-ebs.html)
25
+ * [amazon-instance](http://www.packer.io/docs/builders/amazon-instance.html)
26
+ * [docker](http://www.packer.io/docs/builders/docker.html)
27
+ * [virtualbox-iso](http://www.packer.io/docs/builders/virtualbox-iso.html)
28
+
29
+ ### Provisioners
30
+
31
+ The following [Packer provisioners](http://www.packer.io/docs/templates/provisioners.html) are currently implemented:
32
+
33
+ * [file](http://www.packer.io/docs/provisioners/file.html)
34
+ * [shell](http://www.packer.io/docs/provisioners/shell.html)
35
+
36
+ ### Post-Processors
37
+
38
+ The following [Packer post-processors](http://www.packer.io/docs/templates/post-processors.html) are currently implemented:
39
+
40
+ * [docker-import](http://www.packer.io/docs/post-processors/docker-import.html)
41
+ * [docker-push](http://www.packer.io/docs/post-processors/docker-push.html)
42
+ * [vagrant](http://www.packer.io/docs/post-processors/vagrant.html)
43
+
18
44
  ## Examples
19
45
 
20
46
  ### Packing a Vagrant Basebox from a CentOS ISO Using VirtualBox
@@ -29,7 +55,7 @@ This example is based on the integration test [spec/integration/centos_vagrant_s
29
55
  pconfig.add_variable 'my_version', '0.0.1'
30
56
  pconfig.add_variable 'chef_version', 'latest'
31
57
 
32
- builder = pconfig.add_builder Packer::Builder::VIRTUALBOX_ISO
58
+ builder = pconfig.add_builder 'virtualbox-iso'
33
59
  builder.boot_command ["<tab> text ks=http://#{pconfig.macro.HTTPIP}:#{pconfig.macro.HTTPPort}/#{OS}-ks.cfg<enter><wait>"]
34
60
  builder.boot_wait '10s'
35
61
  builder.disk_size 40960
@@ -62,11 +88,11 @@ This example is based on the integration test [spec/integration/centos_vagrant_s
62
88
  builder.virtualbox_version_file ".vbox_version"
63
89
  builder.vm_name "packer-#{OS}-x86_64"
64
90
 
65
- provisioner = pconfig.add_provisioner Packer::Provisioner::FILE
91
+ provisioner = pconfig.add_provisioner 'file'
66
92
  provisioner.source 'scripts/hello.sh'
67
93
  provisioner.destination '/home/vagrant/hello.sh'
68
94
 
69
- provisioner = pconfig.add_provisioner Packer::Provisioner::SHELL
95
+ provisioner = pconfig.add_provisioner 'shell'
70
96
  provisioner.scripts [
71
97
  'scripts/fix-slow-dns.sh',
72
98
  'scripts/sshd.sh',
@@ -82,7 +108,7 @@ This example is based on the integration test [spec/integration/centos_vagrant_s
82
108
  ]
83
109
  provisioner.execute_command "echo 'vagrant' | #{pconfig.macro.Vars} sudo -S -E bash '#{pconfig.macro.Path}'"
84
110
 
85
- postprocessor = pconfig.add_postprocessor Packer::PostProcessor::VAGRANT
111
+ postprocessor = pconfig.add_postprocessor 'vagrant'
86
112
  postprocessor.output File.join('builds', pconfig.macro.Provider, "#{OS}-x86_64-#{pconfig.variable 'my_version'}.box")
87
113
 
88
114
  pconfig.validate
data/RELEASENOTES.md ADDED
@@ -0,0 +1,6 @@
1
+ # packer-config Release Notes
2
+
3
+ ## 0.0.4
4
+
5
+ * Added the ability to call `#build` with a quiet option. This option turns streaming to stdout off/on. With `quiet: false`, you will see the output of the Packer call on your screen while `#build` is executing it. This can be handy for view Packer status for long running Packer jobs.
6
+ * Started writing release notes!
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ RuboCop::RakeTask.new(:lint)
21
21
 
22
22
  task :default => [:lint, 'test:spec']
23
23
 
24
- task :build => ['test:spec'] do
24
+ task :build => [:lint, 'test:spec', :clean] do
25
25
  `gem build packer-config.gemspec`
26
26
  end
27
27
 
@@ -44,4 +44,4 @@ task :clean do
44
44
  Dir.glob('spec/integration/builds/*').select {|f| File.directory? f}.each do |d|
45
45
  FileUtils.rm_rf(d)
46
46
  end
47
- end
47
+ end
data/TODO.md CHANGED
@@ -5,4 +5,3 @@
5
5
  * Look in to something like VCR to drive the tests of the child classes -- there's a lot of repetitive testing that could be done on them.
6
6
  * Add missing builders, provisioners and post-processors. I only implemented the builders, provisioners and post-processors that I'm currently using.
7
7
  * Refactor the child classes. I get the feeling that these could be implemented in some better, templated, type of way
8
- * Building can take a long time. Look in to a way to query the state of a build. Maybe return the stdout from it on query.
data/lib/packer-config.rb CHANGED
@@ -13,7 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  require 'json'
16
- require 'open3'
16
+ require 'packer/runner'
17
17
  require 'packer/dataobject'
18
18
  require 'packer/builder'
19
19
  require 'packer/provisioner'
@@ -23,7 +23,6 @@ require 'packer/envvar'
23
23
 
24
24
  module Packer
25
25
  class Config < Packer::DataObject
26
-
27
26
  VERSION = '0.0.2'
28
27
 
29
28
  attr_accessor :builders
@@ -53,22 +52,20 @@ module Packer
53
52
  if self.builders.length == 0
54
53
  raise DataValidationError.new("At least one builder is required")
55
54
  end
56
- self.builders.each do |thing|
57
- thing.validate
58
- end
59
- self.provisioners.each do |thing|
60
- thing.validate
61
- end
62
- self.postprocessors.each do |thing|
63
- thing.validate
64
- end
55
+ self.builders.each(&:validate)
56
+ self.provisioners.each(&:validate)
57
+ self.postprocessors.each(&:validate)
65
58
  self.write
59
+ stdout = nil
66
60
  Dir.chdir(File.dirname(self.output_file)) do
67
- cmd = [self.packer, 'validate', File.basename(self.output_file)].join(' ')
68
- stdout, stderr, status = Open3.capture3(cmd)
69
- raise PackerBuildError.new(stderr) unless status == 0
61
+ begin
62
+ stdout = Packer::Runner.run! self.packer, 'validate', File.basename(self.output_file), quiet: true
63
+ rescue Packer::Runner::CommandExecutionError => e
64
+ raise PackerBuildError.new(e.to_s)
65
+ end
70
66
  end
71
67
  self.delete
68
+ stdout
72
69
  end
73
70
 
74
71
  class DumpError < StandardError
@@ -115,15 +112,19 @@ module Packer
115
112
  class PackerBuildError < StandardError
116
113
  end
117
114
 
118
- def build
115
+ def build(quiet: false)
119
116
  self.validate
120
117
  self.write
118
+ stdout = nil
121
119
  Dir.chdir(File.dirname(self.output_file)) do
122
- cmd = [self.packer, 'build', self.packer_options, File.basename(self.output_file)].join(' ')
123
- stdout, stderr, status = Open3.capture3(cmd)
124
- raise PackerBuildError.new(stderr) unless status == 0
120
+ begin
121
+ stdout = Packer::Runner.run! self.packer, 'build', self.packer_options, File.basename(self.output_file), quiet: quiet
122
+ rescue Packer::Runner::CommandExecutionError => e
123
+ raise PackerBuildError.new(e.to_s)
124
+ end
125
125
  end
126
126
  self.delete
127
+ stdout
127
128
  end
128
129
 
129
130
  def description(description)
@@ -176,6 +177,5 @@ module Packer
176
177
  attr_writer :output_file
177
178
  attr_writer :macro
178
179
  attr_writer :envvar
179
-
180
180
  end
181
181
  end
@@ -16,7 +16,6 @@ require 'packer/builders/all'
16
16
 
17
17
  module Packer
18
18
  class Builder < DataObject
19
-
20
19
  AMAZON_EBS = 'amazon-ebs'
21
20
  AMAZON_INSTANCE = 'amazon-instance'
22
21
  DOCKER = 'docker'
@@ -62,4 +61,4 @@ module Packer
62
61
  VALID_BUILDER_TYPES.include? type
63
62
  end
64
63
  end
65
- end
64
+ end
@@ -18,7 +18,6 @@ require 'packer/dataobject'
18
18
  module Packer
19
19
  class Builder < Packer::DataObject
20
20
  class Amazon < Builder
21
-
22
21
  def initialize
23
22
  super
24
23
  self.add_required(
@@ -211,4 +210,4 @@ module Packer
211
210
  end
212
211
  end
213
212
  end
214
- end
213
+ end
@@ -15,7 +15,6 @@
15
15
 
16
16
  module Packer
17
17
  class DataObject
18
-
19
18
  attr_accessor :data
20
19
  attr_accessor :required
21
20
 
@@ -71,7 +70,7 @@ module Packer
71
70
  def __add_array_of_strings(key, values, exclusives = [])
72
71
  self.__exclusive_key_error(key, exclusives)
73
72
  raise TypeError.new() unless Array.try_convert(values)
74
- self.data[key.to_s] = values.to_ary.map{ |c| c.to_s }
73
+ self.data[key.to_s] = values.to_ary.map(&:to_s)
75
74
  end
76
75
 
77
76
  def __add_array_of_array_of_strings(key, values, exclusives = [])
@@ -80,7 +79,7 @@ module Packer
80
79
  self.data[key.to_s] = []
81
80
  values.each do |v|
82
81
  raise TypeError.new() unless Array.try_convert(v)
83
- self.data[key.to_s].push(v.to_ary.map{ |c| c.to_s })
82
+ self.data[key.to_s].push(v.to_ary.map(&:to_s))
84
83
  end
85
84
  end
86
85
 
@@ -17,7 +17,6 @@ require 'packer/dataobject'
17
17
 
18
18
  module Packer
19
19
  class PostProcessor < Packer::DataObject
20
-
21
20
  DOCKER_IMPORT = 'docker-import'
22
21
  DOCKER_PUSH = 'docker-push'
23
22
  VAGRANT = 'vagrant'
@@ -74,4 +73,4 @@ module Packer
74
73
  VALID_POST_PROCESSOR_TYPES.include? type
75
74
  end
76
75
  end
77
- end
76
+ end
@@ -17,7 +17,6 @@ require 'packer/dataobject'
17
17
 
18
18
  module Packer
19
19
  class Provisioner < Packer::DataObject
20
-
21
20
  SHELL = 'shell'
22
21
  FILE = 'file'
23
22
 
@@ -83,4 +82,4 @@ module Packer
83
82
  VALID_PROVISIONER_TYPES.include? type
84
83
  end
85
84
  end
86
- end
85
+ end
@@ -0,0 +1,44 @@
1
+ require 'open3'
2
+ require 'shellwords'
3
+ require 'pty'
4
+
5
+ module Packer
6
+ class Runner
7
+ class CommandExecutionError < StandardError
8
+ end
9
+
10
+ def self.run!(*args, quiet: false)
11
+ cmd = Shellwords.shelljoin(args.flatten)
12
+ status = 0
13
+ stdout = ''
14
+ stderr = ''
15
+ if quiet
16
+ # Run without streaming std* to any screen
17
+ stdout, stderr, status = Open3.capture3(cmd)
18
+ else
19
+ # Run but stream as well as capture stdout to the screen
20
+ status = pty(cmd) do |r,w,pid|
21
+ while !r.eof?
22
+ c = r.getc
23
+ stdout << c
24
+ $stdout.write "#{c}"
25
+ end
26
+ Process.wait(pid)
27
+ end
28
+ end
29
+ raise CommandExecutionError.new(stderr) unless status == 0
30
+ stdout
31
+ end
32
+
33
+ def self.exec!(*args)
34
+ cmd = Shellwords.shelljoin(args.flatten)
35
+ logger.debug "Exec'ing: #{cmd}, in: #{Dir.pwd}"
36
+ Kernel.exec cmd
37
+ end
38
+
39
+ def self.pty(cmd, &block)
40
+ PTY.spawn(cmd, &block)
41
+ $?.exitstatus
42
+ end
43
+ end
44
+ end
@@ -15,7 +15,7 @@
15
15
 
16
16
  Gem::Specification.new do |spec|
17
17
  spec.name = "packer-config"
18
- spec.version = "0.0.3"
18
+ spec.version = "0.0.4"
19
19
  # For deploying alpha versions via Travis CI
20
20
  spec.version = "#{spec.version}-alpha-#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS']
21
21
  spec.authors = ["Ian Chesal"]
@@ -121,7 +121,7 @@ RSpec.describe Packer::DataObject do
121
121
 
122
122
  it 'converts an array of non-strings to strings and assigns them to key' do
123
123
  dataobject.__add_array_of_strings('key', some_array_of_ints)
124
- expect(dataobject.data['key']).to eq(some_array_of_ints.map{ |c| c.to_s })
124
+ expect(dataobject.data['key']).to eq(some_array_of_ints.map(&:to_s))
125
125
  dataobject.data.delete('key')
126
126
  end
127
127
 
@@ -235,5 +235,4 @@ RSpec.describe Packer::DataObject do
235
235
  expect { dataobject.__add_array_of_hashes('key', [some_hash_of_strings, 'illegal']) }.to raise_error
236
236
  end
237
237
  end
238
-
239
- end
238
+ end
@@ -46,7 +46,7 @@ RSpec.describe Packer::Provisioner::Shell do
46
46
 
47
47
  it 'converts all commands to strings' do
48
48
  provisioner.inline(some_array_of_ints)
49
- expect(provisioner.data['inline']).to eq(some_array_of_ints.map{ |c| c.to_s })
49
+ expect(provisioner.data['inline']).to eq(some_array_of_ints.map(&:to_s))
50
50
  provisioner.data.delete('inline')
51
51
  end
52
52
 
@@ -96,7 +96,7 @@ RSpec.describe Packer::Provisioner::Shell do
96
96
 
97
97
  it 'converts all commands to strings' do
98
98
  provisioner.scripts(some_array_of_ints)
99
- expect(provisioner.data['scripts']).to eq(some_array_of_ints.map{ |c| c.to_s })
99
+ expect(provisioner.data['scripts']).to eq(some_array_of_ints.map(&:to_s))
100
100
  provisioner.data.delete('scripts')
101
101
  end
102
102
 
@@ -113,4 +113,4 @@ RSpec.describe Packer::Provisioner::Shell do
113
113
  provisioner.data.delete('scripts')
114
114
  end
115
115
  end
116
- end
116
+ end
@@ -0,0 +1,32 @@
1
+ # Encoding: utf-8
2
+ # Copyright 2014 Ian Chesal
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ require 'spec_helper'
16
+ require 'fakefs/spec_helpers'
17
+
18
+ RSpec.describe Packer::Runner do
19
+ describe '#run!' do
20
+ it 'returns stdout on success' do
21
+ open3 = class_double("Open3").as_stubbed_const(:transfer_nested_constants => true)
22
+ expect(open3).to receive(:capture3).and_return(['output', 'error', 0])
23
+ expect(described_class.run! 'true', quiet: true).to eq('output')
24
+ end
25
+
26
+ it 'raises an error on failure' do
27
+ open3 = class_double("Open3").as_stubbed_const(:transfer_nested_constants => true)
28
+ expect(open3).to receive(:capture3).and_return(['output', 'error', 1])
29
+ expect{ described_class.run! 'false', quiet: true }.to raise_error
30
+ end
31
+ end
32
+ end
@@ -34,8 +34,7 @@ RSpec.describe Packer::Config do
34
34
  describe "#validate" do
35
35
  it 'returns true for a valid instance' do
36
36
  expect(packer.builders).to receive(:length).and_return(1)
37
- open3 = class_double("Open3").as_stubbed_const(:transfer_nested_constants => true)
38
- expect(open3).to receive(:capture3).and_return(['output', 'error', 0])
37
+ expect(Packer::Runner).to receive(:run!).and_return('')
39
38
  FakeFS do
40
39
  expect(packer.validate).to be_truthy
41
40
  end
@@ -86,8 +85,7 @@ RSpec.describe Packer::Config do
86
85
  it 'returns successfully if the build command returns a successful exit code' do
87
86
  expect(packer).to receive(:validate).and_return(true)
88
87
  expect(packer).to receive(:write).and_return(true)
89
- open3 = class_double("Open3").as_stubbed_const(:transfer_nested_constants => true)
90
- expect(open3).to receive(:capture3).and_return(['output', 'error', 0])
88
+ expect(Packer::Runner).to receive(:run!).and_return('')
91
89
  FakeFS do
92
90
  expect(packer.build).to be_truthy
93
91
  end
@@ -109,8 +107,7 @@ RSpec.describe Packer::Config do
109
107
  it 'raises an error if the build command returns an unsuccessful exit code' do
110
108
  expect(packer).to receive(:validate).and_return(true)
111
109
  expect(packer).to receive(:write).and_return(true)
112
- open3 = class_double("Open3").as_stubbed_const(:transfer_nested_constants => true)
113
- expect(open3).to receive(:capture3).and_return(['output', 'error', 1])
110
+ expect(Packer::Runner).to receive(:run!).and_raise(Packer::Runner::CommandExecutionError)
114
111
  FakeFS do
115
112
  expect { packer.build }.to raise_error
116
113
  end
@@ -193,5 +190,4 @@ RSpec.describe Packer::Config do
193
190
  expect(packer.macro.var).to eq('{{ .Var }}')
194
191
  end
195
192
  end
196
-
197
- end
193
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packer-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Chesal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-10 00:00:00.000000000 Z
11
+ date: 2014-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,6 +113,7 @@ files:
113
113
  - Gemfile
114
114
  - LICENSE
115
115
  - README.md
116
+ - RELEASENOTES.md
116
117
  - Rakefile
117
118
  - TODO.md
118
119
  - lib/packer-config.rb
@@ -132,6 +133,7 @@ files:
132
133
  - lib/packer/provisioners/all.rb
133
134
  - lib/packer/provisioners/file.rb
134
135
  - lib/packer/provisioners/shell.rb
136
+ - lib/packer/runner.rb
135
137
  - packer-config.gemspec
136
138
  - spec/integration/README.md
137
139
  - spec/integration/builds/.gitignore
@@ -160,6 +162,7 @@ files:
160
162
  - spec/packer/provisioner_spec.rb
161
163
  - spec/packer/provisioners/file_spec.rb
162
164
  - spec/packer/provisioners/shell_spec.rb
165
+ - spec/packer/runner_spec.rb
163
166
  - spec/packer_config_spec.rb
164
167
  - spec/spec_helper.rb
165
168
  - spec/unit_helper.rb
@@ -215,6 +218,7 @@ test_files:
215
218
  - spec/packer/provisioner_spec.rb
216
219
  - spec/packer/provisioners/file_spec.rb
217
220
  - spec/packer/provisioners/shell_spec.rb
221
+ - spec/packer/runner_spec.rb
218
222
  - spec/packer_config_spec.rb
219
223
  - spec/spec_helper.rb
220
224
  - spec/unit_helper.rb