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

对着背影说爱祢 提交于 2020-05-16 05:15:47

问题


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 a side effect of also installing any executable related to this library. And the resulting Docker image is enormous - 67GB:

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

回答1:


This seems to do it:

stack build --only-dependencies


来源:https://stackoverflow.com/questions/54508207/how-to-pre-install-stack-dependencies-to-reduce-stack-build-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!