After having deployed a Meteor application in under 1 minute, I thought I’d try myself at another deployment. This time I wanted to go for something dynamic and having watched Simple Made Easy by Rich Hickey, the author of Clojure, I thought I’d try myself at deploying that. Again for the impatient, here the 1 minute fix:

Prerequisites

Quick Steps

Put [com.palletops/uberimage "0.4.1"] into the :plugins vector of your :user profile. Add :uberimage {:tag "registry.giantswarm.io/<username>/<repo>:<tag>"} to your project’s project.clj . Open the project root and run lein uberimage . You will get back an image uuid. Run docker push registry.giantswarm.io/<username>/<repo>:<tag> . Create a simple swarm.json using the image you pushed above. swarm up Profit

The Basics

One cool thing with Clojure is that with Leiningen, you get a pretty cool tool for automating projects and builds. There’s tons of plugins for Leiningen, incl. tools for development, testing, and deployment. Luckily, I stumbled upon the lein-uberimage plugin, which basically builds a Docker image that runs your Clojure project’s uberjar.

For getting this plugin running you first need a Java JDK, which you should have anyway, if you’re developing Clojure apps. You also need Leiningen installed, which again should be quite common for Clojure developers. You also need Docker to build, run, and push your image.

Building and Testing Your Application Locally

If you don’t have an own Clojure project, yet, you can clone this helloworld repo that Dennis made. Once you have a Clojure project, you need to add [com.palletops/uberimage "0.4.1"] to the :plugins vector of your :user profile. A minimal ~/.lein/profiles.clj should look like:

{:user {:plugins [[com.palletops/uberimage "0.4.1"]]}}

For more information check out the lein-uberimage GitHub repo.

Now, open the project root and run lein uberimage . You will get back an image uuid. You can test the image locally with

$ docker run -d -p 3000:8080 <image-uuid>

, where 8080 is the port that your application listens on and 3000 the port that the container exposes. Open your browser at http://<docker-host>:3000 to see if it worked.

Preparing and Pushing Your Docker Image to the Registry

However, the image we built above, does not have any name or tag. To make lein ubermage add those to the image it builds, add :uberimage {:tag "registry.giantswarm.io/<username>/<repo>:<tag>"} to your project’s project.clj .

Now you can run lein uberimage again to build an image with your desired name ( <repo> ) and tag. To push this image to your Giant Swarm private registry you just run

$ docker push registry.giantswarm.io/<username>/<repo>:<tag>

Running your Application on the Swarm

Having your image on the registry makes running it on the Swarm a breeze.

First, you create a short swarm.json using the image you pushed above. In my example it looks like following:

{ "name": "clojure-test", "components": { "clojure-test": { "image": "registry.giantswarm.io/puja/clojure-test:1.0", "ports": [ 8080 ], "domains": { "8080/tcp": [ "clojure-puja.gigantic.io" ] } } } }

Note: You should change the image entry to reflect your own username instead of puja .