Very strange behavior and i cant understand where problems.
I have 2 private repositories on Github and i deploy with Capistrano.
First app normal deployed deploy.rb:
require "rvm/capistrano"
require 'bundler/capistrano'
set :rvm_ruby_string, "2.1.0"
set :assets_role, :app
set :normalize_asset_timestamps, false
set :application, "awesome_app_one"
set :scm, :git
set :repository, "git#github.com:myaccount/repo_one.git"
set :branch, :master
set :deploy_via, :remote_cache
set :ssh_options, { forward_agent: true }
set :user, "rails"
set :deploy_to, "/home/rails/#{application}"
set :shared_children, %w(public/system public/files public/uploads log tmp/pids tmp/sockets)
set :use_sudo, false
task :production do
role :web, "123.456.789.0"
role :app, "123.456.789.0"
role :db, "123.456.789.0", primary: true
set :branch, :master
set :deploy_to, "/home/rails/#{application}"
set :rails_env, 'production'
end
Another app have similar deploy.rb recipe and capistrano can`t found repo:
> ** [123.456.789.0 :: err] ERROR: Repository not found.
> ** [123.456.789.0 :: err] fatal: The remote end hung up unexpectedly
Then i try clone repo on server:
$> git clone git#github.com:myaccount/repo_two.git
$> Initialized empty Git repository in /home/rails/repo_two/.git/
$> ERROR: Repository not found.
$> fatal: The remote end hung up unexpectedly
I add my ssh keys from server on repo_one and repo_two. Look the same problem here but no answers.
Update:
I found some solution and now i can clone repo on server but somebody know how tell capistrano use my command to pull repo?
Had this error last night
We had to use this to get around that error:
set :repository, 'https://username:password#github.com/username/repo.git'
We're refactoring, but it worked for us
Related
I'm trying to deploy an app to an amazon webserver. I have git installed and functioning (I already successfully made a push. But when I try to do cap deploy I get "permission denied"
Here's the error:
servers: ["22.229.78.34"]
[ubuntu#22.229.78.34] executing command
** [22.229.78.34 :: out] Cloning into '/home/ubuntu/liquid_admin/releases /20130703153332'...
** [22.229.78.34 :: out] Permission denied (publickey).
** fatal: The remote end hung up unexpectedly
command finished in 779ms
*** [deploy:update_code] rolling back
And here's the deploy file:
require 'bundler/capistrano'
set :user, 'ubuntu'
set :domain, 'ubuntu#22.229.78.34'
set :applicationdir, "~/liquid_admin"
set :scm, 'git'
set :repository, "ssh://ubuntu#22.229.78.34/~/liquid_admin.git"
set :git_enable_submodules, 1 # if you have vendored rails
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :application, "liquid.radio"
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
Or: accurev, bzr, cvs, darcs, git, mercurial, perforce, subversion or none
role :web, "ubuntu#22.229.78.34" # Your HTTP server, Apache/etc
role :app, "ubuntu#22.229.78.34" # This may be the same as your ` Web` server
role :db, "ubuntu#22.229.78.34", :primary => true # This is where Rails migrations will run
set :deploy_to, "~/liquid_admin"
set :deploy_via, :export
default_run_options[:pty] = true
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
Probably a silly time to ask, but I'm wondering if I need to already have ruby and rails installed for this to work. I'm going to do it right now anyway... but I was just wondering (didn't know if cap does it for you.)
But other than that..why would it be failing?
Again git is setup and running fine. Push worked just great. SSH is working fine. Another thing I should note is that I tried it both with running ubuntu#22.229.78.34 and with just running 22.229.78.34. I did it the ubuntu way because that's usually the only way amazon will accept a connection. Any help would be appreciated.
** [22.229.78.34 :: out] Permission denied (publickey).
** fatal: The remote end hung up unexpectedly
Looks like you need to forward your Github ssh key through the ssh connection Capistrano opens to the AWS instance. Add set :ssh_options, { :forward_agent => true } to your deploy.rb
Here's my Capistrano file:
set :application, "mydemoapp"
set :repository, "git#bitbucket.org:sergiotapia/mydemoapp.git"
set :scm, :git
set :user, "serg" # The user on the VPS server.
set :use_sudo, false
set :deploy_to, "/opt/nginx/html/#{application}"
set :deploy_via, :remote_cache
set :keep_releases, 1
set :rails_env, "production"
set :migrate_target, :latest
role :web, "192.168.1.1" # Your HTTP server, Apache/etc
role :app, "192.168.1.1" # This may be the same as your `Web` server
role :db, "192.168.1.1", :primary => true # This is where Rails migrations will run
The IP addresses above are obviously fake, I'm using the IP for my VPS
server in real life.
I ran this command, to verify that BitBucket is allowing me to access the repository:
sergiotapia#jarvis1:~/.ssh$ ssh -T hg#bitbucket.org
conq: logged in as sergiotapia.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
However, running cap deploy again, I get:
[198.211.101.99] executing command
** [192.168.1.1:: err] Permission denied (publickey).
** [192.168.1.1:: err] fatal: The remote end hung up unexpectedly
command finished in 1026ms
*** [deploy:update_code] rolling back
* executing "rm -rf /opt/nginx/html/demoapp/releases/20130601025656; true"
I tried using git clone from my SSH terminal, manually and it worked fine as expected. My project cloned to a folder properly.
It seems Capistrano is running sudo git clone instead of git clone. This is verified by myself running a sudo git clone in the same folder manually on my SSH. Same Permission denied (publickey) error.
Why isn't my Capistrano setting for :use_sudo, false being used?
I need to understand why capistrano doesn't create the folder current. I'm using the following command : cap deploy:setup, cap deploy:check, cap deploy
But when i check in my app directory, i don't current folder.
This my deploy.rb
# Execute "bundle install" after deploy, but only when really needed
require 'bundler/capistrano'
# Automatically precompile assets
load "deploy/assets"
# RVM integration
require "rvm/capistrano"
# Application name
set :application, "app"
# Application environment
set :rails_env, :production
# Deploy username and sudo username
set :user, "ubuntu"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
#We don't want to use sudo (root) - for security reasons
set :use_sudo, false
#Target ruby version
set :rvm_ruby_string, '1.9.3-p374'
#System-wide RVM installation
set :rvm_type, :user
#We use sudo (root) for system-wide RVM installation
set :rvm_install_with_sudo, true
#git is our SCM
set :scm, :git
#Use github repository
set :repository, "git#github.com:.../CM.git"
#master is our default git branch
set :branch, "master"
#Deploy via github
set :deploy_to, "/var/www/app/#{application}"
set :deploy_via, :remote_cache
#We have all components of the app on the same server
server "125.156.125.125", :app, :web, :db, :primary => true
namespace :deploy do
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
task :symlink_shared do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
end
task :assets do
system "rsync -vr --exclude='.DS_Store' public/assets #{user}##{application}:# {shared_path}/"
end
end
after 'deploy:update_code', 'deploy:symlink_shared'
I don't understand where is the error, if someone can i help me ?
Thanks you
It could fail due to folder permissions also.
If the option
set :use_sudo, false
was not present when the first time cap was deployed, the current folder have sudo as the owner. When the user is changed, it might not have sufficient permissions to update the link.
I deleted the symbolic link and ran
cap deploy:create_symlink
This updated the symbolic link for me.
Capistrano creates a current symlink (not directory) as one of the last steps in it's deployment cycle, generally right before the application server gets sent a start/restart command. It cannot create that symlink before deploying as there is nothing to symlink to (no checkouts in /releases).
If it's still not creating the symlink, check your capistrano deploy logs for an error, it won't create the symlink if it has an error before making it to that point. And if there is an error, please post it in your question.
I'm deploying my new Rails application to my hosting (Dreamhost).
I'm using Capistrano for the deployment.
I'm runned
cap deploy
with no problems
When I've tried to run cap deploy:migrations I recieve the following error:
Could not find rake-10.0.3 in any of the sources
To check what is happening, I've used
cap shell
which rake
--> /home/myUser/.gems/bin/rake
/home/myUser/.gems/bin/rake -V
--> rake, version 0.8.7
However, when I check the same info from ssh i get
$ which rake
-->/home/myuser/.gems/bin/rake
$ /home/myuser/.gems/bin/rake -V
-->rake, version 10.0.3
How is it possible that I get those two different results?
Any idea?
In case it helps, I add my deploy.rb file:
default_run_options[:pty] = true
set :user, 'XXX'
set :domain, 'XXX'
set :application, 'XXX'
set :repository, "git#bitbucket.org:XXX"
set :deploy_to, "/home/#{user}/XXX"
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
default_environment["PATH"] = "/home/myUser/.gems/bin:$PATH"
set :shell, '/bin/bash'
server domain, :app, :web
role :db, domain, :primary => true
set :ssh_options, { :forward_agent => true }
namespace :deploy do
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
Thanks!
Solved!
There was a problem of GEM_PATH, where my specific gems where not loaded.
Following added to deploy.rb
default_environment["GEM_PATH"] ="/home/myUser/.gems:/usr/lib/ruby/gems/1.8"
default_environment["PATH"] = "/home/myUser/.gems/bin:/usr/lib/ruby/gems/1.8/bin/:$PATH"
May be rake 0.8 is set in your Gemfile.
And rake 10.0 is last installed version.
I am not sure where exactly the problem is located but Capistrano takes about 5 minutes to deploy an almost empty project.
Can you tell me if I am doing something wrong or is it usual?
I am using:
Capistrano 2.9.0
Rails 3.1.3
Github Repository
not too slow server (4 cores, 1 GB memory)
ngix, passenger
Here is the output I am getting:
https://gist.github.com/1632009
Capfile
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
deploy.rb
# -*- encoding : utf-8 -*-
require "bundler/capistrano"
set :user, 'rubys'
set :domain, 'example.com'
set :application, 'EXAMPLE'
# 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.2'
#set :rvm_type, :user
# file paths
set :repository, "git#github.com:GITHUBREPO/ashop.git"
set :deploy_to, "/apps/#{application}"
# using a local git repository on the server you are deploying to.
set :deploy_via, :remote_cache
set :copy_exclude, [ '.git' ]
# 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
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, false
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
end
EDIT
Networkspeed workplace:
http://www.speedtest.net/result/1714391142.png
Speed Github - Server: ~ 300KiB
Capistrano is probably slow for a bunch of reasons. One is that it opens a new remote shell to your server for every run in your deploy.rb file.
This can be amended a bit by using ssh master channels, which will cause capistrano to actually reuse ssh connections, which means less network overhead.
Here's an article on ruby deployment that mentions ssh master channels: http://alexyoung.org/2011/05/17/deployment/
Another reason is that it copies your entire codebase to a new directory for every deploy.
This is not strictly necessary when using git, and github has a wonderful article on how to "fix" this: https://github.com/blog/470-deployment-script-spring-cleaning