Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Locaweb's Capistrano recipe
require "bundler/capistrano"
set :application, "set your application name here"
set :user, "set your Locaweb's user"
set :server_addr, "set the Locaweb's server ip address or your ftp address"
set :deploy_to, "/home/#{user}/rails_apps/#{application}"
set :rails_env, "production"
set :use_sudo, false
# Git settings
set :scm, :git
set :repository, "set your repository location here"
set :branch, "master"
set :deploy_via, :copy
# Bundler settings
set :bundle_without, [:development, :test, :assets]
# Uses local instead of remote server keys, good for github ssh key deploy.
ssh_options[:forward_agent] = true
# Server role
server server_addr, :app, :web, :db, :primary => true
# Before setup callback
before "deploy:setup",
"db:configure",
"mailer:configure",
"uploader:configure"
# After update code callback
after "deploy:update_code",
"db:symlink",
"mailer:symlink",
"uploader:symlink",
"deploy:assets:precompile",
"deploy:migrate",
"deploy:restart",
"deploy:cleanup"
namespace :deploy do
task :start do ; end
task :stop do ; end
desc "restarts the rails app"
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
namespace :assets do
desc "Run precompile task locally and sync on remote"
task :precompile, :roles => :app do
`bundle exec rake assets:precompile`
run "rm -rf #{shared_path}/assets"
`rsync -r public/assets #{user}@#{server_addr}:#{File.join(shared_path)}`
`rm -rf public/assets`
run "ln -nfs #{shared_path}/assets #{latest_release}/public"
end
end
end
namespace :db do
desc "Create database yaml in shared path"
task :configure do
set :database_name do
Capistrano::CLI.ui.ask "Enter the database name: "
end
set :database_password do
Capistrano::CLI.password_prompt "Database password: "
end
set :database_host do
Capistrano::CLI.ui.ask "Database host address: "
end
db_config = <<-EOF
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: #{database_name}
pool: 5
username: #{database_name}
password: #{database_password}
host: #{database_host}
EOF
run "mkdir -p #{shared_path}/config"
put db_config, "#{shared_path}/config/database.yml"
end
desc "Make symlink for database yaml"
task :symlink do
run "ln -nfs #{shared_path}/config/database.yml #{latest_release}/config/database.yml"
end
end
namespace :mailer do
desc "Create mailer configuration initializer in shared path"
task :configure do
set :domain do
Capistrano::CLI.ui.ask "Enter your domain: "
end
set :username do
Capistrano::CLI.ui.ask "Enter the Locaweb FTP username: "
end
set :password do
Capistrano::CLI.password_prompt "Enter the Locaweb FTP password: "
end
mailer_config = <<-EOF
ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.smtp_settings = {
:address => "localhost",
:port => 587,
:authentication => :login,
:domain => "#{domain}",
:user_name => "#{username}",
:password => "#{password}"
}
EOF
run "mkdir -p #{shared_path}/config/initializers"
put mailer_config, "#{shared_path}/config/initializers/setup_mailer.rb"
end
desc "Make symlink for setup_mailer initializer"
task :symlink do
run "ln -nfs #{shared_path}/config/initializers/setup_mailer.rb #{latest_release}/config/initializers/setup_mailer.rb"
end
end
namespace :uploader do
desc "Create mailer configuration initializer in shared path"
task :configure do
run "mkdir -p #{shared_path}/public/uploads"
end
desc "Make symlink for setup_mailer initializer"
task :symlink do
run "ln -nfs #{shared_path}/public/uploads #{latest_release}/public/"
end
end
@arthurnn

This comment has been minimized.

Copy link

arthurnn commented Mar 10, 2013

Just for the record, I had some issues with this script. I fixed on my fork https://gist.github.com/arthurnn/5129876 .

@mpelos

This comment has been minimized.

Copy link
Owner Author

mpelos commented Jul 23, 2013

Pra mim está funcionando muito bem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.