Skip to content

Instantly share code, notes, and snippets.

@jmglov
Created August 6, 2022 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmglov/74aa9cd7c508c22375dd018b6b72689e to your computer and use it in GitHub Desktop.
Save jmglov/74aa9cd7c508c22375dd018b6b72689e to your computer and use it in GitHub Desktop.
build-deps {:docs "Builds a layer for dependencies"
:requires ([clojure.java.shell :refer [sh]]
[clojure.edn :as edn])
:task (let [{:keys [deps-path target-dir work-dir]} (th/parse-args)
deps-zipfile (th/deps-zipfile target-dir)]
(when-not deps-path
(th/error "Mising required argument: --deps-path"))
(fs/create-dirs target-dir work-dir)
(let [tmp-dir (fs/create-temp-dir)
deps (->> deps-path slurp edn/read-string :deps)]
(spit (fs/file work-dir "deps.edn")
{:deps deps
:mvn/local-repo (format "%s/m2-repo" tmp-dir)})
(println "Downloading deps into" (str tmp-dir))
(let [current-env (into {} (System/getenv))
{:keys [exit err]}
(sh "clojure" "-Spath"
:dir work-dir
:env (assoc current-env
"GITLIBS" (format "%s/gitlibs" tmp-dir)))]
(when (not= 0 exit)
(println "Error:" err)))
(println "Compressing custom runtime layer:" deps-zipfile)
(let [{:keys [exit err]}
(sh "zip" "-r" deps-zipfile
"gitlib"
:dir (str tmp-dir))]
(when (not= 0 exit)
(println "Error:" err)))
(fs/delete-tree tmp-dir)))}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment