Capistrano 3 not updating the releases - ruby-on-rails

I am using Capistrano 3 to deploy my app to the production server.
My server has system wide install of rvm. There is nothing extra ordinary about the deploy script.
However when i run cap production deploy The deploy script gives out successful messages and seems that deploy went without a problem.
However when I check the latest release folder is not updated and only the repo folder is updated.
This was supposed to be much easier while using Capistrano 2. But the respective commands to create symlinks etc all are shown to be passed in the console log while depoying while in the server nothing is being done.
Am I missing something about the capistrano 3 changes.
Ask if you need more information.

Capistrano 3 changed the symlink task, if you overrode it or called it specifically like deploy:create_symlink, you may want to audit your code.

Related

No Releases Folder Generated in Deployment Capistrano Rails

I am using Capistrano 3.4 and Rails 4.2.
Initially, I could deploy my application with cap production deploy, everything was working great.
Suddenly, whenever I did cap production deploy, no errors at all are thrown, but my current folder was not being updated with the newest changes.
I then rm -rf my entire releases folder to start from scratch, run cap production deploy, and now there is no releases folder being generated, but still no errors are being thrown. Help!
In case anyone else stumbles upon my same problem, I was using a VPS and made an image of my dev server, and created my production server from it.
I made all the changes, but I forgot to update `config/deploy/production.rb' with the ip address of the new server, so nothing was happening.
Every time before first deploy on server you should run
cap production deploy:check
It creates all needed folders, checks access rights and required dependencies.

Capistrano 3 database migrations fail and does not create current symlink

I've never worked with Capistrano before and currently I am fighting the urge to just scrap it and go back to my old manual ways.
As I understand, Capistrano V3 does not create the initial database because they feel it is the duty of the DB administrator.
So I must be missing something but I have followed their instructions but the initial cap staging deploy fails when it gets to the rake db:migrate step because the database does not exist.
Because of the failure, the symlink for current -> releases never gets created.
Is it just accepted general practice that we SSH into our boxes and cd into the first folder under releases and manually run rake db:create...?
And then from there, am I supposed to just run cap staging deploy again so that it finishes creating the symlinks?
Seems hacky for something that is supposed to make things easier and I am not sure if I am understanding this correctly or not.
Thanks.
It does make sense to leave certain things out of a deployment. As the initial set up and the routine deployments are very separate functions and require different specialties, or in large deployments even different skillsets. That said.. I'm totally with you - on the first deploy having to manually set up the database and certain files (specifically linked files like secrets.yml) is a step that just wastes my time.
I use this plugin:
https://github.com/capistrano-plugins/capistrano-postgresql
just add the require capistrano/postgresql to your capfile as you would any plugin
then run cap staging setup before the first time you run cap staging deploy

How to setup the development environment using cap

I would like to run cap development deploy:setup and cap development deploy to setup the dev environment for my rails app. In order to do this, I will have to remove the project folder from the remote machine, is there a way to automate this in some fashion using cap.
I basically want to remove the app folder in remote machine before I do a full deploy.
The Capistrano app folder is structured like this:
releases - Contains separate folders (named using commit IDs or timestamps) for each deployment made so far
current - Linked to the latest deployment folder under releases
shared - Shared logs, gem files, and tmp which are used between deployments
Now do you really want to clean the entire app folder? That could be dangerous since you'll lose logs.
current is just a symbolic link, it points to the latest release only.
If you want to clean up old releases, check this answer. You can set keep_releases to 1.
If you want to delete the shared folder as well, then you have to write your own Capistrano hook as #Strik3r mentioned.
before 'deploy:setup', 'removecode'
task :removecode do
run "rm -rf <path>", :shell => fetch(:rvm_shell)
end
add this code in to your deploy.rb file, this will call before deploy:setup
in this way you can create a task and do what ever you want to do

From manual pull on server to Capistrano

I've always deployed my apps through SSH by manually logging in and running git pull origin master, running migrations and pre-compiling assets.
Now i started to get more interested in Capistrano so i gave it a try, i setup a recipe with the repository pointing to github and deploy_to to /home/myusername/apps/greatapp
The current app on the server is already hooked up with Git too so i didn't know why i had to specify the github url in the recipe again, but i ran cap deploy which was successful.
The changes didn't apply, so out of curiosity i browsed to the app folder on the server and found out that Capistrano created folders: shared, releases and current. the latter contained the app, so now i have 2 copies one in /home/myusername/apps/greatapp and another in /home/myusername/apps/greatapp/current.
Is this how it should be? and I have to migrate user uploads to current and destroy the old app?
Does Capistrano pull the repo on my localhost then upload it through SSH or run pull on the server? in other words can someone outline how the deployment works?
Does Capistrano run precompile:assets?
/releases/ is for previous versions incase you want to do cap:rollback.
/current/ as you rightly pointed out is for the current version of your app.
/shared/ is for files and folders that you want to persist between deployments, they typically get symlinked to your /current/ folder as part of your recipe.
Capistrano connects to your server in a shell and then executes the git commands on the server.
Capistrano should automatically put anything in public/system (the rails convention for stored user-uploaded files) into the shared directory, and set up the necessary symlinks.
If you put in the github url, it actually fetches from your github repo. Read https://help.github.com/articles/deploying-with-capistrano for more info.
It does, by default.

What is your version control and deployment workflow with Rails?

Especially when considering a fresh Rails project, what does your version control and deployment workflow look like? What tools do you use?
I'm interested in answers for Mac, *nix and Windows work machines. Assume a *nix server.
I'll edit for clarity if need be.
Create a copy of my personal Rails 2.1.1 template with preinstalled plugins and frozen gems.
Change DB passwords, session secret/name and deploy.rb.
Create a private or public repository on GitHub as needed.
Push the empty rails project to GitHub.
SSH to Server and configure apache (copy Virtual Host file and mongrel config files from old project)
Create empty database on MySQL server
cap deploy:setup && cap deploy:cold
If everything works so far: Start developing and committing to GitHub. cap deploy as needed.
Update: Don't forget to write tests for everything you do!
Using Windows Vista and a fresh Ubuntu install at Slicehost.
Create a new empty project in
NetBeans.
Fire deprec (http://www.deprec.org) to install
the Rails stack, including version
control, on the target slice.
Commit the empty project to Subversion.
Using Capistrano, test deploy.
Begin actual development after I've verified that I can access the
Rails start page and, possibly,
scaffolding. (This is really not
necessary because I've done this several times and the software works like it says it does.)
Deprec is seriously magic -- it takes the time it takes to clean-start a Rails project (including server configuration and all that jazz) from about a working day down to about an hour -- and that is an hour where you can be doing coding while everything installs.
this guy documents every workflow he's ever experienced
http://subtlegradient.com/articles/2007/03/30/web-development-environment-and-workflow

Resources