How to cache deps with deps.edn, to speed docker image builds?

602 views
Skip to first unread message

Jason Whitlark

unread,
Jun 3, 2018, 2:30:05 PM6/3/18
to Clojure
When building docker images with lein, I frequently have a run lein.deps before building, to cache the deps in the image.  I'm not clean on how to accomplish the same thing with deps.edn.  Any suggestions?

Cheers,
~Jason

Luke Burton

unread,
Jun 3, 2018, 3:18:05 PM6/3/18
to Clojure
I have an outstanding pull request to add explicit copying of deps to a target folder (like lein libdir) to depstar:


(for esoteric reasons one of the places I deploy demands I use "thin jars" which is essentially the app and dependencies side-by-side in individual jars)

But if all you want to do is make sure you're caching the deps in their own step in the dockerfile, just run something like clj -Stree before your build step.

If you want to control the exact place where they end up instead of ~/.m2, there's probably an environment variable somewhere to customize that.

Luke.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Miller

unread,
Jun 3, 2018, 5:55:09 PM6/3/18
to Clojure


On Sunday, June 3, 2018 at 2:18:05 PM UTC-5, Luke Burton wrote:
I have an outstanding pull request to add explicit copying of deps to a target folder (like lein libdir) to depstar:


(for esoteric reasons one of the places I deploy demands I use "thin jars" which is essentially the app and dependencies side-by-side in individual jars)

But if all you want to do is make sure you're caching the deps in their own step in the dockerfile, just run something like clj -Stree before your build step.

If you want to control the exact place where they end up instead of ~/.m2, there's probably an environment variable somewhere to customize that.

You can set :mvn/local-repo in your deps.edn to use something other than ~/.m2/repository. 

Luke Burton

unread,
Jun 3, 2018, 7:00:54 PM6/3/18
to Clojure
Oh, by the way, scraping GitHub with some search filters can often yield some good boilerplate to get a Dockerfile started. You can search for Dockerfiles that seem to be based off the clojure:tools.deps "official" image:

filename:dockerfile "clojure:tools.deps"

Aside: this yielded only 11 Dockerfiles :/ I'm building all my new projects using tools.deps targeting Kubernetes via Docker containers – if you're not doing this you're missing out :) Perhaps a blog post is called for …

Anyway, here's someone doing exactly what the OP requested:


Slightly different search yields a couple more Dockerfiles (only 7, my admonishment still stands)

filename:dockerfile clojure "deps.edn"

One of which is for the "dispatchframework.io" Clojure image:


Which looks pretty cool. Anyone using it? https://github.com/vmware/dispatch


Jason Whitlark

unread,
Jun 3, 2018, 10:00:18 PM6/3/18
to Clojure
Yea, I'm experimenting with kubernetes patterns, and wanted to revisit use of deps.edn for them.

Last time I searched for that, I didn't find much useful. Times have changed!


Thanks!
~Jason
Reply all
Reply to author
Forward
0 new messages