Hosting rails on ec2 - ruby-on-rails

I want to deploy a rails onto amazon ec2. I've had a look at poolparty and ec2onrails but neither seem to be maintained anymore.
What are people using to do this? Is it all homebrewed puppet and capistrano or is there a project that will get me going?

I can recommend two projects:
If you have a single Rails app, take a look at Rubber. It's a gem that can provision EC2 instances for you, install software and deploy your app. It's based on Capistrano. There are recipes for the most common components (mysql, apache, passenger, postgres, etc.).
In case you have more complex setup (e.g. multiple apps or specific needs that aren't covered by Rubber) I recommend Chef. It does have quite a learning curve, so prepare yourself. Take a look at OpsCode to get started with Chef.

You may want to take a look at our Rubystack AMIs. They are free and we keep them up to date. You still need to do work for automating deployment and integrating in your workflow, the AMIs mainly address the environment and runtime setup.

Related

Deploying Ruby on Rails Apps with Mongoid (MongoDB), Redis, Resque, Capistrano, etc

I am creating a Ruby on Rails website deployed on AWS. I am running into configuration issues and I can't seem to find docs/tutorials that cover configuration of the various tools mentioned and how to set them up BOTH for ease of use in development (on localhost) and while deploying.
Right now I have a Rails app set up and I am using Bundler for all my Ruby gems.
I have two major goals.
Ease of development - Ideally somebody should just have to clone the repo and run 'rails server' and should be good to go. All other stuff like Redis servers, Resque workers, Mongo DB databases, should automatically be started/created.
Ease of deployment - Given some configuration file (like YAML files), I should be easily able to deploy to various stages by simply running 'cap production deploy' or something similar. It should automatically run all the rspec tests, and prevent deploying if something goes wrong. Once deployed it should also handle all other aspects like restarting Apache/Nginx, handling DB migrations, restarting Resque workers, etc. I know how to do this all manually, but again I am looking for a solution that will let a novice (i.e. unexperienced with my app's deployment process, not novice in general) easily be able to deploy.
I have looked at various tools/gems like Foreman, God, etc. but I am not clear on how to use them correctly and how they work in different environments like development and production.
I am looking for either docs/tutorials on how to do this or even Github repo's of Rails app that have solved these problems (preferably smaller repo's so that I don't have to wade through application specific stuff to get the information I looking for).
I am also looking for a way to monitor my Rails app. As what kind of errors are happening? how frequently are they happening? Is Splunk a good tool to do so?
Note : I am not tied down to use any of the tools mentioned above, since I am only starting to develop my website.
This is pretty comprehensive if you want to deploy to a small EC2 instance using Capistrano and Apache.
For monitoring I'd suggest New Relic or just checking your logfiles.
However, you're going to have to be more specific about your technology questions. You're covering a lot of breadth here and going deeper into answering this would require a lengthy essay and possibly a consulting fee.

Ruby on Rails application deployment on multiple servers

What are the useful gems or softwares that will help deployment of RoR 3.2 application on the clouds?
There is no specific requirements since I just want to get experience with it. But I am thinking of Amazon EC2 as a primary environment to test the application. The goal is to deploy it in the multiple servers.
I guess the most naive way would be launching the same application on multiple servers at the same time, but that will requires a lot of manual restart/reboot which requires a lot of human resources.
Is a single application of ruby on rails just not suited well for deployment on multiple servers?
We use Capistrano (https://github.com/capistrano/capistrano) to communicate with multiple EC2 instances on AWS.
We use Chef (https://github.com/opscode/chef) to do the system management configuration.
You can get cookbooks for various applications that you want to install (eg nginx, monit, logrotate...) from Opscode (http://community.opscode.com/cookbooks)
You will need both Capistrano and Chef to setup and deploy to AWS.
Puppet is another system management configuration that you can use too. (https://github.com/puppetlabs/puppet)
This is what Capistrano is for.
https://github.com/capistrano/capistrano/wiki/

The current state of Rails deployment

A few years ago it seemed fairly tricky to get a rails application deployed. However, from what I have been reading recently it seems that rails has improved much in this area. However, given the various versions of Ruby and gem dependency issues, is deployment still a headache (to heroku or engine yard, for example)?
No. Heroku makes deployment ridiculously easy: it's entirely managed by Git, your app is isolated so there are no dependency conflicts, and it's free for small scale apps. Other services like EngineYard and DotCloud offer similar service (although EY isn't cheap and DotCloud isn't as ruby-focused).
There are a bunch of tools to make deployment and management easier for you.
Heroku
Heroku is totally managed by git via the heroku gem. Essentially, you call heroku push instead of git push and your changes get pushed to the server, built, and your site is automatically updated
Bundler
Bundler has made managing gems a lot easier, and it is super straightforward.
RVM
RVM is actually a good tool to use on servers. It allows you to have one server serve multiple Rails applications, each on a different version of Ruby, with it's own totally unique Gemset (This means that you won't have gem conflicts for multiple apps using the same ruby version. Gem conflicts are gone!).
Capistrano
Capistrano lets you define everything you need to happen during deployment, and allows you to start and end it all with one simple command - cap deploy. It greatly simplifies the deployment process.
Foreman
If your application requires multiple services to start (Server, Delayed::Job, Sphinx, etc), Foreman is the tool for you. It lets you define what services you need, and start them all at once by calling foreman start. It works nicely with Capistrano, and makes the console output of your services nice and easy to read.
Overall, I'd say that the state of Rails deployment is an order of magnitude better than it was a few years ago, but there's always room for improvement. The projects mentioned above are a good start, and it's just a matter of finding what fits your organization best.
Deployment might be a headache depending on your needs. If you're running a single application in a server, it's easy to build it, install ruby and setup your deployment environment using Capistrano (here's a sample of how to do it using Nginx and Unicorn).
If, on the other end, you require many different applications on your server (possibly running on different rubies and groups of gems), you'll have more work but it's completely possible. To have many different rubies installed at the same time without conflicting with each other you'll use RVM and to make sure all your app dependencies are defined, your Rails app has to use Bundler (or maybe something else that does the same).
So, your requirements are going to make it simpler or not, but is isn't really impossible and it won't drive anyone crazy with the amount and quality of tools available for the job.

Chef and application deploy

How is it possible to keep my rails application up to date using chef?
While reading documentation I understood how to set up servers from scratch using knife bootstrap. But is it possible to run another tasks after this?
Earlier I have used capistrano but now we have two staging and ten production servers which needs to be up to date when new version of the application is released.
The best thing to do is to look at the built in Deploy resource
You might also want to look at the Application cookbook. This is a bit harder to grok, but it lets you deploy an application driven off a databag.
I found new gem on this topic:
https://github.com/iain/roundsman - it's capistrano + chef-solo integrated

Why is it supposedly "hard" to deploy Ruby on Rails to production?

I admit that I don't follow much of anything "right" on deploying test versus production code. I have been using ASP.NET, and I typically run it locally in Visual Studio, it works, I upload it, I test it again on the production server.
I have read several people say that deploying Rails apps is harder and there are special programs/ways on the ruby site about deploying RoR. I've only toyed with RoR. What is special about deployment? You don't just copy and paste the code and run it (from development machine to the production)? Is it because one is in Apache and the other running on the built in server?
This will be on a Mac Server if it matters.
Deploying RoR is not difficult anymore, especially with Phusion Passenger.
What is somewhat difficult, is getting a automated production environment setup with capistrano, vlad, etc. If you don't mind simply copying your code to the server, you can do that just fine. Most people choose not to do it that way because you lose out on a lot of the benefits that the automated deployment tools give you.
I guess people consider a Rails app harder to deploy than say some PHP apps or such where you just plop the code somewhere and point Apache or whatever at it. But, as mentioned above, you could do that now with Phusion Passenger.
We use Nginx+Passenger, but not for simplicity of deployment. Capistrano is our deploy tool of choice, and really, unless you have a very simple app, you're going to want something like Capistrano anyway. For example, with our deploy, we do a slew of things:
run any database migrations
generate release notes automatically, based on all the commits to Git between the last deploy and this one
notify various people via email (with differing lists depending on whether the deploy is to our staging environment or production) - we do this via cap_gun which integrates with Capistrano.
Notify New Relic RPM of the deploy so it can mark it in our RPM analysis
Notify Hoptoad of the deploy, so it too can have that data when reporting any exceptions
produce our sitemap.xml file, and ping Google to tell them there's a new one
update crontab files (I store our crontab files for each server in our git repo, and then on deploy it sees if there is a new version and updates accordingly, etc.).
flush/restart memcached
There are other ways aside from Capistrano, but it's a proven tool, with a lot of flexibility, yet pretty simple to setup a vanilla configuration.
So, my take is that once you get into any app that is beyond just the very simplest of apps, you're going to need/want to be doing things other than just simply updating the code. In the beginning though, if you just need the code updates, and maybe Rails migrations, then you can do simpler things like Passenger and code sync, or look at tools like Heroku or Engine Yard's stuff where they do a deploy by doing a Git clone (and then offer some additional abilities).
Another super easy way to deploy is with http://heroku.com/
Some of the issues you face with deploying rails to production:
Database connection.
You need to be sure that the database connector is set up for the production environment.
Database migrations.
You have to run database migrations against the production database even though you may have already run them in production/testing/staging
Ruby version. The version or sub-version or Ruby can trip you up, e.g. An error occurred while installing debugger-linecache (1.1.1), and Bundler cannot continue
Gem dependency.
Your production environment may have different packages and gems from development. Bundler will figure this out for the most part and install the dependencies but occasionally there are still issues that you have to resolve manually.
Dependencies.
Some gems on some machine have particular dependencies. I have seen frequent problems with using gems on my unix box that work on OSX and vice-versa.
Note the last 3 shouldn't affect you if on the same machine but I included them based on the title and to be comprehensive.
It's not especially hard. If you stick to conventions then with a little bit of configuration it boils down to this:
cap deploy
...however there is sometimes a bit of effort needed up front to get the workflow in place.
The good news is that lots of people have packaged up solutions and stacks for RoR that you can just plug and play. For example, google ec2onrails - this is a packaged Ubuntu image and set of capistrano tasks for running rails apps in Amazon's EC2 cloud, with lots of common stuff set up already out of the box.
Choose a good hosting provider and you should be able to find something similar for that also.
An easy way to deploy Rails apps is to use Phusion Passenger. Deployment doesn't get much easier than that for any programming language or framework. You can do that on a Mac server.
Another really easy way to deploy rails is with jruby and the glassfish gem.

Resources