First Steps
Zero to running in five minutes with lein.
Install leiningen
The first thing we need is leiningen, a build tool for clojure. You can downlaod this with your web browser, curl or wget or your favourite download tool, following the install instructions.
Install leiningen plugins (lein 1.x only)
We will need leiningen plugins for lein 1.x (1.6.2 or later). Let’s install them:
bash$ lein plugin install lein-newnew 0.3.5
bash$ lein plugin install pallet/lein-template 0.2.7
Note that this is only required for lein 1 (as installed when following the steps above). For lein 2, no plugins need to be installed.
Create a new project
Now we can create a new clojure project using lein, we will call it ‘quickstart’.
bash$ lein new pallet quickstart
Created new project in: quickstart
bash$ cd quickstart
If you are using lein 1.x, then you need to run lein deps at this point, to pull in the plugins into the local lib/dev directory.
Configure your credentials
Now you can configure your credentials.
bash$ lein pallet add-service aws aws-ec2 "your-aws-key" "your-aws-secret-key"
Note that this creates a ~/.pallet/services/aws.clj file with your credentials in it.
The second argument above is the name of the jclouds provider, which is cloud specific. To find the value for other clouds, you can list the supported providers with:
bash$ lein pallet providers
Start the REPL and load pallet
Start a repl with lein repl and load pallet with require at the repl user=> prompt.
(require 'pallet.core 'pallet.compute 'pallet.configure)
Start a cloud node
You can now start your first compute node:
(pallet.core/converge
(pallet.core/group-spec "mygroup"
:count 1
:node-spec (pallet.core/node-spec
:image {:os-family :ubuntu :image-id "us-east-1/ami-3c994355"}))
:compute (pallet.configure/compute-service :aws))
To shut the node down again, change the :count value to zero:
(pallet.core/converge
(pallet.core/group-spec "mygroup" :count 0)
:compute (pallet.configure/compute-service :aws))
Authorising yourself
Of course it would be nice to be able to ssh into the node. To enable this we add a call to automated-admin-user in the :bootstrap phase, which is run whenever a new node is started with the group-spec.
(use '[pallet.crate.automated-admin-user :only [automated-admin-user]])
(pallet.core/converge
(pallet.core/group-spec "mygroup"
:count 1
:node-spec (pallet.core/node-spec
:image {:os-family :ubuntu :image-id "us-east-1/ami-3c994355"})
:phases {:bootstrap automated-admin-user})
:compute (pallet.configure/compute-service :aws))
If you are running a ssh agent (e.g. you are on Mac OS X), then you must ensure that your key is available to the agent. You can make this change permanently using:
ssh-add -K your-private-key-file
Note that if your id_rsa key has a passphrase, and you’re not running an ssh-agent, then this will not work.
You should now be able to log into your new node via ssh (using your own username), and note that you can use sudo. You can find the host IP address by listing your nodes:
(pallet.compute/nodes (pallet.configure/compute-service :aws))
Installing something
Now we can log into the node, we can ask pallet to install and configure things.
Pallet can run as many different phases as you need, but by default it runs the :configure phase. Here we use the :configure phase to install curl.
(use '[pallet.action.package :only [package]]
'[pallet.phase :only [phase-fn]])
(pallet.core/converge
(pallet.core/group-spec "mygroup"
:count 1
:node-spec (pallet.core/node-spec
:image {:os-family :ubuntu :image-id "us-east-1/ami-3c994355"})
:phases {:bootstrap automated-admin-user
:configure (phase-fn (package "curl"))})
:compute (pallet.configure/compute-service :aws))
Next
Hopefully this has given you a small taste of running pallet from the REPL.
The example project generates some code as a template for how you might define your group-specs, so explore under the src directory.
The pallet plugin for lein that is enabled in the generated project is also useful for things like triggering a lift or converge, or listing nodes, from the command line.
Don’t hesitate to ask questions, either through the site here, via the mailing list, or on #pallet on freenode irc.