-
-
Save lfborjas/28d1eb02e70b1b13407eabfa8bb25974 to your computer and use it in GitHub Desktop.
Optimized multistage Dockerfile for Haskell Stack builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Loosely based on https://www.fpcomplete.com/blog/2017/12/building-haskell-apps-with-docker | |
FROM fpco/stack-build:lts-13.27 as dependencies | |
RUN mkdir /opt/build | |
WORKDIR /opt/build | |
# GHC dynamically links its compilation targets to lib gmp | |
RUN apt-get update \ | |
&& apt-get download libgmp10 | |
RUN mv libgmp*.deb libgmp.deb | |
# Docker build should not use cached layer if any of these is modified | |
COPY stack.yaml package.yaml stack.yaml.lock /opt/build/ | |
RUN stack build --system-ghc --dependencies-only | |
# ------------------------------------------------------------------------------------------- | |
FROM fpco/stack-build:lts-13.27 as build | |
# Copy compiled dependencies from previous stage | |
COPY --from=dependencies /root/.stack /root/.stack | |
COPY . /opt/build/ | |
WORKDIR /opt/build | |
RUN stack build --system-ghc | |
RUN mv "$(stack path --local-install-root --system-ghc)/bin" /opt/build/bin | |
# ------------------------------------------------------------------------------------------- | |
# Base image for stack build so compiled artifact from previous | |
# stage should run | |
FROM ubuntu:16.04 as app | |
RUN mkdir -p /opt/app | |
WORKDIR /opt/app | |
# Install lib gmp | |
COPY --from=dependencies /opt/build/libgmp.deb /tmp | |
RUN dpkg -i /tmp/libgmp.deb && rm /tmp/libgmp.deb | |
COPY --from=build /opt/build/bin . | |
EXPOSE 8080 | |
CMD ["/opt/app/app", "8080"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment