Wednesday, 2 May 2007

How To Deploy Rails with SVN and Capistrano to a Secondary Domain on TextDrive

I just deployed my first rails app to one of my secondary domains on TextDrive’s shared hosting space.

If that sounds like a recipe for disaster….you’re right!

While Rails is a great development tool, there’s lots of work to do in simplifying, stabilizing, and documenting the deployment process. The app in question is very, very tiny for the express purpose of getting deployment nailed. In fact, it’s taken me longer to deploy than to develop.

For you, and Future Garrick, here’s the process.

  1. Freeze Rails so you’re not plagued with different-version-itis:
    rake rails:freeze:edge TAG=rel_-2-3
  2. Create an Subversion repository in your primary domain,
    Not in your secondary domain. If the repository is in a secondary domain, your primary account can’t see it. Using your primary domain and primary account is easier – if not as tidy as I’d like.
  3. Give your primary account access to the new Subversion repository.
  4. Grab the TextDrive deploy.rb from nuby on rails. Verify deploy_to and server.document-root are /web and /web/public respectively.
  5. Do the initial import into the repository and an initial checkout back to your local machine.
  6. cd to your local app and run cap setup. Confirm you now have a /web/shared directory. It should contain the following directories: log, pids, and system. In log you should have at least production.log and fastcgi.crash.log. Create and chmod them to 666 if they don’t exist.
  7. Follow TextDrive’s instructions for setting up lighttpd, rails, and a proxy.
  8. Change the /web/public/ paths in APPNAME.conf and to /web/current/public/
  9. Follow TextDrive’s instructions to start up lighttpd and rails.
    Running their file didn’t work for me, editing and manually running the script did.

After all this, cap deploy will deploy your app for you as advertised.

After I tweak a couple more dials and flip a couple more switches I’ll point you to the app.

Tuesday, 27 February 2007

How To Install MacPorts, Apache2, Rails, MySql, Mongrel, and Subversion on an Intel Mac

Now that I’m just about ready to deploy my first rails app, I thought I’d get the deployment environment set up rock solid on both the production and the development machines (one Mac Mini and one MacBookPro).

Like many other tutorials on this same subject, your mileage may vary. In fact I’m writing this now, because mine did. After stalling out in many of the tutorials all different places, this is what worked for me.

  1. Download and install MacPorts (used to be DarwinPorts)
  2. Open up a terminal and type:
    sudo port selfupdate
    making sure everything is the way it should be.
    If you’re like me, you get port: command not found in return.
  3. I fixed this by opening up .bash_profile in a text editor (Textmate: mate ~/.bash_profile) and adding the line
    export PATH=/opt/local/bin:$PATH
  4. Next download and install MySQL5
    I grabbed the binary from the bottom of the MySQL 5 download page. It comes with a System Preference Pane and checkbox for auto-startup. I’m using CocoaSQL for admin.
  5. Change the MySQL5 root password

    /opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
    /opt/local/lib/mysql5/bin/mysqladmin -u root -h [HOSTNAME] password 'new-password'
  6. Next load up the Apache2 package
    sudo port install apache2
    (this takes a while)
  7. sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist to launch Apache2 on startup. I’ve disabled Apple’s default Web Sharing in the System Preferences.
  8. Create an initial http.conf file
    cd /opt/local/apache2/conf
    sudo cp httpd.conf.sample httpd.conf
  9. Start up Apache2
    sudo /opt/local/apache2/bin/apachectl -k start
  10. Load up http://localhost. It should say “It works!”

  11. sudo port install fcgi
    sudo port install lighttpd +ssl
    sudo port install mod_fastcgi
  12. Next load up Subversion package with the mod_dav_svn for Apache2
    sudo port install subversion +mod_dav_svn +tools
  13. Next load up Ruby, RubyGems, Termios, RB-MySQL5 Bridge, and ImageMagick Packages
    sudo port install ruby
    sudo port install rb-rubygems
    sudo port install rb-termios
    sudo port install rb-fcgi
    sudo port install rb-mysql (I had some errors on this one.)
    sudo port install imagemagick
  14. Install a bunch of useful gems, like rails and capistrano.

    sudo gem install --include-dependencies rake
    sudo gem install --include-dependencies rails
    sudo gem install --include-dependencies termios
    sudo gem install --include-dependencies capistrano

    sudo gem install daemons gem_plugin mongrel mongrel_cluster --include-dependencies
    sudo gem install --include-dependencies mongrel
    sudo gem install --include-dependencies mongrel_cluster

    sudo gem install mysql --

    (thanks to d. robert adams for the last bit)
  15. Create a rails app
    rails testapp
  16. Connect the rails app to mongrel

    mongrel_rails cluster::configure -e development -p 8000 -a -N3 -c /RAILS/ROOT/OF/TESTAPP

Wednesday, 11 October 2006

How To Set Up Subversion, svnX, for TextDrive on OS X

I’m walking through the latest beta version of Agile Web Development with Rails 2nd Edition, specifically the new bits on deploying Rails apps. Capistrano – the preferred and recommended deployment utility. Thing is – Capistrano hinges on Subversion. Not something covered in AWDwR or appropriate to be covered. There’s plenty of other books on the subject.

Though, that left me stuck on how to set up a Subversion repository and access it.

I do my hosting at TextDrive, and in the interest of making this process just a hair simpler, I set up my svn repository there. Here’s how I did it:

  1. Set up repository on TextDrive domain in webmin.[your-server]
    There’s a ‘subversion repository’ menu option right when you sign-in.
  2. Assign svn access rights to a TextDrive domain user.
    It’s a radio button and select list selection in their profile.
  3. Install Subversion on your local Mac – I did via macports
  4. Install svnX and in svnX preferences, confirm your path to svn in svnX (macports uses /opt/local/bin)
  5. Import your project into the TextDrive repository
    svn import /Users/your/local/path/to/the/app http://[your-domain]/svn/[repository-name]/ -m 'initial import' --username=[your-svn-account-name]
  6. Connect svnX to the repository
    Path: http://[your-domain]/svn/[your-repository-name]
    User: [your-svn-user-name]
    Pass: [your-svn-user-name-pass]
  7. Check out your project back on to your mac by clicking the ‘svn checkoutexport‘ button and picking a directory to put it (not your original directory). I created an /svn directory within my main project directory.
  8. Now, if everything worked, double-clicking the repository should load it up in a new window.
  9. I’ve got a weird proxy between me and the internet right now, so I’ll make sure the commits work tomorrow. UPDATE: Yep, it works. Yah!