Skip to content

Instantly share code, notes, and snippets.

View mlafeldt's full-sized avatar

Mathias Lafeldt mlafeldt

View GitHub Profile
@mlafeldt
mlafeldt / Rakefile
Created August 22, 2013 21:35
Encrypt environment variables for Travis
desc 'Encrypt environment variables for Travis'
task :travis_encrypt, [:aws_key_id, :aws_secret] do |t, args|
raw_vars = "AWS_ACCESS_KEY_ID=#{args[:aws_key_id]} AWS_SECRET_ACCESS_KEY=#{args[:aws_secret]}"
sh 'travis', 'encrypt', raw_vars
end
@mlafeldt
mlafeldt / Rakefile
Created August 14, 2013 15:08
Validate CloudFormation templates with aws-sdk
require 'aws-sdk'
def validate_template(body)
cfn = AWS::CloudFormation.new
cfn.validate_template(body)
end
desc 'Validate CloudFormation template files'
task :test do
Dir.glob('*.json').each do |template|
bundle package
mkdir /tmp/gem_server
mv vendor/cache/ /tmp/gem_server/gems
gem generate_index -d /tmp/gem_server/
cd /tmp/gem_server/gems
python -m SimpleHTTPServer
@mlafeldt
mlafeldt / Gemfile.lock
Last active December 12, 2015 03:38
Fun with ChefSpec dependencies
PATH
remote: .
specs:
chefspec (1.0.0)
chef (>= 0.9.12)
erubis
fauxhai (~> 0.1)
minitest-chef-handler (~> 0.6.0)
moneta (< 0.7.0)
rspec (~> 2.12.0)
@mlafeldt
mlafeldt / rules.rb
Created December 4, 2012 12:08
BP001 foodcritic rule
# Bigpoint's foodcritic rules
rule 'BP001', 'Missing poem in README' do
tags %w(style readme poem)
cookbook do |path|
file = File.join(path, 'README.md')
# XXX FC011 already checks that the README exists.
if File.file?(file) && (File.read(file) !~ /^Poem/)
[ file_match(file) ]
end
@mlafeldt
mlafeldt / berkshelf.patch
Created November 30, 2012 16:17
Patch Berkshelf to keep a cookbook's .git folder
--- a/vendor/gems/ruby/1.9.1/gems/berkshelf-1.0.4/lib/berkshelf/berksfile.rb
+++ b/vendor/gems/ruby/1.9.1/gems/berkshelf-1.0.4/lib/berkshelf/berksfile.rb
@@ -38,10 +38,6 @@
# Dir.glob does not support backslash as a File separator
src = cb.path.to_s.gsub('\\', '/')
FileUtils.cp_r(Dir.glob(File.join(src, "*")), dest)
+
+ # Copy .git dir if present
+ git_dir = File.join(src, ".git")
+ FileUtils.cp_r(git_dir, dest) if File.exists?(git_dir)
@mlafeldt
mlafeldt / Cheffile.rb
Created November 28, 2012 12:11
Add github method to Cheffile (similar to Berkshelf's github shortcut)
# vi: set ft=ruby :
def github(user, repo, protocol = :git)
prefix = {
:git => 'git://github.com/',
:ssh => '[email protected]:',
:https => 'https://github.com/'
}[protocol]
"#{prefix}#{user}/#{repo}.git"
end
@mlafeldt
mlafeldt / bootstap.sh
Created November 16, 2012 18:17
Bundler bootstrap
#!/usr/bin/env sh
set -e
APP_ROOT="$(cd -P -- $(dirname -- "$0") && pwd)"
cd "$APP_ROOT"
echo "Setting up your environment..."
if command -v ruby >/dev/null; then
@mlafeldt
mlafeldt / parse_cheffile.rb
Created October 23, 2012 15:08
Parse Cheffile in Ruby
#!/usr/bin/env ruby
class CookbookSource
attr_reader :name, :options
def initialize(name, options = {})
@name = name
@options = options
end
end
@mlafeldt
mlafeldt / default_spec.rb
Created October 19, 2012 13:39
ChefSpec matcher for ark resource
require File.expand_path('../spec_helper', __FILE__)
describe 'The recipe RECIPE::default' do
let (:chef_run) do
ChefSpec::ChefRunner.new.converge 'RECIPE::default'
end
it "should install PACKAGE via ark" do
chef_run.should install_ark "PACKAGE"
end