Capistrano deployment from svn failing - ruby-on-rails

I am trying to use capistrano 2 to deploy my app from subversion to a local server. Here is the code I am trying to deploy, it is just the default rails app:
https://www.assembla.com/code/capistranotest/subversion/nodes
Here is the my deploy.rb file which points to my svn repo:
set :application, "CapistranoTest"
set :user, "jack"
set :repository, "https://subversion.assembla.com/svn/capistranotest/"
set :scm, :subversion
set :deploy_to, "/home/jaeren/capistranotest"
role :web, "192.168.169.129"
role :app, "192.168.169.129"
role :db, "192.168.169.129", :primary => true
set :scm_username, "jack"
set :runner, "jack"
set :use_sudo, false
My cap deploy:setup works and creates the necessary folders. However when I run cap deploy:cold and enter my username and password when prompted of my assembla account I get this error. Can anyone tell me why?
Jacks-MacBook-Pro:capistranotest Jack$ cd trunk
Jacks-MacBook-Pro:trunk Jack$ cap deploy:cold
* 2015-04-27 00:31:45 executing `deploy:cold'
* 2015-04-27 00:31:45 executing `deploy:update'
** transaction: start
* 2015-04-27 00:31:45 executing `deploy:update_code'
executing locally: "svn info https://subversion.assembla.com/svn/capistranotest/ --username \"jack\"--password \"\"--no-auth-cache -rHEAD"
Authentication realm: <https://subversion.assembla.com:443> Assembla Restricted Area
Password for 'jack--password': *************************
Authentication realm: <https://subversion.assembla.com:443> Assembla Restricted Area
Username: jack
Password for 'jack': *************************
command finished in 53369ms
* executing "svn checkout -q --username \"jack\"--password \"\"--no-auth-cache -r6 https://subversion.assembla.com/svn/capistranotest/ /home/jack/capistranotest/releases/20150426233238 && (echo 6 > /home/jack/capistranotest/releases/20150426233238/REVISION)"
servers: ["192.168.169.129"]
[192.168.169.129] executing command
** [192.168.169.129 :: err] Authentication realm: <https://subversion.assembla.com:443> Assembla Restricted Area
** [192.168.169.129 :: err] Password for 'jack--password':
Password:
** [192.168.169.129 :: err] Authentication realm: <https://subversion.assembla.com:443> Assembla Restricted Area
** [192.168.169.129 :: err] Username:
--EDIT--
Tried changing to capistrano 2.12.0, it outputs different commands but I still get the same error:
Jaerens-MacBook-Pro:trunk Jaeren$ cap deploy:cold
* executing `deploy:cold'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "svn info https://subversion.assembla.com/svn/capistranotest/ --username jaeren --password --no-auth-cache -rHEAD"
Authentication realm: <https://subversion.assembla.com:443> Assembla Restricted Area
Username: Jaeren
Password for 'Jaeren': ***********
command finished in 8473ms
* executing "svn checkout -q --username jaeren --password --no-auth-cache -r6 https://subversion.assembla.com/svn/capistranotest/ /home/jaeren/capistranotest/releases/20150427001157 && (echo 6 > /home/jaeren/capistranotest/releases/20150427001157/REVISION)"
servers: ["192.168.169.129"]
[192.168.169.129] executing command
** [192.168.169.129 :: err] Authentication realm: <https://subversion.assembla.com:443> Assembla Restricted Area
** [192.168.169.129 :: err] Username:
Thanks.

Looks like it's trying to authenticate as jack--password because there's no space here between the value of username and the --password option that follows it.
executing locally: "svn info https://subversion.assembla.com/svn/capistranotest/ --username \"jack\"--password \"\"--no-auth-cache -rHEAD"
I suspect it's a bug in whatever is executing that command, which might be a built-in to Capistrano. Try upgrading to the latest Capistrano and then if that doesn't fix the issue, file a GitHub issue on the Capistrano project.

Ryan Bigg is correct. There is a bug in the SVN authentication task that Capistrano uses to login to the remote SVN repository.
I'm running Capistrano version 2.15.6 and the path to the file in question is at
capistrano-YOURVERSION/lib/capistrano/recipes/deploy/scm/subversion.rb
Open this file for editing and look for the authentication definition block towards the bottom.
def authentication
username = variable(:scm_username)
return "" unless username
result = %(--username "#{variable(:scm_username)}")
result << %(--password "#{variable(:scm_password)}") unless variable(:scm_auth_cache) || variable(:scm_prefer_prompt)
result << "--no-auth-cache " unless variable(:scm_auth_cache)
result
end
Notice the lack of white space where --password and --no-auth-cache are being concatenated to the result variable. I simply added a space in here
def authentication
username = variable(:scm_username)
return "" unless username
result = %(--username "#{variable(:scm_username)}")
result << %( --password "#{variable(:scm_password)}") unless variable(:scm_auth_cache) || variable(:scm_prefer_prompt)
result << " --no-auth-cache " unless variable(:scm_auth_cache)
result
end
It's possible that the OP isn't being prompted for SVN credentials when checking the repository out as they have saved the password against their SSH user. Capistrano accepts SCM credentials so it doesn't need to prompt the user for them during deployments. The reason why you're seeing a prompt to enter the details because with out the extra white space in the code above, it looks to the server as if Capistrano is trying to authenticate without sending a password.

Related

fatal: could not read Username for 'https://github.com ': No such device or address - rubyonrails - aws

I have a rubyonrails website which function in such a way that when a user signup with his username it create a repo in that username in my github account. It is working flawlessly in heroku. When I switched to amazon web service I initially get
intializing git
sh: git: command not found
sh: line 0: cd: /home/webapp: No such file or directory
I overcome this error by adding a config file in .ebextensions like
commands:
01_mkdir_webapp_dir:
# use the test directive to create the directory
# if the mkdir command fails the rest of this directive is ignored
test: 'mkdir /home/webapp'
command: 'ls -la /home/webapp'
02_chown_webapp_dir:
command: 'chown webapp:webapp /home/webapp'
03_chmod_webapp_dir:
command: 'chmod 700 /home/webapp'
packages:
yum:
git: []
Then I have a new error log like
fatal: could not read Username for 'https://github.com ': No such device or address
As a side note when I run this script locally, and I signed up the site at localhost:3000 terminal prompt me to submit github username and password. Is that normal. Is this is the cause of the error fatal: could not read Username for 'https://github.com ': No such device or address.
But this code works flawlessly in heroku.
Full log is below.
https://drive.google.com/file/d/1yPYsS1ETHhrEoYFWHJxt4y52jHYRkooj/view?usp=sharing
I have these environment set in aws.
https://photos.app.goo.gl/GeQHXdUWUMuixTgNA
Try to create git config file directly
#/home/webapp/.gitconfig
[user]
name = soumjoyel
email = soumjoyel#gmail.com
using this script
files:
"/home/webapp/.gitconfig" :
mode: "000644"
owner: webapp
group: webapp
content: |
[user]
name = soumjoyel
email = soumjoyel#gmail.com

Rails deployment to staging using capistrano generates the following error

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

Amazon EC2, deployment with capistrano, how to? [closed]

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

Capistrano deploy with gitosis and application server at the same server?

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 deploy incomplete

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.

Resources