首页 > 解决方案 > 使用 Haskell-stack 构建 docker 容器时出现问题:如何确保 Haskell-stack 继续构建到最后?

问题描述

这是发生了什么:我用堆栈构建了一个 docker 映像,但该过程被中断了五次。消息说每次中断都发生在构建包 Cabal-2.4.1.0 时。该过程以代码退出:ExitFailure (-9) (THIS MAY INDICATE OUT OF MEMORY)

我想在 docker-script 中自动化该过程,因此堆栈必须完成它。那是我的问题。这是构建时发生的事情(我省略了一些行以使您的滚动保持在合理的范围内,所以希望看到<... skipping <n> lines ...>)时不时地。(将在底部继续。)

BA92-C02VP224HTDF:Ampersand stefjoosten$ docker build -t amp:latest .
Sending build context to Docker daemon  70.28MB
Step 1/8 : FROM ubuntu:latest
 ---> 7698f282e524
Step 2/8 : RUN apt-get update &&     apt-get --yes install curl &&     apt-get --yes install git-core
 ---> Using cache
 ---> 81322e02eb2a
Step 3/8 : RUN curl -sSL https://get.haskellstack.org/ | sh   # install Haskell and stack
 ---> Using cache
 ---> 0ff9ca0665b9
Step 4/8 : WORKDIR /Ampersand/                                # build from the Ampersand source code directory
 ---> Using cache
 ---> a66b539a6868
Step 5/8 : RUN git clone https://github.com/AmpersandTarski/Ampersand/ .
 ---> Using cache
 ---> 1806c9a40c82
Step 6/8 : RUN git checkout feature/rio-phase2                # get Ampersand sources in the correct version
 ---> Using cache
 ---> 456074437186
Step 7/8 : RUN stack setup                                    # set up Haskell stack (version taken from stack.yaml)
 ---> Using cache
 ---> fcadefd6812c
Step 8/8 : RUN stack install                                  # installs Ampersand executables in /root/.local/bin
 ---> Running in 0a8d298a757c
Updating package index Hackage (mirrored at https://s3.amazonaws.com/hackage.fpcomplete.com/) ...
Selected mirror https://s3.amazonaws.com/hackage.fpcomplete.com/
Downloading root
Selected mirror https://s3.amazonaws.com/hackage.fpcomplete.com/
Downloading timestamp
Downloading snapshot
Downloading mirrors
Cannot update index (no local copy)
Downloading index
Updated package index downloaded
Update complete
Populating index cache ...
Populated index cache.
[1 of 2] Compiling Main             ( /root/.stack/setup-exe-src/setup-mPHDZzAJ.hs, /root/.stack/setup-exe-src/setup-mPHDZzAJ.o )
[2 of 2] Compiling StackSetupShim   ( /root/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /root/.stack/setup-exe-src/setup-shim-mPHDZzAJ.o )
Linking /root/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.4 ...
Cabal-2.4.1.0: download
StateVar-1.1.1.1: download
HsYAML-0.1.1.3: download
StateVar-1.1.1.1: configure
SHA-1.6.4.4: download
StateVar-1.1.1.1: build
HsYAML-0.1.1.3: configure
HsYAML-0.1.1.3: build
Cabal-2.4.1.0: configure
StateVar-1.1.1.1: copy/register

<...  skipping 55 lines  ...>

cereal-0.5.8.0: download
cereal-0.5.8.0: configure
cereal-0.5.8.0: build
basement-0.0.10: copy/register
cereal-0.5.8.0: copy/register
blaze-html-0.9.1.1: copy/register

--  While building package Cabal-2.4.1.0 using:
      /root/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.4 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.4.0.1 build --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure (-9) (THIS MAY INDICATE OUT OF MEMORY)
    Logs have been written to: /Ampersand/                                # build from the Ampersand source code directory/.stack-work/logs/Cabal-2.4.1.0.log

    Configuring Cabal-2.4.1.0...
    Preprocessing library for Cabal-2.4.1.0..
    Building library for Cabal-2.4.1.0..
    [  1 of 220] Compiling Distribution.Compat.Binary ( Distribution/Compat/Binary.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/Binary.o )
    [  2 of 220] Compiling Distribution.Compat.Directory ( Distribution/Compat/Directory.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/Directory.o )
    [  3 of 220] Compiling Distribution.Compat.Exception ( Distribution/Compat/Exception.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/Exception.o )
    [  4 of 220] Compiling Distribution.Compat.Internal.TempFile ( Distribution/Compat/Internal/TempFile.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/Internal/TempFile.o )
    [  5 of 220] Compiling Distribution.Compat.MonadFail ( Distribution/Compat/MonadFail.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/MonadFail.o )
    [  6 of 220] Compiling Distribution.Compat.Newtype ( Distribution/Compat/Newtype.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/Newtype.o )

<...  skipping 56 lines  ...>

    [ 63 of 220] Compiling Distribution.System ( Distribution/System.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/System.o )
    [ 64 of 220] Compiling Distribution.SPDX.LicenseReference ( Distribution/SPDX/LicenseReference.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/SPDX/LicenseReference.o )
    [ 65 of 220] Compiling Distribution.SPDX.LicenseId ( Distribution/SPDX/LicenseId.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/SPDX/LicenseId.o )
The command '/bin/sh -c stack install                                  # installs Ampersand executables in /root/.local/bin' returned a non-zero code: 1
BA92-C02VP224HTDF:Ampersand stefjoosten$ docker start  `docker ps -q -l` # restart it in the background
0a8d298a757c
BA92-C02VP224HTDF:Ampersand stefjoosten$ docker attach `docker ps -q -l`
cmark-gfm-0.1.8: build
clock-0.7.2: copy/register
colour-2.3.4: download
colour-2.3.4: configure
colour-2.3.4: build

<...  skipping 200 lines  ...>

primitive-0.6.4.0: copy/register
reflection-2.1.4: copy/register
hxt-9.3.1.16: copy/register

--  While building package Cabal-2.4.1.0 using:
      /root/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.4 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.4.0.1 build --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure (-9) (THIS MAY INDICATE OUT OF MEMORY)
    Logs have been written to: /Ampersand/                                # build from the Ampersand source code directory/.stack-work/logs/Cabal-2.4.1.0.log

    Configuring Cabal-2.4.1.0...
    Preprocessing library for Cabal-2.4.1.0..
    Building library for Cabal-2.4.1.0..
    [  1 of 220] Compiling Distribution.Compat.Binary ( Distribution/Compat/Binary.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/Binary.o )
    [  2 of 220] Compiling Distribution.Compat.Directory ( Distribution/Compat/Directory.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/Directory.o )
    [  3 of 220] Compiling Distribution.Compat.Exception ( Distribution/Compat/Exception.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/Exception.o )
    [  4 of 220] Compiling Distribution.Compat.Internal.TempFile ( Distribution/Compat/Internal/TempFile.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/Internal/TempFile.o )
    [  5 of 220] Compiling Distribution.Compat.MonadFail ( Distribution/Compat/MonadFail.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/MonadFail.o )
    [  6 of 220] Compiling Distribution.Compat.Newtype ( Distribution/Compat/Newtype.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Compat/Newtype.o )

<...  skipping 104 lines  ...>

    [111 of 220] Compiling Distribution.Types.AbiDependency ( Distribution/Types/AbiDependency.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Types/AbiDependency.o )
    [112 of 220] Compiling Distribution.Simple.InstallDirs ( Distribution/Simple/InstallDirs.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Simple/InstallDirs.o )
    [113 of 220] Compiling Distribution.Types.LegacyExeDependency ( Distribution/Types/LegacyExeDependency.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Types/LegacyExeDependency.o )
    [114 of 220] Compiling Distribution.Types.BuildInfo ( Distribution/Types/BuildInfo.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Distribution/Types/BuildInfo.o )
BA92-C02VP224HTDF:Ampersand stefjoosten$ docker start  `docker ps -q -l` # restart it in the background
0a8d298a757c
BA92-C02VP224HTDF:Ampersand stefjoosten$ docker attach `docker ps -q -l`
regex-base-0.93.2: copy/register
regex-pcre-builtin-0.94.4.8.8.35: download

<...  skipping 678 lines with three more interruptions  ...>

pandoc-2.5: copy/register
pandoc-crossref-0.3.4.0: download
pandoc-crossref-0.3.4.0: configure
pandoc-crossref-0.3.4.0: build
pandoc-crossref-0.3.4.0: copy/register
Building all executables for `ampersand' once. After a successful build of all of them, only specified executables will be rebuilt.
ampersand-3.17.0: configure (lib + exe)
[1 of 2] Compiling Main             ( /Ampersand/                                # build from the Ampersand source code directory/Setup.hs, /Ampersand/                                # build from the Ampersand source code directory/.stack-work/dist/x86_64-linux/Cabal-2.4.0.1/setup/Main.o )
[2 of 2] Compiling StackSetupShim   ( /root/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /Ampersand/                                # build from the Ampersand source code directory/.stack-work/dist/x86_64-linux/Cabal-2.4.0.1/setup/StackSetupShim.o )
Linking /Ampersand/                                # build from the Ampersand source code directory/.stack-work/dist/x86_64-linux/Cabal-2.4.0.1/setup/setup ...
Configuring ampersand-3.17.0...
ampersand-3.17.0: build (lib + exe)



Warning: Cannot read previously generated src/Ampersand/Prototype/StaticFiles_Generated.hs:
src/Ampersand/Prototype/StaticFiles_Generated.hs: openFile: does not exist (No such file or directory)
This warning should disappear the next time you build Ampersand. If the error persists, please report this as a bug.

Static files have changed, updating src/Ampersand/Prototype/StaticFiles_Generated.hs

Preprocessing library for ampersand-3.17.0..
Building library for ampersand-3.17.0..
[  1 of 113] Compiling Ampersand.Basics.Prelude ( src/Ampersand/Basics/Prelude.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Ampersand/Basics/Prelude.o )
[  2 of 113] Compiling Ampersand.Basics.Languages ( src/Ampersand/Basics/Languages.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Ampersand/Basics/Languages.o )
[  3 of 113] Compiling Ampersand.Basics.Exit ( src/Ampersand/Basics/Exit.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Ampersand/Basics/Exit.o )
[  4 of 113] Compiling Ampersand.Basics.BuildInfo_Generated ( src/Ampersand/Basics/BuildInfo_Generated.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Ampersand/Basics/BuildInfo_Generated.o )
[  5 of 113] Compiling Ampersand.Basics.Auxiliaries ( src/Ampersand/Basics/Auxiliaries.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Ampersand/Basics/Auxiliaries.o )
[  6 of 113] Compiling Ampersand.Basics.String ( src/Ampersand/Basics/String.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Ampersand/Basics/String.o )

<...  skipping 103 lines  ...>

[110 of 113] Compiling Ampersand.Test   ( src/Ampersand/Test.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Ampersand/Test.o )
[111 of 113] Compiling Ampersand        ( src/Ampersand.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Ampersand.o )
[112 of 113] Compiling MainApps         ( src/MainApps.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/MainApps.o )
[113 of 113] Compiling Paths_ampersand  ( .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/autogen/Paths_ampersand.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Paths_ampersand.o )
Preprocessing executable 'ampersand' for ampersand-3.17.0..
Building executable 'ampersand' for ampersand-3.17.0..
[1 of 2] Compiling Main             ( app/Ampersand/Main.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/ampersand/ampersand-tmp/Main.o )
[2 of 2] Compiling Paths_ampersand  ( .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/ampersand/autogen/Paths_ampersand.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/ampersand/ampersand-tmp/Paths_ampersand.o )
Linking .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/ampersand/ampersand ...
ampersand-3.17.0: copy/register
Installing library in /Ampersand/                                # build from the Ampersand source code directory/.stack-work/install/x86_64-linux/lts-13.16/8.6.4/lib/x86_64-linux-ghc-8.6.4/ampersand-3.17.0-K72VvTMgyU7EFfE6avLPOe
Installing executable ampersand in /Ampersand/                                # build from the Ampersand source code directory/.stack-work/install/x86_64-linux/lts-13.16/8.6.4/bin
Registering library for ampersand-3.17.0..
Completed 25 action(s).
Copying from /Ampersand/                                # build from the Ampersand source code directory/.stack-work/install/x86_64-linux/lts-13.16/8.6.4/bin/ampersand to /root/.local/bin/ampersand

Copied executables to /root/.local/bin:
- ampersand

看到构建过程由于(可能的)内存耗尽原因而中断很奇怪,但是在重新启动 docker-build 过程后,该过程愉快地继续。我需要重新启动 5 次才能到达终点。

我尝试增加 docker 的内存,尝试使用以下命令:

docker build -m 4g -t amp:latest .
docker build -m 12g -t amp:latest .

但这并没有什么值得注意的区别。

我会很感激任何想法...

标签: dockerdockerfilecabalhaskell-stack

解决方案


你最好的选择可能是--jobs 1传给stack. 这将关闭并发构建,从而减少内存需求。GHC 通常会占用大量内存,特别是某些代码在编译时确实会占用大量内存。可能发生的情况是,两个都占用大量内存的模块最终同时构建,当这种情况发生时,您将最终得到 OOM。但是每次运行构建时,都会构建更多的包并且构建顺序可能会改变,所以最终你运气好,内存猪不会同时构建,所以构建能够完成。


推荐阅读