require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails/migrations'
require 'capistrano/rails/assets'
cap dev deploy
cap sandbox deploy
cap production deploy
# server-based syntax
# ======================
server 'dev.horidashi.com', user: 'ubuntu', roles: %w{app db web}, primary: true
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
# server 'db.example.com', user: 'deploy', roles: %w{db}
# role-based syntax
# ==================
role :app, %w{ubuntu@dev.horidashi.com}
role :web, %w{ubuntu@dev.horidashi.com}
role :db, %w{ubuntu@dev.horidashi.com}
set :default_env, { path: "/home/ubuntu/.nvm/versions/node/v4.4.7/bin/:$PATH" }
# Default value for keep_releases is 5
# set :keep_releases, 5
set :keep_releases, 10
namespace :setup do
desc "Upload config file."
task :upload_config do
on roles(:app) do
execute "mkdir -p #{shared_path}/config"
upload! StringIO.new(File.read("config/database.yml")), "#{shared_path}/config/database.yml"
end
end
end
namespace :deploy do
task :restart do
on roles(:web) do
site_dir = "#{current_path}";
within site_dir do
puts capture(:env)
puts capture(:npm, 'i')
puts capture(:bower, 'i')
puts capture(:grunt, 'build')
puts capture(:pm2, 'restart', 'hub')
end
end
end
before :deploy, "deploy:env"
after :deploy, "deploy:restart"
end
set :ssh_options, {
keys: %w(/home/ubuntu/.ssh/id_rsa),
forward_agent: true,
auth_methods: %w(publickey password)
}
set :application, 'hub'
set :user, "ubuntu"
set :deploy_to, '/home/ubuntu/service/hub'
set :repo_url, 'git@bitbucket.org:adplayhubteam/hub.git'
set :branch, "master"
after "deploy", "deploy:cleanup"
append :linked_files, 'config/database.yml', 'config/secrets.yml'
append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system'
cap production deploy:rollback ROLLBACK_RELEASE=20160614133327
# db/migrate/20160801115659_adplay.rb
class Adplay < ActiveRecord::Migration[5.0]
def change
add_column :adplays, :google_play_url, :string
add_column :adplays, :itunes_url, :string
end
end
cap production db:rollback STEP=1