Skip to content

Instantly share code, notes, and snippets.

View iafonov's full-sized avatar
🌴

Igor Afonov iafonov

🌴
View GitHub Profile
application 'some_application' do
path "/var/www/apps/some_application"
owner 'deploy'
group 'deploy'
purge_before_symlink ['log']
symlinks 'api_keys.yml' => "config/api_keys/#{node['some_application']['environment']}.yml",
'secret_token' => 'secret_token',
'log' => 'log'
@iafonov
iafonov / gist:3349101
Created August 14, 2012 13:07
Chef git templates

Chef git templates

Chef should allow creating cookbooks and chef-repo using templates. It should maintain the ability to create artifacts offline but a special switch could be supplied to knife wich will tell it to clone the remote repository rather than create a hardcoded structure.

Use cases:

knife chef-repo create --template https://github.com/fnichol/chef-bootstrap-repo knife cookbook create ntpd --template https://github.com/test/cookbook-with-minitest-and-berkshelf

Basically knife should clone the repository into folder and remove .git directory.

@iafonov
iafonov / Rakefile
Created June 23, 2012 16:14
Dumb git cookbooks resolver
require 'yaml'
desc "Install cookbooks"
task :cookbooks do
cookbooks = YAML.load(File.read("cookbooks.yml"))
cookbooks.each do |name, data|
data ||= {}
target = "cookbooks/#{name}"
@iafonov
iafonov / gist:2828887
Created May 29, 2012 14:55
Smart cucumber test runner for Jenkins CI
require 'fileutils'
BUILDS_PATH = '/var/lib/jenkins/jobs/secret_project/builds'
# list of build directories
builds = Dir.entries(BUILDS_PATH).select{|dir| dir =~ /^\d{1,4}$/}.map{|dir| dir.to_i}.sort
stats = builds.inject({}) do |stats, build_number|
`grep -r "cucumber" #{File.join(BUILDS_PATH, build_number.to_s)}`.each do |line|
line.match /workspace\/(.*?)\:(\d*).*Scenario: (.*)/
@iafonov
iafonov / knife script
Created February 6, 2012 15:48
Depoyer
require 'script/util/ssh_wrapper.rb'
class Deployer
def initialize(query_str)
query = Chef::Search::Query.new
@nodes = query.search(:node, query_str)[0]
@ssh = SshWrapper.new
@ssh.configure_session(@nodes)
end
@iafonov
iafonov / deploy
Created October 5, 2011 10:22
Deployment with chef
require 'script/util/deployer.rb'
abort("usage: knife exec script/deploy QUERY") unless ARGV[2]
Deployer.new(ARGV[2]).deploy
exit 0
@iafonov
iafonov / dci_and_aggregate.rb
Created August 15, 2011 08:33 — forked from MitinPavel/dci_and_aggregate.rb
DCI and Aggregate
class Human
attr_accessor :address
end
class Address
def to_s
"City: #{@city}"
end
private
#!/bin/sh
unset DISPLAY
if [ ! -f /tmp/.X99-lock ]; then
Xvfb :99 -ac &
fi
export DISPLAY=:99
bundle install --path ../bundle --quiet --without development production &&
@iafonov
iafonov / gist:1101460
Created July 23, 2011 14:01
parse the link and put custom host into it
When /^(?:I|they) follow "([^"]*?)" in the email$/ do |link|
def parse_email_for_anchor_text_link(link_text)
if current_email.body =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>}
URI.split($1)[5..-1].compact!.join("?").gsub("&amp;", "&")
end
end
url_path = parse_email_for_anchor_text_link(link)
visit "http://test1.localhost:31337#{url_path}"
WebMock.allow_net_connect!
Before("@webmock") do
WebMock.disable_net_connect!(:allow_localhost => true)
end
After("@webmock") do
WebMock.allow_net_connect!
end