How do I just run a migration in Capistrano - ruby-on-rails

Is it possible to get Capistrano to update a currently deployed app with a migration (that's all that has been committed as a change since last deployment), update the deployed app with just this code (without running a new full deployment) and just run the migration?

A deployment is what it is, a deployment.
You are asking to deploy without deploying (!?)
IMHO, your issue is more related to SCM (svn, git, etc...) than to capistrano.
You probably want to deploy part of your code (one migration) but not everything that is committed to trunk/master. What you have to do is to branch/tag for deployment, and deploy from that branch/tag.
For example, if I'm using svn I always add these lines to my deploy.rb:
set(:tag) { Capistrano::CLI.ui.ask("Tag to deploy: ") }
set(:repository) { "#{repository_root}/tags/#{tag}" }
this way I can deploy a particular tag and my SVN has clearly defined my production code.
In your case, the procedure would be:
branch your last production revision
apply any changes to this branch (your desired migration)
tag it (for example, prod-with_my_desired_migration)
deploy that tag including cap deploy:migrate
Every tool has its purpose and we have to leverage the power of each of them.

Related

Ruby on Rails - Testing changes to Capistrano's deploy.rb

I'm trying to test some changes out on production without having to commit and push the changes because I only want to commit what actually works. The project I'm working on was created with Rails (3.0.2), and deploys with Capistrano (3.1). I've tried making changes in the root folder of my app and redeploying, and the changes are not reflected on the website. I've tried making changes in the root/current directory and redeploying and that didn't work.
Is there any way I can redeploy changes to the server without having to push it to Github first?
Is there any way I can redeploy changes to the server without having
to push it to Github first?
No this isn't possible since one of the first things that Capistrano will do is git clone the latest from whatever branch you've specified in your deploy config.
I'm not sure what your familiarity with Rails is but the proper way to do this would be to create a new staging environment and deploy to that. The staging environment would have similar settings to your production environment with a separate database so that you don't affect production data.
Capistrano 3 supports this flow out of the box so that once you've set everything up you can simply call
cap staging deploy
to deploy to the staging environment, and
cap production deploy
to deploy to the production environment.

Capistrano 3 simple update

I have a Rails application which I deployed to a remote server with git and Capistrano 3. It works fine.
Sometimes after I change some files (in app/views, for example), I want to upload those changes to the current release without running the full cycle of deploy process.
I need one command to upload changed files (files in the last commit in git) to the current release directory on the remote server.
What is the best way to do it?
Improve Performance with Remote Cache
The way Capistrano works, it will create a new clone/export of your repository on every deploy. That can be slow, so there’s an option to add some extra commands to our deploy.rb recipe to speed things up. Add the following to the section of your deploy.rb where you describe your scm settings: set :deploy_via, :remote_cache
This command makes Capistrano do a single clone/checkout of your repository on your server the first time, then do an svn up or git pull on every deploy instead of doing an entire clone/export. If you deploy often, you’ll notice that this speeds up your deployments significantly.
Hope this help you what you are looking for!!!
For more detail check out this link. deploy-with-capistrano

Rails: creating a test website that is not local

How is a test site created with Rails 4?
I'm building a Rails 4 app. I develop locally, have a github repo, and have a live production Heroku site.
Now I want a 'test' or 'dev' site that is on the web, so all the employees working with the app can see features even before they are rolled out.
It sounds like a standard enough issue that I suspect Rails has some built in approach, making use of the "dev", "test, and "production" environment variables.
Heroku has a methodology for this --
https://devcenter.heroku.com/articles/multiple-environments
I prefer to use standard git mechanics to control the flow. On a web application we develop this really helps us. We have a reasonable sized team and what we do is:
Create a feature branch (tools like git-flow can help with keeping standards in your team)
When done we push up to our git remote, create a pull request and someone reviews the contribution. Once the changes are good they get merged into master.
As part of continuous integration (after our specs are run successfully) we have a simple Jenkins job that clean rebases into the appropriate branch and pushes to the remote.
Everyone has their own flow, but you can use your master branch as development then when you're ready merge/rebase into your other environment branches.
On your destination Rails platform (in my case Ninefold, because it's really easy), pick the branch and deploy. On Ninefold as soon as you push to your branch your app is redeployed via a Post-receive hook.
We configure up the application's environment by passing RAILS_ENV=staging / RAILS_ENV=production, and ensure you have an appropriate (environment).rb file with all the relevant settings for your environment.

Git + Capistrano = Automatic Release Notes Generator?

We use git (github) and capistrano (like 99% of the Rails shops out there) to deploy our app to production.
What I'd like to do is, after every cap * deploy generate a text file containing all the git commit comments since the last deploy. I can then take that list of commit comments, clean it up, and put it somewhere for consumption.
"git log" http://book.git-scm.com/3_reviewing_history_-_git_log.html has plenty of options for fetching log messages, but I don't see an easy way in capistrano to return the current and previous commits, or even the last date/time a deployment occurred, so I can pass that to git log
Thoughts? I can't be the first one doing this... Thanks!
If capistrano doesn't do this, you can wrap it in another script/tool, say, release.
When you launch release, it records the commit, compares it with the previously recorded commit, calls a release notes generator script/tool, and then calls capistrano.

Automated Deployment in Rails

I'm working on my first rails app and am struggling trying to find an efficient and clean solution for doing automated checkouts and deployments.
So far I've looked at both CruiseControl.rb (having been familiar with CruiseControl.NET) and Capistrano. Unfortunately, unless I'm missing something, each one of them only does about half of what I want (with each one doing a different half).
For what I've seen so far:
CruiseControl
Strengths
Automated builds on repository checkouts upon commit
Also runs unit/functional tests and reports back
Weaknesses
No built-in deployment mechanisms (best I can find so far is writing your own bash scripts)
Capistrano
Strengths
Built for deployments
Weaknesses
Has to be kicked off via a command (i.e. doesn't do automated checkouts upon commit)
I've found ways that I can string the two together -- i.e. have CruiseControl ping the repository for changes, do a checkout upon commit, run the tests, etc. and then make a call to Capistrano when finished to do the deployment (even though Capistrano is also going to do a repository checkout).
Basically, when all is said and done, I'd like to have three projects set up:
Dev: Checkout/Deployment is entirely no touch. When someone commits a file, something checks it out, runs the tests, deploys the changes, and reports back
Stage: Checkout/Deployment requires a button click
Prod: Button click does either a tagged check out or moves the files from stage
I have this working with a combination of CruiseControl.NET and MSBuild in the .NET world, and it was fairly straightforward. I would guess this is also a common pattern in the ruby deployment world, but I could easily be mistaken.
I would give Hudson a try (free and open source). I started off using CruiseControl but got sick of having to relearn the XML configuration every time I needed to change a setting or add a project. Then I started using Hudson and never looked back. Hudson is more or less completely configurable over the web. It was initially a continuous integration tool for Java but has plugins for other development stack such as .NET and Ruby on Rails. There's a Rake plugin. If that doesn't work, you can configure it to execute any arbitrary command line after running your Rake builds/tests.
I should also add it's extremely easy to get Hudson going:
java -jar hudson.war
Or you can drop the war in any servlet container.
I would use two system to build and deploy anyway. At least two reasons: you should be able to run it separately and you should have two config files one for deploy and one for build. But you can easily glue the two systems together.
Just create a simple capistrano task, that tests and reports back to you. You can use the "run" command to do anything you want.
If you don't want any command line tool there was webistrano 2 years ago.
To could use something like http://github.com/benschwarz/gitnotify/tree/master to trigger the build deploy if you use git as repository.
At least for development automated deployments, check out the hook scripts available in git:
http://git-scm.com/docs/githooks
I think you'll want to focus on the post-receive hook script, since this runs after a push to a remote server.
Also worth checking out Mislav's git-deploy on github. Makes managing deployments pretty clean.
http://github.com/mislav/git-deploy

Resources