lein-immutant Plugin 1.0.1 Released

We just released version 1.0.1 of our Leiningen plugin. This is a patch release, with the following changes:

  • Archive creation no longer uses lib/ as a staging area for dependencies - this prevents stale dependencies from being picked up in development after creating an archive.
  • Archives are no longer created in the current directory, but under project-root/target/ instead. The exact location will depend on the profiles that are active. The archive command will output the full path to the archive.
  • The url used by the install and overlay tasks to download Immutant has been changed to use a CDN. This should provide shorter download times, and allows us to track download counts to get a feel for usage.

Get it

If you're already using lein-immutant you probably already know how to do this, but just in case - to install it, add it to the :plugins list in your :user profile in ~/.lein/profiles.clj:

{:user {:plugins [[lein-immutant "1.0.1"]]}}

Get in touch

If you have any questions, issues, or other feedback, you can always find us on #immutant on freenode or you can file an issue on lein-immutant.

lein-immutant Plugin 1.0.0.beta1 Released

As we approach a 1.0.0 of Immutant, we've also been focusing on getting our Leiningen plugin ready for a 1.0.0 release as well.

Today, we're as pleased as a punch bug player to announce the first 1.0.0 beta release of the plugin: 1.0.0.beta1.

For 1.0.0.beta1, we've made quite a few changes to the plugin, some of which are not backwards compatible. We'll talk about all of the changes, starting with the breaking ones.

The base install dir location and structure

When we wrote the initial version of the plugin, we used .lein/immutant as base directory for storing Immutant installs and other files. But as the plugin has grown, we've realized that's not the best place for storing those files, since they aren't Leiningen specific. Therefore, we've moved the base directory to ~/.immutant.

In addition, we've reorganized the layout of ~/.immutant/releases to be a bit cleaner.

Since the new plugin will be looking in ~/.immutant, it won't see the prior installs in ~/.lein/immutant. You'll need to re-install the Immutant versions you need, and can safely delete ~/.lein/immutant.

The plugin now installs the latest release by default

Pre-1.0.0.beta1, the plugin installed the latest incremental build when you executed lein immutant install. As we approach 1.0.0 of Immutant, we've changed the plugin to install the latest stable release instead.

So, to install the latest stable release:

lein immutant install

If you want to install the latest incremental build:

lein immutant install LATEST

You can still specify any stable release version or incremental build number to get an exact version.

Listing installed versions

A couple of releases ago, we added the lein immutant list command that lists currently deployed applications. In 1.0.0.beta1, this command has been extended with a --installs flag (or -i) to list all of the installed Immutant versions instead of deployments:

$ lein immutant list --installs
The following versions of Immutant are installed to /home/tobias/.immutant
(* is currently active via /home/tobias/.immutant/current):

   0.10.0                         (type: full)
   0.10.0                         (type: slim)
   0.6.0                          (type: full)
   0.9.0                          (type: slim)
   0.9.0                          (type: full)
 * 1.0.0.beta1                    (type: slim)
   1.x.incremental.879            (type: slim)
   1.x.incremental.882            (type: slim)

You'll also now see this list after every lein immutant install invocation.

Overriding the base directory

In addition to moving the base directory to ~/.immutant, we've added the option to override its location, either per-project or globally.

You can override it on a per-project basis by setting :lein-immutant {:base-dir "/path"} in your project.clj

You can override it globally two ways:

  • by setting :lein-immutant {:base-dir "/path"} in your user profile in .lein/profiles.clj
  • by setting an environment variable: $LEIN_IMMUTANT_BASE_DIR

Setting the base directory in project.clj will override the setting in .lein/profiles.clj. Using the environment variable will override both.

Get it

If you're already using lein-immutant you probably already know how to do this, but just in case - to install it, add it to the :plugins list in your :user profile in ~/.lein/profiles.clj:

{:user {:plugins [[lein-immutant "1.0.0.beta1"]]}}

Get in touch

We realize this release has quite a few changes, and we may not have all of the kinks worked out. If you have any questions, issues, or other feedback, you can always find us on #immutant on freenode or you can file an issue on lein-immutant.

Getting Started: Installing Immutant v2

Greetings! This article covers the new, improved method for installing Immutant, and replaces the first in the getting started series of tutorials with Immutant. This entry covers setting up a development environment and installing Immutant. This tutorial assumes you are on a *nix system. It also assumes you have Leiningen installed. If not, follow these instructions, then come back here.

Installing the lein plugin

We provide a lein plugin for creating your Immutant applications and managing their life-cycles. As of this post, the latest version of the plugin is 0.3.1. Check clojars for the current version.

Let's install it as a global plugin:

 $ lein plugin install lein-immutant 0.3.1
Copying 3 files to /a/nice/long/tmp/path/lib
Including lein-immutant-0.3.1.jar
Including clojure-1.2.0.jar
Including clojure-contrib-1.2.0.jar
Including data.json-0.1.1.jar
Including fleet-0.9.5.jar
Including overlay-1.0.1.jar
Including progress-1.0.1.jar
Created lein-immutant-0.3.0.jar

Now, run lein immutant to see what tasks the plugin provides:

 $ lein immutant
Manage the deployment lifecycle of an Immutant application.

Subtasks available:
install    Downloads and installs Immutant
overlay    Overlays features onto ~/.lein/immutant/current or $IMMUTANT_HOME
env        Displays paths to the Immutant that the plugin can find
new        Creates a new project skeleton initialized for Immutant
init       Adds a sample immutant.clj configuration file to an existing project
deploy     Deploys the current project to the Immutant specified by ~/.lein/immutant/current or $IMMUTANT_HOME
undeploy   Undeploys the current project from the Immutant specified by ~/.lein/immutant/current or $IMMUTANT_HOME
run        Starts up the Immutant specified by ~/.lein/immutant/current or $IMMUTANT_HOME, displaying its console output

We'll only talk about the install and run tasks in this article - we covered the application specific management tasks in our second tutorial, and cover overlay in its own article.

Installing Immutant

Now we need to install an Immutant distribution. We've yet to make any official releases, but our CI server is setup to publish an incremental build every time we push to the git repo. The latest incremental build is always available at http://immutant.org/builds/immutant-dist-bin.zip. The previous version of this tutorial walked you through downloading and installing the latest incremental manually, but with the new install task, that's no longer necessary - the install task will download and install the latest incremental build for you. Let's see that in action:

 $ lein immutant install
Downloading http://repository-projectodd.forge.cloudbees.com/incremental/immutant/LATEST/immutant-dist-bin.zip
done!                                                                           
Extracting /a/nice/long/tmp/path/lib/immutant-dist-bin.zip
Extracted /Users/tobias/.lein/immutant/releases/immutant-1.x.incremental.51
Linking /Users/tobias/.lein/immutant/current to /Users/tobias/.lein/immutant/releases/immutant-1.x.incremental.51

Part of the install process links the most recently installed version to ~/.lein/immutant/current so the plugin can find the Immutant install without requiring you to set $IMMUTANT_HOME. If $IMMUTANT_HOME is set, it will override the current link.

If you want to install a specific incremental build, specify the build number (available from our builds page) as an argument to lein:

 $ lein immutant install 50

You can also have it install to a directory of your choosing (if you want the latest build, specify 'latest' as the version):

 $ lein immutant install latest /some/other/path

~/.lein/immutant/current will be linked to that location.

Running Immutant

To verify that Immutant is properly installed, let's fire it up. To do so, use the lein immutant run command. This is a convenient way to start the Immutant's JBoss server, and will run in the foreground displaying the console log. You'll see lots of log messages that you can ignore - the one to look for should be the last message, and will tell you the Immutant was properly started:

 $ lein immutant run
Starting Immutant via /Users/tobias/.lein/immutant/current/jboss/bin/standalone.sh
...
(a plethora of log messages deleted)
...
09:18:03,709 INFO  [org.jboss.as] (Controller Boot Thread) JBoss AS 7.1.0.Beta1 "Tesla" started in 2143ms - Started 149 of 211 services (61 services are passive or on-demand)

You can kill the Immutant with Ctrl-C.

Wrapping up

If you've done all of the above, you're now ready to deploy an application. We covered that in our second tutorial.

Since Immutant is still in a pre-alpha state, none of what I said above is set in stone. If anything does change, We'll update this post to keep it accurate.

If you have any feedback or questions, get in touch!

Getting Started: Deploying a Web Application

Welcome back! This article covers creating a basic Ring web application and deploying to an Immutant. It is the second installment in a series of tutorials on getting started with Immutant. If you haven't read the first installment, go do so now, since it covers installation and setup. This tutorial assumes you are on a *nix system.

Creating an Immutant Clojure application

In our previous article, we installed the lein plugin. Let's take another look at the tasks it provides:

~/immutant $ lein immutant
Manage the deployment lifecycle of an Immutant application.

Subtasks available:
new        Create a new project skeleton initialized for immutant.
init       Adds a sample immutant.clj configuration file to an existing project
deploy     Deploys the current project to the Immutant specified by $IMMUTANT_HOME
undeploy   Undeploys the current project from the Immutant specified by $IMMUTANT_HOME
run        Starts up the Immutant specified by $IMMUTANT_HOME, displaying its console output

We talked about run last time. This time, we'll cover new and deploy. To do so, we'll build a basic application that demonstrates the current web features. To get started, let's create an Immutant project:

~/immutant $ lein immutant new immutant-demo
Created new project in: /Users/tobias/immutant/immutant-demo
Look over project.clj and start coding in immutant_demo/core.clj
Wrote sample immutant.clj

The new task creates a Leiningen project and gives it a sample Immutant configuration file (immutant.clj). It is equivalent to calling:

~/immutant $ lein new immutant-demo && cd immutant-demo && lein immutant init

We'll come back to immutant.clj in a sec. Now, let's add a ring handler to our core namespace:

(ns immutant-demo.core)

(defn ring-handler [request]
  {:status 200
    :headers {"Content-Type" "text/html"}
    :body "Hello from Immutant!" })

Configuring the application for Immutant

When the Immutant deploys an application, it looks for a file named immutant.clj at the root and evaluates it if it exists. This file is used to configure the Immutant services you want your application to consume. It's the single place you defines all the components required by your application, and saves you from having to keep external configuration files in sync (crontabs, message queue definitions, init scripts, etc).

The file has example code for configuring web endpoints and messaging services, but we're just going to deal with web endpoints in this article. Edit your immutant.clj so it looks like:

(ns immutant-demo.init
  (:use immutant-demo.core)
  (:require [immutant.messaging :as messaging]
            [immutant.web :as web]))

(web/start "/" #'ring-handler)

We'll come back to what web/start is doing after we get the application running.

Deploying your application

Before we can start up an Immutant, we need to tell it about our application. We do that by deploying (for this to work, you need to have IMMUTANT_HOME set - see the previous article for details):

~/immutant/immutant-demo $ lein immutant deploy
Deployed immutant-demo to /Users/tobias/immutant/current/jboss/standalone/deployments/immutant-demo.clj

This writes a deployment descriptor to Immutant's deploy directory which points back to the application's root directory. Now the Immutant can find your application - so let's fire it up.

Starting Immutant

To launch an Immutant, use the lein immutant run command. This will start the Immutant's JBoss server, and will run in the foreground displaying the console log. You'll see lots of log messages that you can ignore - the one to look for should be the last message, and should tell you the app was deployed:

~/immutant/immutant-demo $ lein immutant run
Starting Immutant via /Users/tobias/immutant/current/jboss/bin/standalone.sh
...
(a plethora of log messages deleted)
...
13:04:39,888 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "immutant-demo.clj"

Now, let's verify that our app is really there. Immutant runs on port 8080 by default, so let's hit it and see what happens:

~ $ curl http://localhost:8080/immutant-demo/
Hello from Immutant!

Yay!

You can kill the Immutant with Ctrl-C.

Context Paths

Remember our call to web/start earlier? Let's talk about what that is doing. To do that, however, we need to first talk about context paths. The context path is the portion of the URL between the hostname and the routes within the application. It basically tells Immutant which requests to route to a particular application.

An Immutant can host multiple applications at the same time, but each application must have a unique context path. If no context path is provided when an application is deployed, it defaults to one based on the name of the deployment. The deployment name is taken from the name of the deployment descriptor, which in turn is taken from the name of the project given to defproject in project.clj. So for our sample app above, the context path defaults to /immutant-demo. You can override this default by specifying a :context-path within an :immutant map in your project.clj. Let's go ahead and do that:

(defproject immutant-demo "1.0.0-SNAPSHOT"
  :description "A basic demo"
  :dependencies [[org.clojure/clojure "1.2.1"]]
  :immutant {:context-path "/"})

Now, when you call lein immutant deploy, the context path will be picked up from your project.clj and included in the deployment descriptor and any web endpoints your application stands up will be accessible under that context path.

Which brings us back to web/start. web/start stands up a web endpoint for you, and takes two arguments: a sub-context path and a Ring handler function. The sub-context path is relative to the application's context path, so a context path of "/ham" and a sub-context path of "/" makes the handler function available at /ham, whereas a sub-context path of "/biscuits" makes the handler function available at /ham/biscuits. Make sense?

You can register as many web endpoints as you like within an application - they just each need an application unique sub-context path. If we add this to our core.clj:

(defn another-ring-handler [request]
  {:status 200
   :headers {"Content-Type" "text/html"}
   :body "Pssst! Over here!"})

And this to our immutant.clj:

(web/start "/biscuits" #'another-ring-handler)

Redeploy the application to pick up the :context-path from immutant.clj:

~/immutant/immutant-demo $ lein immutant deploy
Deployed immutant-demo to /Users/tobias/immutant/current/jboss/standalone/deployments/immutant-demo.clj

Then fire an Immutant up again with lein immutant run, we can see they both work:

~ $ curl http://localhost:8080
Hello from Immutant!
~ $ curl http://localhost:8080/biscuits
Pssst! Over here!

web/start has a companion function for shutting down a web endpoint: web/stop. It takes the sub-context path for the endpoint, and can be called from anywhere. You aren't required to shut down your endpoints - Immutant will do that on your behalf when it is shut down or the application is undeployed.

Wrapping up

I hope you've enjoyed this quick run-through of deploying a web application to Immutant. Since Immutant is still in a pre-alpha state, none of what I said above is set in stone. If anything does change, I'll edit this post to keep it accurate. I've posted the demo application we've built if you want to download it.

If you have any feedback or questions, get in touch! And stay tuned - our next tutorial will cover using Immutant's messaging features.

Getting Started: Installing Immutant

This article is out of date - see our new tutorial for the latest instructions for installing Immutant.

Greetings! This article is the first in a series of tutorials on getting started with Immutant. This entry covers setting up a development environment and installing Immutant. This tutorial assumes you are on a *nix system. It also assumes you have Leiningen installed. If not, follow these instructions, then come back here.

Installing the lein plugin

We provide a lein plugin for creating your Immutant applications and managing their life-cycles. As of this post, the latest version of the plugin is 0.2.0. Check clojars for the current version.

Let's install it as a global plugin:

~ $ lein plugin install lein-immutant 0.2.0
Copying 3 files to /a/nice/long/tmp/path/lib
Including lein-immutant-0.2.0.jar
Including clojure-1.2.0.jar
Including commons-exec-1.1.jar
Including fleet-0.9.5.jar
Created lein-immutant-0.2.0.jar

Now, run lein immutant to see what tasks the plugin provides:

~ $ lein immutant
Manage the deployment lifecycle of an Immutant application.

Subtasks available:
new        Create a new project skeleton initialized for immutant.
init       Adds a sample immutant.clj configuration file to an existing project
deploy     Deploys the current project to the Immutant specified by $IMMUTANT_HOME
undeploy   Undeploys the current project from the Immutant specified by $IMMUTANT_HOME
run        Starts up the Immutant specified by $IMMUTANT_HOME, displaying its console output

We'll only talk about the run task today, and save the rest for the next tutorial.

Installing Immutant

Now we need to install an Immutant distribution. We've yet to make any official releases, but our CI server is setup to publish an incremental build every time we push to the git repo. The latest incremental build is always available at http://immutant.org/builds/immutant-dist-bin.zip.

At this point, I'd love to tell you to install Immutant via:

lein immutant install # coming soon!

But that currently won't work. Until we actually implement that, you'll have to download and setup Immutant manually. Go ahead and download our latest incremental build.

Once you have the zip file downloaded, unzip it somewhere handy. For this walk-through, I'm going to put it in ~/immutant/. When unzipped, the distribution will have the build number in the directory name. It's handy to have a consistent path to the distribution, allowing us to download other incremental builds in the future with minimal fuss. To do that, link the distribution to current. Here is my shell session doing just that:

~ $ mkdir immutant
~ $ cd immutant
~/immutant $ unzip -q ../downloads/immutant-dist-bin.zip
~/immutant $ ln -s immutant-1.x.incremental.15 current
~/immutant $ ls
current                     immutant-1.x.incremental.15
~/immutant $ ls -l
total 8
lrwxr-xr-x  1 tobias  staff   27 Nov  7 22:41 current -> immutant-1.x.incremental.15
drwxrwxr-x  3 tobias  staff  102 Nov  7 13:20 immutant-1.x.incremental.15

Now we'll set a environment variable pointing to the distribution:

export IMMUTANT_HOME=~/immutant/current

This will tell the lein plugin where to find Immutant. Once we implement lein immutant install, this requirement will go away.

Running Immutant

To verify that Immutant is properly installed, let's fire it up. To do so, use the lein immutant run command. This is a convenient way to start the Immutant's JBoss server, and will run in the foreground displaying the console log. You'll see lots of log messages that you can ignore - the one to look for should be the last message, and will tell you the Immutant was properly started:

~/immutant $ lein immutant run
Starting Immutant via /Users/tobias/immutant/current/jboss/bin/standalone.sh
...
(a plethora of log messages deleted)
...
22:46:31,663 INFO  [org.jboss.as] (Controller Boot Thread) JBoss AS 7.x.incremental.182 "Ahoy!" started in 2990ms - Started 136 of 200 services (61 services are passive or on-demand)

You can kill the Immutant with Ctrl-C.

Wrapping up

If you've done all of the above, you're now ready to deploy an application. We'll cover that in our next tutorial.

Since Immutant is still in a pre-alpha state, none of what I said above is set in stone. If anything does change, I'll edit this post to keep it accurate.

If you have any feedback or questions, get in touch!