blog

Let's talk about testing

RubyonRails Freebsd 8.0 RC1

We’re a Ruby on Rails shop at our place and we work on a number of different platforms for developing and testing our stuff; the devs normally work on macs, while the staging environment – this week – is Ubuntu’s Jaunty Jackalope (9.04) distribution. However I’m a big FreeBSD fan, and have been for a number of years. Speaking personally for myself, FreeBSD makes sense in every aspect of its operation and configuration, and the ports collection is second to none for all aspects of application management. (disclaimer – *nix distributions are more like pairs of jeans than they are operating systems in the hearts and minds of regular users; what fits well on one user, doesn’t fit at all on another. So I’m absolutely not saying FreeBSD is best, it’s just best for me). When the FreeBSD 8.0 RC1 build was made available I decided to put together a test server for deploying new builds of our apps for first round QA work. More or less from a standing start this is the road I travelled, which at the end resulted in a fully operational test server.

First off was the installation of the 8.0-RC1 build itself on the test server machine, which was my Lenovo X60 laptop with 2GB of RAM. I got a hold of a build ISO image from a mirror detailed on the main “Get FreeBSD” site page, and took disc 1 only. The idea was to make a minimal install which meant only the first disc was necessary. With a minimal install you don’t get add the ports collection by default, so the first post installation task was getting this added. At this point, I was ready to install Rails, but as I also wanted a desktop I went ahead and installed KDE4. I’m not going to go into the details here, as there are other fine posts about this easily found with a Google search, but the process is fairly straight forward with no major gotchas yet takes around 10 – 12 hours to complete.

If you follow the same thing then you’ll have all the main ports installed that you need and you can get to the meat and potatoes stuff. As a precondition to running Rails you need to have MySQL installed. It doesn’t make any difference if you go for 5.0 or 5.1 as long as it’s there (and up at the time you start final configuration on a rails app).

Checking what version of Ruby I had at this point I could see 1.8 installed (as default).

This is fine, and the choice is there to install 1.9 if you want as there is a port for it in /usr/ports/lang/ruby19.

Gems isn’t installed as default, so the next task is putting that in. A simple “make search name=gems” shows the gem port in /usr/ports/devel/ruby-gems. Following the standard “make install clean” actions it will put the 1.3.5 version on your machine.

[root@iceman /usr/ports/devel/ruby-gems]# gem –version
1.3.5

Okay, now you’re good to go with putting on the specific gems to get Rails apps running. We begin of course with rails itself. (‘#’ denotes running command as root; ‘>’ denotes running command as non privileged user). A word of advice here, you’ll save yourself errors later on if you install the 2.2.3 version explicitly. The 2.3.4 version seemed broken with the latest build of Ruby.

# gem install -v 2.2.3 rails

This gives you a collection of gems that comprise the rails framework, and the Ruby documentation pages as well. Next up you need the MySQL gem, and I needed authlogic gems as we use this functionality in our customer portal for user management.

# gem install mysql

# gem install authlogic

# gem install authlogic-oid

# gem install ruby-openid

Because of the way character sets are interpreted (more like mangled) at the O/S level it can cause headaches for Ruby. It’s easily resolved by installing the character set conversion library and the accompanying ruby bindings, if you don’t you’ll run into runtime problems (which is exactly what happened to me).

# /usr/ports/converters/iconv make install clean

# /usr/ports/converters/ruby-iconv make install clean

Rake is the Rails functionality that sets up your database schema and needs to be present for the application configuration stage (when you’re finalising your application setup). Getting that installed is done by:

# gem install rake

However this version was one step behind what was needed, so you need an upgrade right after with this command:

# rake gems:install

This does quite a significant upgrade as you’ll see when you follow it’s progress, but at the end of it, you’ve got a number of gems on up-to-date versions compatible with rails.

Next come the test framework gems, and “thin”, which is the Rails web server, which we use to run our web app(s).

# gem test-unit -v 1.2.3

# gem install thin.

Finally, because of the type of application we have, which has a brick that takes a feed from our blog, I needed to added a gem from a Ruby developer who has developed an extremely good library for this. However, it’s not installed on the usual gem source so this had to be configured and added seperately in this way (You will notice quite a few other gems being installed as dependencies).

# gem sources -a http://gems.github.com

# gem install pauldix-feedzirra

Once all this was done, I had everything in place gem wise. If you follow the same path you’ll end up with a gem list that looks something – if not exactly – like this.

Now you’re right to configure your application database settings, and finally run your app. If you follow the standard convention for Rails development the database configuration is located in

# /path/to/your/app/config/database.yml

Create a mysql database; add the user (with GRANT); put these details here in this file. Once done, you can setup the database tables and schema with rake.

# rake db:schema:load

It’ll be pretty obvious if this worked or not by the output to stdout; you’ll either see a list of tables and properties that are defined, or error messages on some misconfigured property. Hopefully the former.

All that remains is to start your app server with

# /path/to/your/app/script/server

Which all things remaining equal will go through the successful bootstrap procedure of spinning up a web server instance and your application.

Best of luck, and I hope this was useful. It’s my experience that FreeBSD 8.0 makes setting up a Rails environment very simple and by-the-numbers. It just worked; which is really the catch cry of FreeBSD. I attempted to go through the same setup on an OpenSolaris 2009.06 environment and ran into so many problems I threw in the towel when I started running out of time to test a new build from our Dev team and fell back to getting old faithful – FreeBSD – configured and installed. If I feel like banging my head up against a brick wall again anytime soon I might retry that, but it won’t be for a while yet. I want to let the ringing in my ears and bleeding eyeballs subside first.