Chef and application deploy - ruby-on-rails

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

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.

How to install Ruby script on server?

I apologize in advance for the fairly simple question.
I am familiar with PHP, but am trying to install this Ruby script on my server for the first time. It's an open source script that I've forked from github, but unfortunately does not have any instructions. I have Ruby on Rails, and MongoDB installed already.
Does anyone know what the beginner steps are to get started? Should I upload everything via FTP to the public directory, or is there something else to this?
Most Rails projects are much better served by having a proper deployment strategy. Typically this involves making your own repository, easily done by forking that existing application, and cloning that on to your server using git. To make changes in the future, do your work on a development copy, push that into the repository, and pull down the changes on the server.
Unlike PHP where many parts of the application can function independently, Rails applications tend to be far more integrated and uploading it piece by piece is not going to work in the long run.
Rails applications can run stand-alone using the provided rails server tool but this is really only intended for light-duty testing or development work. A more permanent solution is to use something like Passenger to do the hosting for you.
Passenger will take care of launching your application when calls are made to the site you've configured in Apache or nginx, depending on which you end up using. Passenger is popular because it's quite easy to get running.
There are other approaches like unicorn if you're feeling more adventurous.
When you make changes to your Rails application in production mode you will have to create a tmp/restart.txt file in the main application directory to tell your web server to restart the process. This is not a requirement in development mode.
Due to the relative complexity of this process once you include all the various steps, you will probably want to use a deployment automation tool like capistrano.

Deploying a Ruby On Rails application

Once I've finished my Ruby On Rails app, I want to deploy it on a server.
What steps should I do?
Should I generate a file as for example a .war in Java?
Thanks a lot
Capistrano is the most popular way to deploy Ruby On Rails. Enjoy this screencast.
If you're deploying to regular server (non cloud) you can use the capistrano gem here's a good screencast on how to. If you want a cloud based service you can't beat Heroku.
You can follow this link.You will get a clear idea about Ruby On Rails app deploy
http://rubyonrails.org/deploy
Ideal and Easy way - you need to you best practices like
Version control with Git
Heroku Setup (which is free) (You can think for engine yard)
Here is the few links
Version control with Git
Deploying with Heroku
Link from Heroku
Please let me know if you need more information on this.

Hosting rails on ec2

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.

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