Trunk Mephisto, Edge Rails, Piston, and Mongrel. Oh, My.
Here are some notes from my latest endeavor, which was to switch my main site over to mephisto. I’d read about using piston to manage local changes to the mephisto code base, and that definitely sounded like the way to go.
This is not the easiest or fastest way to install Mephisto.
A lot of the steps below are overkill if you don’t need to keep mephisto in your own SVN repo, or if you don’t want to manage your themes in your repo. But this outlines what I think is a solid way of maintaining mephisto in a production environment.
Prerequisites
Make sure you’ve got the TZinfo gem installed on your production server. It’s a binary gem, so it really shouldn’t be frozen into the repository.
gem list tzinfo
Back on Your Development Machine…
Piston
Piston absolutely rocks for things like this. By using piston, you can make local changes, save them in SVN, and upgrade around them without blinking. Much like butter. I’m using edge mephisto here, because a) I want those plugins, and b) that’s just how I roll.
piston import http://svn.techno-weenie.net/projects/mephisto/trunk trunk
svn commit -m 'pistoned mephisto trunk to /trunk'
svn up # keep piston happy
Everything after this happens under trunk, so…
cd trunk
Rails
We’re also going to use piston to grab rails. Since we’re using edge Mephisto, we’ve got to stick with edge Rails.
piston import http://dev.rubyonrails.org/svn/rails/trunk vendor/rails
svn commit -m 'froze rails'
svn up # keep piston happy
As of this writing, edge rails had a bug causing the following error:
LoadError (Expected /home/tammersaleh/apps/tammersaleh/releases/20070922180713/app/models/assigned_section.rb to define AssignedSection)
Boooo. But this is what you face rollin’ on edge. Thanks to piston, it’s not a problem. I’ve got another blog running on rails release 7420, so we’ll downgrade to that:
piston upgrade -r 7420 vendor/rails
svn commit -m 'downgraded rails to 7420'
svn up # I pretty much do this all the time
TZinfo plugin
Gotta grab the latest version of that…
piston import svn://rubyforge.org/var/svn/tzinfo/trunk vendor/plugins/tzinfo
svn commit -m 'added tzinfo plugin'
svn up
Database
Create a config/database.yml file, and configure it with a production db. It’s just the standard rails database.yml, but the contents are completely installation specific. Once you’ve created that file:
svn add config/database.yml
svn commit -m 'configured database'
svn up
Default Theme in SVN
We’d like to be able to make changes to our theme from the command line and keep the changes in svn. So let’s do this part of the bootstrap by hand.
svn mkdir themes/site-1
svn cp themes/default themes/site-1/simpla
svn commit -m 'installed default theme'
svn up
Tweak the svn repository
Make some missing dirs and set ignores. These probably don’t matter if you don’t plan on running a development version or running the tests.
mkdir -p log tmp/cache tmp/pids tmp/sessions tmp/sockets tmp/attachment_fu
svn add log tmp
svn propset svn:ignore '*' log
svn propset svn:ignore '*' tmp/cache
svn propset svn:ignore '*' tmp/pids
svn propset svn:ignore '*' tmp/sessions
svn propset svn:ignore '*' tmp/sockets
svn propset svn:ignore '*' tmp/attachment_fu
svn propset svn:ignore 'tmp' test/fixtures
svn commit -m 'added log, tmp, and set ignores'
svn up
We’re going to be using capistrano, so let’s not save our images in the deploy directories—otherwise they would all go poof with each release.
ln -s system/assets public/
svn add public/assets
svn commit -m 'created assets symlink'
svn up
Capistrano
Your capistrano setup is going to be environment specific, but otherwise just like any other application you’d deploy. There’s nothing Mephisto-specific here.
svn add config/deploy.rb
svn commit -m 'configured capistrano'
svn up # why not?
Mongrel
This is also going to be site-specific, but here’s an example config/mongrel_cluster.yml file:
cwd: /path/to/apps/tammersaleh/current
port: "3110"
environment: production
address: 127.0.0.1
pid_file: log/mongrel.pid
servers: 2
The port information should match whatever your apache configuration gives you.
svn add config/mongrel_cluster.yml
svn commit -m 'added mongrel cluster config'
Fixes
If you make the log dir like I did, you’ll need to remove the line that tries to create it on the server in the bootstrap task. Just comment out line 5 in lib/tasks/bootstrap.rake which reads mkdir_p File.join(RAILS_ROOT, 'log').
You’ll also have to tell mephisto to load the ActionWebServices. Edit the environment.rb file, adding the following line right below the config.load_paths definition in the initializer block (line 22 for me):
config.load_paths += %W(#{RAILS_ROOT}/vendor/rails/actionwebservice/lib)
Deploy
We need to run that db:bootstrap task before we run migrations.
cap setup
Now ssh into your account, cd to the rails_root, and run rake db:bootstrap. We also need to create the assets directory. On the production server, run mkdir /apps/tammersaleh/shared/system/assets, replacing tammersaleh with your application name.
Finally, back on your dev machine, run the deploy:
cap cold_deploy
You should now have a running mephisto installation. If anything goes wrong, check out the log files under RAILS_ROOT/log and the Mephisto Forum.
Leave a comment...