Skip to content

Instantly share code, notes, and snippets.

@ryanmoon
Created August 17, 2017 18:58
Show Gist options
  • Save ryanmoon/ac171ad79201667bc6912c98b334f304 to your computer and use it in GitHub Desktop.
Save ryanmoon/ac171ad79201667bc6912c98b334f304 to your computer and use it in GitHub Desktop.
Rakefile for Chef Cookbooks
# YTS Cookbook Rakefile
# 08/17/2017
# Cobbled together by Ryan Moon
###########
# REQUIRES
###########
require 'rspec/core/rake_task'
require 'cookstyle'
require 'rubocop/rake_task'
require 'foodcritic'
require 'kitchen'
######################################
# STYLE TESTS, RUBOCOP AND FOODCRITIC
######################################
namespace :style do
desc 'Run Ruby style checks'
RuboCop::RakeTask.new(:ruby)
desc 'Run Chef style checks'
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = {
tags: %w(~FC078),
fail_tags: ['any'],
}
end
end
desc 'Run all style checks'
task style: ['style:chef', 'style:ruby']
#####################
# RSPEC AND CHEFSPEC
#####################
desc 'Run ChefSpec examples'
RSpec::Core::RakeTask.new(:spec)
######################################
# INTEGRATION TESTS WITH TEST-KITCHEN
######################################
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
end
###############################################
# BERKSHELF, DID NOT PROVIDE DESC SO THAT YOU
# CAN ONLY CALL THEM WITH THE GROUPED
# RAKE CALL UPLOAD OR WRONG
##############################################
namespace :berks do
task :install do
sh 'chef exec berks install'
end
task :upload do
sh 'chef exec berks upload -e integration'
end
task :force do
sh 'rm -rf Berksfile.lock;chef exec berks install -e integration;chef exec berks upload -e integration --force'
end
end
desc 'Workflow to add cookbook to server'
task upload: ['berks:install', 'berks:upload']
desc 'Workflow to forcefully add cookbook to server'
task wrong: ['berks:force']
##########
# DEFAULT
##########
task default: %w(style spec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment