Skip to content

Instantly share code, notes, and snippets.

Avatar
🌴

Igor Afonov iafonov

🌴
View GitHub Profile
View gist:4298625
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 Aug 14, 2012
Chef git templates
View gist:3349101

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 Jun 23, 2012
Dumb git cookbooks resolver
View Rakefile
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
Smart cucumber test runner for Jenkins CI
View gist:2828887
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: (.*)/
View knife script
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 Oct 5, 2011
Deployment with chef
View deploy
require 'script/util/deployer.rb'
abort("usage: knife exec script/deploy QUERY") unless ARGV[2]
Deployer.new(ARGV[2]).deploy
exit 0
View dci_and_aggregate.rb
class Human
attr_accessor :address
end
class Address
def to_s
"City: #{@city}"
end
private
View gist:1113433
#!/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 Jul 23, 2011
parse the link and put custom host into it
View gist:1101460
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}"
View gist:992876
WebMock.allow_net_connect!
Before("@webmock") do
WebMock.disable_net_connect!(:allow_localhost => true)
end
After("@webmock") do
WebMock.allow_net_connect!
end