Skip to content

Instantly share code, notes, and snippets.

@snorremd
Last active April 21, 2019 11:29
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 snorremd/9db3e0891368ae597353bf91e7c317ae to your computer and use it in GitHub Desktop.
Save snorremd/9db3e0891368ae597353bf91e7c317ae to your computer and use it in GitHub Desktop.
Clojure tools.deps multi-stage Dockerfile setup to compile Clojure code inside Dockerfile
FROM clojure:openjdk-11-tools-deps-1.10.0.442 as builder
WORKDIR /app
# Install deps
COPY ./deps.edn ./
RUN clojure -Abuild -e "(clojure-version)"
# Compile Clojure code
ADD . /app
RUN clojure -Abuild
FROM openjdk:11.0.2-slim
COPY --from=builder /app/target/lib/lib /app/lib
COPY --from=builder /app/target/classes /app/classes
WORKDIR /app
CMD java $JAVA_OPTS -cp "classes:lib/*" our-app.core
@snorremd
Copy link
Author

The builder stage tries to be smart about copying only the deps.edn file and executing a simple Clojure script (clojure-version) to get the dependencies. Only then does it copy over application files and start the actual build. This should help with caching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment