How do you deploy your Rails application? - ruby-on-rails

Do you upload your rail application to your host via FTP first?
I'm currently using Passenger and Capistrano. If I do "cap deploy" in my local machine then I think Capistrano should upload my rail application to my host, right?
Someone from my host is saying that I need to run "cap deploy" in server. I think it doesn't make sense.

You should be able to run cap deloy on your local machine and that should get the current version of your software to the server. However, you need to set up first how this is supposed to happen. I for example use Git to manage my code and also use it to get my software on the server. However, you could also use SVN or FTP if you prefer that. If you google for Capistrano together with the Software youbeant to transfer the code with and maybe even your hosting providers name, you probably will find a decent step by step explanation. For me John Numemaker's post on deploying with Capistrano and Git on Dreamhost really helped: http://railstips.org/blog/archives/2008/12/14/deploying-rails-on-dreamhost-with-passenger/
As an alternative you also might want to check out heroku.com. Their smallest offer is free and enough for most projects. The deployment process is so easy a monkey could deploy a Rails app on their platform. I generally can only recommend heroku.

Related

deploying a rails project to a remote server

is it possible to deploy a rails project to a remote server using FileZilla ? the server is running nginx/1.4.6 (ubuntu)
if no what is the best way to deploy the project if there is already a running version !
To answer your question yes, the code needs to be up, so FTP should do the trick. You might need to restart nginx to pick up the changes, usually touching a restart.txt is enough, but that's particular to your setup.
Is this the best way? Possibly not!
Others suggested capistrano and that would be a good fit for a server you maintain, or go Heroku (or similar) service for a simpler setup.
Deploying a Rails app is a tough job. There is always the easy way (heroku) however shared servers don't deal well with rails. Theoretically you can but usually this shared servers have really outdated ruby and rails versions and are absolutely useless. And you can try to connect via ssh and try to update it but i doubt you will be able to do that. So... If you are a rails developer i can suggest.
1- For small apps run Heroku (easy and free) however cost grows like hell with the app's growth
2- If you're thinking about developing big apps get a dedicated server (you can get cheap ones for 5€/month) and configure it as u would for your computer except when you run rails you run it in production.
3- Trust me... i fought enough Rails and shared servers and i quit... I just gave up

Using capistrano to deploy same project from different machines

We have a team of 2 people writing Rails application. We use DigitalOcean as of VPS and capistrano to deploy it.
But the capistrano deployment scripts are only on one of our two machines.
Is it possible to set up capistrano on the second machine to deploy same project also from it? If yes, how this looks like?
P.S. This might be very easy like adding some SSH keys and running cap production deploy from second machine as the remote VPS has whole infrastructure set up. But we can't take the risk on production system.
There are a couple ways of doing this:
Commit your Cap scripts to the repository alongside your code (this is how I tend to do it; it works well with Ruby on Rails, the config structure matches). Anyone who wants to deploy just needs their SSH key set up on the server.
Create another repository with the deploy scripts; similarly to above, you need SSH keys.
Use a CI server to deploy.
Come up with something else more esoteric. Capistrano is pretty flexible.
Where I work, we generally just add Capistrano to a Rails app's Gemfile, and anyone who checks it out can deploy it to any server to which they have access. Developer SSH keys are added to the servers for this purpose.
Good luck!

Version Control and Deploy Rails Project with cPanel

In my server, what option i got is a basic unlimited server can host unlimited rails project
possible to manage gem because it is using cpanel latest version with a ssh
now my confuse is ,
how can i use the no ssh feature in the cpanel and ease my deployment ?
i don't know is that possible to use the capistrano and git with it
any guidance for this ? to make it possible to update with git push feature
i never deploy anything before ,
i tried to use heroku but i don't know why many user can make their file fit the 5mb space...
my project is now 30% at progress but the space used was 14mb...
so, i bought a cheap standard web server with cpanel . any one could help me in this case ?
usually how you guy deploy and where you deploy ?
recently one guy gave me a link for the github deployment, is that possible to make github use in the cpanel server ?
i mean like host and push the file into github and then link to the personal server ?
anyway, thx for person who reply me recently ^.^
i just develop for hobby...any cheap rails server suggest ?
Thx a lot for reply~
You could also try heroku (www.heroku.com) as a hosting platform. It has a simple deployment workflow that uses git.
Unelss you've done it already, you'll need to install git on your local machine.
Here's a bit about capistrano too.
Capistrano is basically a series of scripts (that you run from your local machine) that get your code and put it on your web server(s). You can configure capistrano to either check out your code from git on the production server, or to copy your code from your local machine.

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.

RoR Server Construction and Capistrano Support

I have been creating a website with Ruby on Rails, and will be hosting it through a friend. He has the space and capacity to host the server, and I have a system to devote to being a dedicated server. And this is my first attempt at a Rails website, plus self-hosting with a friend.
I will be formatting and preparing the server today and tomorrow with the following software configuration:
Apache2
Phusion Passenger (aka, mod_rails)
Ruby Enterprise Edition
MySQL 5
I do have a number of questions, and I apologize for their complexity. I haven't found a guide for this configuration yet, and being new to Rails I haven't the experience to navigate my way through this yet.
What build of Linux is most recommended for this configuration?
I have been planning to deploy on CentOS. The caveat is that I have been a Windows user since my early days, and have only used Linux as a webhost and very few development commands (such as CVS). Thus my knowledge of Linux is rather small, and my experience smaller. If I run into any deployment snags, technicalities thanks to the distro of Linux, or anything of the sort ... I'm totally hung out to dry.
This includes things like building anything from source code.
How do I set up Capistrano on my server for remote deployment?
I know this is an oxymoron (Capistrano is client-side, not server-side) but I don't know what it needs on the server. Does it need FTP? SFTP? SSL? SSH? What?
What do I configure on my server, and how do I configure it, to enable Capistrano to run smoothly?
Also, how do I refer Capistrano to the fact that my SCM is on localhost and is by Mercurial? (I used TortoiseMg.) I could convert to SVN and probably set up a repository on the server, but I'm not entirely sure how to do that.
What is the biggest snag you watch for when deploying from a localhost development, to deployment on a totally different OS?
Miscellaneous
Why not deploy to Windows then? Because I'm footing the bill, and I don't want to pay for another copy of XP or possibly 2000; I refuse to use Vista. Plus, Linux is much more secure than Windows for a server environment.
Why not read the existing guides? I am; this is my first site with Ruby on Rails, my budget is in the less than double-digits area now, and I'm trying to expand my horizons by doing the server configuration and the remote deployment (for further development of the site) by myself. I've relied on hosts in the past for my PHP websites, but they're much more homogeneous in their configuration. Ruby servers are expensive, prohibitively so for me, and to learn its configuration wouldn't hurt to know.
What build of Linux is most recommended for this configuration?
Any of the distributions will work fine as long as they can run Apache2 (which is almost all of them) and you can install Passenger (along with ruby and rails).
I personally use CentOS and find its package manger to be ridiculously easy to use (yum).
yum install -y httpd ruby
gem install rails passenger
Then all you have to do is a little configuration in /etc/httpd/conf/httpd.conf to add Passenger (following the install file for Passenger passenger-install-apache2-module) and point it to your deployment folder .../app_name/current/public.
Since you are using Passenger you should override the restart task to work for it.
config/deploy.rb
namespace :deploy do
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
end
How do I set up Capistrano on my server for remote deployment?
All Capistrano needs is SSH access with sufficient permissions to deploy, migrate, restart app server, etc. Just follow the getting started guide at the Capistrano website and you will be up and running in no time.
Capistrano needs access to your SCM, you will need to allow it to connect to your machine. All Capistrano does is checkout your code into a release folder and moves the symbolic link from the old version and restarts your app server.
What is the biggest snag you watch for when deploying from a localhost development, to deployment on a totally different OS?
The biggest snag is with migrations, test, test, test, and test them some more. A bug in your application is easy to fix and redeploy, but a bug in your migration could end up a huge pain in the ass with the possibility of data loss.
I've found the articles posted at Slicehost.com (a VPS hosting company) to be pretty helpful.
The full list of articles are at: http://articles.slicehost.com/sitemap . You'll find a number of articles there related to production deployment of a Ruby on Rails application.
I recommend using Ubuntu server and deprec, as it provides a ton of sysadmin recipes that make things even easier.

Resources