Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

clojure: lein tar

DZone's Guide to

clojure: lein tar

· Java Zone
Free Resource

The single app analytics solutions to take your web and mobile apps to the next level.  Try today!  Brought to you in partnership with CA Technologies

A co-worker recently asked how I package and deploy my clojure code. There's nothing special about the code, but I'm making it available here for anyone who wants to cut and paste. Deploy is the easy part - scp a tar to the prod box. Building the tar is very easy as well. I've run this on a few different linux distros without issue, but YMMV. Without further ado.

(ns leiningen.tar
  (:require leiningen.jar leiningen.clean
            [clojure.java.io :as io])
  (:use clojure.java.shell))

(defn normalize-path [root path]
  (let [f (io/file path)]
    (.getAbsolutePath (if (.isAbsolute f) f (io/file root path)))))

(defn tar [project & args]
  (let [build-version (-> (System/getenv "BUILD_VERSION")
                          (or (first args))
                          (or "0.0.0.0"))
        release (str (:description project) "-" build-version)
        build-dir (normalize-path (:root project) (str "deploy/" release))
        jars-dir (normalize-path build-dir "jars")
        jar-file (leiningen.jar/jar project)
        tar-file (clojure.java.io/file (:root project) (str release ".tar.gz"))]
    (.delete tar-file)
    (sh "rm" "-rf" build-dir)
    (sh "mkdir" "-p" jars-dir)
    (sh "cp" "-R" (normalize-path (:root project) "src/web") build-dir)
    (sh "cp" "-R" (normalize-path (:root project) "lib/jars") build-dir)
    (sh "mv" jar-file jars-dir)
    (sh "tar" "--gzip" "--create"
      (str "--file=" (.getName tar-file))
      (str "--directory=" (normalize-path (:root project) "deploy/")) release)
    (println "Wrote" (.getName tar-file))))

I'm sure there are easier ways, and I know I could do it programically - but this works and is easy to maintain. That's good enough for me. 

CA App Experience Analytics, a whole new level of visibility. Learn more. Brought to you in partnership with CA Technologies.

Topics:

Published at DZone with permission of Jay Fields, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

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

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}