[Haskell-cafe] Building stack projects as docker images

Daniel Rolls daniel.rolls.27 at googlemail.com
Tue Sep 4 11:21:55 UTC 2018

I am building Haskell web services using docker. I do this utilising the
stack tool within the official Haskell Docker image. Doing this has a
number of advantages

- It's predictable - I can control bringing in new versions of stack and
- It's easy to share - no stack or Haskell installation is required to
build the image
- These services can interact with other services in a controlled
environment using Docker compose.

One downside is that I doing this naively means waiting for a modules to
download every time docker build is run since the stack build command will
start from scratch each time. I worked around this by adding two build
steps. The first runs a hello world example with the stack.yml and
package.yml from my project. The second build builds the intended code.
This trick separated the downloading of dependent libraries from building
the code and means day to day code changes are quick to build since the
first stack build is cached as a docker image layer. Still though, making a
small change to a stack yml file means a long wait re-downloading all
dependent libraries.

Firstly, is there a better way of doing this? I know stack supports
building within docker but when I worked this way I still found projects
depended on the system stack and would commonly fail due to stack bugs.

Secondly, my two "stack build" calls where the first builds a hello world
program feels a bit hacky. is there a better way to achieve this?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180904/b3947ce8/attachment.html>

More information about the Haskell-Cafe mailing list