Capistrano Pointing to Old Release That No Longer Exists - ruby-on-rails

I have altered this question quite a bit based on changing circumstances.
My deploy.rb file:
set :rails_env "production"
set :branch, "master"
set :keep_releases, 1
set :app_server, "ip address"
set :db_server, "ip address"
server app_server, :app, :web
role :db, db_server, :primary => true
set :deploy_to, "/var/www"
set :user, :cool_user
set :repository, "git account"
set :scm, "git"
set :scm_username, "my username"
set :scm_passphrase, "password"
ssh_options[:forward_agent] = true
after 'deploy:restart', 'deploy:cleanup'
after 'deploy:update', 'deploy:symlink'
When I run deploy everything looks fine in the console, no errors. But when I visit the site, it's pointing an old release that no longer exists in the server.
For example, when I visit the /pricing page I receive this error...
Unknown action
The action 'pricing' could not be found for DirectController
On another page, I receive this error...
Template is missing
Missing template layouts/anonymous
I have no idea how to point capistrano to the most recent version. Any help is appreciated! Thanks.
If I were to reboot the server then I receive this error.
Sprockets::FileNotFound in Home#index
couldn't find file 'angular'
(in /var/www/releases/20140428003009/app/assets/javascripts/application.js:21)
UPDATE:

I've solved the problem by moving my angular_js gem out of the assets group and into the all group in my bundler. I also did an apache restart from within the server instead of rebooting from the hosting website. Thanks for all the help though!

Related

Deploying a Rails App to Multiple Servers using Capistrano - Best Practices

I have a rails application that I need to deploy to 3 servers - machine1.com, machine2.com and machine3.com. I want to be able to deploy it to all machines at once and each machine individually. Can someone help me out with a skeleton Capistrano config file / recipe? Should it all be in deploy.rb or should I break it out in machine1.rb, etc?
I thought I was on the right track getting Capistrano to take in command line arguments, but it choked when I tried set the roles within the namespaces. I'd pass in 'hosts=1,2,3' as an argument and set the role:app/web/db to "machine#{host}.com" after splitting on the command and going into an each do |host| {}...
Anyway, other than creating 4 different deploy.rb files and renaming it before running cap:deploy each time, I'm stumped. I'd like to be able to do the following:
cap deploy:machine1:latest_version_from_svn
cap deploy:all_machines:latest:version_from_svn
Just don't know if it should all be in deploy.rb split up with namespaces or if it should be broken into multiple *deploy**.rb files.
It should all go in one file. Here's an example:
set :application, "my-app"
set :repository, "git#git.my-git-host.com:my-app.git"
set :keep_releases, 5
set :deploy_via, :remote_cache
set :git_enable_submodules, true
set :scm, :git
set :user, 'your-user-here'
set :deploy_to, "/var/www/staging.mydomain.com"
set :branch, 'staging'
set :rails_env, 'staging'
role :web, "machine1.mydomain.com", "machine2.mydomain.com", "machine3.mydomain.com"
role :app, "machine1.mydomain.com", "machine2.mydomain.com", "machine3.mydomain.com"
role :db, "db.mydomain.com"
# ...
You'll see that only one db server was specified. This is the machine the migrations will be run from. If you only have one database (99.9% chance of the answer to that question being YES), then make sure to only provide one.
I had to use a slightly different syntax.
role :app, %w{s01.foobaz.com s02.foobaz.com}, user: 'deployer'
role :web, %w{s01.foobaz.com s02.foobaz.com}, user: 'deployer'

Rails, Slicehost, Capistrano - Deployment port issues

I'm getting a port error when I try to deploy my app via:
cap deploy:cold
The error:
ssh: connect to host domain.com port 22: Connection refused
My deploy.rb (replaced sensitive info where appropriate):
set :user, 'user'
set :domain, 'domain.com'
set :application, "App Name"
# file paths
set :repository, "user#domain.com:git/appname.git"
set :port, 9728
set :deploy_to, "/home/ruby/public_html/appname"
# distribute your applications across servers (the instructions below put them)
# all on the same server, definied above as 'domain', adjust as necessary
role :web, domain
role :app, domain
role :db, domain, :primary => true
# you might need to set this if you aren't seeing password prompts
# default_run_options[:pty] = true
# As Capistrano executes in a non-interactive mode and therefore doesn't cause
# any of your shell profile scripts to be run, the following might be needed
# if (for example) you have locally installed gems or applications. Note:
# this needs to contain the full values for the variables set, not simply
# the deltas.
# miscellaneous options
set :deploy_via, :remote_cache
set :scm, :git
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
# task which causes Passenger to initiate a restart
namespace :deploy do
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
# optional task to reconfigure databases
after "deploy:update_code", :configure_database
desc "copy database.yml into the current release path"
task :configure_database, :roles => :app do
do_config = "#{deploy_to}/config/database.yml"
run "cp #{db_config} #{release_path}/config/database.yml"
end
I understand the error, but can't see where to make the change. I figured :set port, would handle it.
Have you tried putting the port in your repository path ? Something like ssh://user#domain.com:9728/git/appname.git
I think Capistrano only uses the port you specify in set :port to log in your remote servers.
Here's what works: you must have
set :port, port#
set :repository, "ssh://#{user}#IPAddress:#{port}/~/path/to/git
Or also try:
Here's a possible fix. add ssh_options[:port] = port# May work
Sorry to state the obvious, but:
Is the port actually open on the server?
Have you changed it to something else?
Is it accessible from the outside?
Is your firewall blocking it?
please try it
server "domain:9728", :web, :app, :db

Capistrano + Git + DreamHost

I'm trying to deploy my rails application by using Passenger and Capistrano on Dreamhost. I'm using Git as a version control and we bought an account from GitHub.
I have installed all required gems, Passenger and Capistrano in my local machine and I have cloned the repository of my project from GitHub in my local machine as wel.
According to Dreamhost support, they have Passenger, Ruby, Rails and etc on their server as well.
I'm currently following this article http://github.com/guides/deploying-with-capistrano for my deployment.
The following is my deploy.rb.
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
# be sure to change these
set :user, 'gituser'
set :domain, 'github.com'
set :application, 'MyProjectOnGit'
#git#github.com:MyProjectOnGit.git
# the rest should be good
set :repository, "git#github.com:MyProjectOnGit.git"
set :deploy_to, "/ruby.michaelsync.net/"
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
set :use_sudo, false
set :git_enable_submodules, 1
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
When I run "cap deploy", I'm getting the error below.
[deploy:update_code] exception while rolling back: Capistrano::ConnectionError, connection failed for: github.com (Net::SSH::AuthenticationFailed: gituser) connection failed for: github.com (Net::SSH::AuthenticationFailed: gituser)
Thanks in advance..
don't worry, you'll get it working in the end, I used to use the very same setup as yourself.... i.e. Dreamhost/Passenger/Capistrano/Git (and at one time, SVN) - it can be quite frustrating
Some things for you to do:
1) Read the following two articles by John Nunemaker # railstips.com - I used to refer to them every single time I had to setup a server on Dreamhost (the second one is the most important but the first link gives you some tips that are well worth following)
1.1) http://railstips.org/blog/archives/2008/11/23/gitn-your-shared-host-on/
1.2) http://railstips.org/blog/archives/2008/12/14/deploying-rails-on-dreamhost-with-passenger/
2) I think github is complaining about "gituser" - you do appear to set your username to "gituser" in your capfile - i would change that to your own name
3) you've got your domain down as github.com - again, this should be your own domain name and not github.... From what I recall..
4) start using heroku
good luck - hope this helps, let us know if it does or not....
cheers
You use your private url to clone your repository. Try with public clone URL
git://github.com/Myproject.git
i did to do sudo ln -s /opt/ruby/bin/packet_worker_runner /usr/bin/packet_worker_runner” and it solved the problem..
Thanks.

Capistrano and Git, Ruining my life. "Unable to resolve revision for [HEAD] on repository ..."

I searched all of the relevant Capistrano issues, but couldn't find something that even elucidated anything here for me.
git version 1.6.4.2
Capistrano v2.5.10
Basically, when I run my cap deploy.rb script, it connects to the server, starts executing the deploy:update task, then in the deploy:update_code task:
*** [deploy:update_code] rolling back
* executing "rm -rf /home/user_name/public_html/project_name/releases/20091223094358; true"
servers: ["project_name.com"]
It fails with the following error:
/Library/Ruby/Gems/1.8/gems/capistrano-2.5.10/lib/capistrano/recipes/deploy/scm/git.rb:231:in `query_revision': Unable to resolve revision for 'master' on repository 'ssh://git#slice_ip:path_to_git_repository'. (RuntimeError)
Here's my deploy script, I've tried including and omitting:
set :branch 'master'
I also just thought my path to the repository was off, but i've tried just about every permutation (absolute, not absolute, .git suffix, no suffix). There's definitely a bare git repository at the path i'm pointing to.
**I do have multiple projects being hosted on one slice. The other projects is also a rails project, but is running SVN. Capistrano deployments work fine.
Any pointers in the right direction or any ideas would help reduce the amount of drinking I am planning on doing if I can't figure this out. (Paths / IPs obfuscated, dont hack me bro!)
set :application, "project1"
set :user, "username"
set :repository, "ssh://git#67.24.9.133/home/git/project1.git"
set :branch, "master"
set :port, 696969
set :deploy_to, "/home/username/public_html/#{application}"
set :scm, :git
role :app, application
role :web, application
role :db, application, :primary => true
# deployment via remote client (workstation)
set :deploy_via, :copy
set :runner, user
# mod_rails
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do ; end
end
end
This was the most relevant post (extremely relevant even), but I couldn't really figure out what they were saying the fix is. I'm pretty new with git / capistrano configs.
https://capistrano.lighthouseapp.com/projects/8716/tickets/56-query_revision-unable-to-resolve-revision-for-head-on-repository
Ok I seemed to have fixed it.
Basically, since I have 2 separate repositories on the remote server, I think the "git" user was failing because I hadn't registered an ssh keypair for the git user. That explains why one of my deploy.rb scripts was working properly, while this one wasn't.
In the link I posted in the question, one of the commenters pointed out the issue:
https://capistrano.lighthouseapp.com/projects/8716/tickets/56-query%5Frevision-unable-to-resolve-revision-for-head-on-repository
Note this error is also displayed if
you are using multiple github keys per
http://capistrano.lighthouseapp....
and you do not have these keys and a
corresponding entry in your
.ssh/config on the workstation you're
running the deploy from. so the
ls-remote is run locally. is there a
way to reference the repository at
github.com for this request while the
remote deploy uses
git#github-project1:user/project1.git
Also, see the following link for more details, since the whole ssh issue would apply even if you're not using github.
http://github.com/guides/multiple-github-accounts
Both your workstation and your server must be able to reach the repository at the address specified, if not then you may have to set :local_repository to how you access it from your workstaion, and :repository to be how your servers should access it.
For me Capistrano deployments with Git only seem to work when setting set :copy_cache, true
I've only used capistrano with git once, but never used or seen the use of ssh:// in the repository definition.
Try using set :repository, "git#67.24.9.133/home/git/project1.git" instead
Make sure the branch you are deploying from exists.
set :branch, "upgrade-to-2013.4.3"
is not equal to
set :branch, "upgrade-to-2013.3.4"

Why is Capistrano not checking out the latest version of my code from SVN?

I'm using Capistrano and Rails 2.3.4. I've already done a deploy:cold to the remote server. Now on my local box I changed a layout file and committed it to the repository (I am using Netbeans 6 as my IDE). I type cap deploy and Capistrano runs through it's commands and tells me that it's checked out and deployed the most recent version of my code. On the server, however, the changes aren't there and when I looked at the layout file, it was using the old version not the one I just committed and supposedly deployed.
Anyone experience this?
EDIT: The weird thing is that I changed some image files and those were updated on the server, but the HTML layout I modified was not. Could it just be a cookies issue?
EDIT2: I checked the repository itself (I am using ProjectLocker) and sure enough the code is in there, modified. The issue is only that Capistrano is NOT checking it out even though it says that it is, and it's not reporting any errors.
Here is my deploy.rb file (scrubbed, of course):
# Application
set :application, "myapp"
set :deploy_to, "/var/www/html/#{application}"
# Settings
default_run_options[:pty] = true
set :use_sudo, true
# Servers
set :user, "deploy"
set :domain, "111.111.111.111"
set :runner, "deploy"
server domain, :app, :web
role :db, domain, :primary => true
# SVN
set :repository, "http://myhosting.com/svn/myapp/trunk"
set :scm_username, "wayne#mysite.com"
set :scm_password, "secret"
set :checkout, "export"
# Passenger
namespace :passenger do
desc "Restart Application"
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
after :deploy, "passenger:restart"
It works sometimes, it seems. For instance I made some changes to code earlier and it checked it out fine. I had an issue with it not checking out my database.yml file either; I was forced to edit it on the server.
Just a shot in the dark here, but did you actually look at the layout file or did you hit the website and then look at the webpage source?
If you are in production the layout will be cached (config.action_controller.perform_caching = true), you need to reboot the server. This does not occur in development mode by default, since the above setting is set to false.
See this for more info.

Resources