Skip to content

Commit

Permalink
Update CircleCI testing for ChefDK & parallel
Browse files Browse the repository at this point in the history
Using ChefDK to maintain the dependency chain.
Parallelize kitchen testing across multiple CircleCI workers.

Skip testing Debian via Docker until we sort out the service runner.
  • Loading branch information
miketheman committed Mar 13, 2016
1 parent d0c7c2c commit a921767
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .kitchen.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ driver:
use_sudo: false

platforms:
- name: debian-7
# - name: debian-7

<% %w(12.04 14.04).each do |ubver| %>
- name: ubuntu-<%= ubver %>
Expand All @@ -15,7 +15,7 @@ platforms:
run_command: /sbin/init
<% end %>

# @todo figure out how to test systemd in docker
# @todo figure out how to run service via systemd
# - name: ubuntu-15.04
# driver:
# run_command: /lib/systemd/systemd
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env rake

require 'foodcritic'
require 'kitchen'
require 'rake/clean'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

load './test/circle_parallel.rake'

CLEAN.include %w(.kitchen/ coverage/ doc/)
CLOBBER.include %w(Berksfile.lock Gemfile.lock .yardoc/)

Expand Down
19 changes: 12 additions & 7 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
machine:
environment:
KITCHEN_LOCAL_YAML: .kitchen.docker.yml
ruby:
version: 2.2.2
services:
- docker

dependencies:
bundler:
without: [development, kitchen_cloud, kitchen_vagrant]
override:
- curl -L https://www.chef.io/chef/install.sh | sudo bash -s -- -P chefdk -v 0.11.2
- chef gem install kitchen-docker -v '~> 2.3.0'
cache_directories:
- "~/.chefdk"

test:
pre:
- eval "$(/opt/chefdk/bin/chef shell-init bash)"
override:
- bundle exec rake
- bundle exec kitchen verify:
timeout: 1800
- chef --version
- gem query -d chefspec rubocop foodcritic rake
- chef exec rake circle:
parallel: true
timeout: 900

general:
artifacts:
Expand Down
38 changes: 38 additions & 0 deletions test/circle_parallel.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'kitchen/rake_tasks'

desc 'Run Kitchen tests using CircleCI parallelism mode, split by platform'
task :circle do
# Load environment-defined config
def kitchen_loader
Kitchen::Loader::YAML.new(local_config: ENV['KITCHEN_LOCAL_YAML'])
end

def kitchen_config
Kitchen::Config.new(loader: kitchen_loader)
end

def total_workers
ENV['CIRCLE_NODE_TOTAL'].to_i
end

def current_worker
ENV['CIRCLE_NODE_INDEX'].to_i
end

def command
commands = []

kitchen_config.platforms.sort_by(&:name).each_with_index do |platform, index|
next unless index % total_workers == current_worker
# Escape the platform name to somehting the CLI will understand.
# TODO: This could likely be pulled from kitchen_config.instances somehow
name = platform.name.delete('.')

commands.push "kitchen verify #{name}"
end

commands.join(' && ')
end

sh command unless command.empty?
end

0 comments on commit a921767

Please sign in to comment.