7

Our team is using Docker for building our Haskell app in it, and in order to optimize build times, we work towards sharing the ~/.stack directory from OS with the one inside docker containers. Initial implementation was to just reuse the one from OS, but it turned out this doesn't work quite well, it fails with an error like this:

The GHC located at /root/.stack/programs/x86_64-linux/ghc-8.0.1/bin/ghc failed to compile a sanity check. Please see:
    http://docs.haskellstack.org/en/stable/install_and_upgrade/
for more information. Exception was:                                                                                                                                                 Running /root/.stack/programs/x86_64-linux/ghc-8.0.1/bin/ghc /tmp/stack-sanity-check48/Main.hs -no-user-package-db in directory /tmp/stack-sanity-check48/ exited with ExitFailure 127

/root/.stack/programs/x86_64-linux/ghc-8.0.1/bin/ghc: line 9: /home/ubuntu/.stack/programs/x86_64-linux/ghc-8.0.1/lib/ghc-8.0.1/bin/ghc: No such file or directory
make: *** [adserver_executables] Error 1

It seems like somewhere in ~/.stack there is a cache which states an absolute path to GHC, and when we mount ~/.stack in docker, it gets mounted as /root/.stack instead of /home/<user>/.stack, thus compiler can't be found by that path.

Our current decision is to make a separate directory ~/.docker-stack, which we will use for all the docker-based builds, without interfering with the OS-level one. This is not ideal since it will use more space and will bring a need to re-compile packages even when they were compiled in non-docker OS-level environment.

Is there a better approach someone can propose to share ~/.stack with inner-docker stack? Thank you.

Konstantine Rybnikov
  • 2,457
  • 1
  • 22
  • 29
  • 2
    Are you manually starting your Docker containers, as opposed to using Stack's built-in Docker support? The latter handles properly separating out host compilers and packages vs the container versions. – Michael Snoyman Sep 05 '17 at 16:53
  • why are you mounting .stack in the firat place? docker could have its own .stack or a data only container that contains .stack – madnight Sep 06 '17 at 06:50
  • @MichaelSnoyman please see answer from our devops engineer https://gist.github.com/k-bx/695578ed7437a1fa37cc1cca722fb145 – Konstantine Rybnikov Sep 06 '17 at 07:47
  • @madnight we create new staging env for every developer's branch/PR, building from scratch takes hours, so we need to have some nice caching – Konstantine Rybnikov Sep 06 '17 at 07:51
  • If the goal is to control the Docker images yourselves and reduce build time, I'd recommend building the necessary dependencies within a Docker image, and then (as @madnight mentions) mounting a Docker-specific directory for caching additional work. Such an approach is available at: https://github.com/fpco/stack-docker-image-build – Michael Snoyman Sep 06 '17 at 14:12
  • 1
    i can confirm @MichaelSnoyman i think you are heading into the wrong direction with mounting ~/.stack from host – madnight Sep 08 '17 at 14:12

0 Answers0