Skip to content

Instantly share code, notes, and snippets.

@pwaller
Created January 8, 2019 11:12
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 pwaller/9f9626246ca735561aaf2049f3312b44 to your computer and use it in GitHub Desktop.
Save pwaller/9f9626246ca735561aaf2049f3312b44 to your computer and use it in GitHub Desktop.
Attempt at doing fast cached rebuilds with stack.
# syntax = docker/dockerfile:experimental
# Build with DOCKER_BUILDKIT=1 while support for caching features is not 'on by default' in Docker.
FROM ubuntu:18.04
ENV STACK_VERSION=1.9.3 STACK_SHA256SUM=c9bf6d371b51de74f4bfd5b50965966ac57f75b0544aebb59ade22195d0b7543
RUN wget --no-verbose https://github.com/commercialhaskell/stack/releases/download/v${STACK_VERSION}/stack-${STACK_VERSION}-linux-x86_64-static.tar.gz \
&& echo ${STACK_SHA256SUM} stack-${STACK_VERSION}-linux-x86_64-static.tar.gz | sha256sum --check --strict \
&& tar \
--directory /usr/local/bin \
--file stack-${STACK_VERSION}-linux-x86_64-static.tar.gz \
--strip-components=1 \
--extract stack-${STACK_VERSION}-linux-x86_64-static/stack
WORKDIR /app
# Copy in the stack configuration and run stack update.
COPY stack.yaml .
RUN --mount=type=cache,target=/root/.stack,id=dotstack \
--mount=type=cache,target=/app/.stack-work,id=stack-work \
\
stack update
# Copy in the cabal files, so that we can install dependencies. This is done as
# a separate step so that dependencies don't need to be invalidated for typical
# builds - only if these files are changed.
COPY project.cabal .
COPY subproject/subproject.cabal subproject/subproject.cabal
COPY subproject1/subproject1.cabal subproject1/subproject1.cabal
COPY subproject2/subproject2.cabal subproject2/subproject2.cabal
COPY subproject3/subproject3.cabal subproject3/subproject3.cabal
COPY subproject4/subproject4.cabal subproject4/subproject4.cabal
# Fetch dependencies from the network.
RUN --mount=type=cache,target=/root/.stack,id=dotstack \
--mount=type=cache,target=/app/.stack-work,id=stack-work \
\
stack build --prefetch --dry-run --test --bench --flag some-flags-are-passed
# Build dependencies.
RUN --mount=type=cache,target=/root/.stack,id=dotstack \
--mount=type=cache,target=/app/.stack-work,id=stack-work \
\
stack build --dependencies-only --test --bench --flag some-flags-are-passed
COPY . /app
# Build the project and subprojects.
RUN --mount=type=cache,target=/root/.stack,id=dotstack \
--mount=type=cache,target=/app/.stack-work,id=stack-work \
\
stat subproject1/subproject1.cabal \
&& stack build --test --bench --no-run-benchmarks --no-run-tests --flag some-flags-are-passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment