Created
February 23, 2012 21:26
-
-
Save barnaba/1895143 to your computer and use it in GitHub Desktop.
Wyborny recept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.gem | |
.bundle | |
Gemfile.lock | |
pkg/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.youtube.com/watch?v=MmodAONmMj4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _cset(name, *args, &block) | |
unless exists?(name) | |
set(name, *args, &block) | |
end | |
end | |
def prompt_with_default(var, default) | |
Capistrano::CLI.ui.ask("#{var}: ") { |q| q.default = default } | |
end | |
def confirmed | |
Capistrano::CLI.ui.say "Are you sure?" | |
(/y/i =~ Capistrano::CLI.ui.agree) and yield | |
end | |
def each_server | |
servers = find_servers_for_task(current_task) | |
servers.each do |s| | |
yield(s) | |
end | |
end | |
def one_server | |
servers = {} | |
roles.each_pair do |name, role| | |
role.servers.each do |server| | |
servers[server] = [] unless servers.has_key? server | |
servers[server] << name | |
end | |
end | |
choices = servers.map do |server, roles| | |
"#{server} (#{roles.uniq.join ", "})" | |
end | |
if (choices.size > 1 ) | |
choice = Capistrano::CLI.ui.choose(*choices) | |
server = servers.keys[choices.index(choice)] | |
else | |
server = servers.keys.first | |
end | |
yield(server) | |
end | |
def symlink_shared(*files) | |
files.flatten! | |
files.each do |file| | |
run "ln -nfs #{shared_path}/#{file} #{release_path}/#{file}" | |
end | |
end | |
def banner(text, banner_color=:blue) | |
stars = (80 - (text.length + 2))/2 | |
reminder = (80 - (text.length + 2))%2 | |
Capistrano::CLI.ui.say "<%= color '*'*80, :#{banner_color}%>" | |
Capistrano::CLI.ui.say "<%= color '*'*#{stars}, :#{banner_color} %> #{text} <%= color '*'*#{stars+reminder}, :#{banner_color} %>" | |
Capistrano::CLI.ui.say "<%= color '*'*80, :#{banner_color} %>" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'capistrano/ext/multistage' | |
require 'capistrano_colors' | |
require 'wyborny_recept/common' | |
configuration = Capistrano::Configuration.respond_to?(:instance) ? | |
Capistrano::Configuration.instance(:must_exist) : | |
Capistrano.configuration(:must_exist) | |
configuration.load do | |
set :stages, %w(test staging production) | |
set :default_stage, "test" | |
set :use_sudo, false | |
set :scm, :git | |
set :branch, "master" | |
set :port, 22 | |
set :normalize_asset_timestamps, false | |
ssh_options[:forward_agent] = true | |
set :deploy_via, :remote_cache | |
default_run_options[:pty] = true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "http://rubygems.org" | |
# Specify your gem's dependencies in wyborny_recept.gemspec | |
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'wyborny_recept/common' | |
require 'yaml' | |
configuration = Capistrano::Configuration.respond_to?(:instance) ? | |
Capistrano::Configuration.instance(:must_exist) : | |
Capistrano.configuration(:must_exist) | |
configuration.load do | |
namespace :log do | |
task :default, :role => :app do | |
run "tail -n 200 -f #{shared_path}/log/#{rails_env}.log" | |
end | |
end | |
namespace :deploy do | |
desc "Restart application" | |
task :restart, :roles => :app, :except => { :no_release => true } do | |
run "touch #{release_path}/tmp/restart.txt" | |
end | |
desc "Links the proper configuration files" | |
task :update_symlinks do | |
run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml" | |
end | |
task :cold do | |
update | |
load_schema | |
start | |
end | |
task :load_schema, :roles => :app do | |
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:schema:load" | |
end | |
task :seed, :roles => :app do | |
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:seed" | |
end | |
task :update_symlinks do | |
symlink_shared shared_files | |
end | |
after 'deploy:update_code' do | |
update_symlinks | |
restart | |
end | |
end | |
namespace :ssh do | |
task :default do | |
one_server do |server| | |
banner(server.to_s) | |
banner(release_path) | |
system "ssh #{ENV['SSH_USER'] || server.user || user || ENV['USER']}@#{server.host} -p #{server.port || port || 22} -C " | |
end | |
end | |
task :config, :roles => :app do | |
output = "" | |
each_server do |server| | |
output += "Host #{application}-#{stage}\n" | |
output += " user #{user}\n" | |
output += " port #{port}\n" | |
output += " hostname #{server.host}\n" | |
end | |
puts "=" * 80 | |
puts output | |
puts "=" * 80 | |
if Capistrano::CLI.ui.agree "Write to your .ssh/config?" | |
File.open(File.expand_path('~/.ssh/config'), 'a') {|f| f.write(output) } | |
end | |
end | |
end | |
namespace :dump do | |
task :default, :roles => :app do | |
target_file = prompt_with_default("target file", "/tmp/dump.sql.gz") | |
database_config_yaml = capture("cat #{shared_path}/config/database.yml") | |
database_config = YAML::parse(database_config_yaml) | |
credentials = database_config[rails_env] | |
tempfile = (capture "mktemp").chomp | |
run "mysqldump -u#{credentials["username"].value} -p#{credentials["password"].value} #{credentials["database"].value} | gzip > #{tempfile}" | |
download(tempfile, target_file, :via => :scp) | |
run "rm #{tempfile}" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module WybornyRecept | |
VERSION = "0.0.2" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
$:.push File.expand_path("../lib", __FILE__) | |
require "wyborny_recept/version" | |
Gem::Specification.new do |s| | |
s.name = "wyborny_recept" | |
s.version = WybornyRecept::VERSION | |
s.authors = ["Barnaba Turek"] | |
s.email = ["barnabaturek@gmail.com"] | |
s.homepage = "https://gist.github.com/1895143" | |
s.summary = %q{Wyborny recept - przydatne rzeczy do capistrano} | |
s.description = %q{Description} | |
#s.rubyforge_project = "wyborny_recept" | |
s.files = `git ls-files`.split("\n") | |
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | |
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | |
s.require_paths = ["lib"] | |
# specify any dependencies here; for example: | |
# s.add_development_dependency "rspec" | |
s.add_runtime_dependency "capistrano" | |
s.add_runtime_dependency "capistrano-ext" | |
s.add_runtime_dependency "capistrano_colors" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "wyborny_recept/version" | |
module WybornyRecept | |
# Your code goes here... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment