main logo

I'm Sebastien Orban and I'm a hacker and a painter.

31 December 2014

Building clojure application

This post is harder than it should, because we need to first clarify what we mean by building :

  • create a binary ready to be used,
  • create an aggregate of file ready to be used,
  • something else ?

All nuances are welcome of course : with test, with deployment, with...

So now that we know what we want, there's the second confusing part : so many tools, all interesting (like make, cmake, rake, lein), but all giving us their own definition of what it means to build.

First we need to define what we need for a ClojureScript webapp : - compile (transform here) the .cljs source into Javascript - prepare, the related files (images, html) - use this .js in an html files

For the first part, it's quite easy : cljsbuild take care of it. Then we need to modify the html that launch it, because it's not exactly the same call for dev/prod (mainly for optimization and for linked JavaScript framework call). Getting other files ready follow the same idea : get the final result, move it to the right place. To automate this repetitive task I've settle on rake : cleaner than a bash script, easy to write, easy to understand. Lein, for me, is not the proper tool to that this - it's a compiler first and foremost.

Now, for a simple Clojure webapp, it's even easier :

lein uberwar


This doesn't cover any of the other required step of course : getting ready for deployment involve database migration or update, sending properly the files, restarting services if need be... For me those step are a mix of rsync to send the files to the server, and of Ansible to handle the server side work.

One advantage of it all is that it's self documenting - no worry about being wrong, forgetting something, or any other human mistakes that can (and will) happen along the way. To be fair, one disadvantage is that it take times to put that in motion, and it's not always clear why this is needed.