Aug 15, 2012

Deploying clojure on dotcloud

Clojure ring apps can be compiled into war files and run in the dotclould java process but that doesn’t work if you want to.

  1. Run a webserver other than jetty (Aleph, Webbit)
  2. Run a clojure worker process.

Luckily compiling and running lein projects is easy with dotcloud’s custom service type.

First create a buildscript. This can go somewhere like scripts/build_web and is a simple bash script that builds your project’s uberjar. It seems that lein is installed on the dotcloud build servers but I was having problems because it wasn’t the latest version. Luckily it’s copied to a directory you have permission to edit so you can just upgrade it manually. Assuming you have a -main function in my-main-namespace.core this would be something like.

This will build an uberjar and copy the standalone version (which bundles all your dependencies) to the home directory (which is where everything is run from on dotcloud)

Then define a custom service in your dotcloud.yml file that will use this buildscript and call the run.jar.

Make sure your web app binds to the port in the environment var PORT_WWW and you should be good to go. If it’s a worker process you don’t have to worry about that and you can drop the ports section of the yml config.

Happy dotclouding!

About
/home/steveo/blog | @olsenator4 | github.com/saolsen | Subscribe via RSS.