Deploy failed with Gitolite and Capistrano - capistrano

In a project, I use gitolite and capistrano. It's work fine for another developper.
The issue is it's doesn't work for me : I can't actually deploy with capistrano.
When I run the cap deploy command, it ask me the password of the server (here, ok) and the password of the gitolite, which doesn't exist.
C:\wamp\www\miiaou>cap deploy
* ←[32m2012-12-12 15:12:34 executing `deploy'←[0m
* ←[32m2012-12-12 15:12:34 executing `deploy:update'←[0m
** transaction: start
* ←[32m2012-12-12 15:12:34 executing `deploy:update_code'←[0m
updating the cached checkout on all servers
←[33mexecuting locally: "git ls-remote gitolite#miiaou.fr:miiaou master"←[0m
←[2;37mcommand finished in 1351ms←[0m
* ←[33mexecuting "if [ -d /home/miiaou/miiaou_prod/shared/cached-copy ]; then
cd /home/miiaou/miiaou_prod/shared/cached-copy && git fetch -q origin && git fet
ch --tags -q origin && git reset -q --hard 117b2bb34817d89a1fbe34f1891ac3c823a23
fce && git clean -q -d -x -f; else git clone -q gitolite#miiaou.fr:miiaou /home/
miiaou/miiaou_prod/shared/cached-copy && cd /home/miiaou/miiaou_prod/shared/cach
ed-copy && git checkout -q -b deploy 117b2bb34817d89a1fbe34f1891ac3c823a23fce; f
i"←[0m
servers: ["miiaou.fr"]
Password:
[miiaou.fr] executing command
** [miiaou.fr :: out] Error reading response length from authentication socket.
** [miiaou.fr :: out] gitolite#miiaou.fr's password:
Password:
** [miiaou.fr :: out]
** ←[31m[miiaou.fr :: out] Permission denied, please try again.
** gitolite#miiaou.fr's password:←[0m
Password:
** [miiaou.fr :: out]
** ←[31m[miiaou.fr :: out] Permission denied (publickey,password).
** fatal: The remote end hung up unexpectedly←[0m
←[2;37mcommand finished in 36755ms←[0m
*** [←[34mdeploy:update_code←[0m] ←[34mrolling back←[0m
* ←[33mexecuting "rm -rf /home/miiaou/miiaou_prod/releases/20121212141318; tru
e"←[0m
servers: ["miiaou.fr"]
[miiaou.fr] executing command
←[2;37mcommand finished in 133ms←[0m
failed: "if [ -d /home/miiaou/miiaou_prod/shared/cached-copy ]; then cd /home/mi
iaou/miiaou_prod/shared/cached-copy && git fetch -q origin && git fetch --tags -
q origin && git reset -q --hard 117b2bb34817d89a1fbe34f1891ac3c823a23fce && git
clean -q -d -x -f; else git clone -q gitolite#miiaou.fr:miiaou /home/miiaou/miia
ou_prod/shared/cached-copy && cd /home/miiaou/miiaou_prod/shared/cached-copy &&
git checkout -q -b deploy 117b2bb34817d89a1fbe34f1891ac3c823a23fce; fi" on miiao
u.fr
I don't understand why it need a password because the ssh keys works.
Can anybody help me?
Thanks
edit : if that help, here my deploy.rb
require "bundler/capistrano"
# Rails 3.1 : laod capistrano task to precompile assets
# bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile
load "deploy/assets"
set :stages, %w(production)
set :default_stage, "production"
set :application, "miiaou"
set :repository, "gitolite#miiaou.fr:#{application}"
set :domain, "miiaou.fr"
# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
set :deploy_to, "/home/miiaou/#{application}_prod"
set :shared_path, "/home/miiaou/#{application}_prod/shared"
set :scm, "git"
set :branch, "master"
# Agent Forwarding : use local keys for git
ssh_options[:forward_agent] = true
set :deploy_via, :remote_cache
default_run_options[:pty] = true
ssh_options[:paranoid] = false
set :user, "root"
set :runner, "root"
set :use_sudo, false
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
# Add RVM's lib directory to the load path.
#$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
#require "rvm/capistrano"
#set :rvm_ruby_string, '1.9.2'
task :clean_assets, :roles => :app do
run "rm -rf #{shared_path}/assets/*"
end
task :more_symlinks, :roles => :app do
# linkage des fichiers de config
%w(database).each do |config_file|
run "ln -nfs #{shared_path}/config/#{config_file}.yml #{release_path}/config/#{config_file}.yml"
end
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
end
task :restart_daemons, :roles => :app do
#run "cd #{release_path} && bundle exec whenever --set 'environment=#{rails_env}' --update-crontab"
#run "cd #{release_path} && RAILS_ENV=#{rails_env} ruby script/delayed_job restart"
end
# 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
before :'deploy:assets:precompile', :more_symlinks

Related

capistrano cannot run ssh: no such file or directory

I'm new to capistrano and I'm trying to set up a test project, but as you can guess, without much success. When I run cap deploy:update, I get following output:
$ cap deploy
* 2014-12-27 21:48:06 executing `deploy'
* 2014-12-27 21:48:06 executing `deploy:update'
** transaction: start
* 2014-12-27 21:48:06 executing `deploy:update_code'
executing locally: "git ls-remote git#github.com:hstandaert/test.git production"
command finished in 1281ms
* executing "git clone -q -b production git#github.com:hstandaert/test.git/customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807 && cd /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807 && git checkout -q -b deploy 5604624725df4d3c7dd4f88fc77cfd5d9d8ddf26 && (echo 5604624725df4d3c7dd4f88fc77cfd5d9d8ddf26 > /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807/REVISION)"
servers: ["ssh.stocksolutions.be"]
stocksolutions.be#ssh.stocksolutions.be's password:
stocksolutions.be#ssh.stocksolutions.be's password:
[ssh.stocksolutions.be] executing command
** [ssh.stocksolutions.be :: out] error: cannot run ssh: No such file or directory
** [ssh.stocksolutions.be :: out] fatal: unable to fork
command finished in 1611ms
*** [deploy:update_code] rolling back
* executing "rm -rf /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807; true"
servers: ["ssh.stocksolutions.be"]
[ssh.stocksolutions.be] executing command
command finished in 957ms
failed: "sh -c 'git clone -q -b production git#github.com:hstandaert/test.git /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807 && cd /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807 && git checkout -q -b deploy 5604624725df4d3c7dd4f88fc77cfd5d9d8ddf26 && (echo 5604624725df4d3c7dd4f88fc77cfd5d9d8ddf26 > /customers/4/b/b/stocksolutions.be/httpd.www/private/releases/20141227204807/REVISION)'" on ssh.stocksolutions.be
And here's the deploy.rb file:
begin
require 'colored'
rescue LoadError
$stderr.puts <<-INSTALL
You need the both the capistrano-ext and colored gems to deploy this application
Install the gems like this:
gem install colored
INSTALL
exit 1
end
set :application, "stocksolutions"
set :repository, "git#github.com:hstandaert/test.git"
set :branch, "production"
set :user, 'stocksolutions.be'
set :deploy_to, "/customers/4/b/b/#{user}/httpd.www/private"
set :use_sudo, false
set :scm, :git
default_run_options[:pty] = true
server "ssh.stocksolutions.be", :app, :web
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
Anyone who can spot my mistake?
Your log seems to suggest that either there is no ssh client installed in your deployment server, or the command cannot be found in the server's PATH.
Try if cloning the repo via https instead of ssh will work, by changing the following:
BEFORE
set :repository, "git#github.com:hstandaert/test.git"
AFTER
set :repository, "https://github.com/hstandaert/test.git"
You'll be asked to provide your login credentials for github to be able to clone the repo.

capifony no such file or directory on cap deploy

i've the following easy capifony script to copy the local project to my server:
set :application, "project"
set :domain, "88.88.88.88"
set :deploy_to, "/var/www/project"
set :app_path, "app"
set :user, "root"
set :scm, :git
set :repository, "file:///Users/berlin/vagrant-workspace/essen"
set :deploy_via, :capifony_copy_local
set :use_composer, true
set :use_composer_tmp, false
set :copy_vendors, true
role :web, domain
role :app, domain, :primary => true
set :use_sudo, false
set :keep_releases, 3
logger.level = Logger::MAX_LEVEL
This is my output for cap:deploy:setup:
* 2014-10-06 21:55:38 executing `deploy:setup'
* executing "mkdir -p /var/www/project /var/www/project/releases /var/www/project/shared"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
command finished in 119ms
* executing "chmod g+w /var/www/project /var/www/project/releases /var/www/project/shared"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
command finished in 144ms
And then i can't deploy because of a missing folder. It looks like that the script doesn't create the folder inside releases.
cap deploy
* 2014-10-06 21:55:59 executing `deploy'
* 2014-10-06 21:55:59 executing `deploy:update'
** transaction: start
* 2014-10-06 21:55:59 executing `deploy:update_code'
triggering before callbacks for `deploy:update_code'
--> Updating code base with capifony_copy_local strategy
--> Using Copy Local Strategy
executing locally: "git ls-remote file:///Users/berlin/vagrant-workspace/project HEAD"
command finished in 12ms
* getting (via checkout) revision a7ba07ac38fee4b5375c6d383886a906c1a551d5 to /var/folders/l6/ptd6l19s2vb98z6bbnb1k7b00000gq/T/20141006195559
executing locally: git clone -q file:///Users/berlin/vagrant-workspace/project /var/folders/l6/ptd6l19s2vb98z6bbnb1k7b00000gq/T/20141006195559 && cd /var/folders/l6/ptd6l19s2vb98z6bbnb1k7b00000gq/T/20141006195559 && git checkout -q -b deploy a7ba07ac38fee4b5375c6d383886a906c1a551d5
command finished in 72ms
* 2014-10-06 21:55:59 executing `symfony:composer:install'
triggering before callbacks for `symfony:composer:install'
* 2014-10-06 21:55:59 executing `symfony:composer:copy_vendors'
--> Copying vendors from previous release
* executing "vendorDir=/var/www/project/current/vendor; if [ -d $vendorDir ] || [ -h $vendorDir ]; then cp -a $vendorDir /var/www/project/releases/20141006195559; fi;"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
command finished in 103ms
* 2014-10-06 21:56:00 executing `symfony:composer:get'
* executing "if [ -e /var/www/project/releases/20141006195559/composer.phar ]; then echo 'true'; fi"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
command finished in 90ms
--> Downloading Composer
* executing "sh -c 'cd /var/www/project/releases/20141006195559 && curl -s http://getcomposer.org/installer | php'"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
*** [err :: 88.88.88.88] sh: line 0: cd: /var/www/project/releases/20141006195559: No such file or directory
command finished in 106ms
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/project/releases/20141006195559; true"
servers: ["88.88.88.88"]
[88.88.88.88] executing command
command finished in 102ms
failed: "sh -c 'sh -c '\\''cd /var/www/project/releases/20141006195559 && curl -s http://getcomposer.org/installer | php'\\'''" on 88.88.88.88
I can't find any solution.
Does anybody have an idea for my problem? Thank you very much.
If someone will have the same problem. This is a working script for me:
set :application, "project"
set :domain, "88.88.88.88"
set :deploy_to, "/var/www/project"
set :app_path, "app"
set :user, "root"
set :scm, :git
set :repository, "file:///Users/berlin/vagrant-workspace/project"
set :deploy_via, :capifony_copy_local
set :use_composer, true
set :use_composer_tmp, true
role :web, domain
role :app, domain, :primary => true
set :use_sudo, false
set :keep_releases, 3
set :shared_files, ["app/config/parameters.yml"]
set :shared_children, [app_path + "/logs"]
#logger.level = Logger::MAX_LEVEL
after "deploy:finalize_update" do
capifony_pretty_print "--> Set permissions for writable directories"
run "chown -R www-data:www-data #{latest_release}/#{cache_path}"
run "chown -R www-data:www-data #{latest_release}/#{log_path}"
run "chmod -R 777 #{latest_release}/#{cache_path}"
puts "✔"
end
I don't know exactly the difference, but this snippet works fine.

rails 4 + mina deployment failure

i am deploying a rails 4 application using mina deployment. my deployment script is as
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rvm' # for rvm support. (http://rvm.io)
set :domain, 'someplace.com'
set :deploy_to, '/home/deploy/projects/website'
set :repository, 'git#github.com:someone/repo.git'
set :branch, 'master'
set :identity_file, "#{ENV['HOME']}/.ssh/id_rsa"
set :user, 'deploy' # Username in the server to SSH to.
set :shared_paths, ['config/database.yml', 'config/credentials.yml', 'log', 'tmp']
task :environment do
invoke :'rvm:use[ruby-2.1.0#default]'
end
task :setup => :environment do
queue! %[mkdir -p "#{deploy_to}/shared/log"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
queue! %[mkdir -p "#{deploy_to}/shared/config"]
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]
queue! %[touch "#{deploy_to}/shared/config/database.yml"]
queue %[echo "-----> Be sure to edit 'shared/config/database.yml'."]
queue! %[touch "#{deploy_to}/shared/config/credentials.yml"]
queue %[echo "-----> Be sure to edit 'shared/config/credentials.yml'."]
end
desc "Deploys the current version to the server."
task :deploy => :environment do
deploy do
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:assets_precompile'
to :launch do
queue "touch #{deploy_to}/tmp/restart.txt"
end
end
end
when i deploy as 'mina deploy', i get error as
...
Symlinking shared paths
$ mkdir -p "./config"
$ mkdir -p "."
$ rm -rf "./config/database.yml"
$ ln -s "/home/deploy/projects/website/shared/config/database.yml" "./config/database.yml"
$ rm -rf "./config/credentials.yml"
$ ln -s "/home/deploy/projects/website/shared/config/credentials.yml" "./config/credentials.yml"
$ rm -rf "./log"
$ ln -s "/home/deploy/projects/website/shared/log" "./log"
$ rm -rf "./tmp"
$ ln -s "/home/deploy/projects/website/shared/tmp" "./tmp"
-----> Installing gem dependencies using Bundler
$ mkdir -p "/home/deploy/projects/website/shared/bundle"
$ mkdir -p "./vendor"
$ ln -s "/home/deploy/projects/website/shared/bundle" "./vendor/bundle"
$ bundle install --without development:test --path "./vendor/bundle" --binstubs bin/ --deployment
...
Your bundle is complete!
Gems in the groups development and test were not installed.
It was installed into ./vendor/bundle
-----> Precompiling asset files
$ RAILS_ENV="production" bundle exec rake assets:precompile RAILS_GROUPS=assets
rake aborted!
File exists # dir_s_mkdir - /home/deploy/projects/website/tmp/build-138935597031149/tmp
/home/deploy/projects/website/tmp/build-138935597031149/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.1/lib/sprockets/cache/file_store.rb:25:in `[]='
/home/deploy/projects/website/tmp/build-138935597031149/vendor/bundle/ruby/2.1.0/gems/sprockets-2.10.1/lib/sprockets/caching.rb:34:in `cache_set'
Make sure that shared/tmp directory is created if not ssh into the server and
$ mkdir /home/deploy/projects/website/shared/tmp
make sure you have the right permissions too.
drwxr-xr-x
If you are symlinking your tmp directory ensure that it exists. If it doesn't the broken symlink will cause the same issue.

Capistrano deploy from local machine

Im trying to create a new user to deploy my application from my local machine to my external server.
I've got it working using root but understand it's not secure to use root, therefore I want to create a user called 'deployer'. I've added this user to my external server and copied my local is_rsa.pub key to /.ssh/authorized_keys on the server, however when I run cap development deploy I keep getting the following error:
failed: "sh -c 'if [ -d /var/www/vhosts/xyz.co.uk/shared/cached-copy ]; then cd
/var/www/vhosts/xyz.co.uk/shared/cached-copy && git fetch -q origin && git fetch --
tags -q origin && git reset -q --hard 2b738f4ca8008dcf9e84c4be5d63d906a7bfd760 && git clean
-q -d -x -f; else git clone -q git#github.com:xyz/xyz.co.uk.git
/var/www/vhosts/xyz.co.uk/shared/cached-copy && cd /var/www/vhosts/xyz.co.uk/shared/cached-
copy && git checkout -q -b deploy 2b738f4ca8008dcf9e84c4be5d63d906a7bfd760; fi'" on
x.xx.xx.xxx
If I run ssh -T git#github.com on the external server it says:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
This username is not deployer though, I assume its the username of the github account.
Any ideas what I need to do? Do I need to create the deployer user on my local machine too?
Here is my deploy.rb file:
set :stage_dir, 'app/config/deploy' # needed for Symfony2 only
set :stages, %w(production staging development)
require 'capistrano/ext/multistage'
set :application, "xyz.co.uk"
set :user, "deployer" # The server's user for deploys
set :normalize_asset_timestamps, false
set :repository, "git#github.xyz/xyz.co.uk.git"
set :scm, :git
set :keep_releases, 3
after "deploy:update", "deploy:cleanup"
set :use_sudo, false
set :web_path, "web"
set :shared_files, ["app/config/parameters.yml"]
set :shared_children, [app_path + "/logs", web_path + "/uploads"]
set :use_composer, true
set :update_vendors, true
set :dump_assetic_assets, true
set :deploy_via, :remote_cache
#logger.level = Logger::MAX_LEVEL
after "deploy:update_code" do
capifony_pretty_print "--> Ensuring cache directory permissions"
run "setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX #{latest_release}/#{cache_path}"
run "setfacl -dR -m u:www-data:rwX -m u:`whoami`:rwX #{latest_release}/#{cache_path}"
capifony_puts_ok
end
deveopment.rb file:
server 'x.xx.xx.xxx', :app, :web, :db, :primary => true
ssh_options[:port] = 1234
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :deploy_to, "/var/www/vhosts/xyz.co.uk"
set :symfony_env_prod, "dev"
set :branch, "develop"
# Need to clear *_dev controllers
set :clear_controllers, false
Thanks
You want to have the target machine use your local SSH credentials to authenticate to Github. Do this by putting the following two entries into your deploy.rb
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
Or, another way is to go to your Github repo and add the public SSH key of your target server as a deploy key
https://github.com/your_github/your_repo/settings/keys
This gives the target server checkout access to only the specified repository without having to use your personal SSH key.
The problem was because the 'deployer' user didn't have write permissions on the server.

capistrano symlink permission denied

I am using cap deploy to deploy to staging. cap deploy:setup created the releases and shared folder.
This is the deploy.rb code.
set :stages, %w(staging production)
set :default_stage, "staging"
set :stage_dir, "capistrano"
require 'capistrano/ext/multistage'
set :application, "application"
set :repository, "git#github.com:owner/#{application}.git"
set :scm, :git
set :local_user, ENV['USER'] || ENV['USERNAME'] || "unknown"
set :user, "server_owner"
set :deploy_via, :copy
set :use_sudo, false
set :copy_remote_dir, "/home/#{user}/tmp/capistrano"
namespace :deploy do
desc "Change Permissions"
task :change_permissions, :except => { :no_release => true } do
run "find #{current_path}/ -type d -exec chmod 755 {} \\;"
run "find #{current_path}/ -type f -exec chmod 644 {} \\;"
end
desc "Create symlinks for shared items"
task :update_shared_symlinks, :except => { :no_release => true} do
< ln -s command to create the links>
end
end
before "deploy:finalize_update", "deploy:update_shared_symlinks"
And this is the staging code
role :app, "ipaddress"
set :branch, "staging"
set :deploy_to, "/home/#{user}/_#{application}_beta/"
When deploying with cap deploy i get the following error
ln: creating symbolic link `/home/narayan/_instaprint_beta/releases/20130130102815/': Permission denied
Can anyone tell me why this is happening?
Two things:
Use chmod straight away instead of a find and exec, like so: chmod 755 #{current_path}
Check if the server_owner user has permission to current_path. If not, then use sudo like so: sudo "chmod 755 #{current_path}"