Good day! I'll try to be very specific with this. I'm sorry, but I've had experience a lot of troubles while trying to deploy my application. I'm totally new at rails, so I followed the Agile Web Development with Rails 4th Edition and I'm trapped on the segment of deploy with capistrano I've tried the exact code on the book, didn't work, and take some advices from this and others forums that prove to be helpful, but I'm still can't deploy correctly my deploy.rb goes like this:
require 'bundler/capistrano'
set :user, 'user_created_for_this_example'
set :domain, 'IPADDRESS'
set :application, 'depot'
# file paths
set :repository, "#{user}##{domain}:depot.git"
set :deploy_to, "/home/#{user}/#{domain}"
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess
based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
#roles server
role :web, domain
role :app, domain
role :db, domain, :primary => true
#deploy config
set :deploy_to, "/home/#{user}/#{domain}"
set :deploy_via, :copy
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
after "deploy:update_code", :bundle_install
desc "install the necesary prerequisites"
task :bundle_install, :roles => :app do
run "cd #{release_path} && bundle install"
end
When i run the cap deploy:setup and cap deploy:check all seems to be working fine:
~/rails_projects/depot$ cap deploy:setup
* 2012-11-13 10:37:35 executing `deploy:setup'
* executing "mkdir -p /home/git/xx.xx.xx.xx /home/git/xx.xx.xx.xx/releases /home/git
/xx.xx.xx.xx/shared /home/git/xx.xx.xx.xx/shared/system /home/git/xx.xx.xx.xx/shared/log
/home/git/xx.xx.xx.xx/shared/pids"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 158ms
* executing "chmod g+w /home/git/xx.xx.xx.xx /home/git/xx.xx.xx.xx/releases /home/git/xx.xx.xx.xx/shared /home/git/xx.xx.xx.xx/shared/system /home/git/xx.xx.xx.xx/shared/log /home/git/xx.xx.xx.xx/shared/pids"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 7ms
~/rails_projects/depot$ cap deploy:check
* 2012-11-13 10:37:39 executing `deploy:check'
* executing "test -d /home/git/xx.xx.xx.xx/releases"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 152ms
* executing "test -w /home/git/xx.xx.xx.xx"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 5ms
* executing "test -w /home/git/xx.xx.xx.xx/releases"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 5ms
* executing "which tar"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 6ms
You appear to have all necessary dependencies installed
But when the cap deploy:migrations, cap deploy or cap deploy:cold command comes the next pops up:
~/rails_projects/depot$ cap deploy:migrations
* 2012-11-13 10:37:42 executing `deploy:migrations'
* 2012-11-13 10:37:42 executing `deploy:update_code'
executing locally: "git ls-remote git#xx.xx.xx.xx:depot.git master"
command finished in 241ms
* getting (via checkout) revision c3f88ca97e5868dd476f20e9a044b7dad800274a to /tmp/20121113173743
executing locally: git clone git#xx.xx.xx.xx:depot.git /tmp/20121113173743 && cd /tmp/20121113173743 && git checkout -b deploy c3f8
8ca97e5868dd476f20e9a044b7dad800274a
Cloning into '/tmp/20121113173743'...
remote: Counting objects: 392, done.
remote: Compressing objects: 100% (257/257), done.
remote: Total 392 (delta 111), reused 392 (delta 111)
Receiving objects: 100% (392/392), 8.59 MiB, done.
Resolving deltas: 100% (111/111), done.
Switched to a new branch 'deploy'
command finished in 769ms
* Compressing /tmp/20121113173743 to /tmp/20121113173743.tar.gz
executing locally: tar czf 20121113173743.tar.gz 20121113173743
command finished in 652ms
servers: ["xx.xx.xx.xx"]
** sftp upload /tmp/20121113173743.tar.gz -> /tmp/20121113173743.tar.gz
[xx.xx.xx.xx] /tmp/20121113173743.tar.gz
*** upload via sftp failed on xx.xx.xx.xx: Net::SFTP::StatusException
(Net::SFTP::StatusException open /tmp/20121113173743.tar.gz (3, "permission denied"))
upload via sftp failed on xx.xx.xx.xx: Net::SFTP::StatusException (Net::SFTP::StatusException open /tmp/20121113173743.tar.gz (3, "permission denied"))
I'm sorry if this is some dummy issue, an easy-fix or an already posted one, but I don't know what else to try, again I'm just starting with this stuff and I'm truly lost. I'm running all from the same machine and all the xx.xx.xx.xx stands for my ip address. Any suggestions will be really appreciated. I've tried to be specific as possible, but if something is missing I'll post it. Thanks beforehand for your time and help.
Your problem here is that your source and destination locations for sftp are the same:
** sftp upload /tmp/20121113173743.tar.gz -> /tmp/20121113173743.tar.gz
in order to fix the issue you may specify parameter copy_dir in your config/deploy.rb file, something like this:
set :copy_dir, "/tmp/sftp"
no need to create that folder manually then.
Try adding this line to your deploy.rb configuration file:
default_run_options[:pty] = true
We changed the Capfile from
set :deploy_via, :copy
to
set :deploy_via, :remote_cache
and this worked for us. We did not add the below line
default_run_options[:pty] = true
Related
When trying to deploy a Rails app to a production server with Capistrano, it doesn't seem to recognize my project as being a git repo, despite me having cloned the project directly from GitHub.
THE GIT LOG:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
CAP LOG:
$ cap production deploy
triggering load callbacks
* 2016-06-01 16:30:26 executing `production'
triggering start callbacks for `deploy'
* 2016-06-01 16:30:26 executing `multistage:ensure'
* 2016-06-01 16:30:26 executing `deploy'
* 2016-06-01 16:30:26 executing `deploy:update'
** transaction: start
* 2016-06-01 16:30:26 executing `deploy:update_code'
executing locally: "git ls-remote git#github.com:mitigation/mpm.git r1"
command finished in 662ms
* refreshing local cache to revision 8c86d067abde1464f88902566324a99e22cd3147 at /var/folders/xs/5qz1glwj30v51rwpxhyclw880000gn/T/mpm
executing locally: cd /var/folders/xs/5qz1glwj30v51rwpxhyclw880000gn/T/mpm && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 8c86d067abde1464f88902566324a99e22cd3147 && git clean -q -d -x -f
fatal: Not a git repository (or any of the parent directories): .git
command finished in 13ms
shell command failed with return code pid 52560 exit 128
Here's my Capfile:
load 'deploy'
load 'deploy/assets'
load 'config/deploy'
Here's my DEPLOY.RB:
require 'soprano'
require 'bundler/capistrano'
require 'capistrano/ext/multistage'
require 'whenever/capistrano'
require 'leipreachan/capistrano2'
set :default_environment, {
'PATH' => '/home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:$PATH'
}
set :web_server, :nginx
set :keep_releases, 3
set :repository, 'git#github.com:mitigation/mpm.git'
set :deploy_via, :copy
set :copy_exclude, %w(.git .idea .yardoc tmp log .DS_Store doc/* public/uploads.tar db/*.sql vendor/cache)
set :copy_cache, true
set :bundle_without, [:development, :test]
set :bundle_flags, '--deployment --binstubs'
set :user, 'deploy'
before 'deploy:setup', :db
after 'deploy:create_symlink', 'utils:version'
after 'deploy:update_code', 'db:symlink'
#For troubleshooting only
namespace :deploy do
task :update_code, :except => { :no_release => true } do
#on_rollback { run "rm -rf #{release_path}; true" }
strategy.deploy!
finalize_update
end
end
During deploys to various environments, capistrano3 creates a directory tree and puts the git information in a folder called repo_path. You'd have to travel inside that directory on your production server and "$git log" would work indicated its a .git repo
You also shouldn't need .git in your copy_exclude.
Try running through the capistrano3 set up process all over again with your app for different environments.
I'm using the Capistrano gem and this tutorial to deploy my application to my remote server. Everything works fine until the end of the cap deploy command. I'm receiving this error:
** [ps123456.dreamhostps.com :: out] sh: myapp.git/releases/20130916201449/REVISION: No such file or directory
command finished in 2266ms
*** [deploy:update_code] rolling back
* executing "rm -rf myapp.git/releases/20130916201449; true"
servers: ["ps123456.dreamhostps.com"]
[ps123456.dreamhostps.com] executing command
command finished in 254ms
failed: "sh -c 'git clone --depth 1 ssh://username#ps123456.dreamhostps.com/~/myapp.git myapp.git/releases/20130916201449 && cd myapp.git/releases/20130916201449 && git checkout -b deploy 497af4d996358f8d1f42dc9658e276ee8d9fa64f && git submodule init && git submodule sync && export GIT_RECURSIVE=$([ ! \"`git --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && git submodule update --init $GIT_RECURSIVE && rm -Rf myapp.git/releases/20130916201449/.git && (echo 497af4d996358f8d1f42dc9658e276ee8d9fa64f > myapp.git/releases/20130916201449/REVISION)'" on ps123456.dreamhostps.com
Here is my deploy.rb:
require 'bundler/capistrano'
set :user, 'username'
set :domain, 'ps123456.dreamhostps.com'
set :applicationdir, "myapp.git"
default_run_options[:pty] = true
set :scm, 'git'
set :repository, "ssh://username#ps123456.dreamhostps.com/~/myapp.git"
set :git_enable_submodules, 1 # if you have vendored rails
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
# roles (servers)
role :web, domain
role :app, domain
role :db, domain, :primary => true
# deploy config
set :deploy_to, applicationdir
set :deploy_via, :export
# additional settings
default_run_options[:pty] = true # Forgo errors when deploying from windows
# Passenger
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
What is going wrong?
It's hard to say exactly, but it's clear that your releases/#{revision} dir is missing by the time you try to push the git revision into the file REVISION.
One likely issue that should probably get fixed is your :deploy_to dir is the same directory on the same machine as the git repo you are cloning from. Try this instead:
In your deploy.rb
set :deploy_to, "/home/#{user}/app/#{application}"
Then make sure to run this the first time:
cap deploy:setup
Then feel free to:
cap deploy
After a lot of head scratching, oddly enough, it was cap deploy:setup that was my downfall. I am still unsure as to what was going on, but I have thoroughly tested and verified that deleting the deployment directory and redeploying the application without running cap deploy:setup will work.
For some reason, running cap deploy:setup, even after successful deploys, will cause permission errors and causes cap deploy to be unable to create and write to directories.
I'm trying to deploy with Capistrano and RVM and even though when running cap bundler:install_bundler which is supposed to install bundler, and succeeds. After, when running cap deploy it fails with an error that bundler is not installed.
** [out :: victorstan.com] ERROR: Gem bundler is not installed, run `gem install bundler` first.
Any ideas why it installs bundler, but then can't find it, or installs it in the wrong place (i guess?). Thanks!
here is part of my deploy.rb script:
set :application, "dinner"
set :domain, "victorstan.com"
set :repository, "ssh://#{domain}/~/#{application}.git"
set :use_sudo, false
set :user, "victorstan" # The server's user for deploys
set :scm, :git
set :scm_username, "passenger"
set :deploy_to, "/srv/www/#{application}"
set :keep_releases, 2
set :branch, "master"
set :deploy_via, :copy # won't make cap prompt for password when deploying
set :scm_verbose, true
set :rvm_ruby_string, 'ruby-2.0.0-p195#dinner'
set :rvm_type, :user
set :rvm_install_type, :stable
set :whenever_command, "bundle exec whenever"
require "bundler/capistrano"
require "rvm/capistrano"
require "whenever/capistrano"
If I try to use cap to install bundler, it works:
cap bundler:install_bundler
* 2013-06-08 15:33:54 executing `bundler:install_bundler'
* executing "gem install bundler"
servers: ["victorstan.com"]
[victorstan.com] executing command
** [out :: victorstan.com] Successfully installed bundler-1.3.5
** [out :: victorstan.com] 1 gem installed
command finished in 1373ms
And here is the output when running cap deploy:
Switched to a new branch 'deploy'
command finished in 984ms
* Compressing /var/folders/w4/_6g_9lqd491_6cmhzb0kcmzh0000gn/T/20130608192600 to /var/folders/w4/_6g_9lqd491_6cmhzb0kcmzh0000gn/T/20130608192600.tar.gz
executing locally: tar czf 20130608192600.tar.gz 20130608192600
command finished in 53ms
servers: ["victorstan.com"]
** sftp upload /var/folders/w4/_6g_9lqd491_6cmhzb0kcmzh0000gn/T/20130608192600.tar.gz -> /tmp/20130608192600.tar.gz
[victorstan.com] /tmp/20130608192600.tar.gz
[victorstan.com] done
* sftp upload complete
* executing "cd /srv/www/dinner/releases && tar xzf /tmp/20130608192600.tar.gz && rm /tmp/20130608192600.tar.gz"
servers: ["victorstan.com"]
[victorstan.com] executing command
command finished in 467ms
* 2013-06-08 15:26:05 executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* 2013-06-08 15:26:05 executing `bundle:install'
* executing "cd /srv/www/dinner/releases/20130608192600 && bundle install --gemfile /srv/www/dinner/releases/20130608192600/Gemfile --path /srv/www/dinner/shared/bundle --deployment --quiet --without development test"
servers: ["victorstan.com"]
[victorstan.com] executing command
** [out :: victorstan.com] ERROR: Gem bundler is not installed, run `gem install bundler` first.
command finished in 598ms
*** [deploy:update_code] rolling back
* executing "rm -rf /srv/www/dinner/releases/20130608192600; true"
servers: ["victorstan.com"]
[victorstan.com] executing command
command finished in 513ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-2.0.0-p195#dinner' -c 'cd /srv/www/dinner/releases/20130608192600 && bundle install --gemfile /srv/www/dinner/releases/20130608192600/Gemfile --path /srv/www/dinner/shared/bundle --deployment --quiet --without development test'" on victorstan.com
is ruby-2.0.0-p195#dinner installed / created on the server?
you can ensure it is with adding:
before 'deploy:setup', 'rvm:install_ruby'
more details on using rvm-capistrano can be found here: https://github.com/wayneeseguin/rvm-capistrano#readme
I have read some more examples on setting up deploy script and i've re-arranged the order of elements of my deploy script, as well as ena
set :application, "dinner"
set :domain, "victorstan.com"
set :repository, "ssh://#{domain}/~/#{application}.git"
set :use_sudo, false
set :user, "victorstan" # The server's user for deploys
set :scm, :git
set :scm_username, "passenger"
set :scm_passphrase, "*********" # The deploy user's password
set :deploy_to, "/srv/www/#{application}"
set :keep_releases, 2
set :branch, "master"
set :deploy_via, :copy # won't make cap prompt for password when deploying
set :scm_verbose, true
set :rvm_ruby_string, :local
set :rvm_type, :user
set :rvm_install_type, :stable
set :default_shell, :bash
set :whenever_command, "bundle exec whenever"
default_run_options[:pty] = true
# before 'deploy', 'rvm:install_ruby'
before 'deploy:setup', 'rvm:install_ruby'
require "rvm/capistrano"
require "bundler/capistrano"
require "whenever/capistrano"
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true # This is where Rails migrations will run
Some notable elements that have changed:
set :rvm_ruby_string set to :local instead of explicitly naming it: 'ruby-2.0.0-p195#dinner', not sure if this has any implication on the issue though, seems unlikely.
set :default_shell, :bash was another parameter I added.
And, as I mentioned, the ordering or the different DSL types might make a difference: set comes first, then before hooks, then require and then role after which comes the rest of the deploy script. Perhaps this can help someone in a similar situation.
Note, when I first tested this script I had before 'deploy', 'rvm:install_ruby' enabled, but I have since disabled it and the script continues to work...
I've been using Capistrano to deploy for a while, but always with the SVN repository on a different machine from the production host I'm deploying to.
Now I have a situation where the repository and the production machine are the same. Here is my deploy.rb file...
set :application, 'my_app'
set :repository, "file:///home/ethan/svn/my_app/trunk"
set :deploy_to, "/var/www/#{application}"
set :use_sudo, false
role :app, 'ethan#my_production_host.com'
namespace :deploy do
task :start, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
end
Here's what Capistrano returns when I try to deploy (I'm running this command on my development machine)...
$ cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "svn info file:///home/ethan/svn/my_app/trunk -rHEAD"
svn: Unable to open an ra_local session to URL
svn: Unable to open repository 'file:///home/ethan/svn/my_app/trunk'
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/my_app/releases/20110919111200; true"
servers: ["my_production_host.com"]
[ethan#my_production_host.com] executing command
command finished
Command svn info file:///home/ethan/svn/my_app/trunk -rHEAD returned status code 256
Any suggestions?
You will have to use the local_repository option as is documented here: https://github.com/capistrano/capistrano/wiki/2.x-Significant-Configuration-Variables.
I am trying to deploy my rails application for the first time.
Server is running Ubuntu 10.4 server (64bit)
Local machine is running Windows XP.
Repository is at github
I have successfully run
cap deploy:setup
but when I run
cap deploy:cold
I get the following error:
D:\Rails\rails_apps\fx>cap deploy:cold
You are running Ruby 1.8.6, which has a bug in its threading implementation.
You are liable to encounter deadlocks running Capistrano, unless you install
the fastthread library, which is available as a gem:
gem install fastthread
* executing `deploy:cold'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/fx/releases/20100818215651; true"
servers: ["pragmaticriskmanagement.gotdns.com"]
[pragmaticriskmanagement.gotdns.com] executing command
command finished
D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy.rb:37:in ``': No such file or directory - git rev-parse master (Errno::ENOENT)
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy.rb:37:in `load'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy.rb:87:in `with_env'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy.rb:37:in `load'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistran/recipes/deploy/scm/git.rb:154:in `query_revision'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy/scm/base.rb:35:in `send'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy/scm/base.rb:35:in `method_missing'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy/scm/base.rb:63:in `local'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy/scm/base.rb:35:in `method_missing'
... 39 levels...
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/cli/execute.rb:14:in `execute'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/bin/cap:4
from D:/Rails/ruby/bin/cap:19:in `load'
from D:/Rails/ruby/bin/cap:19
Here is my 'deploy.rb' file
set :application, "fx" #"pragmaticriskmanagement.gotdns.com"
set :repository, "git#github.com:jmedding/Fx.git"
set :deploy_to, "/var/www/#{application}"
set :git_enable_submodules, 1 # Make sure git submodules are populated
set :location, "pragmaticriskmanagement.gotdns.com"
set :user, "xxxxx"
set :use_sudo, false
set :scm, :git
role :app, location #"your app-server here"
role :web, location #"your web-server here"
role :db, location, :primary => true #"your db-server here", :primary => true
namespace :deploy do
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
desc "Make symlink for database.yml"
task :symlink_dbyaml do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
desc "Create empty database.yml in shared path"
task :create_dbyaml do
run "mkdir -p #{shared_path}/config"
put '', "#{shared_path}/config/database.yml"
end
end
after 'deploy:setup', 'deploy:create_dbyaml'
after 'deploy:update_code', 'deploy:symlink_dbyaml'
after "deploy", "deploy:cleanup"
and now I'm stuck...
Any help would be greatly appreciated.
Thanks,
Jon
Sorry to resurrect such an old thread, but I solved this by adding the default location of my git binaries (C:\Program Files (x86)\Git\bin) to my PATH variable.
Ok, I have made some progress.
It seems that the error indicates that the git ls-remote command could not be found on the local system (win xp). As a test, I opened the GIT Bash shell and tried the command - it worked. Next, I tried
cap deploy
from the GIT Bash shell. Command not found. OK, I added my rails path
D:\Rails\ruby\bin
to the windows 'path' variable. Now, try
cap deploy
from the bash shell. This seems to have solved this problem, which now leads to my next problem
** [xxxxxxxx.com :: out] Cloning into /var/www/fx/shared/cached-copy...
** [xxxxxxxx.com :: err] Permission denied (publickey).
** [xxxxxxxx.com :: err] fatal: The remote end hung up unexpectedly
I can successfully run cap deploy from my linux box with the same public key. Also, I can push to my Github repo from this laptop with this key. Of course, the key in question should be on the server, but if it works when I run 'cap' from the linux box, why wouldn't it run from here?