Rails Cloud Deployment

Related: Deploying a Project to an Aptana Cloud, this page discusses only the differences at the very end of the deployment process for Ruby on Rails projects.

Aptana Studio's Smart Sync does not include the functionality frequently required when deploying Rails apps and so while Smart Sync can still be used with Rails projects we recommend that Capistrano be used for pushing changes to your project out to the Cloud.

Capistrano can run database migrations, restarting the web server, and deploy out of your source code repository rather than directly from the files system. Further, if members of your Cloud development team use Capistrano all members should because Smart Sync will not be able to follow file changes properly. As part of the initial deployment process Aptana Studio will generate a capistrano deployment recipe in the config folder of your rails project. This recipe is set up to work with the SVN (the default) or Git repositories that are included on your Cloud.

Contents

Getting Capistrano

Capistrano is a package written in Ruby which provides powerful tools for managing deployments and related changes to remote computers, and is widely used in the Rails community for deploying Rails applications. These instructions assume you have Ruby, Rails and Rubygems installed. To install Capistrano, open a command line and enter the following command:

[sudo] gem install capistrano

Capistrano Requirements

Capistrano deployments will require a local install of the command line executables for svn or git (whichever SCM you're using). You can download the SVN command line client from subversion's home page (requires registration) or a 3rd-party site. You can download git from Git's home page. Window's users will typically want to grab the MSYS binary for git.

Capistrano Deployment (and generated Recipe)

The Aptana Cloud plugin will generate a working deploy.rb Capistrano recipe for you on Rails projects. If a version of that file already exists in your project it's renamed to deploy.rb.bak. The generated recipe is set up by default to use the SVN repository created as a part of your Cloud site, though you can change it to use Git instead.

The recipe includes tasks to generate your production database.yml file and manage it for you on the deployed cloud site. It will create a database matching your site's name (for instance, example-site.aptanacloud.com gets a database called example_site) as well as a MySQL account for an app_user user granted all privileges on localhost. The deploy task also properly restarts your Rails app after completing its other tasks.

Capistrano recipes are written in Ruby and can be quite powerful, check their website for tutorials and other kinds of recipes which might be helpful for your applications.

To get started: Open a command line/terminal, change to your Rails project root directory and run the following commands:

cap deploy:setup
cap svn:import (or cap git:import) [optional, see below]
cap deploy
cap deploy:migrations [optional, see below]

This command sets up the Cloud box for deployments, imports your project's contents into the source code repository and makes the first push of the project codebase out to the Cloud. Further deployments should be done by checking your code into the source code repository and then running cap deploy.

svn:import and git:import

cap svn:import and cap git:import are one time commands to import your current project into the supplied SVN or Git repository on your Cloud box. If you already have your project under source control, you'll need to edit the recipe to point at them and you can skip this command. If the code isn't checked in then please run one of these two commands before trying to run cap deploy. Deployment assumes your code is in the repository pointed at by the recipe and will attempt to check the code out. It will fail if the code is not checked in!

Deploy and Run Migrations

cap deploy:migrations is a command that will run your pending DB migrations remotely on your Cloud. If you have any pending migrations that need to be run you should run this command.

Listing available tasks

Capistrano has a switch which allows you to see the list of available tasks. The builtin set of tasks will usually cover most of your needs and you should take a look at what is there to manage your rails application.

To view the list enter:

cap -T

Tailing your Rails application log

If you run into issues running migrations or want to see the logs for your Cloud Rails application, you can view, download or tail your rails application log from the Logs tab for the site in the My Cloud section of My Aptana. The links will appear alongside other common logs like the apache access and error logs.

Git repository

A bare (empty) Git repository is created on every box in the /var/git folder and the clone URL is user@example.aptanacloud.com:/var/git. The specific value for your site can be found in the Access information section of the MyCloud Overview alongside details on your MySQL application username and password, the SVN URL, etc.

Itfd be nice to give the commands to push the initial contents of their project into the repo. I donft use Git so Ifm not sure what those are, I think you do a ggit add remote <clone-url> master? and then a ggit push?. Kris R can probably provide these steps.

Gem Management

Gems must be installed and uninstalled manually by SSHing into your server and running the gem command under sudo (i.e. sudo gem install mongrel)—currently the gem command is the only command permitted under sudo.

Use your Aptana ID password when prompted for a password by sudo.

All team members for a site have SSH access to the box.

Enabling/Disabling Rails support

The deployment wizard has an option to enable or disable Rails support. For RadRails projects, this is automatically detected and set to enabled. Non-RadRails users can select Enable manually.

Enabling Rails support also alters your DocumentRoot slightly to work properly (appends /public to the base setting).