- install all the gems required by the app (this can be a long list).
- install and configure the database used by the app.
- install and configure a webserver.
- ensure all the required services are started at boot time.
Dister to the rescue!Dister is a command line tool similar to the one used by Heroku (one of the coolest ways to run your Rails app into the cloud). Within a few steps you will be able to create a SUSE Studio appliance running your rails application, download it and deploy wherever you want. Dister is named after SUSE Studio robot. It has been created by Dominik Mayer and me during the latest hackweek.
How it worksWe are going to create a SUSE Studio appliance running a rails application called "SUSE history". The app uses bundler to handle its dependencies. This is its Gemfile file:
gem 'rails', '3.0.5'
gem 'pg' gem "flutie", "~>; 1.1"As you can see the app uses rails3, the flutie gem and PostgreSQL as database.
Appliance creationMove into the suse_history directory and execute the following command:
dister create suse_historyAs you can see dister has already done a couple of things for you:
- created an appliance using latest version of openSUSE supported by SUSE Studio (you can use a different base system of course)
- added the devel:language:ruby:extensions repository to the appliance: this repo contains tons of ruby packages (like mod_passenger)
- installed a couple of things:
- devel_C_C++ pattern: this will allow you to build native gems.
- devel_ruby pattern: provides ruby, rubygems and a couple of development packages needed to build native gems.
- rubygem-bundler: bundler is required by dister in order to handle the dependencies of your rails application.
- rubygem-passenger-apache2: dister uses passenger and apache2 to deploy your rails application.
- postgresql-server: dister noticed suse_history uses PostgreSQL as database, hence it automatically installs it.
- rubygem-pg: dister noticed suse_history uses PostgreSQL as database, hence it automatically installs the ruby's library forPostgreSQL.
- uploaded a custom build script which ensures:
- mod_passenger module is loaded by Apache
- both Apache and PostgreSQL are always started at boot time.
- all dependencies are installed: this is done only during the first boot using bundler.
- the database user required by your rails app is created. This is done only during the first boot using some SQL code.
- the database used by the appliance is properly initialized (aka rails db:create db:migrate). This is done only during the first boot.
Upload your codeIt's time to upload suse_history code. This is done using the following command:
dister pushAs you can see dister packaged the application source code and all its dependencies into a single archive. Then uploaded the archive to SUSE Studio as an overlay file. Dister uploaded also the configuration files required by Apache and by PostgreSQL setup.
Build your applianceIt's build time!
dister buildThe appliance has automatically being built using the raw disk. You can use different formats of course.
Testdrive is one of the coolest features of SUSE Studio. Unfortunately dister doesn't support it yet. Just visit your appliance page and start testdrive from your browser. Just enable testdrive networking and connect to your appliance:
DownloadYour appliance is working flawlessly. Download it and deploy it wherever you want.
Current statusAs you can see dister handles pretty fine a simple Rails application, but there's still room for improvements. Here's a small list of the things on my TODO list:
- The dependency management should install gems using rpm packages. This would make the installation of native gems easier, right now the user has to manually add all the development libraries required by the gem. Moreover it would reduce the size of the overlay files uploaded to SUSE Studio.
- SUSE Studio Testdrive should be supported.
- It should be possible to deploy the SUSE Studio directly to EC2.
- Fix bugs!