Skip to content

Instantly share code, notes, and snippets.

@cpfarher
Created December 10, 2013 14:38
Show Gist options
  • Select an option

  • Save cpfarher/7891591 to your computer and use it in GitHub Desktop.

Select an option

Save cpfarher/7891591 to your computer and use it in GitHub Desktop.
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Includes tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails/tree/master/assets
# https://github.com/capistrano/rails/tree/master/migrations
#
require 'capistrano/rvm'
require 'capistrano/rails' #incluye bundler, assets y migrations
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
set :application, 'myapp'
#set :repo_url, '[email protected]:christian/myapp.git'
set :repo_url, 'http://[email protected]/christian/myapp.git'
set :deploy_to, '/home/christian/myapp'
set(:branch, ask(:branch, "Branch for deploy: "))
set :scm, :git
set :scm_verbose, true
set :ssh_options, {:forward_agent => true}
set :format, :pretty
set :log_level, :debug
set :pty, true
set :keep_releases, 10
set :deploy_via, :copy
set :bundle_without, [:development, :test]
set :rails_env, 'production'
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
set :bundle_gemfile, -> { release_path.join('Gemfile') }
set :bundle_dir, -> { shared_path.join('bundle') }
set :bundle_flags, '--deployment'
set :bundle_without, %w{test development}.join(' ')
set :bundle_binstubs, -> { shared_path.join('bin') }
set :bundle_roles, :all
#before 'deploy:assets:precompile', 'deploy:migrate'
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
end
end
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
after :finishing, 'deploy:cleanup'
end
set :stage, :production
# Simple Role Syntax
# ==================
#vps
role :web, '10.8.0.6'
role :app, '10.8.0.6'
role :db, '10.8.0.6', :primary=>true
set :db_name, "myapp_produccion"
set :db_user, 'myapp'
set :db_passwd, ask(:db_passwd, "Password para usuario db #{:db_user}:")
server '10.8.0.6',
roles: %w{web app},
ssh_options: {
user: 'christian', # overrides user setting above
forward_agent: true,
auth_methods: %w(publickey)
}
christian@toshichri:~/public_html/rails/myapp$ bundle exec cap production deploy --trace
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke deploy (first_time)
** Execute deploy
** Invoke deploy:starting (first_time)
** Invoke deploy:set_shared_assets (first_time)
** Execute deploy:set_shared_assets
** Execute deploy:starting
** Invoke deploy:check (first_time)
** Execute deploy:check
** Invoke git:check (first_time)
** Invoke git:wrapper (first_time)
** Execute git:wrapper
INFO [638106a2] Running mkdir -p /tmp/myapp/ on 10.8.0.6
DEBUG [638106a2] Command: ( RVM_BIN_PATH=~/.rvm/bin mkdir -p /tmp/myapp/ )
INFO [638106a2] Finished in 10.279 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/myapp/git-ssh.sh 0.0%
INFO Uploading /tmp/myapp/git-ssh.sh 100.0%
INFO [0eccb936] Running chmod +x /tmp/myapp/git-ssh.sh on 10.8.0.6
DEBUG [0eccb936] Command: ( RVM_BIN_PATH=~/.rvm/bin chmod +x /tmp/myapp/git-ssh.sh )
INFO [0eccb936] Finished in 1.010 seconds with exit status 0 (successful).
** Execute git:check
Please enter branch: |Branch for deploy: |
master
DEBUG [81c723e9] Running git ls-remote http://[email protected]/christian/myapp.git on 10.8.0.6
DEBUG [81c723e9] Command: ( RVM_BIN_PATH=~/.rvm/bin GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/myapp/git-ssh.sh git ls-remote http://[email protected]/cpfarher/myapp.git )
DEBUG [81c723e9] 9710509d2ed20f4bef97c14bce5d839ca1f3fda3
DEBUG [81c723e9]
DEBUG [81c723e9] HEAD
DEBUG [81c723e9]
DEBUG [81c723e9] 9710509d2ed20f4bef97c14bce5d839ca1f3fda3
DEBUG [81c723e9]
DEBUG [81c723e9] refs/heads/master
DEBUG [81c723e9] Finished in 11.555 seconds with exit status 0 (successful).
** Invoke deploy:check:directories (first_time)
** Execute deploy:check:directories
INFO [3a15081e] Running mkdir -pv /home/christian/myapp/shared /home/christian/myapp/releases on 10.8.0.6
DEBUG [3a15081e] Command: ( RVM_BIN_PATH=~/.rvm/bin mkdir -pv /home/christian/myapp/shared /home/christian/myapp/releases )
INFO [3a15081e] Finished in 10.123 seconds with exit status 0 (successful).
** Invoke deploy:check:linked_dirs (first_time)
** Execute deploy:check:linked_dirs
INFO [73e686bc] Running mkdir -pv /home/christian/myapp/shared/public/assets on 10.8.0.6
DEBUG [73e686bc] Command: ( RVM_BIN_PATH=~/.rvm/bin mkdir -pv /home/christian/myapp/shared/public/assets )
INFO [73e686bc] Finished in 9.786 seconds with exit status 0 (successful).
** Invoke deploy:check:make_linked_dirs (first_time)
** Execute deploy:check:make_linked_dirs
** Invoke deploy:check:linked_files (first_time)
** Execute deploy:check:linked_files
** Invoke rvm:hook (first_time)
** Execute rvm:hook
** Invoke rvm:init (first_time)
** Execute rvm:init
DEBUG [231d29b3] Running [ -d /usr/local/rvm ] on 10.8.0.6
DEBUG [231d29b3] Command: [ -d /usr/local/rvm ]
DEBUG [231d29b3] Finished in 9.582 seconds with exit status 1 (failed).
DEBUG [79c577f5] Running ~/.rvm/bin/rvm current on 10.8.0.6
DEBUG [79c577f5] Command: ( RVM_BIN_PATH=~/.rvm/bin ~/.rvm/bin/rvm current )
DEBUG [79c577f5] ruby-1.9.3-p484
DEBUG [79c577f5]
DEBUG [79c577f5] Finished in 4.797 seconds with exit status 0 (successful).
** Invoke deploy:started (first_time)
** Execute deploy:started
** Invoke deploy:updating (first_time)
** Invoke deploy:new_release_path (first_time)
** Execute deploy:new_release_path
** Execute deploy:updating
** Invoke git:create_release (first_time)
** Invoke git:update (first_time)
** Invoke git:clone (first_time)
** Invoke git:wrapper
** Execute git:clone
DEBUG [c697d981] Running [ -f /home/christian/myapp/repo/HEAD ] on 10.8.0.6
DEBUG [c697d981] Command: [ -f /home/christian/myapp/repo/HEAD ]
DEBUG [c697d981] Finished in 9.655 seconds with exit status 0 (successful).
INFO The repository mirror is at /home/christian/myapp/repo
** Execute git:update
DEBUG [8ac891bd] Running if test ! -d /home/christian/myapp/repo; then echo "Directory does not exist '/home/christian/myapp/repo'" 1>&2; false; fi on 10.8.0.6
DEBUG [8ac891bd] Command: if test ! -d /home/christian/myapp/repo; then echo "Directory does not exist '/home/christian/myapp/repo'" 1>&2; false; fi
DEBUG [8ac891bd] Finished in 10.501 seconds with exit status 0 (successful).
INFO [c14a8130] Running git remote update on 10.8.0.6
DEBUG [c14a8130] Command: cd /home/christian/myapp/repo && ( RVM_BIN_PATH=~/.rvm/bin git remote update )
DEBUG [c14a8130] Fetching origin
DEBUG [c14a8130]
DEBUG [c14a8130] ssh: connect to host bitbucket.org port 22: Connection timed out
DEBUG [c14a8130] fatal: The remote end hung up unexpectedly
DEBUG [c14a8130]
DEBUG [c14a8130] error: Could not fetch origin
DEBUG [c14a8130]
cap aborted!
git stdout: Nothing written
git stderr: Nothing written
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/command.rb:94:in `exit_status='
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:125:in `block (4 levels) in _execute'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `call'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:551:in `do_request'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:561:in `channel_request'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:269:in `wait'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:147:in `block (2 levels) in _execute'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `call'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:205:in `process'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh/connection/session.rb:169:in `loop'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:149:in `block in _execute'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:106:in `tap'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:106:in `_execute'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:54:in `execute'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/capistrano-3.0.1/lib/capistrano/tasks/git.rake:48:in `block (4 levels) in <top (required)>'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/abstract.rb:81:in `within'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/capistrano-3.0.1/lib/capistrano/tasks/git.rake:47:in `block (3 levels) in <top (required)>'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:42:in `instance_exec'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:42:in `run'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => git:create_release => git:update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment