A branch named 'deploy' already exists - ruby-on-rails

In a capistrano deploy of a Ruby-on-Rails project the deployment fails and aborts with a fatal error. The message is
A branch named 'deploy' already exists.
Of course the branch already exists, because we are trying to deploy that branch. Any idea what goes wrong? This is the log, we are using Git, the capistrano branch is set to deploy, the capistrano version is 2.15.9, ruby version is 2.3.1
$ cap staging deploy
triggering load callbacks
* 2016-09-13 12:12:38 executing `staging'
triggering start callbacks for `deploy'
* 2016-09-13 12:12:38 executing `multistage:ensure'
* 2016-09-13 12:12:38 executing `deploy'
* 2016-09-13 12:12:38 executing `deploy:update'
** transaction: start
* 2016-09-13 12:12:38 executing `deploy:update_code'
executing locally: "git ls-remote git#git.my-company.com:developer-group/my-site.git deploy"
command finished in 615ms
* executing "git clone -q -b deploy --depth 1 git#git.my-company.com:developer-group/my-site.git /home/my-user/sites/my-domain.de/releases/20160913101239 && cd /home/my-user/sites/my-domain.de/releases/20160913101239 && git checkout -q -b deploy fe7bd80727d9cce1a275a531c6e21b84e15ab0cd && rm -Rf /home/my-user/sites/my-domain.de/releases/20160913101239/.git && (echo fe7bd80727d9cce1a275a531c6e21b84e15ab0cd > /home/my-user/sites/my-domain.de/releases/20160913101239/REVISION)"
servers: ["my-server"]
[my-server] executing command
** [my-server :: err] fatal: A branch named 'deploy' already exists.
command finished in 2481ms
The command that fails is git checkout -q -b deploy sha_value.

It turns out deploy is a reserved name for Capistrano, so you are not allowed to use it as a branch name. Capistrano apparently tries to create a temporary "deploy" branch if you deploy a Git project.
https://github.com/capistrano/capistrano/issues/359
In general "deploy", "doctor", and "install" are all reserved names in Capistrano, which are also not allowed as stage names (such as "production" or "staging").

Related

Capistrano and Git Deploy Rails App

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.

capistrano deploy task failing in Yosemite

Here is the command I'm giving to deploy my code to a server.
$ cap production deploy:migrations
* executing `production'
triggering start callbacks for `deploy:migrations'
* executing `multistage:ensure'
* executing `deploy:migrations'
* executing `deploy:update_code'
triggering before callbacks for `deploy:update_code'
* executing `dj:stop'
* executing "RAILS_ENV=production god stop dj"
servers: ["xyz.com"]
connection failed for: xyz.com (ArgumentError: non-absolute home)
I am able to ssh into xyz.com. My capistrano version is
$ cap --version
Capistrano v2.5.19
And it is dependant on net-ssh-2.1.3. The ruby version is ruby 1.9.2p290
Read through similar questions in Stackoverflow, all seem to are suggesting a check on /etc/passwd file in the server. I checked the file and ENV['HOME'] is correctly set for the ssh user.
HOME variable in Server.
$ echo $HOME
/home/deploy
HOME has always been like this from the start. Why would it fail all of a sudden.
Anyone facing the same issue?

Deploy a rails project with capistrano

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.

Capistrano Deployment: git-checkout-index: unable to write file, cannot create directory

I am new to deploying rails websites using capistrano.
I pushed my changes to the git repository successfully without getting any error.
Now I need to push the same changes to the production server using Capistrano.
When I run cap deploy I get the following error:
urjit#urjit-Lenovo:~/workspace/dev$ cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote git#github.com:devrepublicrep/devcockpit.git HEAD"
/usr/bin/git
* executing "git clone -q git#github.com:devrepublicrep/devcockpit.git /home/devcockpit/releases/20120820062500 && cd /home/devcockpit/releases/20120820062500 && git checkout -q -b deploy c51262dbb81a66f307127c85add0786552c03cad && (echo c51262dbb81a66f307127c85add0786552c03cad > /home/devcockpit/releases/20120820062500/REVISION)"
servers: ["dev.devrepublic.nl"]
Password:
[dev.devrepublic.nl] executing command
** [dev.devrepublic.nl :: err] error: git-checkout-index: unable to write file public/javascripts/ckeditor/_source/plugins/embed/dialogs/embed.js
** [dev.devrepublic.nl :: err] fatal: cannot create directory at public/javascripts/ckeditor/_source/skins/v2/images
** [dev.devrepublic.nl :: err] fatal: Untracked working tree file '.gitignore' would be overwritten by merge.
command finished
*** [deploy:update_code] rolling back
* executing "rm -rf /home/devcockpit/releases/20120820062500; true"
servers: ["dev.devrepublic.nl"]
[dev.devrepublic.nl] executing command
command finished
failed: "sh -c 'git clone -q git#github.com:devrepublicrep/devcockpit.git /home/devcockpit/releases/20120820062500 && cd /home/devcockpit/releases/20120820062500 && git checkout -q -b deploy c51262dbb81a66f307127c85add0786552c03cad && (echo c51262dbb81a66f307127c85add0786552c03cad > /home/devcockpit/releases/20120820062500/REVISION)'" on dev.devrepublic.nl
Please Help me.
Thanks.
I got the answer need to clean up some space.
so I ran cap deploy:cleanup command.

Trying to deploy app via Capistrano for first time, having problems

I am trying to deploy a Rails app via Capistrano but am having problems. The messages that get returned in Terminal are as follows:
victor$ cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote git#github.com:victory/PUM.git HEAD"
/Library/Ruby/Gems/1.8/gems/capistrano-2.5.19/lib/capistrano/recipes/deploy.rb:98: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
/Library/Ruby/Gems/1.8/gems/capistrano-2.5.19/lib/capistrano/recipes/deploy.rb:98: command not found: git ls-remote git#github.com:victory/PUM.git HEAD
*** [deploy:update_code] rolling back
* executing "rm -rf /passenger/nginx/pumpl/releases/20101020025555; true"
servers: ["188.126.236.269"]
Password:
I tried to do a Google search but am having a bit of trouble finding a good answer
Would seem your remote installation lacks git.
Have you tried doing a
cap deploy:check
To check the environment and a
cap deploy:setup
To setup the required files?
I finally figured it out.
I just switched to a new Mac that didn't have Xcode installed. This is why Macports was not working correctly. I installed Xcode and after that, I am now able to deploy just fine.

Resources