2013-06-17 15:23:22 executing `deploy'
* 2013-06-17 15:23:22 executing `deploy:update'
** transaction: start
* 2013-06-17 15:23:22 executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "hg log --verbose -r tip --template \"{node|short}\""
command finished in 74ms
* executing "if [ -d /home/user/shared/cached-copy ]; then hg pull --verbose --repository /home/user/shared/cached-copy ssh://hg#bitbucket.org/user/myapp && hg update --verbose --repository /home/user/shared/cached-copy --clean 70d2fc5e4a40; else hg clone --verbose --noupdate ssh://hg#bitbucket.org/user/myapp /home/user/shared/cached-copy && hg update --verbose --repository /home/user/shared/cached-copy --clean 70d2fc5e4a40; fi"
[192.168.1.204] executing command
** [192.168.1.204 :: out] running ssh hg#bitbucket.org 'hg -R user/myapp serve --stdio'
** [192.168.1.204 :: out] pulling from ssh://hg#bitbucket.org/user/myapp ** [192.168.1.204 :: out] searching for changes
** no changes found
** [192.168.1.204 :: out] remote: Warning: Permanently added the RSA host key for IP address '207.223.240.182' to the list of known hosts.
** [192.168.1.204 :: out] abort: unknown revision '70d2fc5e4a40'!
i made a deploy.rb script to deploy a rails application via capistrano the problem is that when i run cap deploy there is something wrong with the cloning process and id on't know what this revision is. this is my deploy.rb :
require "rvm/capistrano"
require "bundler/capistrano"
set :application, "myapp"
set :use_sudo , false
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :rvm_type, :user
set :rvm_install_with_sudo, true
set :rvm_ruby_string, ENV['GEM_HOME'].gsub(/.*\//,"")
set :scm, :mercurial
set :repository, "ssh://hg#bitbucket.org/user/myapp"
set :deploy_to, "/home/user/"
set :user, "user"
set :scm_verbose, true
set :deploy_via, :remote_cache
ssh_options[:forward_agent] = true
can anyone help me?
PS : i forget to tell that my repository has two sub repositories would that be the problem or do i need to set any options for that?
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 want to deploy my project with capistrano. Here is my settings file:
deploy.rb
require "capistrano/ext/multistage"
require "capistrano_colors"
require "bundler/capistrano"
require "rvm/capistrano" # Load RVM"s capistrano plugin.
set :application, "project"
set :copy_exclude, %w(.git .gitignore doc features log spec test tmp Capfile)
#set :shared_children, shared_children + %w(public/uploads)
set :use_sudo, false
set :user, "app"
set :stages, %w(staging production)
namespace :deploy do
task :start, roles: :app, except: { no_release: true } do
run "cd #{current_path} && bundle exec unicorn_rails -c config/unicorn.rb -E #{rails_env} -D"
end
task :stop, roles: :app, except: { no_release: true } do
run "kill -KILL -s QUIT `cat #{shared_path}/pids/unicorn.pid`"
end
task :restart, roles: :app, except: { no_release: true } do
stop
start
end
end
def confirm
puts "\n\e[0;36m#{stage}\e[0m\e[0;31m Do you really deploy? (yes/no) \e[0m\n"
proceed = STDIN.gets rescue nil
exit unless proceed.chomp! == "yes"
end
For the multistage, I have created two files (one by environment):
deploy/production.rb
server "myserver.net", :app, :web, :db, primary: true
set :rails_env, "production"
set :rvm_type, :user
set :rvm_ruby_string, "ruby-2.0.0-p0"
set :scm, :git
set :repository, 'ssh://xxxx#11.111.111.111:54333/~/git-workspace/myproject.git'
set :deploy_via, :remote_cache
confirm
and almost the same for the staging one.
( As you have guessed, I have changed project, server name and port number for security purposes)
I first executed :
bundle exe cap production deploy:check
then :
bundle exe cap production deploy:setup
without any problem, when calling the deploy command (bundle exe cap production deploy), i get the below message :
xxxx-no-MacBook-Air:myproject xxxx$ bundle exe cap deploy
triggering load callbacks
triggering start callbacks for `deploy'
* 2013-10-08 13:43:12 13:43:12 == Currently executing `multistage:ensure'
No stage specified. Please specify one of: staging, production (e.g. `cap staging deploy')
xxxx-no-MacBook-Air: xxxx$ bundle exe cap production deploy
triggering load callbacks
* 2013-10-08 13:43:18 13:43:18 == Currently executing `production'
production Do you really want to deploy? (yes/no)
yes
triggering start callbacks for `deploy'
* 2013-10-08 13:43:20 13:43:20 == Currently executing `multistage:ensure'
* 2013-10-08 13:43:20 13:43:20 == Currently executing `deploy'
* 2013-10-08 13:43:20 13:43:20 == Currently executing `deploy:update'
** transaction: start
* 2013-10-08 13:43:20 13:43:20 == Currently executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote ssh://xxxx#11.111.111.111:54333/~/git-workspace/myproject.git HEAD"
Bonjour xxxx
xxxx#11.111.111.111's password:
command finished in 6010ms
* executing "if [ -d /u/apps/myproject/shared/cached-copy ]; then cd /u/apps/myproject/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e000681dc88244f04ac2e82dd2cf8d94bfa9d930 && git clean -q -d -x -f; else git clone -q ssh://xxxx#11.111.111.111:54333/~/git-workspace/myproject.git /u/apps/myproject/shared/cached-copy && cd /u/apps/myproject/shared/cached-copy && git checkout -q -b deploy e000681dc88244f04ac2e82dd2cf8d94bfa9d930; fi"
servers: ["myserver.net"]
Enter passphrase for /Users/myname/.ssh/id_rsa:
[myserver.net] executing command
** [myserver.net :: out] Bonjour xxxx
** [myserver.net :: out] xxxx#11.111.111.111's password:
Password:
** [myserver.net :: out]
** [myserver.net :: out] Permission denied, please try again.
** xxxx#11.111.111.111's password:
Password:
** [myserver.net :: out]
** [myserver.net :: out] Permission denied, please try again.
** xxxx#11.111.11.111's password:
Password:
** [myserver.net :: out]
** [myserver.net :: out] Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
** [myserver.net :: out] fatal: The remote end hung up unexpectedly
command finished in 36598ms
*** [deploy:update_code] rolling back
* executing "rm -rf /u/apps/myproject/releases/20131008044412; true"
servers: ["myserver.net"]
[myserver.net] executing command
command finished in 1182ms
failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell 'ruby-2.0.0-p0' -c 'if [ -d /u/apps/myserver/shared/cached-copy ]; then cd /u/apps/myserver/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e000681dc88244f04ac2e82dd2cf8d94bfa9d930 && git clean -q -d -x -f; else git clone -q ssh://xxxx#11.111.111.111:54333/~/git-workspace/myproject.git /u/apps/myproject/shared/cached-copy && cd /u/apps/myproject/shared/cached-copy && git checkout -q -b deploy e000681dc88244f04ac2e82dd2cf8d94bfa9d930; fi'" on myserver.net
xxx-no-MacBook-Air:myprojectxxxxx$
I have generated keys (in my local environment) and put the public one in the authorized_keys file (server side).
You seem to have taken a lot of the right steps, so now with this kind of error, you should test the permissions directly:
Ensure that you can ssh from your development machine (where you're running capistrano) to the deployment server as that user. (E.g., that might be something along the lines of ssh deploy#myserver.com.
Once you've made sure that works, then while logged in on the server, as the deployment user, try connecting to the repository server. E.g., something like ssh -T git#github.com as described here.
99% of the time, if you can do these two things successfully, there will be no permissions problems.
I'm trying to deploy my application using Capistrano towards my DigitalOcean server.
This isn't the first time I've configured a RoR server on DigitalOcean with Capistrano deploys that's why I'm confused; I haven't changed anything in my workflow.
Here is my Capistrano configuration file:
require 'bundler/capistrano'
require 'rvm/capistrano'
set :application, "foobar"
set :repository, "git#bitbucket.org:sergiotapia/foobar.git"
set :ping_url, "http://192.168.1.1/"
set :scm, :git
set :scm_verbose, true
default_run_options[:pty] = true
set :user, "sergiotapia" # The user on the VPS server.
set :password, "hunter2"
set :use_sudo, false
set :deploy_to, "/home/sergiotapia/www/#{application}"
set :deploy_via, :remote_cache
set :keep_releases, 1
set :rails_env, "production"
set :migrate_target, :latest
role :web, "192.168.1.1"
role :app, "192.168.1.1"
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, roles: :app, except: { no_release: true } do
run "sudo touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
# Add this to add the `deploy:ping` task:
namespace :deploy do
task :ping do
system "curl --silent #{fetch(:ping_url)}"
end
end
namespace :gems do
task :bundle, :roles => :app do
run "cd #{release_path} && bundle install --without development && rake db:migrate RAILS_ENV=production"
end
end
after "deploy:update_code", "gems:bundle"
# Add this to automatically ping the server after a restart:
after "deploy:restart", "deploy:ping"
When running a cap deploy:setup and cap deploy:check everything comes back green-lighted (working fine).
It fails on the actual cap deploy command.
** [192.168.1.1 :: out] Enter passphrase for key '/home/sergiotapia/.ssh/id_rsa':
Password:
** [192.168.1.1 :: out]
** [192.168.1.1 :: out] Permission denied (publickey).
** [192.168.1.1 :: out]
** [192.168.1.1 :: out] fatal: Could not read from remote repository.
** [192.168.1.1 :: out]
** [192.168.1.1 :: out]
** [192.168.1.1 :: out] Please make sure you have the correct access rights
** [192.168.1.1 :: out]
** [192.168.1.1 :: out] and the repository exists.
** [192.168.1.1 :: out]
I've already added my id_rsa.pub file to BitBucket and also made sure it's added to my SSH agent using the ssh-add -l command.
Even testing out SSH from the remote server works fine:
sergiotapia#tappia:~/www$ ssh -T git#bitbucket.org
logged in as sergiotapia.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
So what gives, why is denying me access to the repository on BitBucket?
Is Capistrano running as a user other than sergiotapia? Would that be the cause of it?
Make sure to add your ssh key to the authentication agent:
ssh-add ~/.ssh/id_rsa
and ensure in deploy.rb
ssh_options[:forward_agent] = true
Edit:
If you are losing the ssh-add configuration on reboots, you should do the following:
As of macOS Sierra 10.12.2 Apple added an ssh_config option called UseKeychain which allows a 'proper' resolution to the problem. Add the following to your ~/.ssh/config file:
Host *
AddKeysToAgent yes
UseKeychain yes
You can setup the SSH agent on the :app server,
Setup keys that do not require a passphrase between the :app server and bitbucket.
Change deploy_via to: :deploy_via, :copy (No need for the deployed server to checkout files, potentially slower though.)
I'm trying to setup my Rails app on Linode and I'm at the stage of trying to get Capistrano setup.
I have a git server setup on the same server as where I'm deploying. I have my SSH keys setup (I think) -- at least I can SSH in no problem.
Both 'cap deploy:setup' and 'cap deploy:check' run without error.
But then when I try to run 'cap deploy:migrations' I get the following:
ray#ray-ThinkPad-SL:~/mini-saler$ cap deploy:migrations
* executing `deploy:migrations'
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git#XX.207.243.215:mini-saler.git master"
command finished in 12446ms
* executing "if [ -d /home/railsu/bianbian.com/shared/cached-copy ]; then cd /home/railsu/bianbian.com/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard 8e8aa8f849a9438851a3767b338ab711d6470299 && git clean -d -x -f; else git clone git#XX.207.243.215:mini-saler.git /home/railsu/bianbian.com/shared/cached-copy && cd /home/railsu/bianbian.com/shared/cached-copy && git checkout -b deploy 8e8aa8f849a9438851a3767b338ab711d6470299; fi"
servers: ["XX.207.243.215"]
[XX.207.243.215] executing command
** [XX.207.243.215 :: out] Cloning into /home/railsu/bianbian.com/shared/cached-copy...
** [XX.207.243.215 :: err] Host key verification failed.
** [XX.207.243.215 :: err] fatal: The remote end hung up unexpectedly
command finished in 2009ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3' -c 'if [ -d /home/railsu/bianbian.com/shared/cached-copy ]; then cd /home/railsu/bianbian.com/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard 8e8aa8f849a9438851a3767b338ab711d6470299 && git clean -d -x -f; else git clone git#XX.207.243.215:mini-saler.git /home/railsu/bianbian.com/shared/cached-copy && cd /home/railsu/bianbian.com/shared/cached-copy && git checkout -b deploy 8e8aa8f849a9438851a3767b338ab711d6470299; fi'" on XX.207.243.215
deploy.rb
set :user, 'railsu'
set :domain, 'XX.207.243.215'
set :application, 'mini-saler'
# adjust if you are using RVM, remove if you are not
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user
# file paths
set :repository, "git##{domain}:mini-saler.git"
set :deploy_to, "/home/railsu/bianbian.com"
# distribute your applications across servers (the instructions below put them
# all on the same server, defined above as 'domain', adjust as necessary)
role :app, domain
role :web, domain
role :db, domain, :primary => true
# miscellaneous options
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
set :rails_env, :production
namespace :deploy do
desc "cause Passenger to initiate a restart"
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
desc "reload the database with seed data"
task :seed do
run "cd #{current_path}; rake db:seed RAILS_ENV=#{rails_env}"
end
end
after "deploy:update_code", :bundle_install
desc "install the necessary prerequisites"
task :bundle_install, :roles => :app do
run "cd #{release_path} && bundle install"
end
I can use ssh to connect my vps.
I don't recall if any git commands are called on cap deploy:setup or cap deploy:check - I don't think there are.
Assuming you're using gitolite, check to make sure that your configuration has your railsu user's public key is in the keydir directory.
Or perhaps agent forwarding is what you want? Deploying with Capistrano can help you there.
I'm deploying using git and capistrano with passenger. I've been banging my head for a few hours trying to make this work, and haven't made much progress. cap deploy:setup works ok, but cap deploy is failing with Permission issues. I tried changing permissions/ownership on my slice, but it's still failing.
require 'bundler/capistrano'
set :user, 'some_user'
set :domain, 'example.com'
set :applicationdir, "/home/some_user/public_html/example"
set :port, 30000
set :scm, 'git'
set :repository, "ssh://git#123.45.678.910:50000/home/git/example"
set :branch, 'master'
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, :remote_cache
# additional settings
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
# 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
results in the following error:
executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote ssh://git#123.45.678.910:50000/home/git/example.com master"
/Users/some_user/.rvm/gems/ruby-1.9.2-p0/gems/capistrano-2.6.0/lib/capistrano/recipes/deploy.rb:104: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
command finished in 78068ms
* executing "if [ -d /home/some_user/public_html/example.com/shared/cached-copy ]; then cd /home/some_user/public_html/example.com/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard c7f73668d0656c665a6445c33870d05a8550ab2c && git clean -d -x -f; else git clone ssh://git#123.45.678.910:50000/home/git/example.com /home/some_user/public_html/example.com/shared/cached-copy && cd /home/some_user/public_html/example.com/shared/cached-copy && git checkout -b deploy c7f73668d0656c665a6445c33870d05a8550ab2c; fi"
servers: ["example.com"]
[example.com] executing command
** [example.com :: out] fatal: could not create work tree dir '/home/some_user/public_html/example.com/shared/cached-copy'.: Permission denied
command finished in 353ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/some_user/public_html/example.com/releases/20110610173027; true"
servers: ["example.com"]
[example.com] executing command
command finished in 218ms
failed: "sh -c 'if [ -d /home/some_user/public_html/example.com/shared/cached-copy ]; then cd /home/some_user/public_html/example.com/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard c7f73668d0656c665a6445c33870d05a8550ab2c && git clean -d -x -f; else git clone ssh://git#123.45.678.910:50000/home/git/example.com /home/some_user/public_html/example.com/shared/cached-copy && cd /home/some_user/public_html/example.com/shared/cached-copy && git checkout -b deploy c7f73668d0656c665a6445c33870d05a8550ab2c; fi'" on example.com
Not sure how much this will help, but I always have a permissions issue after a deploy:setup
When you run deploy:setup it creates the initial directories for you. However those folders it creates are usually owned by root (In most of my situations anyway).
webapp/
shared root:root
releases root:root
To remedy this I will change ownership of those new folders to the user that will be using.
webapp/
shared myuser:myuser
releases myuser:myuser
Once this is done, I'll continue with my deploy:update
I've just encountered this problem as well. Here's what I found out.
If you have not yet been able to deploy successfully, you might want to temporarily move your deploy folder (in your server) to another location (or simply rename it)
Make sure you have this inside your recipe: set :use_sudo, false
Run this again: cap deploy:setup
Then try another run of cap deploy
You will definitely run into other troubles with permissions if you have built your deploy folders using the wrong user and tell capistrano that it has sudo permissions.
I hope this works for you, as it worked for me.