Crane: Heavy Lifting for Clojure Sevices

DZone 's Guide to

Crane: Heavy Lifting for Clojure Sevices

· Cloud Zone ·
Free Resource
Having grown out of a need to easily deploy Hadoop clusters in Amazon S3 and EC2, the open source project Crane has added Clojure-based webserver, database (SQL or distributed), and worker cluster deployments to its repertoire.  Crane is authored by Bradford Cross, a co-founder, head researcher, and architect at FlightCaster.  Crane works with AWS out of box.  It is also released under MIT.

Deploying a Web Service with Crane
Deploying a web service is pretty simple with Crane.  First you add Crane's leiningen plugin with the crane dependency in your project.clj.
[crane "1.0-SNAPSHOT"]
[crane/lein-crane "0.0.1"]
Then you add a deploy.clj file into the src directory.  The config files are formatted as Clojure maps.  In Crane, no-arg functions can be called in your deploy.clj as targets. 
lein crane web
The deploy.clj file can access anything in your project classpath, including Crane.  Crane is used as a normal library.

Web must be a target in the deploy.clj:
(defn web []
(bootstrap :webconfig :webcreds)))
In this example, the webserver is deployed using Crane's bootstrap capabilities.

Bootstrap in Crane
Crane's three basic phases are install, push, and run.  Crane mostly builds up vectors of strings (of commands to run or files to sync) in addition to supplying basic configuration attributes such as groups, project roots, etc.  "Anywhere that you could supply a string, you can supply a vector of strings and keywords, and the keyworkds will be replaced with their corresponding values from the config map," said Cross.

The install phase will install packages on your linux distro, and you can supply a vector of install commands as strings.  The push phase syncs both local and remote files.  Lastly, the run phase runs the commands and starts your webserver, worker processes, databases, or other service.  

For more info on Crane, read a recent blog by Cross.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}