Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

feat: Cache Clojure dependencies #553

Closed
wants to merge 3 commits into from
Closed

Conversation

mainej
Copy link

@mainej mainej commented Apr 29, 2021

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 mainej requested a review from a team as a code owner April 29, 2021 01:20
@mainej
Copy link
Author

mainej commented Apr 29, 2021

I believe this would fix #485.

@mainej mainej changed the title Cache Clojure dependencies feat: Cache Clojure dependencies Apr 29, 2021
@mainej mainej requested a review from a team June 4, 2021 17:52
This speeds up builds of Clojure repos by avoiding network calls to
download dependencies.

When a repo has a `deps.edn` file, we assume it is a Clojure repo and
would benefit from pre-populating and caching its primary dependencies.

Since Clojure dependencies are ultimately stored in the global `.m2`
directory, along with other Java dependencies, it suffices to restore
`.m2`. The directory is automatically populated during a build performed
with the [Clojure CLI tools][clojure-cli].

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

[clojure-cli]: https://clojure.org/reference/deps_and_cli
For repos that are built with the [Clojure CLI tools][clojure-cli]
(i.e., repos marked with a `deps.edn` file), we cache and restore the
`.cpcache` directory. Clojure uses this directory to avoid unnecessarily
re-calculating the JVM classpath. For most projects this additional
cache will not lead to a large improvement in build times.

We also download dependencies to the `.m2` cache before handing off to
the build script. Technically, this is unnecessary since, presumably,
the build script uses the Clojure CLI tools which have a side-effect of
populating `.m2`. Therefore, the benefit of this change is simply to
separate the two steps, isolating any errors that occure while fetching
dependencies.

[clojure-cli]: https://clojure.org/reference/deps_and_cli
The [Clojure CLI tools][clojure-cli] have a mechanism of downloading
dependencies directly from git repositories rather than from a package
manager. This patch caches the directory which stores these downloads,
speeding up builds of repos that use these types of dependencies.

[clojure-cli]: https://clojure.org/guides/deps_and_cli
@mainej mainej requested a review from a team September 25, 2021 18:42
@minikomi
Copy link

minikomi commented Oct 7, 2021

Would love to see this merged!

@kitop
Copy link
Contributor

kitop commented Aug 24, 2022

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 kitop closed this Aug 24, 2022
@mainej
Copy link
Author

mainej commented Aug 26, 2022

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants