Skip to content

Instantly share code, notes, and snippets.

@jeffbyrnes
Created September 24, 2014 18:01
Show Gist options
  • Save jeffbyrnes/42210f116db672f3ce28 to your computer and use it in GitHub Desktop.
Save jeffbyrnes/42210f116db672f3ce28 to your computer and use it in GitHub Desktop.
Travis CI + Test Kitchen
language: ruby
rvm:
- 1.9.3
before_install:
- openssl aes-256-cbc -K $encrypted_755628117be5_key -iv $encrypted_755628117be5_iv
-in travis_ci_ec2.pem.enc -out ~/.ssh/travis_ci_ec2.pem -d
- chmod 600 ~/.ssh/travis_ci_ec2.pem
install:
- bundle install --without vagrant
- bundle exec berks install
script:
- bundle exec rake travis
after_script:
- bundle exec rake integration:cloud_destroy
#!/usr/bin/env bash
echo -n 'Enter AWS_ACCESS_KEY_ID: '
read data
echo 'Encrypting...'
travis encrypt AWS_ACCESS_KEY_ID=$data --add
echo -n 'Enter AWS_SECRET_ACCESS_KEY: '
read data
echo 'Encrypting...'
travis encrypt AWS_SECRET_ACCESS_KEY=$data --add
echo 'Encrypting AWS_KEYPAIR_NAME'
travis encrypt AWS_KEYPAIR_NAME='travis_ci_ec2' --add
echo 'Encrypting EC2_SSH_KEY_PATH'
travis encrypt EC2_SSH_KEY_PATH='~/.ssh/travis_ci_ec2.pem' --add
echo 'Encrypting travis_ci_ec2.pem'
travis encrypt-file ~/.ssh/travis_ci_ec2.pem --add
#!/usr/bin/env rake
require 'bundler/setup'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'foodcritic'
require 'kitchen'
namespace :style do
desc 'Run Ruby style checks'
RuboCop::RakeTask.new(:ruby)
desc 'Run Chef style checks'
FoodCritic::Rake::LintTask.new(:chef)
end
desc 'Run all style checks'
task style: ['style:chef', 'style:ruby']
desc 'Run ChefSpec unit tests'
RSpec::Core::RakeTask.new(:unit) do |t|
t.rspec_opts = '--color --format progress'
end
namespace :integration do
desc 'Run Test Kitchen with Vagrant'
task :vagrant do
Kitchen.logger = Kitchen.default_file_logger
Kitchen::Config.new.instances.each do |instance|
instance.test(:always)
end
end
desc 'Run Test Kitchen with cloud plugins'
task :cloud do
run_kitchen = true
if ENV['TRAVIS'] == 'true' && ENV['TRAVIS_PULL_REQUEST'] != 'false'
run_kitchen = false
end
if run_kitchen
Kitchen.logger = Kitchen.default_file_logger
@loader = Kitchen::Loader::YAML.new(project_config: './.kitchen.cloud.yml')
config = Kitchen::Config.new(loader: @loader)
config.instances.each do |instance|
instance.test(:always)
end
end
end
desc 'Destroy all cloud-based Test Kitchen nodes'
task :cloud_destroy do
Kitchen.logger = Kitchen.default_file_logger
@loader = Kitchen::Loader::YAML.new(project_config: './.kitchen.cloud.yml')
config = Kitchen::Config.new(loader: @loader)
config.instances.each do |instance|
instance.destroy
end
end
end
desc 'Run all tests on Travis'
task travis: %w(style unit integration:cloud)
# Default
task default: %w(style unit integration:vagrant)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment