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.