poise-boiler 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd1b2217f90d2b5e97250517db809e44a9922f86
4
- data.tar.gz: ef8ddebba565e10342604fde82e2fe5f860e1ddc
3
+ metadata.gz: fbb661ad23215d6e2cc998c52f72e75564aabe6a
4
+ data.tar.gz: 96e0f665a92f32f71a25269ac9c8efc8fdacf320
5
5
  SHA512:
6
- metadata.gz: 0062710d338b8d3773ae3048a361461cae0e3e9344e77da7dc3646c4fce8341f47918631887cda0d7df044d920693209d77a4b8cbdecdbfa54ba1734a92f9e99
7
- data.tar.gz: 6e5772aa9071c4a6e27d4007518ff6df3f324535bca64a0936cb4ae5823bd6d55e6db5fad5264ca406fb48d9bd0614b85c8fe554b947e8c638e2f4220b171c95
6
+ metadata.gz: 82927ab621c179ad8cc61efdc3587aaeb3bfefad43cd10e7e6b02e615a831826b974b21e38cc338f4a1d6bbebba5e078b4d7efe0c912a6679382130b7fd25969
7
+ data.tar.gz: efa5581c318d27ece306af470391e052539141c43a4a300ddfb09e2bfc8c8833b9d899ebab39bcb46a4ee1acab9712eb6a4b64a669bd5d820cc9e6bd54e2fe5b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.7.0
4
+
5
+ * Revamped Test Kitchen helper to improve build speed and stability.
6
+
3
7
  ## v1.6.0
4
8
 
5
9
  * New rake task to update copyright years.
@@ -14,13 +14,13 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
- require 'poise_boiler/kitchen/provisioner'
17
+ require 'poise_boiler/helpers/kitchen/provisioner'
18
18
 
19
19
 
20
20
  # @api private
21
21
  module Kitchen
22
22
  module Provisioner
23
23
  # An alias for Kitchen plugin loading.
24
- PoiseSolo = PoiseBoiler::Kitchen::Provisioner
24
+ PoiseSolo = PoiseBoiler::Helpers::Kitchen::Provisioner
25
25
  end
26
26
  end
@@ -24,10 +24,10 @@ RUN ln -sf /bin/true /sbin/initctl
24
24
  <% end %>
25
25
  ENV DEBIAN_FRONTEND noninteractive
26
26
  RUN apt-get update -o dockercachebust=<%= Date.today %>
27
- RUN apt-get install -y sudo openssh-server curl lsb-release net-tools
27
+ RUN apt-get install -y sudo openssh-server curl lsb-release net-tools rsync
28
28
  <% when 'rhel', 'centos', 'fedora' %>
29
29
  RUN yum clean all
30
- RUN yum install -y sudo openssh-server openssh-clients which curl net-tools passwd
30
+ RUN yum install -y sudo openssh-server openssh-clients which curl net-tools iproute rsync passwd
31
31
  <%# CentOS 7 does not install hostname by default, but EL6 has no hostname package. %>
32
32
  RUN yum install -y hostname || true
33
33
  RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
@@ -48,6 +48,7 @@ RUN cave resolve -zx net-misc/openssh app-admin/sudo
48
48
  RUN ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
49
49
  RUN ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
50
50
  <% when 'freebsd' %>
51
+ <%# SUPER UN-TESTED BULLSHIT %>
51
52
  RUN echo "nameserver 8.8.8.8" >> /etc/resolv.conf \
52
53
  && env ASSUME_ALWAYS_YES=true pkg install sudo curl bash
53
54
  RUN ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
@@ -73,6 +74,11 @@ RUN chmod 0700 <%= homedir %>/.ssh
73
74
  RUN touch <%= homedir %>/.ssh/authorized_keys
74
75
  RUN chown <%= @username %> <%= homedir %>/.ssh/authorized_keys
75
76
  RUN chmod 0600 <%= homedir %>/.ssh/authorized_keys
77
+ <%# Install Chef and Test Kitchen-related gems. %>
78
+ RUN curl -L https://chef.io/chef/install.sh | bash -s --<%= ENV['POISE_MASTER_BUILD'] ? " -n -- #{Date.today}" : PoiseBoiler::Kitchen.instance.chef_version ? " -v #{PoiseBoiler::Kitchen.instance.chef_version}" : '' %> && \
79
+ env GEM_HOME=/tmp/verifier/gems GEM_PATH=/tmp/verifier/gems GEM_CACHE=/tmp/verifier/gems/cache /opt/chef/embedded/bin/gem install --no-rdoc --no-ri --bindir /tmp/verifier/bin busser busser-serverspec serverspec && \
80
+ env GEM_HOME=/tmp/verifier/gems GEM_PATH=/tmp/verifier/gems GEM_CACHE=/tmp/verifier/gems/cache /opt/chef/embedded/bin/gem install --no-rdoc --no-ri bundler && \
81
+ chown -R <%= @username %> /tmp/verifier
76
82
  <%# Custom provisioning commands. %>
77
83
  <% Array(@provision_command).each do |cmd| %>
78
84
  RUN <%= cmd %>
@@ -0,0 +1,101 @@
1
+ #
2
+ # Copyright 2016, Noah Kantrowitz
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
+ #
16
+
17
+ require 'fileutils'
18
+
19
+ require 'halite'
20
+ require 'kitchen/provisioner/chef_solo'
21
+
22
+ require 'poise_boiler/helpers/kitchen/core_ext'
23
+
24
+
25
+ module PoiseBoiler
26
+ module Helpers
27
+ class Kitchen
28
+ class Provisioner < ::Kitchen::Provisioner::ChefSolo
29
+ default_config :gemspec do |provisioner|
30
+ Dir[File.join(provisioner[:kitchen_root], '*.gemspec')].first
31
+ end
32
+ expand_path_for :gemspec
33
+
34
+ def self.name
35
+ 'PoiseSolo'
36
+ end
37
+
38
+ def create_sandbox
39
+ super
40
+ convert_halite_cookbooks unless poise_helper_instance.options['no_gem']
41
+ copy_test_cookbook
42
+ copy_test_cookbooks
43
+ end
44
+
45
+ private
46
+
47
+ def poise_helper_instance
48
+ PoiseBoiler::Kitchen.instance || begin
49
+ raise 'Global poise-boiler kitchen instance not set'
50
+ end
51
+ end
52
+
53
+ def convert_halite_cookbooks
54
+ @real_cookbook_deps = {}
55
+ gems_to_convert = {'poise-profiler' => Halite::Gem.new('poise-profiler')}
56
+ gems_to_check = [poise_helper_instance.cookbook]
57
+ until gems_to_check.empty?
58
+ check = gems_to_check.pop
59
+ # Already in the list, skip expansion.
60
+ next if gems_to_convert.include?(check.name)
61
+ # Not a cookbook, don't expand.
62
+ next unless check.is_halite_cookbook?
63
+ gems_to_convert[check.name] = check
64
+ # Expand dependencies and check each of those.
65
+ check.cookbook_dependencies.each do |dep|
66
+ dep_cook = dep.cookbook
67
+ if dep_cook
68
+ gems_to_check << dep_cook
69
+ else
70
+ @real_cookbook_deps[dep.name] = dep
71
+ end
72
+ end
73
+ end
74
+ # Convert all the things!
75
+ tmpbooks_dir = File.join(sandbox_path, 'cookbooks')
76
+ FileUtils.mkdir_p(tmpbooks_dir)
77
+ gems_to_convert.each do |name, gem_data|
78
+ Halite.convert(gem_data, File.join(tmpbooks_dir, gem_data.cookbook_name))
79
+ end
80
+ end
81
+
82
+ def copy_test_cookbook
83
+ fixture_base = File.join(config[:kitchen_root], 'test', 'cookbook')
84
+ return unless File.exist?(File.join(fixture_base, 'metadata.rb'))
85
+ tmp_base = File.join(sandbox_path, 'cookbooks', "#{poise_helper_instance.cookbook_name}_test")
86
+ FileUtils.mkdir_p(tmp_base)
87
+ FileUtils.cp_r(File.join(fixture_base, "."), tmp_base)
88
+ end
89
+
90
+ def copy_test_cookbooks
91
+ fixtures_base = File.join(config[:kitchen_root], 'test', 'cookbooks')
92
+ return unless File.exist?(fixtures_base)
93
+ tmp_base = File.join(sandbox_path, 'cookbooks')
94
+ FileUtils.mkdir_p(tmp_base)
95
+ FileUtils.cp_r(File.join(fixtures_base, "."), tmp_base)
96
+ end
97
+
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,210 @@
1
+ #
2
+ # Copyright 2015-2016, Noah Kantrowitz
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
+ #
16
+
17
+ require 'halite/helper_base'
18
+
19
+
20
+ module PoiseBoiler
21
+ module Helpers
22
+ # Helpers for Test Kitchen and .kitchen.yml configuration.
23
+ #
24
+ # @see PoiseBoiler::Kitchen.kitchen
25
+ # @since 1.7.0
26
+ class Kitchen < Halite::HelperBase
27
+ # Shorthand names for Test Kitchen platforms.
28
+ #
29
+ # @see #expand_platforms
30
+ PLATFORM_ALIASES = {
31
+ 'ubuntu' => %w{ubuntu-12.04 ubuntu-14.04},
32
+ 'rhel' => %w{centos-6 centos-7},
33
+ 'centos' => %w{rhel},
34
+ 'linux' => %w{ubuntu rhel},
35
+ 'unix' => %w{linux freebsd},
36
+ 'all' => %{unix windows},
37
+ }
38
+
39
+ def initialize(**options)
40
+ # Figure out the directory that contains the kitchen.yml by looking for
41
+ # the first entry in the stack that isn't inside poise-boiler.
42
+ options[:base] ||= if caller.find {|line| !line.start_with?(File.expand_path('../../..', __FILE__)) } =~ /^(.*?):\d+:in/
43
+ File.expand_path('..', $1)
44
+ else
45
+ # ¯\_(ツ)_/¯ hope for the best.
46
+ Dir.pwd
47
+ end
48
+ super(**options)
49
+ end
50
+
51
+ # Generate YAML text for inclusion in a config file.
52
+ #
53
+ # @return [String]
54
+ def to_yaml
55
+ kitchen_config.to_yaml.gsub(/---[ \n]/, '')
56
+ end
57
+
58
+ # The Chef version to use for Test Kitchen or nil for any version.
59
+ #
60
+ # @return [String, nil]
61
+ def chef_version
62
+ # SPEC_BLOCK_CI is used to force non-locking behavior inside tests.
63
+ @chef_version ||= ENV['CHEF_VERSION'] || if ENV['POISE_MASTER_BUILD']
64
+ # We're going to install the latest nightly via Omnitruck later on.
65
+ nil
66
+ elsif ENV['SPEC_BLOCK_CI'] != 'true'
67
+ # If there isn't a specific override, lock TK to use the same version of Chef as the Gemfile.
68
+ require 'chef/version'
69
+ Chef::VERSION
70
+ end
71
+ end
72
+
73
+ def cookbook_name
74
+ options[:cookbook_name] || cookbook.cookbook_name
75
+ end
76
+
77
+ # Make this public for use in {PoiseBoiler::Helpers::Kitchen::Provisioner}.
78
+ public :cookbook
79
+
80
+ private
81
+
82
+ # Which Test Kitchen driver are we going to use.
83
+ #
84
+ # @return [String]
85
+ def kitchen_driver
86
+ @kitchen_driver ||= if options[:driver]
87
+ # Manual override.
88
+ options[:driver]
89
+ elsif File.exist?(File.expand_path('test/docker/docker.key', base))
90
+ # Look for the decrypted private key. In CI this is generated by `rake travis`.
91
+ 'docker'
92
+ elsif ENV['CI']
93
+ # Don't try to use Vagrant on CI ever.
94
+ 'dummy'
95
+ else
96
+ 'vagrant'
97
+ end
98
+ end
99
+
100
+ # Expand the requested platforms using {PLATFORM_ALIASES}.
101
+ #
102
+ # @return [Array<String>]
103
+ def expand_platforms
104
+ # Default platform is linux unless overridden from the helper options.
105
+ platforms = Array(options[:platforms] || 'linux')
106
+ last_platforms = []
107
+ # This is probably not the most effcient solution but oh well.
108
+ while platforms != last_platforms
109
+ last_platforms = platforms
110
+ platforms = platforms.map {|p| PLATFORM_ALIASES[p] || p}
111
+ platforms.flatten!
112
+ platforms.uniq!
113
+ end
114
+ platforms
115
+ end
116
+
117
+ # Generate a Test Kitchen configuration hash.
118
+ #
119
+ # @return [Hash]
120
+ def kitchen_config
121
+ {
122
+ 'driver' => driver_config,
123
+ 'transport' => transport_config,
124
+ 'provisioner' => provisioner_config,
125
+ 'platforms' => expand_platforms.map {|name| platform_config(name) },
126
+ 'suites' => [suite_config],
127
+ }
128
+ end
129
+
130
+ # Generate a Test Kitchen driver configuration hash.
131
+ #
132
+ # @return [Hash]
133
+ def driver_config
134
+ # Default config for all drivers. {#chef_version} returns nil for "any
135
+ # version" so use true to prevent reinstall attempts.
136
+ config = {'name' => kitchen_driver, 'require_chef_omnibus' => chef_version || true}
137
+ case kitchen_driver
138
+ when 'docker'
139
+ # Docker-specific configuration.
140
+ config.update(
141
+ # Custom Dockerfile.
142
+ 'dockerfile' => File.expand_path('../kitchen/Dockerfile.erb', __FILE__),
143
+ # No password for securiteeeee.
144
+ 'password' => nil,
145
+ # Our docker settings.
146
+ 'binary' => (ENV['TRAVIS'] == 'true' ? './' : '') + 'docker',
147
+ 'socket' => 'tcp://docker.poise.io:443',
148
+ 'tls_verify' => 'true',
149
+ 'tls_cacert' => 'test/docker/docker.ca',
150
+ 'tls_cert' => 'test/docker/docker.pem',
151
+ 'tls_key' => 'test/docker/docker.key',
152
+ )
153
+ when 'rackspace'
154
+ # Set a default instance size.
155
+ config['flavor_id'] = options[:rackspace_flavor] || 'general1-1'
156
+ end
157
+ config
158
+ end
159
+
160
+ # Generate a Test Kitchen transport configuration hash.
161
+ #
162
+ # @return [Hash]
163
+ def transport_config
164
+ {
165
+ # Use the sftp transport from kitchen-sync.
166
+ 'name' => 'sftp',
167
+ # Use the generated SSH key from kitchen-docker if present.
168
+ 'ssh_key' => kitchen_driver == 'docker' ? File.expand_path('.kitchen/docker_id_rsa', base) : nil,
169
+ }
170
+ end
171
+
172
+ # Generate a Test Kitchen provisioner configuration hash.
173
+ #
174
+ # @return [Hash]
175
+ def provisioner_config
176
+ {
177
+ # Use the poise_solo provisioner, also part of kitchen-docker.
178
+ 'name' => 'poise_solo',
179
+ # Pass through debug/poise_debug settings to the test instance.
180
+ 'attributes' => {
181
+ 'POISE_DEBUG' => !!((ENV['POISE_DEBUG'] && ENV['POISE_DEBUG'] != 'false') ||
182
+ (ENV['poise_debug'] && ENV['poise_debug'] != 'false') ||
183
+ (ENV['DEBUG'] && ENV['DEBUG'] != 'false')
184
+ ),
185
+ }
186
+ }
187
+ end
188
+
189
+ # Generate a Test Kitchen platform configuration hash.
190
+ #
191
+ # @return [Hash]
192
+ def platform_config(name)
193
+ {
194
+ 'name' => name,
195
+ # On CI enable poise-profiler automatically. Load it here in case the
196
+ # user defines their own suites.
197
+ 'run_list' => ((ENV['CI'] || ENV['DEBUG'] || ENV['PROFILE']) ? %w{poise-profiler} : []),
198
+ }
199
+ end
200
+
201
+ def suite_config
202
+ {
203
+ 'name' => 'default',
204
+ 'run_list' => (File.exist?(File.join(base, 'test', 'cookbook')) || File.exist?(File.join(base, 'test', 'cookbooks'))) ? ["#{cookbook_name}_test"] : [cookbook_name],
205
+ }
206
+ end
207
+
208
+ end
209
+ end
210
+ end
@@ -91,7 +91,7 @@ module PoiseBoiler
91
91
  #
92
92
  # @return [Boolean]
93
93
  def integration_rackspace?
94
- File.exist?('.kitchen.travis.yml') && IO.read('.kitchen.travis.yml').include?('name: rackspace')
94
+ File.exist?('.kitchen.yml') && IO.read('.kitchen.yml') =~ /(driver|name): (['"]?)rackspace\2/
95
95
  end
96
96
 
97
97
  # Convert a Time object to nanoseconds since the epoch.
@@ -30,7 +30,7 @@ module PoiseBoiler
30
30
  # @example Updating all copyright years
31
31
  # $ rake year
32
32
  # @example Updating copyright years on a non-boiler project.
33
- # $ git ls-files | xargs perl -pi -e "s/Copyright ((?\!$(date +%Y))\\d{4})(-\\d{4})?,/Copyright \\1-$(date +%Y),/g"
33
+ # $ git ls-files | xargs perl -pi -e "s/Copyright (?:\(c\) )?((?\!$(date +%Y))\\d{4})(-\\d{4})?,/Copyright \\1-$(date +%Y),/gi"
34
34
  class Year < Halite::HelperBase
35
35
  # Install the rake tasks.
36
36
  #
@@ -20,6 +20,7 @@ module PoiseBoiler
20
20
  #
21
21
  # @since 1.0.0
22
22
  module Helpers
23
+ autoload :Kitchen, 'poise_boiler/helpers/kitchen'
23
24
  autoload :Rake, 'poise_boiler/helpers/rake'
24
25
  autoload :SpecHelper, 'poise_boiler/helpers/spec_helper'
25
26
  end
@@ -14,9 +14,7 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
- require 'bundler'
18
- require 'halite'
19
- require 'kitchen'
17
+ require 'poise_boiler'
20
18
 
21
19
 
22
20
  module PoiseBoiler
@@ -24,168 +22,21 @@ module PoiseBoiler
24
22
  #
25
23
  # @since 1.0.0
26
24
  module Kitchen
27
- extend self
28
- # Shorthand names for kitchen platforms.
29
- #
30
- # @see PoiseBoiler::Kitchen.kitchen
31
- PLATFORM_ALIASES = {
32
- 'ubuntu' => %w{ubuntu-12.04 ubuntu-14.04},
33
- 'rhel' => %w{centos-6 centos-7},
34
- 'centos' => %w{rhel},
35
- 'linux' => %w{ubuntu rhel},
36
- 'unix' => %w{linux freebsd},
37
- 'all' => %{unix windows},
38
- }
25
+ def self.instance
26
+ @instance
27
+ end
39
28
 
40
29
  # Return a YAML string suitable for inclusion in a .kitchen.yml config. This
41
30
  # will include the standard Poise/Halite boilerplate and some default values.
42
31
  #
43
32
  # @param platforms [String, Array<String>] Name(s) of platforms to use by default.
44
- # @see PoiseBoiler::Kitchen::PLATFORM_ALIASES
33
+ # @see PoiseBoiler::Helpers::Kitchen::PLATFORM_ALIASES
45
34
  # @example .kitchen.yml
46
35
  # #<% require 'poise_boiler' %>
47
36
  # <%= PoiseBoiler.kitchen %>
48
- def kitchen(platforms: 'linux', root: nil)
49
- # Figure out the directory that contains the kitchen.yml.
50
- root ||= if caller.find {|line| !line.start_with?(File.expand_path('../..', __FILE__)) } =~ /^(.*?):\d+:in/
51
- File.expand_path('..', $1)
52
- else
53
- # ¯\_(ツ)_/¯
54
- Dir.pwd
55
- end
56
- # SPEC_BLOCK_CI is used to force non-locking behavior inside tests.
57
- chef_version = ENV['CHEF_VERSION'] || if ENV['SPEC_BLOCK_CI'] != 'true'
58
- # If there isn't a specific override, lock TK to use the same version of Chef as the Gemfile.
59
- require 'chef/version'
60
- Chef::VERSION
61
- end
62
- install_arguments = if ENV['POISE_MASTER_BUILD']
63
- # Force it to use any version down below.
64
- chef_version = nil
65
- # Use today's date as an ignored param to force the layer to rebuild.
66
- " -n -- #{Date.today}"
67
- elsif chef_version
68
- " -v #{chef_version}"
69
- else
70
- ''
71
- end
72
- {
73
- 'chef_versions' => %w{12},
74
- 'driver' => {
75
- 'name' => (docker_enabled?(root) ? 'docker' : ENV['TRAVIS'] == 'true' ? 'dummy' : 'vagrant'),
76
- 'require_chef_omnibus' => chef_version || true,
77
- 'dockerfile' => File.expand_path('../kitchen/Dockerfile.erb', __FILE__),
78
- # No password for securiteeeee.
79
- 'password' => nil,
80
- # Our docker settings.
81
- 'binary' => (ENV['TRAVIS'] == 'true' ? './' : '') + 'docker',
82
- 'socket' => 'tcp://docker.poise.io:443',
83
- 'tls_verify' => 'true',
84
- 'tls_cacert' => 'test/docker/docker.ca',
85
- 'tls_cert' => 'test/docker/docker.pem',
86
- 'tls_key' => 'test/docker/docker.key',
87
- # Cache some stuff in the Docker image.
88
- 'provision_command' => [
89
- # Run some installs at provision so they are cached in the image.
90
- # Install net-tools for netstat which is used by serverspec, and
91
- # iproute for ss (only used on EL7).
92
- "test ! -f /etc/debian_version || apt-get install -y net-tools rsync",
93
- "test ! -f /etc/redhat-release || yum -y install net-tools iproute rsync",
94
- # Make sure the hostname utilitiy is installed on CentOS 7. The
95
- # ||true is for EL6 which has no hostname package. Sigh.
96
- "test ! -f /etc/redhat-release || yum -y install hostname || true",
97
- # Install Chef (with the correct verison).
98
- "curl -L https://chef.io/chef/install.sh | bash -s --#{install_arguments}",
99
- # Install some kitchen-related gems. Normally installed during the verify step but that is idempotent.
100
- "env GEM_HOME=/tmp/verifier/gems GEM_PATH=/tmp/verifier/gems GEM_CACHE=/tmp/verifier/gems/cache /opt/chef/embedded/bin/gem install --no-rdoc --no-ri --bindir /tmp/verifier/bin thor busser busser-serverspec serverspec",
101
- # Install bundler for some tests that pull in spechelper gems.
102
- "env GEM_HOME=/tmp/verifier/gems GEM_PATH=/tmp/verifier/gems GEM_CACHE=/tmp/verifier/gems/cache /opt/chef/embedded/bin/gem install --no-rdoc --no-ri bundler",
103
- # Fix directory permissions.
104
- "chown -R kitchen /tmp/verifier",
105
- ],
106
- },
107
- 'transport' => {
108
- 'name' => 'sftp',
109
- 'ssh_key' => docker_enabled?(root) ? File.expand_path('.kitchen/docker_id_rsa', root) : nil,
110
- },
111
- 'provisioner' => {
112
- 'name' => 'poise_solo',
113
- 'attributes' => {
114
- 'POISE_DEBUG' => !!((ENV['POISE_DEBUG'] && ENV['POISE_DEBUG'] != 'false') ||
115
- (ENV['poise_debug'] && ENV['poise_debug'] != 'false') ||
116
- (ENV['DEBUG'] && ENV['DEBUG'] != 'false')
117
- ),
118
- },
119
- },
120
- 'platforms' => expand_kitchen_platforms(platforms).map {|p| platform_definition(p, root) },
121
- 'suites' => [suite_definition(root)],
122
- }.to_yaml.gsub(/---[ \n]/, '')
123
- end
124
-
125
- private
126
-
127
- # Expand aliases from PLATFORM_ALIASES.
128
- def expand_kitchen_platforms(platforms)
129
- platforms = Array(platforms)
130
- last_platforms = []
131
- while platforms != last_platforms
132
- last_platforms = platforms
133
- platforms = platforms.map {|p| PLATFORM_ALIASES[p] || p}.flatten.uniq
134
- end
135
- platforms
37
+ def self.kitchen(**options)
38
+ @instance = PoiseBoiler::Helpers::Kitchen.new(**options)
39
+ @instance.to_yaml
136
40
  end
137
-
138
- def platform_definition(name, root)
139
- {
140
- 'name' => name,
141
- 'run_list' => platform_run_list(name, root) + ((ENV['CI'] || ENV['DEBUG'] || ENV['PROFILE']) ? %w{poise-profiler} : []),
142
- 'driver_config' => platform_driver(name),
143
- }
144
- end
145
-
146
- # Return the platform-level run list for a given platform.
147
- #
148
- # @param platform [String] Platform name.
149
- # @return [Array<String>]
150
- def platform_run_list(platform, root)
151
- if (platform.start_with?('debian') || platform.start_with?('ubuntu')) && !docker_enabled?(root)
152
- %w{apt}
153
- else
154
- []
155
- end
156
- end
157
-
158
- def platform_driver(platform)
159
- if platform.start_with?('freebsd')
160
- {
161
- 'binary' => (ENV['TRAVIS'] == 'true' ? './' : '') + 'docker-1.7.1',
162
- 'image' => 'lexaguskov/freebsd',
163
- 'socket' => ENV['POISE_DOCKER_FREEBSD'] || 'tcp://dockerbsd.poise.io:443',
164
- }
165
- else
166
- {
167
- 'binary' => (ENV['TRAVIS'] == 'true' ? './' : '') + 'docker',
168
- 'socket' => ENV['POISE_DOCKER_LINUX'] || 'tcp://docker.poise.io:443',
169
- }
170
- end
171
- end
172
-
173
- def suite_definition(root)
174
- gemspec_path = Dir[File.join(root, '*.gemspec')].first
175
- unless gemspec_path
176
- puts "Unable to determine gemspec path for #{root}"
177
- return {}
178
- end
179
- gem_data = Halite::Gem.new(Bundler.load_gemspec(gemspec_path))
180
- {
181
- 'name' => 'default',
182
- 'run_list' => (File.exist?(File.join(root, 'test', 'cookbook')) || File.exist?(File.join(root, 'test', 'cookbooks'))) ? ["#{gem_data.cookbook_name}_test"] : [gem_data.cookbook_name],
183
- }
184
- end
185
-
186
- def docker_enabled?(root)
187
- File.exist?(File.expand_path('test/docker/docker.key', root))
188
- end
189
-
190
41
  end
191
42
  end
@@ -16,5 +16,5 @@
16
16
 
17
17
 
18
18
  module PoiseBoiler
19
- VERSION = '1.6.0'
19
+ VERSION = '1.7.0'
20
20
  end
data/lib/poise_boiler.rb CHANGED
@@ -14,15 +14,14 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
- require 'poise_boiler/kitchen'
18
-
19
17
 
20
18
  module PoiseBoiler
21
19
  autoload :Helpers, 'poise_boiler/helpers'
20
+ autoload :Kitchen, 'poise_boiler/kitchen'
22
21
 
23
22
  # (see PoiseBoiler::Kitchen#kitchen)
24
- def self.kitchen(platforms: 'linux')
23
+ def self.kitchen(**options)
25
24
  # Alias in a top-level namespace to reduce typing.
26
- Kitchen.kitchen(platforms: platforms)
25
+ Kitchen.kitchen(**options)
27
26
  end
28
27
  end
data/poise-boiler.gemspec CHANGED
@@ -61,7 +61,7 @@ Gem::Specification.new do |spec|
61
61
  spec.add_dependency 'vagrant-wrapper'
62
62
  spec.add_dependency 'kitchen-docker'
63
63
  spec.add_dependency 'kitchen-sync', '~> 2.1'
64
- spec.add_dependency 'poise-profiler', '~> 1.0.pre'
64
+ spec.add_dependency 'poise-profiler', '~> 1.0'
65
65
 
66
66
  # Travis gems
67
67
  spec.add_dependency 'codeclimate-test-reporter', '~> 0.4'
@@ -69,4 +69,5 @@ Gem::Specification.new do |spec|
69
69
 
70
70
  # Development dependencies (yo dawg)
71
71
  spec.add_development_dependency 'rspec-command', '~> 1.0'
72
+ spec.add_development_dependency 'kitchen-rackspace', '~> 0.20'
72
73
  end
@@ -117,7 +117,20 @@ EOH
117
117
  end # /context secure vars
118
118
 
119
119
  context 'secure vars and Rackspace' do
120
- file '.kitchen.travis.yml', 'name: rackspace'
120
+ file '.kitchen.yml', <<-EOH
121
+ # PoiseBoiler.kitchen(driver: 'rackspace')
122
+ driver:
123
+ name: dummy
124
+
125
+ provisioner:
126
+ name: dummy
127
+
128
+ platforms:
129
+ - name: default
130
+
131
+ suites:
132
+ - name: default
133
+ EOH
121
134
  file '.ssh/stub'
122
135
  environment TRAVIS_SECURE_ENV_VARS: 'true'
123
136
  before do
data/spec/kitchen_spec.rb CHANGED
@@ -19,26 +19,47 @@ require 'chef/version'
19
19
 
20
20
  describe 'poise_boiler/kitchen' do
21
21
  environment SPEC_BLOCK_CI: true
22
+ file 'poise-boiler-test1.gemspec', <<-EOH
23
+ Gem::Specification.new do |spec|
24
+ spec.name = 'poise-boiler-test1'
25
+ spec.version = '1.0.0'
26
+ spec.authors = ['Noah Kantrowitz']
27
+ spec.email = %w{noah@coderanger.net}
28
+ spec.description = %q||
29
+ spec.summary = %q||
30
+ spec.homepage = 'http://example.com/'
31
+ spec.license = 'Apache 2.0'
32
+
33
+ spec.files = []
34
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
35
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
36
+ spec.require_paths = []
37
+
38
+ spec.add_dependency 'halite'
39
+ end
40
+ EOH
22
41
  file '.kitchen.yml', <<-EOH
23
42
  ---
24
43
  #<% require 'poise_boiler' %>
25
44
  <%= PoiseBoiler.kitchen %>
26
-
27
- suites:
28
- - name: default
29
45
  EOH
30
46
 
31
47
  context 'with defaults' do
32
48
  context 'kitchen list' do
33
49
  command 'kitchen list'
34
- its(:stdout) { is_expected.to match(/default-ubuntu-1404\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/) }
50
+ its(:stdout) do
51
+ is_expected.to match(/default-ubuntu-1404\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/)
52
+ is_expected.to match(/default-ubuntu-1204\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/)
53
+ is_expected.to match(/default-centos-6\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/)
54
+ is_expected.to match(/default-centos-7\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/)
55
+ end
35
56
  end # /context kitchen list
36
57
 
37
58
  context 'kitchen diagnose' do
38
59
  command 'kitchen diagnose'
39
- its(:stdout) { is_expected.to match(%r{- curl -L https://chef.io/chef/install.sh | bash -s --$}) }
40
- its(:stdout) { is_expected.to match(%r{/opt/chef/embedded/bin/gem\s+install\s+--no-rdoc\s+--no-ri\s+--bindir\s+/tmp/verifier/bin\s+thor\s+busser\s+busser-serverspec}m) }
41
- its(:stdout) { is_expected.to include('require_chef_omnibus: true') }
60
+ its(:stdout) do
61
+ is_expected.to include('require_chef_omnibus: true')
62
+ end
42
63
  end # /context kitchen diagnose
43
64
  end # /context with defaults
44
65
 
@@ -46,30 +67,31 @@ EOH
46
67
  file '.kitchen.yml', <<-EOH
47
68
  ---
48
69
  #<% require 'poise_boiler' %>
49
- <%= PoiseBoiler.kitchen(platforms: 'linux') %>
50
-
51
- suites:
52
- - name: default
70
+ <%= PoiseBoiler.kitchen(platforms: 'centos') %>
53
71
  EOH
54
72
  command 'kitchen list'
55
- its(:stdout) { is_expected.to match(/default-ubuntu-1404\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/) }
56
- its(:stdout) { is_expected.to match(/default-ubuntu-1204\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/) }
57
- its(:stdout) { is_expected.to match(/default-centos-6\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/) }
58
- its(:stdout) { is_expected.to match(/default-centos-7\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/) }
73
+ its(:stdout) do
74
+ is_expected.to_not match(/default-ubuntu-1404/)
75
+ is_expected.to_not match(/default-ubuntu-1204/)
76
+ is_expected.to match(/default-centos-6\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/)
77
+ is_expected.to match(/default-centos-7\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/)
78
+ end
59
79
  end # /context with a platform alias
60
80
 
61
81
  context 'with $CHEF_VERSION set' do
62
82
  command 'kitchen diagnose'
63
83
  environment CHEF_VERSION: 12
64
- its(:stdout) { is_expected.to match(%r{- curl -L https://chef.io/chef/install.sh | bash -s -- -v 12$}) }
65
- its(:stdout) { is_expected.to include("require_chef_omnibus: '12'") }
84
+ its(:stdout) do
85
+ is_expected.to include("require_chef_omnibus: '12'")
86
+ end
66
87
  end # /context with $CHEF_VERSION set
67
88
 
68
89
  context 'with $CI set' do
69
90
  command 'kitchen diagnose'
70
91
  environment CI: true, SPEC_BLOCK_CI: false
71
- its(:stdout) { is_expected.to match(%r{- curl -L https://chef.io/chef/install.sh | bash -s -- -v #{Chef::VERSION}$}) }
72
- its(:stdout) { is_expected.to include("require_chef_omnibus: #{Chef::VERSION}") }
92
+ its(:stdout) do
93
+ is_expected.to include("require_chef_omnibus: #{Chef::VERSION}")
94
+ end
73
95
  end # /context with $CI set
74
96
 
75
97
  context 'with a platform override' do
@@ -81,12 +103,27 @@ EOH
81
103
  platforms:
82
104
  - name: gentoo
83
105
  - name: arch
84
-
85
- suites:
86
- - name: default
87
106
  EOH
88
107
  command 'kitchen list'
89
- its(:stdout) { is_expected.to match(/default-gentoo\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/) }
90
- its(:stdout) { is_expected.to match(/default-arch\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/) }
108
+ its(:stdout) do
109
+ is_expected.to match(/default-gentoo\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/)
110
+ is_expected.to match(/default-arch\s+(Vagrant|Dummy)\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/)
111
+ end
91
112
  end # /context with a platform override
113
+
114
+ context 'with kitchen-rackspace' do
115
+ file '.kitchen.yml', <<-EOH
116
+ #<% require 'poise_boiler' %>
117
+ <%= PoiseBoiler.kitchen(driver: 'rackspace') %>
118
+ EOH
119
+ file '.ssh/id_rsa.pub'
120
+ command 'kitchen list'
121
+ environment RACKSPACE_USERNAME: 'dummy', RACKSPACE_API_KEY: '1234'
122
+ before do
123
+ _environment['HOME'] = temp_path
124
+ end
125
+ its(:stdout) do
126
+ is_expected.to match(/default-ubuntu-1204\s+Rackspace\s+PoiseSolo\s+(Busser\s+Sftp\s+)?<Not Created>/)
127
+ end
128
+ end # /context with kitchen-rackspace
92
129
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poise-boiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Kantrowitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2016-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -322,14 +322,14 @@ dependencies:
322
322
  requirements:
323
323
  - - "~>"
324
324
  - !ruby/object:Gem::Version
325
- version: 1.0.pre
325
+ version: '1.0'
326
326
  type: :runtime
327
327
  prerelease: false
328
328
  version_requirements: !ruby/object:Gem::Requirement
329
329
  requirements:
330
330
  - - "~>"
331
331
  - !ruby/object:Gem::Version
332
- version: 1.0.pre
332
+ version: '1.0'
333
333
  - !ruby/object:Gem::Dependency
334
334
  name: codeclimate-test-reporter
335
335
  requirement: !ruby/object:Gem::Requirement
@@ -378,6 +378,20 @@ dependencies:
378
378
  - - "~>"
379
379
  - !ruby/object:Gem::Version
380
380
  version: '1.0'
381
+ - !ruby/object:Gem::Dependency
382
+ name: kitchen-rackspace
383
+ requirement: !ruby/object:Gem::Requirement
384
+ requirements:
385
+ - - "~>"
386
+ - !ruby/object:Gem::Version
387
+ version: '0.20'
388
+ type: :development
389
+ prerelease: false
390
+ version_requirements: !ruby/object:Gem::Requirement
391
+ requirements:
392
+ - - "~>"
393
+ - !ruby/object:Gem::Version
394
+ version: '0.20'
381
395
  description: Boilerplate-reduction helpers for Poise/Halite-style gemss.
382
396
  email:
383
397
  - noah@coderanger.net
@@ -399,6 +413,10 @@ files:
399
413
  - lib/poise_boiler.rb
400
414
  - lib/poise_boiler/error.rb
401
415
  - lib/poise_boiler/helpers.rb
416
+ - lib/poise_boiler/helpers/kitchen.rb
417
+ - lib/poise_boiler/helpers/kitchen/Dockerfile.erb
418
+ - lib/poise_boiler/helpers/kitchen/core_ext.rb
419
+ - lib/poise_boiler/helpers/kitchen/provisioner.rb
402
420
  - lib/poise_boiler/helpers/rake.rb
403
421
  - lib/poise_boiler/helpers/rake/badges.rb
404
422
  - lib/poise_boiler/helpers/rake/bump.rb
@@ -410,9 +428,6 @@ files:
410
428
  - lib/poise_boiler/helpers/rake/year.rb
411
429
  - lib/poise_boiler/helpers/spec_helper.rb
412
430
  - lib/poise_boiler/kitchen.rb
413
- - lib/poise_boiler/kitchen/Dockerfile.erb
414
- - lib/poise_boiler/kitchen/core_ext.rb
415
- - lib/poise_boiler/kitchen/provisioner.rb
416
431
  - lib/poise_boiler/rake.rb
417
432
  - lib/poise_boiler/rakefile.rb
418
433
  - lib/poise_boiler/spec_helper.rb
@@ -1,102 +0,0 @@
1
- #
2
- # Copyright 2016, Noah Kantrowitz
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
- #
16
-
17
- require 'fileutils'
18
-
19
- require 'halite'
20
- require 'kitchen/provisioner/chef_solo'
21
-
22
- require 'poise_boiler/kitchen/core_ext'
23
-
24
-
25
- module PoiseBoiler
26
- module Kitchen
27
- class Provisioner < ::Kitchen::Provisioner::ChefSolo
28
- default_config :gemspec do |provisioner|
29
- Dir[File.join(provisioner[:kitchen_root], '*.gemspec')].first
30
- end
31
- expand_path_for :gemspec
32
-
33
- def self.name
34
- 'PoiseSolo'
35
- end
36
-
37
- def create_sandbox
38
- super
39
- convert_halite_cookbooks
40
- copy_test_cookbook
41
- copy_test_cookbooks
42
- end
43
-
44
- private
45
-
46
- def cookbook_gem
47
- @cookbook_gem ||= begin
48
- gemspec = Bundler.load_gemspec(config[:gemspec])
49
- # Fix the gem path because it defaults to where the gem would be installed.
50
- gemspec.full_gem_path = File.dirname(config[:gemspec])
51
- Halite::Gem.new(gemspec)
52
- end
53
- end
54
-
55
- def convert_halite_cookbooks
56
- @real_cookbook_deps = {}
57
- gems_to_convert = {'poise-profiler' => Halite::Gem.new('poise-profiler')}
58
- gems_to_check = [cookbook_gem]
59
- until gems_to_check.empty?
60
- check = gems_to_check.pop
61
- # Already in the list, skip expansion.
62
- next if gems_to_convert.include?(check.name)
63
- # Not a cookbook, don't expand.
64
- next unless check.is_halite_cookbook?
65
- gems_to_convert[check.name] = check
66
- # Expand dependencies and check each of those.
67
- check.cookbook_dependencies.each do |dep|
68
- dep_cook = dep.cookbook
69
- if dep_cook
70
- gems_to_check << dep_cook
71
- else
72
- @real_cookbook_deps[dep.name] = dep
73
- end
74
- end
75
- end
76
- # Convert all the things!
77
- tmpbooks_dir = File.join(sandbox_path, 'cookbooks')
78
- FileUtils.mkdir_p(tmpbooks_dir)
79
- gems_to_convert.each do |name, gem_data|
80
- Halite.convert(gem_data, File.join(tmpbooks_dir, gem_data.cookbook_name))
81
- end
82
- end
83
-
84
- def copy_test_cookbook
85
- fixture_base = File.join(config[:kitchen_root], 'test', 'cookbook')
86
- return unless File.exist?(File.join(fixture_base, 'metadata.rb'))
87
- tmp_base = File.join(sandbox_path, 'cookbooks', "#{cookbook_gem.cookbook_name}_test")
88
- FileUtils.mkdir_p(tmp_base)
89
- FileUtils.cp_r(File.join(fixture_base, "."), tmp_base)
90
- end
91
-
92
- def copy_test_cookbooks
93
- fixtures_base = File.join(config[:kitchen_root], 'test', 'cookbooks')
94
- return unless File.exist?(fixtures_base)
95
- tmp_base = File.join(sandbox_path, 'cookbooks')
96
- FileUtils.mkdir_p(tmp_base)
97
- FileUtils.cp_r(File.join(fixtures_base, "."), tmp_base)
98
- end
99
-
100
- end
101
- end
102
- end