Ruby on Rails
HowToDeployYourRailsAppFromSubversion (Version #10)

Somewhat inspired by this thread on the TextDrive forums: http://forum.textdrive.com/viewtopic.php?id=4199

You can deploy the latest version of your Rails app to your remote host directly from Subversion, provided of course that you have a hosting company that allows SSH access to the server (like TextDrive).

Before starting this you should be comfortable with setting up your application with Subversion (as described here – HowtoUseRailsWithSubversion), and with deploying Rails applications generally on your remote host (one way is like this – LighttpdThePainlessWay, but the following procedure works equally well for applications deployed using Apache)

Once you have developed a production ready version of your application, and committed this version into Subversion, you should:

  • Login to your host using SSH.
  • Change into the directory you want to install your application to (probably something like sites or apps.
  • If you already have a version of your application running, then rename the existing folder.
    mv app_name app_name_old
  • Use the Subversion export command to checkout a clean version of your application.
    svn export http://path_to_your_repository/app_name/trunk app_name

The export command checks out the latest revision of your application, but with all of the Subversion specific directories removed from the directory tree.

Now all that needs to be done is to make sure your configuration is set up properly.

  • Make sure the ‘shebang’ line at the start of all your executable dispatch.* files, points at your host’s Ruby installation (on TextDrive this is #!/usr/local/bin/ruby)
  • Make sure your Rails environment is set to Production (edit config/environment.rb, and make sure the second line is set to RAILS_ENV = ENV['RAILS_ENV'] || 'production')
  • Set up your database.yml file with appropriate values to connect to your database.

Once that’s all done your application should be ready to be deployed using Lighttpd or Apache. This can be quite an involved process, but there’s lots of documentation detailing the necessary steps.

An alternative scenario to that described above would be; instead of exporting your application from Subversion, you could check out a working copy. This would have the advantage that once you have made changes to your app, you could simple update the working copy, and save having to shuffle your old version about. The only disadvantage of this I guess is that every directory will contain the Subversion meta information directories.



What about permissions? These are lost with the export, or can they be preserved in subversion?

Somewhat inspired by this thread on the TextDrive forums: http://forum.textdrive.com/viewtopic.php?id=4199

You can deploy the latest version of your Rails app to your remote host directly from Subversion, provided of course that you have a hosting company that allows SSH access to the server (like TextDrive).

Before starting this you should be comfortable with setting up your application with Subversion (as described here – HowtoUseRailsWithSubversion), and with deploying Rails applications generally on your remote host (one way is like this – LighttpdThePainlessWay, but the following procedure works equally well for applications deployed using Apache)

Once you have developed a production ready version of your application, and committed this version into Subversion, you should:

  • Login to your host using SSH.
  • Change into the directory you want to install your application to (probably something like sites or apps.
  • If you already have a version of your application running, then rename the existing folder.
    mv app_name app_name_old
  • Use the Subversion export command to checkout a clean version of your application.
    svn export http://path_to_your_repository/app_name/trunk app_name

The export command checks out the latest revision of your application, but with all of the Subversion specific directories removed from the directory tree.

Now all that needs to be done is to make sure your configuration is set up properly.

  • Make sure the ‘shebang’ line at the start of all your executable dispatch.* files, points at your host’s Ruby installation (on TextDrive this is #!/usr/local/bin/ruby)
  • Make sure your Rails environment is set to Production (edit config/environment.rb, and make sure the second line is set to RAILS_ENV = ENV['RAILS_ENV'] || 'production')
  • Set up your database.yml file with appropriate values to connect to your database.

Once that’s all done your application should be ready to be deployed using Lighttpd or Apache. This can be quite an involved process, but there’s lots of documentation detailing the necessary steps.

An alternative scenario to that described above would be; instead of exporting your application from Subversion, you could check out a working copy. This would have the advantage that once you have made changes to your app, you could simple update the working copy, and save having to shuffle your old version about. The only disadvantage of this I guess is that every directory will contain the Subversion meta information directories.



What about permissions? These are lost with the export, or can they be preserved in subversion?