From a921767a77f8494788cd857ed61dafd1536cf783 Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Sat, 12 Mar 2016 10:21:56 -0500 Subject: [PATCH] Update CircleCI testing for ChefDK & parallel 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. --- .kitchen.docker.yml | 4 ++-- Rakefile | 3 ++- circle.yml | 19 ++++++++++++------- test/circle_parallel.rake | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 test/circle_parallel.rake diff --git a/.kitchen.docker.yml b/.kitchen.docker.yml index 230979b0e..c323d3dfa 100644 --- a/.kitchen.docker.yml +++ b/.kitchen.docker.yml @@ -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 %> @@ -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 diff --git a/Rakefile b/Rakefile index d9b2212e5..7b481b4e8 100644 --- a/Rakefile +++ b/Rakefile @@ -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/) diff --git a/circle.yml b/circle.yml index 92f4458bd..db7df55d0 100644 --- a/circle.yml +++ b/circle.yml @@ -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: diff --git a/test/circle_parallel.rake b/test/circle_parallel.rake new file mode 100644 index 000000000..f645d745f --- /dev/null +++ b/test/circle_parallel.rake @@ -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