build-image icon indicating copy to clipboard operation
build-image copied to clipboard

feat: Cache Clojure dependencies

Open mainej opened this issue 3 years ago • 2 comments

This PR adds caching for repos built with the Clojure CLI tools. It extends 52f8eb9, which added initial support for building with the Clojure CLI tools, but did not address caching. It is similar to f3a4d49 which introduced caching for Leiningen and Boot, two other ways of building Clojure code.

This PR contains three commits. I'd like to see them all put into use, but the second one is certainly optional.

The first commit will significantly improve build times and decrease network bandwidth for Clojure repos. It does this by restoring the .m2 directory before building, as other JVM based tools do.

The second commit is less important. It has two parts.

  • First, it takes advantage of a cache that the Clojure CLI tools create, a cache which helps them avoid re-calculating a JVM classpath. In practice, I haven't seen any projects where that calculation is so slow that this cache will have much impact.
  • Second, it downloads dependencies to the .m2 directory before starting the build. Technically this is unnecessary. As opposed to a tool like, for example, bundler, which expects to resolve and download dependencies before the "real" code is run, the Clojure CLI tools combine dependency management and code execution into one step. Therefore existing builds that use the Clojure CLI tools already populate .m2. So, this change merely separates the steps, isolating errors that occur during download.

The third commit caches the ~/.gitlibs directory, which the Clojure CLI tools use to cache dependencies procured from git repos (as opposed to from package managers). This will improve build times and decrease network bandwidth for Clojure repos which use this type of dependency procurement.

mainej avatar Apr 29 '21 01:04 mainej

I believe this would fix #485.

mainej avatar Apr 29 '21 01:04 mainej

Would love to see this merged!

minikomi avatar Oct 07 '21 09:10 minikomi

Closing this PR as it's against xenial branch and the Xenial image is going to be deprecated: https://answers.netlify.com/t/please-read-end-of-support-for-xenial-build-image-everything-you-need-to-know/68239

Feel free to reopen against focal.

kitop avatar Aug 24 '22 10:08 kitop

I've reopened this as #831, against the focal branch. I also took the opportunity to simplify the PR. /cc @minikomi

mainej avatar Aug 26 '22 03:08 mainej