Skip to content

Instantly share code, notes, and snippets.

@diogok
Created January 15, 2020 17:47
Show Gist options
  • Save diogok/c4f3a971159019174ad3752ca543830b to your computer and use it in GitHub Desktop.
Save diogok/c4f3a971159019174ad3752ca543830b to your computer and use it in GitHub Desktop.
CLojure dockerfile
FROM clojure:openjdk-13-tools-deps-slim-buster as builder
WORKDIR /usr/src/app
# install cambada builder, as it will not change
RUN clj -Sdeps '{:deps {luchiniatwork/cambada {:mvn/version "1.0.0"}}}' -e :ok
# install main deps, sometimes change
COPY deps.edn /usr/src/app/deps.edn
RUN clj -e :ok
# add files and build, change often
COPY resources/ /usr/src/app/resources
COPY src/ /usr/src/app/src
RUN clj -A:uberjar
# use clean base image
FROM openjdk:13-slim-buster
# set static config
ENV PORT 8080
EXPOSE 8080
# set the command, with proper container support
CMD ["java","-XX:+UseContainerSupport","-XX:MaxRAMPercentage=85","-XX:+UnlockExperimentalVMOptions","-XX:+UseZGC","-jar","/usr/src/app/app.jar"]
# copy the ever changing artifact
COPY --from=builder /usr/src/app/target/app-1.0.0-SNAPSHOT-standalone.jar /usr/src/app/app.jar
FROM clojure:openjdk-11-tools-deps as builder
WORKDIR /usr/src/app
RUN clj -Sdeps '{:deps {luchiniatwork/cambada {:mvn/version "1.0.0"}}}' -e :ok
COPY deps.edn /usr/src/app/deps.edn
RUN clj -e :ok
COPY resources/ /usr/src/app/resources
COPY src/ /usr/src/app/src
RUN clj -A:uberjar# the native-image tool
FROM oracle/graalvm-ce:19.3.1-java11 as native
RUN gu install native-image
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/target/app-1.0.0-SNAPSHOT-standalone.jar /usr/src/app/app.jar# lots of specific flags
RUN native-image --allow-incomplete-classpath --static --enable-http --no-fallback --no-server --initialize-at-build-time --report-unsupported-elements-at-runtime --initialize-at-run-time=io.netty.channel.epoll.EpollEventArray,io.netty.channel.unix.Errors,io.netty.channel.unix.IovArray,io.netty.channel.unix.Socket,io.netty.channel.epoll.Native,io.netty.channel.epoll.EpollEventLoop,io.netty.util.internal.logging.Log4JLogger -jar app.jar app
# use clean image
FROM scratch
COPY --from=native /usr/src/app/app /app
CMD ["/app"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment