I want to deploy a local application to a production server with Capistrano. However something fails and I don't know how to fix it. The good news is that the /shared/cached-copy is fully created on the remote server. How can I fix the rsync error?
cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git#bitbucket.org:foo/bar.git HEAD"
* executing "if [ -d /path/foo/shared/cached-copy ]; then cd /path/foo/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e216d5f840f3d78458a3734a3830a4030750c85c && git clean -q -d -x -f; else git clone -q git#bitbucket.org:foo/bar.git /path/foo/shared/cached-copy && cd /path/foo/shared/cached-copy && git checkout -q -b deploy e216d5f840f3d78458a3734a3830a4030750c85c; fi"
servers: ["foo.com"]
[foo.com] executing command
command finished in 33589ms
copying the cached version to /path/foo/releases/20120204063129
* executing "rsync -lrpt --exclude=\".git\" --exclude=\".DS_Store\" --exclude=\".gitignore\" --exclude=\".gitmodules\" /path/foo/shared/cached-copy/ /path/foo/releases/20120204063129 && (echo e216d5f840f3d78458a3734a3830a4030750c85c > /path/foo/releases/20120204063129/REVISION)"
servers: ["foo.com"]
[foo.com] executing command
*** [err :: foo.com] rsync: mkdir "/path/foo/releases/20120204063129" failed: No such file or directory (2)
*** [err :: foo.com] rsync error: error in file IO (code 11) at main.c(587) [Receiver=3.0.8]
*** [err :: foo.com] rsync: connection unexpectedly closed (9 bytes received so far) [sender]
*** [err :: foo.com] rsync error: error in rsync protocol data stream (code 12) at io.c(601) [sender=3.0.8]
command finished in 899ms
*** [deploy:update_code] rolling back
* executing "rm -rf /path/foo/releases/20120204063129; true"
servers: ["foo.com"]
[foo.com] executing command
command finished in 841ms
failed: "sh -c 'rsync -lrpt --exclude=\".git\" --exclude=\".DS_Store\" --exclude=\".gitignore\" --exclude=\".gitmodules\" /path/foo/shared/cached-copy/ /path/foo/releases/20120204063129 && (echo e216d5f840f3d78458a3734a3830a4030750c85c > /path/foo/releases/20120204063129/REVISION)'" on foo.com
My deploy.rb file:
set :application, "FooBar"
set :repository, "git#bitbucket.org:foo/bar.git"
set :scm, :git
set :deploy_to, "/path/foo"
set :deploy_via, :remote_cache
set :copy_exclude, [".git", ".DS_Store", ".gitignore", ".gitmodules"]
set :user, "foobar"
server "foobar.tdl", :app
ssh_options[:forward_agent] = true
It looks like your first error is:
*** [err :: foo.com] rsync: mkdir "/path/foo/releases/20120204063129" failed: No such file or directory (2)
Does your /path/foo/releases directory already exist on the server? Try creating it.
Related
I get the following when I try to deploy to server using capistrano gem from my local machine(MAC) {Rails app}. I am new to rails
user-mbp:xp user$ cap staging deploy
Server password:
********
DEBUG [c6110f69] Running /usr/bin/env [ -d ~/.rbenv ] as deployer#server.com
DEBUG [c6110f69] Command: [ -d ~/.rbenv ]
DEBUG [c6110f69] Finished in 6.956 seconds with exit status 0 (successful).
INFO [e385c416] Running /usr/bin/env mkdir -p /tmp/pepe/ as deployer#server.com
DEBUG [e385c416] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 /usr/bin/env mkdir -p /tmp/pepe/ )
INFO [e385c416] Finished in 0.098 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/pepe/git-ssh.sh 0.0%
INFO Uploading /tmp/pepe/git-ssh.sh 100.0%
INFO [191046c4] Running /usr/bin/env chmod +x /tmp/pepe/git-ssh.sh as deployer#server.com
DEBUG [191046c4] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 /usr/bin/env chmod +x /tmp/pepe/git-ssh.sh )`enter code here`
INFO [191046c4] Finished in 0.119 seconds with exit status 0 (successful).
INFO [bd99c2fc] Running /usr/bin/env git ls-remote --heads ssh://git#git.xxx.xx.com/xp.git as deployer#server.com
DEBUG [bd99c2fc] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.0.0-p353 GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/pepe/git-ssh.sh /usr/bin/env git ls-remote --heads ssh://git#git.xxx.xx.com/xp.git )
DEBUG [bd99c2fc] Permission denied (publickey,password).
DEBUG [bd99c2fc] fatal: The remote end hung up unexpectedly
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deployer#server.com: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly
SSHKit::Command::Failed: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly
I tried git:check, but still showing the same.
Tasks: TOP => git:check
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deployer#server.com: git exit status: 128
git stdout: Nothing written
git stderr: Permission denied (publickey,password).
fatal: The remote end hung up unexpectedly
Staging.rb
# *************************************************************** #
require 'highline'
set :stage, :staging
set :password, HighLine.new.ask('Server password:') { |q| q.echo = '*'}
server 'xx.x.com', user: 'deployer', password: fetch(:password), roles: %w{web app db}, primary: true
set :test_url, 'https://xx.x.com'
set :version, `git describe --always`
# you can set custom ssh options
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
# and/or per server
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
# setting per server overrides global ssh_options
# fetch(:default_env).merge!(rails_env: :staging)
There are two possible solutions
Copy your private key to your deployment machine
As you can push to Github (this is what I understand) you have a private key on your development machine and the corresponding public key on Github. You can copy your private key onto your deployment machine to get rid of the error
develeopment-machine$ scp ~/.ssh/id-rsa.pub deployment-machine:key
Then ssh to your deployment machine and do
deployment-machine$ mv ~/.ssh/id-rsa.pub ~/.ssh/id-rsa.old
deployment-machine$ mv ~/key ~/.ssh/id-rsa.pub
Create a key on your deployment machine and add public key to Github
There is a easy to follow explanation how to do that at Github Help
Hope this helps.
Links to projects using Capistrano
If you are on Rails 3:
capfile
deploy.rb
environments
development notebook
If you are on Rails 4:
capfile
deploy.rb
environments
development notebook
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I am trying to deploy application to Amazon EC2 with capistrano.
When I run cap deploy:cold or cap deploy I get:
* 2014-08-27 13:23:39 executing `deploy:cold'
* 2014-08-27 13:23:39 executing `deploy:update'
** transaction: start
* 2014-08-27 13:23:39 executing `deploy:update_code'
executing locally: "git ls-remote git#bitbucket.org:username/repository.git HEAD"
command finished in 1929ms
* executing "git clone -q git#bitbucket.org:username/repository.git /var/www/repository/releases/20140827112340 && cd /var/www/repository/releases/20140827112340 && git checkout -q -b deploy 813ea45938eca0ee8bae9663d66592b917ecf4fb && (echo 813ea45938eca0ee8bae9663d66592b917ecf4fb > /var/www/repository/releases/20140827112340/REVISION)"
servers: ["54.XX.XX.XX"]
[54.XX.XX.XX] executing command
** [54.XX.XX.XX :: err] Permission denied (publickey).
** [54.XX.XX.XX :: err] fatal: Could not read from remote repository.
**
** Please make sure you have the correct access rights
** and the repository exists.
command finished in 505ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/repository/releases/20140827112340; true"
servers: ["54.XX.XX.XX"]
[54.XX.XX.XX] executing command
command finished in 246ms
failed: "sh -c 'git clone -q git#bitbucket.org:username/repository.git /var/www/repository/releases/20140827112340 && cd /var/www/repository/releases/20140827112340 && git checkout -q -b deploy 813ea45938eca0ee8bae9663d66592b917ecf4fb && (echo 813ea45938eca0ee8bae9663d66592b917ecf4fb > /var/www/repository/releases/20140827112340/REVISION)'" on 54.XX.XX.XX
My deploy.rb file:
set :application, "appname"
set :scm, :git
set :repository, "git#bitbucket.org:username/repository.git"
set :user, "ubuntu"
set :deploy_to, "/var/www/repository"
server "54.XX.XX.XX", :app, :primary => true
I have been following this tutorial.
I added SSH key on remote and placed it at in git account ssh-keys.
I have write access to this repository.
How to fix that?
Thanks
I'm using Rails 3.2 with Capistrano 2.x, and I've got a deploy script setup. All was working fine until a few days ago. I noticed however, that our new code was not actually getting used on production. It's definitely been merged into the correct branches on the project's github. And, in the output of the cap:deploy, I even see it trying to checkout the correct sha reference for the latest commit. However, the files never actually update. My deploy script is below, as well as some output from running cap:deploy.
Deploy Script
require "bundler/capistrano"
# General
set :application, "foo"
set :domain, "foo.com"
set :user, "deploy"
set :runner, "deploy"
set :use_sudo, false
set :deploy_to, "/var/www/#{application}"
set :release_path, "/var/www/#{application}/current"
set :repository_cache, "#{application}_cache"
set :environment, "production"
# Roles
role :web, domain
role :app, domain
role :db, domain, :primary => true
# GIT
set :repository, "git#github.com:foo/bar.git"
set :branch, "release"
set :keep_releases, 3
set :deploy_via, :remote_cache
set :scm, :git
# SSH
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
ssh_options[:paranoid] = true # comment out if it gives you trouble. newest net/ssh needs this set.
######## Callbacks - No More Config ########
before "deploy", "deploy:backup_db"
before "deploy", "deploy:copy_ck_editor_assets"
after 'deploy:create_symlink', 'deploy:cleanup' # makes sure there's only 3 deployments, deletes the extras
after "deploy", "deploy:migrate"
after "deploy", "deploy:put_back_ck_editor_assets"
# Custom Tasks
namespace :deploy do
task(:start) {}
task(:stop) {}
desc "Restart Application"
task :restart, :roles => :web, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
desc "Back up db"
task :backup_db do
puts "Backing up the database"
run "cd #{release_path}; RAILS_ENV=production bundle exec rake db:data:backup"
puts "Backed up DB"
end
desc "Copy CK Editor assets"
task :copy_ck_editor_assets do
puts "copying assets"
run "cd #{release_path}; cp -R public/ckeditor_assets/ ~"
end
desc "Putting CK Editor assets back"
task :put_back_ck_editor_assets do
puts "putting assets back"
run "cd #{release_path}; cp -R ~/ckeditor_assets public/"
end
end
And I believe this is the relevant excerpt from the cap:deploy output....
2014-01-09 23:14:11 executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git#github.foo/bar.git release"
command finished in 1841ms
* executing "if [ -d /var/www/bar/shared/bar_cache ]; then cd /var/www/bar/shared/bar_cache && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 4dbce9382fb4e9b532bf26c71a731e35b3970966 && git clean -q -d -x -f; else git clone -q -b release git#github.com:foo/bar.git /var/www/bar/shared/bar_cache && cd /var/www/bar/shared/bar_cache && git checkout -q -b deploy 4dbce9382fb4e9b532bf26c71a731e35b3970966; fi"
servers: ["bar.com"]
[bar.com] executing command
command finished in 3369ms
copying the cached version to /var/www/bar/current
* executing "cp -RPp /var/www/bar/shared/bar_cache /var/www/bar/current && (echo 4dbce9382fb4e9b532bf26c71a731e35b3970966 > /var/www/bar/current/REVISION)"
The sha hash is correct. And no errors are being thrown anywhere in the deploy process. This sha hash definitely has what I want on the git repo. But all I see in my releases folder is older stuff, and my current folder definitely has an old version (like several days old).
Any thoughts here are much appreciated... I'm totally unsure how to go about solving this one, since there aren't really any errors, and it worked only several days ago with no changes on the deploy script.
Also, if it helps... I did do a chmod to 755 of the main app directory (under which the release and current folders live) a few days ago. That was to fix this other issue we were having.
Thanks!!!
I build gitosis server and stage server on the same VPS server. Clone the repository from gitosis in my local machine or stage server are work well. But cap deploy in local machine always ask me input password as below, I have no idea which password is and I try every password all doesn't work.
And I know could copy local repository with deploy_via: copy, but I prefer build a gitosis server for the other projects.
Any ideas? thanks.
environment
gitosis and stage server ip: 106.187.xxx.xxx (mask some number for security reason)
log
* executing `deploy'
triggering before callbacks for `deploy'
* executing `check:revision'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote gitosis#106.187.xxx.xxx:foo_project.git master"
command finished in 1105ms
* executing "if [ -d /home/deployer/apps/railsapp/shared/cached-copy ]; then cd /home/deployer/apps/railsapp/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 07827de89355c5366c4511ee22fdd9c68a31b0be && git clean -q -d -x -f; else git clone -q gitosis#106.187.xxx.xxx:foo_project.git /home/deployer/apps/railsapp/shared/cached-copy && cd /home/deployer/apps/railsapp/shared/cached-copy && git checkout -q -b deploy 07827de89355c5366c4511ee22fdd9c68a31b0be; fi"
servers: ["106.187.xxx.xxx"]
[106.187.xxx.xxx] executing command
** [106.187.xxx.xxx :: out] Password:
Password:
** [106.187.xxx.xxx :: out]
** [106.187.xxx.xxx :: out] Password:
Password:
** [106.187.xxx.xxx :: out]
** [106.187.xxx.xxx :: out] Password:
Password:
** [106.187.xxx.xxx :: out]
** [106.187.xxx.xxx :: out] Permission denied (publickey,keyboard-interactive).
** [106.187.xxx.xxx :: out] fatal: The remote end hung up unexpectedly
deploy.rb
server "106.187.xxx.xxx", :web, :app, :db, primary: true
set :application, "railsapp"
set :user, "deployer"
set :local_user, "joshchang"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :use_sudo, false
set :rails_env, "stage"
set :scm, "git"
set :repository, "gitosis#106.187.xxx.xxx:foo_project.git"
set :deploy_via, :remote_cache
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
Sorry, a little hard to understand the question, but there are two ways to use git within capistrano. The first is to grant the server direct access to the git repository; on GitHub, for example, you have an option to install "deploy keys" -- the public key(s) of the server(s) that need access. So check if gitosis has this option.
But before you do, consider the other approach, which is to pass the git authorization of the user doing the deploy, so when you deploy, you pull as yourself, rather than instructing the server to do so. There are pros and cons to each method, but I think the second method is much easier to manage in the long run.
To use the second method, the machine of the person deploying (running capistrano) needs to 1) have ssh-agent running, and 2) needs to use ssh-add to authorize ssh-agent to use your public key -- it's very secure, and once you have it set up, it's transparent.
When you use the second method, access to git will be the same as it is locally, so shouldn't prompt for password. Otherwise your settings in deploy.rb are fine as is.
Capistrano and Git worked properly till I moved my site to another server. My first attempt to deploy went wrong because of an SSH-known-hosts related problem.
Even if I managed to solve this problem, another one raised and I can't deploy any more:
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote collimarco#mywebsite.com:/home/collimarco/git/foto-fiori.git master"
* executing "if [ -d /home/collimarco/mywebsite.com/shared/cached-copy ]; then cd /home/collimarco/mywebsite.com/shared/cached-copy && git fetch origin && git reset --hard 7de27a6a1de7a94508f943596413e5e0f217f57e; else git clone --depth 1 collimarco#mywebsite.com:/home/collimarco/git/foto-fiori.git /home/collimarco/mywebsite.com/shared/cached-copy && cd /home/collimarco/mywebsite.com/shared/cached-copy && git checkout -b deploy 7de27a6a1de7a94508f943596413e5e0f217f57e; fi"
servers: ["mywebsite.com"]
[mywebsite.com] executing command
** [mywebsite.com :: out] * refusing to create funny ref 'remotes/origin/*' locally
** [mywebsite.com :: out] collimarco#mywebsite.com's password:
Password:
** [mywebsite.com :: out]
** [mywebsite.com :: out] fatal: Needed a single revision
command finished
*** [deploy:update_code] rolling back
* executing "rm -rf /home/collimarco/mywebsite.com/releases/20091027191027; true"
servers: ["mywebsite.com"]
[mywebsite.com] executing command
command finished
failed: "sh -c \"if [ -d /home/collimarco/mywebsite.com/shared/cached-copy ]; then cd /home/collimarco/mywebsite.com/shared/cached-copy && git fetch origin && git reset --hard 7de27a6a1de7a94508f943596413e5e0f217f57e; else git clone --depth 1 collimarco#mywebsite.com:/home/collimarco/git/foto-fiori.git /home/collimarco/mywebsite.com/shared/cached-copy && cd /home/collimarco/mywebsite.com/shared/cached-copy && git checkout -b deploy 7de27a6a1de7a94508f943596413e5e0f217f57e; fi\"" on mywebsite.com
My git repository seems intact: why do I get "Needed a single revision"?
Any suggestion is greatly appreciated.
Thanks in advance!
UPDATE: someone suggested to remove the remote cache, how do I do that?
UPDATE: I have renamed shared/cached-copy into shared/cached-copy-old.
Then I have created a shared/cached-copy empty folder.
Now I get "Not a git repository":
http://pastie.org/672254.txt
Check your git versions on the client and the server; I bet you need to update one of them to 1.6.