This repository has been archived by the owner. It is now read-only.


Raynes edited this page Jun 16, 2011 · 1 revision

Cake contexts allow you to easily configure your application to run in different contexts. Some common contexts are dev/qa/stage/production. Contexts are declared using the defcontext macro and can be placed in project.clj or in context.clj in your project root.

(defcontext qa
  :deploy {:hosts ["" ""]
           :copy  [[:war "web.xml"]]}
  :db {:database "qa"
       :username "test"
       :host     ""})

(defcontext production
  :deploy {:hosts ["" "" ""]
           :copy  [[:war "web.xml"]]}
  :db {:database "production"
       :username "live"
       :host     ""})

Contexts are implemented as an overlay on top of cake/*project*, so defaults can be added directly to defproject and current context data will appear in *project*. In this example, to access your database config in code, just do something like this:

(with-connection (:db *project*)

Cake commands can also be run in a specific context using the --context command line option or the @ command line shortcut. So the following two commands both start a repl using the qa context:

cake repl --context=qa
cake repl @qa

You can also make use of contexts in your built artifacts. Add the key :bake to your project with value true, and cake will generate a file and insert it into your jar so that the context in effect at the time the jar was built will be available as it the code was still running in cake.