Chris Stryczynski
Chris Stryczynski

Reputation: 34001

How to pre-install stack dependencies, to reduce stack build time?

I'm building a docker image from a Haskell application, I'm executing stack build from within the container.

Because stack build is starting from a 'fresh/vanilla' docker image - all the libraries need to be installed/pulled.


Is there a way I can pre-install these library dependencies? For the end goal of reducing the docker image build time (stack build). I'd also like to be able to later on 'add' an additional dependency without having to once again stack build everything over from start.

A possible solution:

I tried a series of:

RUN stack install --only-dependencies --resolver="lts-14.27" aeson
RUN stack install --only-dependencies --resolver="lts-14.27" aeson-pretty
RUN stack install --only-dependencies --resolver="lts-14.27" ansi-terminal
RUN stack install --only-dependencies --resolver="lts-14.27" ansi-wl-pprint
RUN stack install --only-dependencies --resolver="lts-14.27" appar
RUN stack install --only-dependencies --resolver="lts-14.27" array
RUN stack install --only-dependencies --resolver="lts-14.27" asn1-encoding
RUN stack install --only-dependencies --resolver="lts-14.27" asn1-parse
RUN stack install --only-dependencies --resolver="lts-14.27" asn1-types
RUN stack install --only-dependencies --resolver="lts-14.27" async
RUN stack install --only-dependencies --resolver="lts-14.27" attoparsec
RUN stack install --only-dependencies --resolver="lts-14.27" authenticate-oauth
RUN stack install --only-dependencies --resolver="lts-14.27" auto-update
RUN stack install --only-dependencies --resolver="lts-14.27" base
RUN stack install --only-dependencies --resolver="lts-14.27" base-compat
RUN stack install --only-dependencies --resolver="lts-14.27" base-orphans
RUN stack install --only-dependencies --resolver="lts-14.27" base16-bytestring

However this has several limitations:

docker images
REPOSITORY                                                      TAG                                                   IMAGE ID            CREATED             SIZE
<none>                                                          <none>                                                d2a95ef3622d        11 seconds ago      67GB

Upvotes: 2

Views: 700

Answers (2)

Chris Stryczynski
Chris Stryczynski

Reputation: 34001

One can manually install the dependencies in a single step with something like :

stack install --resolver lts-14.27 Cabal Only RSA SHA StateVar adjunctions aeson ...

Upvotes: 1

sam46
sam46

Reputation: 1271

This seems to do it:

stack build --only-dependencies

Upvotes: 6

Related Questions