Over a million developers have joined DZone.

Crane: Heavy Lifting for Clojure Sevices

· Cloud Zone

Download the Essential Cloud Buyer’s Guide to learn important factors to consider before selecting a provider as well as buying criteria to help you make the best decision for your infrastructure needs, brought to you in partnership with Internap.

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.

The Cloud Zone is brought to you in partnership with Internap. Read Bare-Metal Cloud 101 to learn about bare-metal cloud and how it has emerged as a way to complement virtualized services.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}