Commit 59ea3fa5
Changed files (15)
config
lib
capistrano
old_cap
config/deploy.rb
@@ -4,14 +4,18 @@ lock '3.2.1'
set :application, 'cakeside'
set :repo_url, 'git@bitbucket.org:cakeside/cakeside.git'
+set :user, "deployer"
+
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
# Default deploy_to directory is /var/www/my_app
# set :deploy_to, '/var/www/my_app'
+set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
# Default value for :scm is :git
-# set :scm, :git
+set :scm, :git
+set :scm_verbose, true
# Default value for :format is :pretty
# set :format, :pretty
@@ -33,9 +37,14 @@ set :repo_url, 'git@bitbucket.org:cakeside/cakeside.git'
# Default value for keep_releases is 5
# set :keep_releases, 5
+set :keep_releases, 3
+#set :normalize_asset_timestamps, false
+set :ssh_options, { forward_agent: true }
-namespace :deploy do
+set :rbenv_type, :user # or :system, depends on your rbenv setup
+set :rbenv_ruby, '2.1.2'
+namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
@@ -54,5 +63,4 @@ namespace :deploy do
# end
end
end
-
end
lib/capistrano/tasks/delayed_job.rake
@@ -0,0 +1,19 @@
+namespace :delayed_job do
+ %w[start stop restart status].each do |command|
+ desc "#{command} delayed_job"
+ task command do
+ on roles(:app) do
+ run "#{sudo} service delayed_job_#{fetch(:application)} #{command}"
+ end
+ end
+ #after "deploy:#{command}", "delayed_job:#{command}"
+ #after "deploy:finish", "delayed_job:restart"
+ end
+
+ desc "tail the delayed jobs logs on an app server (cap staging delayed_job:logs)"
+ task :logs do
+ on roles(:app) do
+ stream "tail -f #{fetch(:shared_path)}/log/delayed_job.log"
+ end
+ end
+end
old_cap/recipes/nginx.rb → lib/capistrano/tasks/nginx.rake
@@ -1,8 +1,10 @@
namespace :nginx do
%w[start stop restart].each do |command|
desc "#{command} nginx"
- task command, roles: :web do
- run "#{sudo} service nginx #{command}"
+ task command do
+ on roles(:web) do
+ run "#{sudo} service nginx #{command}"
+ end
end
end
end
lib/capistrano/tasks/postgresql.rake
@@ -0,0 +1,19 @@
+set(:postgresql_host, "localhost")
+#set(:postgresql_user) { fetch(:application) }
+#set(:postgresql_password) { Capistrano::CLI.password_prompt "PostgreSQL Password: " }
+#set(:postgresql_database) { "#{fetch(:application)}_#{fetch(:rails_env)}" }
+
+namespace :postgresql do
+ desc "Backup the database and copy it locally"
+ task :backup do
+ on roles(:db) do
+ filename = "#{fetch(:rails_env)}-#{Time.now.strftime('%Y-%m-%d-%H-%M')}.dump"
+ backup_path = "#{fetch(:shared_path)}/backups"
+ run "mkdir -p #{fetch(:shared_path)}/backups"
+
+ ask(:postgresql_password, "default", echo: false)
+ run "PGPASSWORD='#{postgresql_password}' pg_dump -Fc --no-acl --no-owner -h #{fetch(:postgresql_host)} -U deployer cakeside > #{backup_path}/#{filename}"
+ download("#{backup_path}/#{filename}", "db/backups/", :via => :scp)
+ end
+ end
+end
old_cap/tasks/rails.rb → lib/capistrano/tasks/rails.rake
@@ -1,12 +1,16 @@
namespace :rails do
desc "Remote console"
- task :console, :roles => :app do
- run_interactively "bundle exec rails console #{rails_env}"
+ task :console do
+ on roles(:app) do
+ run_interactively "bundle exec rails console #{fetch(:rails_env)}"
+ end
end
desc "Remote dbconsole"
- task :dbconsole, :roles => :app do
- run_interactively "bundle exec rails dbconsole #{rails_env}"
+ task :dbconsole do
+ on roles(:app) do
+ run_interactively "bundle exec rails dbconsole #{fetch(:rails_env)}"
+ end
end
def run_interactively(command, server=nil)
lib/capistrano/tasks/unicorn.rake
@@ -0,0 +1,18 @@
+namespace :unicorn do
+ %w[start stop restart].each do |command|
+ desc "#{command} unicorn"
+ task command do
+ on roles(:app) do
+ run "service unicorn_#{fetch(:application)} #{command}"
+ end
+ end
+ #after "deploy:#{command}", "unicorn:#{command}"
+ end
+
+ desc "tail the logs on an app server (cap staging unicorn:logs)"
+ task :logs do
+ on roles(:app) do
+ stream "tail -f #{fetch(:shared_path)}/log/unicorn.log"
+ end
+ end
+end
lib/capistrano/tasks/utility.rake
@@ -0,0 +1,17 @@
+desc "tail the logs on an app server (cap staging logs)"
+task :logs do
+ on roles(:app) do
+ #stream "tail -f #{fetch(:shared_path)}/log/#{fetch(:rails_env)}.log"
+ execute "tail -F #{shared_path}/log/#{fetch(:rails_env)}.log"
+ end
+end
+
+task :sync_logs do
+ on roles(:app) do
+ execute "s3cmd sync #{shared_path}/log/#{fetch(:rails_env)}.log-*.gz s3://cakeside-logs/#{fetch(:rails_env)}/rails/"
+ execute "s3cmd sync #{shared_path}/log/delayed_job.log-*.gz s3://cakeside-logs/#{fetch(:rails_env)}/delayed_job/"
+ execute "s3cmd sync #{shared_path}/log/unicorn.log-*.gz s3://cakeside-logs/#{fetch(:rails_env)}/unicorn/"
+ #execute "chown deployer /var/log/nginx/cakeside.*.log-*.gz"
+ #execute "s3cmd sync /var/log/nginx/cakeside.*.log-*.gz s3://cakeside-logs/#{fetch(:rails_env)}/nginx/"
+ end
+end
old_cap/recipes/base.rb
@@ -1,3 +0,0 @@
-def set_default(name, *args, &block)
- set(name, *args, &block) unless exists?(name)
-end
old_cap/recipes/delayed_job.rb
@@ -1,14 +0,0 @@
-namespace :delayed_job do
- %w[start stop restart status].each do |command|
- desc "#{command} delayed_job"
- task command, roles: :app do
- run "#{sudo} service delayed_job_#{application} #{command}"
- end
- after "deploy:#{command}", "delayed_job:#{command}"
- end
-
- desc "tail the delayed jobs logs on an app server (cap staging delayed_job:logs)"
- task :logs, roles: :app do
- stream "tail -f #{shared_path}/log/delayed_job.log"
- end
-end
old_cap/recipes/monit.rb
@@ -1,12 +0,0 @@
-namespace :monit do
- %w[start stop restart syntax reload status].each do |command|
- desc "run monit #{command} script"
- task command do
- run "#{sudo} service monit #{command}"
- end
- end
-
- task :version do
- run "#{sudo} service monit -V"
- end
-end
old_cap/recipes/postgresql.rb
@@ -1,30 +0,0 @@
-set_default(:postgresql_host, "localhost")
-set_default(:postgresql_user) { application }
-set_default(:postgresql_password) { Capistrano::CLI.password_prompt "PostgreSQL Password: " }
-set_default(:postgresql_database) { "#{application}_#{rails_env}" }
-
-namespace :postgresql do
- desc "create a database"
- task :create_database, roles: :db, only: { primary: true } do
- run %Q{#{sudo} -u postgres psql -c "create user #{postgresql_user} with password '#{postgresql_password}';"}
- run %Q{#{sudo} -u postgres psql -c "create database #{postgresql_database} owner #{postgresql_user};"}
- end
- after "deploy:setup", "postgresql:create_database"
-
- desc "symlink the database.yml file into the latest release"
- task :symlink, roles: :app do
- run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
- end
- after "deploy:finalize_update", "postgresql:symlink"
-
- desc "Backup the database and copy it locally"
- task :backup, roles: :db, only: {primary: true} do
- filename = "#{rails_env}-#{Time.now.strftime('%Y-%m-%d-%H-%M')}.dump"
- backup_path = "#{shared_path}/backups"
- run "mkdir -p #{shared_path}/backups"
-
- #run "PGPASSWORD='#{postgresql_password}' pg_dump -Fc --no-acl --no-owner -h #{postgresql_host} -U #{postgresql_user} #{postgresql_database} > #{backup_path}/#{filename}"
- run "PGPASSWORD='#{postgresql_password}' pg_dump -Fc --no-acl --no-owner -h #{postgresql_host} -U deployer cakeside > #{backup_path}/#{filename}"
- download("#{backup_path}/#{filename}", "db/backups/", :via => :scp)
- end
-end
old_cap/recipes/unicorn.rb
@@ -1,14 +0,0 @@
-namespace :unicorn do
- %w[start stop restart].each do |command|
- desc "#{command} unicorn"
- task command, roles: :app do
- run "service unicorn_#{application} #{command}"
- end
- after "deploy:#{command}", "unicorn:#{command}"
- end
-
- desc "tail the logs on an app server (cap staging unicorn:logs)"
- task :logs, roles: :app do
- stream "tail -f #{shared_path}/log/unicorn.log"
- end
-end
old_cap/tasks/utility.rb
@@ -1,12 +0,0 @@
-desc "tail the logs on an app server (cap staging logs)"
-task :logs, roles: :app do
- stream "tail -f #{shared_path}/log/#{rails_env}.log"
-end
-
-task :sync_logs, roles: :app do
- run "s3cmd sync #{shared_path}/log/#{rails_env}.log-*.gz s3://cakeside-logs/#{rails_env}/rails/"
- run "s3cmd sync #{shared_path}/log/delayed_job.log-*.gz s3://cakeside-logs/#{rails_env}/delayed_job/"
- run "s3cmd sync #{shared_path}/log/unicorn.log-*.gz s3://cakeside-logs/#{rails_env}/unicorn/"
- run "chown deployer /var/log/nginx/cakeside.*.log-*.gz"
- run "s3cmd sync /var/log/nginx/cakeside.*.log-*.gz s3://cakeside-logs/#{rails_env}/nginx/"
-end
old_cap/deploy.rb
@@ -11,28 +11,6 @@ load "config/recipes/monit"
load "config/tasks/utility"
load "config/tasks/rails"
-set :application, "cakeside"
-set :user, "deployer"
-set :use_sudo, false
-default_run_options[:pty] = true # password prompt
-
-# git
-set :scm, :git
-set :scm_verbose, true
-set :repository, "git@bitbucket.org:cakeside/cakeside.git"
-set :branch, "master"
-set :deploy_via, :remote_cache
-
-#copy
-#set :scm, :none
-#set :repository, "."
-#set :deploy_via, :copy
-
-set :deploy_to, "/home/#{user}/apps/#{application}"
-set :keep_releases, 3
-set :normalize_asset_timestamps, false
-set :ssh_options, {:forward_agent => true}
-
after "deploy", "deploy:cleanup" # remove old releases
require './config/boot'
Capfile
@@ -15,11 +15,11 @@ require 'capistrano/deploy'
# https://github.com/capistrano/rails
#
# require 'capistrano/rvm'
-# require 'capistrano/rbenv'
+require 'capistrano/rbenv'
# require 'capistrano/chruby'
-# require 'capistrano/bundler'
-# require 'capistrano/rails/assets'
-# require 'capistrano/rails/migrations'
+require 'capistrano/bundler'
+require 'capistrano/rails/assets'
+require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }