Haskell:应用构建故障排除(docker 入门)

Haskell: app build troubleshooting (docker primer)

如果导入的库无法构建,我应该如何进行故障排除?

$ stack new any-tool simple
$ cd any-tool/
$ stack build

样板构建。

import Turtle 添加到 Main.hs:

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Turtle

main :: IO ()
main = do
  putStrLn "hello world"

turtle 添加到 any-tool.cabal:

....
executable any-tool
  hs-source-dirs:      src
  main-is:             Main.hs
  default-language:    Haskell2010
  build-depends:       base >= 4.7 && < 5
                     , turtle

不会构建:

$ stack build
clock-0.7.2: configure
clock-0.7.2: build
hashable-1.2.6.1: download
hashable-1.2.6.1: configure
hashable-1.2.6.1: build
hashable-1.2.6.1: copy/register
Progress: 2/30
--  While building custom Setup.hs for package clock-0.7.2 using:
      /home/alexey/.stack/setup-exe-cache/x86_64-linux-tinfo6-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0 build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /home/alexey/spaces/haskell/any-tool/.stack-work/logs/clock-0.7.2.log

...

看起来没什么特别的惊喜:turtle 有几十个依赖项,任何不兼容的地方,她都会去。问题是,我的下一步是什么?

你最好把沼泽排干。

https://www.fpcomplete.com/blog/2015/08/stack-docker

https://docs.haskellstack.org/en/stable/docker_integration

https://hub.docker.com/r/fpco/stack-build

我花了 docker 从代表那里安装,

$  docker pull fpco/stack-build
...
$ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED SIZE
...
fpco/stack-build    latest              4e3c147fca48        4 months ago        4.3GB
...

并向我项目的 stack.yaml 添加三行:

docker:
  enable: true
  image: 4e3c147fca48

图像不是很轻,但非常值得。

您可以将图像名称直接放入 stack.yaml 而不受惩罚:

docker:
  enable: true
  repo: "fpco/stack-build"