Skip to content

Commit ab8fa3f

Browse files
authored
Merge pull request #602 from DataDog/kbogtob/run-kitchen-tests-on-ci
Run Kitchen tests on CircleCI
2 parents deb9851 + 339a2f8 commit ab8fa3f

5 files changed

Lines changed: 134 additions & 0 deletions

File tree

.circleci/config.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,28 @@ jobs:
263263
name: Run tests
264264
command: rvm $RUBY_VERSION --verbose do bundle exec rake test
265265

266+
kitchen-tests:
267+
machine: true
268+
environment:
269+
KITCHEN_LOCAL_YAML: .kitchen.docker.yml
270+
STRICT_VARIABLES: 'yes'
271+
RUBY_VERSION: '2.5.3'
272+
steps:
273+
- checkout
274+
- run:
275+
name: Install Ruby versions
276+
command: rvm install $RUBY_VERSION
277+
- run:
278+
name: Install bundler
279+
command: rvm $RUBY_VERSION --verbose do gem install bundler:1.17.3
280+
- run:
281+
name: Install gem dependencies
282+
command: rvm $RUBY_VERSION --verbose do bundle install --path .bundle
283+
- run:
284+
name: Execute Kitchen tests
285+
command: rvm $RUBY_VERSION --verbose do bundle exec rake circle
286+
no_output_timeout: 900
287+
266288
workflows:
267289
version: 2
268290
build_and_test:
@@ -297,3 +319,4 @@ workflows:
297319
- specs-ruby26-puppet60
298320
- specs-ruby26-puppet65
299321
- verify-gemfile-lock-dependencies
322+
- kitchen-tests

.kitchen.docker.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
driver:
3+
name: docker
4+
5+
provisioner:
6+
name: puppet_apply
7+
manifests_path: environments/etc/manifests
8+
modules_path: /tmp/modules
9+
require_puppet_repo: true
10+
require_chef_for_busser: false
11+
puppet_debug: true
12+
puppet_verbose: true
13+
custom_pre_apply_command: 'cp -r /tmp/modules/* /tmp/kitchen/modules/'
14+
15+
platforms:
16+
- name: centos-7
17+
driver_config:
18+
# we use a custom image that runs systemd
19+
image: 'datadog/docker-library:chef_kitchen_systemd_centos_7'
20+
run_command: /root/start.sh
21+
22+
driver:
23+
provision_command:
24+
- rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
25+
- yum install -y puppet
26+
27+
- mkdir /home/kitchen/puppet
28+
- printf <%= File.read('environments/etc/Puppetfile').inspect %> > /home/kitchen/puppet/Puppetfile
29+
30+
- gem install r10k -v 2.6.7
31+
- cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules
32+
33+
- name: centos-8
34+
driver_config:
35+
# we use a custom image that runs systemd
36+
image: 'datadog/docker-library:chef_kitchen_systemd_centos_8'
37+
run_command: /root/start.sh
38+
39+
driver:
40+
provision_command:
41+
- dnf install -y https://yum.puppetlabs.com/puppet-release-el-8.noarch.rpm
42+
- dnf install -y puppet
43+
44+
- mkdir /home/kitchen/puppet
45+
- printf <%= File.read('environments/etc/Puppetfile').inspect %> > /home/kitchen/puppet/Puppetfile
46+
47+
- gem install r10k -v 2.6.7
48+
- cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules
49+
50+
- name: ubuntu-16.04 # we use the official image
51+
driver:
52+
provision_command:
53+
- apt-get install -y apt-utils apt-transport-https ca-certificates
54+
- wget https://apt.puppetlabs.com/puppet6-release-xenial.deb
55+
- dpkg -i puppet6-release-xenial.deb
56+
- apt-get install -y puppet
57+
58+
- mkdir /home/kitchen/puppet
59+
- printf <%= File.read('environments/etc/Puppetfile').inspect %> > /home/kitchen/puppet/Puppetfile
60+
61+
- gem install r10k -v 2.6.7
62+
- cd /home/kitchen/puppet && r10k puppetfile install --moduledir=/tmp/modules
63+
64+
verifier:
65+
name: serverspec
66+
67+
suites:
68+
- name: dd-agent
69+
manifests: init.pp
70+
verifier:
71+
default_pattern: true
72+
additional_install_commmand: source /etc/profile.d/rvm.sh
73+
env_vars:
74+
TARGET_HOST: 127.0.0.1
75+
TARGET_PORT: 2222
76+
LOGIN_USER: root
77+
LOGIN_PASSWORD: puppet

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ group :development do
2121
gem "librarian-puppet"
2222
gem "kitchen-puppet"
2323
gem "kitchen-vagrant"
24+
gem "kitchen-docker"
2425
gem "kitchen-verifier-serverspec"
2526

2627
if RUBY_VERSION >= '2.3'

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ GEM
5656
json-schema (2.8.1)
5757
addressable (>= 2.4)
5858
json_pure (1.8.6)
59+
kitchen-docker (2.9.0)
60+
test-kitchen (>= 1.0.0)
5961
kitchen-puppet (3.5.1)
6062
librarian-puppet (>= 3.0)
6163
net-ssh (>= 3)
@@ -312,6 +314,7 @@ PLATFORMS
312314
DEPENDENCIES
313315
fast_gettext
314316
json (= 2.1.0)
317+
kitchen-docker
315318
kitchen-puppet
316319
kitchen-vagrant
317320
kitchen-verifier-serverspec

Rakefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ require 'puppet-syntax/tasks/puppet-syntax'
33
require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any?
44
require 'puppet-lint/tasks/puppet-lint'
55
require 'rubocop/rake_task'
6+
require 'kitchen/rake_tasks'
67

78
exclude_paths = [
89
"pkg/**/*",
@@ -23,3 +24,32 @@ task :test => [
2324
'rubocop',
2425
'spec',
2526
]
27+
28+
desc 'Run Kitchen tests using CircleCI parallelism mode, split by worker'
29+
task :circle do
30+
def kitchen_config
31+
raw_config = Kitchen::Loader::YAML.new(
32+
local_config: ENV['KITCHEN_LOCAL_YAML']
33+
)
34+
35+
Kitchen::Config.new(loader: raw_config)
36+
end
37+
38+
def total_workers
39+
ENV.fetch('CIRCLE_NODE_TOTAL', 1).to_i
40+
end
41+
42+
def current_worker
43+
ENV.fetch('CIRCLE_NODE_INDEX', 0).to_i
44+
end
45+
46+
def command
47+
kitchen_config.instances.sort_by(&:name).each_with_object([]).with_index do |(instance, commands), index|
48+
next unless index % total_workers == current_worker
49+
50+
commands << "kitchen test #{instance.name}"
51+
end.join(' && ')
52+
end
53+
54+
sh command unless command.empty?
55+
end

0 commit comments

Comments
 (0)