Skip to content

Instantly share code, notes, and snippets.

@arthurnn
Forked from mpelos/deploy.rb
Last active December 14, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurnn/5129876 to your computer and use it in GitHub Desktop.
Save arthurnn/5129876 to your computer and use it in GitHub Desktop.
Locaweb deploy capistrano script
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_app/#{application}"
set :rails_env, "production"
set :use_sudo, false
# Git settings
set :scm, :none
set :repository, "set your repository location here"
set :deploy_via, :copy
set :copy_local_tar, "/usr/bin/gnutar" if `uname` =~ /Darwin/
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment