March 20, 2009 09:22
by: harm Edit

Passenger and adva

This developer section is powered by adva (lowercase!) and Passenger! Two pieces of superb software. In this short post I'll take you through the steps needed to setup adva in combination with Passenger.

Rails 2.3 got released last week and we'll be using that for it's support for engines and templates. Just create a new rails app with the adva template as described on the adva github page. From there on the situation got a bit less clear. Sure you can run script/server and have the stuff run on localhost but that is hardly what you want. We want a Git repo which we can deploy with Capistrano!

To this end I initialized a new git repository. To my surprise this didn't include the vendor/adva directory. That is because installing adva via the template based solution leaves a git repo in vendor/adva. Which makes kind of sense. You want to be able to update. Maybe git submodules would be a better fit but there are not known for their clarity.

What I ended up doing, and this is what the guys in the IRC channel suggested, was to remove the vendor/adva directory altogether and use the same approach Rails/Capistrano use as to link the log/system/etc directories. So I cloned the adva git repository from github and switched to the 0.1.2 branch. Then I modified the deploy.rb to create the symlink after updating the code:

task :finalize_update, :except => { :no_release => true } do
  run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)

  # mkdir -p is making sure that the directories are there for some SCM's that don't
  # save empty folders
  run <<-CMD
    rm -rf #{latest_release}/log #{latest_release}/public/system #{latest_release}/tmp/pids &&
    mkdir -p #{latest_release}/public &&
    mkdir -p #{latest_release}/tmp &&
    ln -s #{shared_path}/log #{latest_release}/log &&
    ln -s #{shared_path}/system #{latest_release}/public/system &&
    ln -s #{shared_path}/pids #{latest_release}/tmp/pids &&
    ln -s #{shared_path}/adva #{latest_release}/vendor/adva
  CMD

  if fetch(:normalize_asset_timestamps, true)
    stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
    asset_paths = %w(images stylesheets javascripts).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
    run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
  end
end

Basically all I did was copy paste the original task and added the last symlink creation. I'm sure there is a far more elegant way of doing this. Please do let me know!

There was one final hiccup. When creating the initial Rails project the template linked all the Rails engines in the vendor/plugins directory. These symlinks are not valid on an other machine. I removed them and symlinked them by hand using the relative paths.

That's it! Enjoy the new adva install!

Leave your reply

Preview