Tag: railsstack.deb
Setting up the whole Rails stack from a single Debian meta package in 10 minutes
by Christoph Olszowka on Jan.22, 2009, under Ubuntu, rails, ruby
After staying almost the whole last week in the hospital because all of a sudden my appendix decided to hurt and part ways with me, I finally managed to finish my article I announced earlier on installing a whole Rails stack with Apache2, MySQL, Ruby, Rubygems, Phusion Passenger from a single Debian package file using the DebGem service and the Brightbox Passenger Debian packages.
This article won’t cover many basics of using the DebGem service. If you need an introduction, you might want to check out my earlier postings on the topic.
Preparing the VM
Just like in my second post on DebGem, I used a vanilla Ubuntu JeOS 8.04.1 LTS install in Virtualbox. Apart from the openssh-server package for easier access to the machine and an initial sudo apt-get update && sudo apt-get upgrade, the machine was untouched.
To start out, I installed the most basic required cli tools with
sudo apt-get install bash-completion nano wget curl
since JeOS is so much “Just enough OS” it does not even supply these very common packages. After this, the machine is ready to install the stack.
Adding the DebGem and Brightbox repositories
The additional debian repositories needed to be added to the apt package sources now in order for the Gems and Passenger to be installed properly:
# Switch to root shell sudo -s # Add debgem repository sh -c 'echo "deb http://www.debgem.com/apt ubuntu-8.04 rubyforge" > /etc/apt/sources.list.d/debgem.list' sh -c 'wget -q http://www.debgem.com/apt/debgem.gpg -O- | apt-key add -' sh -c 'echo "APT::Cache-Limit 33554432;" > /etc/apt/apt.conf' # Add brightbox passenger repository sh -c 'echo "deb http://apt.brightbox.net hardy main" > /etc/apt/sources.list.d/brightbox.list' sh -c 'wget -q -O - http://apt.brightbox.net/release.asc | apt-key add -' # Update repository index apt-get update
Installing the stack from the deb file
I uploaded the sample .deb file and it’s sources to github. The tarball of the project can be retrieved and extracted with:
wget -nv http://github.com/colszowka/railsstack.deb/tarball/master -O- | tar xzv -C ~/
Now just switch over to the extracted folder’s subdirectory ‘deb’:
cd colszowka-railsstack.deb-8bfcf1812c76766c095eb5a1510f2e84742b703a/deb/
The installation of the whole stack can now be invoked with
dpkg -i --force-depends railsstack.deb
Unfortunately, the dpkg command is unable to resolve remote dependencies, so the output will print a multitude of unresolved ones. But worry not, these will get automatically resolved by apt-get when running the following command:
apt-get -f install
The whole install will kick off now, installing as much as ruby, ri, rdoc, irb, rubygems, apache2, mysql-server-5.0, mysql-client-5.0, rails2.2.2-ruby1.8, libfastthread-ruby1.8, libapache2-mod-passenger and libmysql-ruby completely automatically. You will get asked for your desired MySQL root user password once, but that’s about it. After a couple of minutes, everything should be ready for the big test. Do not forget though to exit the root shell when installing Typo!
Test run with Typo 5.1.98
To check if Apache2/Passenger, MySQL, Ruby, Rails and everything else worked fine, I gave it a spin with the Typo Rails open source blog app:
cd ~ wget http://rubyforge.org/frs/download.php/49562/typo-5.1.98.tgz tar xfz typo-5.1.98.tgz cd typo-5.1.98 cp config/database.yml.example config/database.yml nano config/database.yml # Enter db credentials...
As a next step, the databases needed to be setup and the hideous .htaccess file from Typo’s public folder must be removed due to the problems it causes in combination with Apache.
rake db:create:all rake db:migrate RAILS_ENV=production rm public/.htaccess
To finish things, I just removed the default Apache2 host and defined my own for the Typo app using Passenger:
sudo rm /etc/apache2/sites-enabled/000-default sudo nano /etc/apache2/sites-enabled/passenger
The config looks like this:
<VirtualHost *:80>
ServerName 127.0.0.1
DocumentRoot /home/colszowka/typo-5.1.98/public
</VirtualHost>
Just a restart of Apache missing, sudo /etc/init.d/apache2 restart, and everything’s done, done! Let’s verify everything works:
$ curl localhost <html><body>You are being <a href="http://localhost/accounts/signup">redirected</a>.</body></html>
Sweet! To have a look at the site with my web browser, I created a port forwarding in VirtualBox (I wrote on how to accomplish that earlier) and pointed my browser to localhost:3123, the port I chose for the forwarding. The result in pictures rather than words:
The structure of the .deb package
The Debian (meta-)package used to setup the whole Apache/Passenger/MySQL/Ruby/Rails stack in merely ten minutes is pretty straight forward. It only consists of a control file sitting inside a DEBIAN folder. The file only describes the packages it depends upon, which then will be pulled in by apt-get. Take a look at it over at github
The control file looks like following:
Package: railsstack Essential: no Priority: extra Section: metapackages Maintainer: Christoph OlszowkaArchitecture: i386 Version: 1 Depends: ruby, ri, rdoc, irb, rubygems, apache2, mysql-server-5.0, mysql-client-5.0, rails2.2.2-ruby1.8, libfastthread-ruby1.8, libapache2-mod-passenger, libmysql-ruby Description: Metapackage for installing a Ruby on Rails stack on Apache2 with MySQL using Passenger (built by Brightbox) and DebGem.com
Note: Unfortunately and as mentioned before, this will currently still pull in loads of Rails versions and it’s dependencies since obviously the DebGem gem dependency list is still not working properly (or it is intendend to work like this, which to me makes no sense when I pull in a specific version of Rails, like I did in the control file with depending upon rails2.2.2-ruby1.8)
Building the package is simple: dpkg -b package railsstack.deb. After that, just put the .deb file on your server and execute mentioned commands:
dpkg -i --force-depends railsstack.deb apt-get -f install
Conclusion
Providing .deb metapackages allows for really simple, quick and straight-forward deployment of any Rails app on a vanilla Ubuntu JeOS Server. Rubygems even get updated automatically by DebGem to the latest version, so I did not have to stick with the old default Ubuntu package of Rubygems.
I did not try this yet with the actual Ubuntu Server distribution, which is much more widely used on servers, but since the server edition depends upon the same basic packages (apache2, mysql-server-5.0) as JeOS does, things should work the same way, maybe even quicker if you install the basic packages like Apache and MySQL from the CD.
Update, 2009-01-12: I actually tried this process on a new install of Ubuntu Server 8.04 with preinstalled LAMP, and everything worked just perfectly with the same steps as described above. The package manager recognized the already installed MySQL and Apache packages and did not try to reinstall them, just pulling in Passenger, Ruby and Rails.
Similar packages for Sinatra, Merb or anything you might want up and running quickly on your server should be no problem at well with a customized Railsstack.deb, so with a little help from DebGem and Brightbox, setting up a working Ruby environment for almost any Ruby server application becomes a no-brainer.
With the steps mentioned above, I was able to go from a freshly installed Ubuntu JeOS 8.04.1 to accessing the Typo site hosted on the machine in just 10 minutes, and plenty of this time was spent with downloading old Rails versions from DebGem, which hopefully will get sorted while the service is still in beta. When it becomes possible to pull in just the required versions of gems, it might be possible to have Typo running in just 5 minutes.









