Install dependencies in container using deps.edn

Viewed 230

I inherited a clojure code base and I'm trying to containerize it for local development. The creators used deps.edn to manage the dependencies. However, I can't figure out what RUN command I should use to pre-install the dependencies for the project.

Currently, my entrypoint is the following ['clj', '-m', 'app'] which installs the dependencies every time I start the container.

How do I pre-install dependencies for a clojure project using a Docker RUN command?

2 Answers

Deps/CLI caching is described here. Generally speaking, dependencies are downloaded once and saved in a subdirectory of the project directory named

./.cpcache  # "class path cache"

The ./.cpcache directory is analagous to the ~/.m2 cache directory used by Maven and related tools (e.g. Leiningen).

If you run the code locally, you should be able to copy the .cpcache dir with its cached dependencies into your Docker container. Then the dependencies don't need to be re-downloaded for each startup of the Docker container.

See also the Deps/CLI overview.


P.S.

This template project is set up to run using both lein and Deps/CLI via the Kaocha tool. You may find the comparison helpful.


P.P.S.

You may find it easiest to run your code by building an uberjar file which contains all your code and all dependencies in a single artifact. You can do this either using Leiningen or other tools such as depstar. You then invoke the application with a single command like:

java -jar demo-0.1.0-standalone.jar
Related