作为我努力使miso-isomorphic-stack尽可能顺畅的一部分,我制作了几个带有GHCJS和一些新的stack版本(仓库在这里和hub在这里)的docker镜像,基于这些发行版。您可以在repo中看到如何使用它们,也许这个脚本可以更好地集成到您的流程中。
因此,理想情况下,您将通过类似以下内容的方式让stack管理docker镜像:
很遗憾,stack将开始在主机系统上寻找GHCJS,因此不会注意到已经在使用的容器镜像中构建了GHCJS。我怀疑这与setup-info有关,但我不太清楚如何解决这个问题。
我希望这里的某个人能更了解stack以及编译器是如何处理的。
这些镜像本身非常简单,它们只是在其中安装了GHCJS,这意味着您无需花费数小时来构建GHCJS,也无需面临任何问题,可以快速开始尝试GHCJS。
更新
尝试使用@mgsloan的建议会导致以下失败。
这是做什么的:
换句话说:如何使 stack 的 docker 支持能够发现已安装的 GHCJS 编译器?
因此,理想情况下,您将通过类似以下内容的方式让stack管理docker镜像:
resolver: lts-9.21
compiler: ghcjs-0.2.1.9009021_ghc-8.0.2
compiler-check: match-exact
setup-info:
ghcjs:
source:
ghcjs-0.2.1.9009021_ghc-8.0.2:
url: https://github.com/matchwood/ghcjs-stack-dist/raw/master/ghcjs-0.2.1.9009021.tar.gz
sha1: b1740c3c99e5039ac306702894cd6e58283f4d31
docker:
enable: true
repo: "tehnix/ghcjs-docker" # It will automatically add :lts-x.xx
auto-pull: true
system-ghc: false
很遗憾,stack将开始在主机系统上寻找GHCJS,因此不会注意到已经在使用的容器镜像中构建了GHCJS。我怀疑这与setup-info有关,但我不太清楚如何解决这个问题。
我希望这里的某个人能更了解stack以及编译器是如何处理的。
这些镜像本身非常简单,它们只是在其中安装了GHCJS,这意味着您无需花费数小时来构建GHCJS,也无需面临任何问题,可以快速开始尝试GHCJS。
更新
尝试使用@mgsloan的建议会导致以下失败。
No information found for ghcjs-0.2.1.9009021_ghc-8.0.2.
Supported versions for OS key 'source': GhcjsVersion 0.1.0.20150924 7.10.2
使用stack -v build
的完整构建日志:
Version 1.6.3, Git revision b27e629b8c4ce369e3b8273f04db193b060000db (5454 commits) x86_64 hpack-0.20.0
2018-04-24 12:56:42.195877: [debug] Loading project config file frontend/stack.yaml
@(Stack/Config.hs:868:13)
2018-04-24 12:56:42.205781: [debug] Run process: /usr/local/bin/docker --version
@(System/Process/Log.hs:37:3)
2018-04-24 12:56:42.559527: [debug] Process finished in 353ms: /usr/local/bin/docker --version
@(System/Process/Log.hs:44:3)
2018-04-24 12:56:42.559917: [debug] Run process: /usr/local/bin/docker inspect tehnix/ghcjs-docker:lts-9.21
@(System/Process/Log.hs:37:3)
2018-04-24 12:56:42.643497: [debug] Process finished in 83ms: /usr/local/bin/docker inspect tehnix/ghcjs-docker:lts-9.21
@(System/Process/Log.hs:44:3)
2018-04-24 12:56:42.657949: [debug] Run process: /usr/local/bin/docker create --net=host -e STACK_IN_CONTAINER=1 -e STACK_ROOT=/Users/christiankjaerlaustsen/.stack -e STACK_PLATFORM_VARIANT=dkb61b2dc4e76119fbba7cceb60d5ffa49 -e HOME=/Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend/.stack-work/docker/_home -e PATH=/opt/host/bin:/Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend/.stack-work/docker/_home/.local/bin:/root/.cabal/bin:/root/.local/bin:/opt/ghc/8.2.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -e PWD=/Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack -v /Users/christiankjaerlaustsen:/Users/christiankjaerlaustsen -v /Users/christiankjaerlaustsen/.stack:/Users/christiankjaerlaustsen/.stack -v /Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend:/Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend -v /Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend/.stack-work/docker/_home:/Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend/.stack-work/docker/_home -w /Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack -e USER=christiankjaerlaustsen -e SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.D8v3WjTyAg/Listeners -v /private/tmp/com.apple.launchd.D8v3WjTyAg/Listeners:/private/tmp/com.apple.launchd.D8v3WjTyAg/Listeners -v /Users/christiankjaerlaustsen/.stack/programs/x86_64-linux/stack-1.6.3/stack:/opt/host/bin/stack -t -i tehnix/ghcjs-docker:lts-9.21 /opt/host/bin/stack --internal-re-exec-version=1.6.3 --internal-docker-entrypoint "DockerEntrypoint {deUser = Just (DockerUser {duUid = 501, duGid = 20, duGroups = [20,12,61,79,80,81,98,702,33,100,204,250,395,398,399,701], duUmask = 18})}" --stack-yaml=frontend/stack.yaml -v build
@(System/Process/Log.hs:37:3)
2018-04-24 12:56:42.909494: [debug] Process finished in 248ms: /usr/local/bin/docker create --net=host -e STACK_IN_CONTAINER=1 -e STACK_ROOT=/Users/christiankjaerlaustsen/.stack -e STACK_PLATFORM_VARIANT=dkb61b2dc4e76119fbba7cceb60d5ffa49 -e HOME=/Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend/.stack-work/docker/_home -e PATH=/opt/host/bin:/Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend/.stack-work/docker/_home/.local/bin:/root/.cabal/bin:/root/.local/bin:/opt/ghc/8.2.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -e PWD=/Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack -v /Users/christiankjaerlaustsen:/Users/christiankjaerlaustsen -v /Users/christiankjaerlaustsen/.stack:/Users/christiankjaerlaustsen/.stack -v /Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend:/Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend -v /Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend/.stack-work/docker/_home:/Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend/.stack-work/docker/_home -w /Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack -e USER=christiankjaerlaustsen -e SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.D8v3WjTyAg/Listeners -v /private/tmp/com.apple.launchd.D8v3WjTyAg/Listeners:/private/tmp/com.apple.launchd.D8v3WjTyAg/Listeners -v /Users/christiankjaerlaustsen/.stack/programs/x86_64-linux/stack-1.6.3/stack:/opt/host/bin/stack -t -i tehnix/ghcjs-docker:lts-9.21 /opt/host/bin/stack --internal-re-exec-version=1.6.3 --internal-docker-entrypoint "DockerEntrypoint {deUser = Just (DockerUser {duUid = 501, duGid = 20, duGroups = [20,12,61,79,80,81,98,702,33,100,204,250,395,398,399,701], duUmask = 18})}" --stack-yaml=frontend/stack.yaml -v build
@(System/Process/Log.hs:44:3)
2018-04-24 12:56:42.910090: [debug] Creating process: /usr/local/bin/docker start -a -i 791fe386a759de5b23f7bf62a2cca15bdfa540287528024ec9931c4c69b4d913
@(System/Process/Log.hs:22:3)
Version 1.6.3, Git revision b27e629b8c4ce369e3b8273f04db193b060000db (5454 commits) x86_64 hpack-0.20.0
2018-04-24 10:56:48.844354: [debug] Loading project config file frontend/stack.yaml
@(Stack/Config.hs:868:13)
2018-04-24 10:56:48.856002: [debug] Run process: /usr/sbin/groupadd -o --gid 20 stack
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:48.887487: [debug] Process finished in 31ms: /usr/sbin/groupadd -o --gid 20 stack
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:48.890291: [debug] Run process: /usr/sbin/useradd -oN --uid 501 --gid 20 --home /Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend/.stack-work/docker/_home stack
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:48.929204: [debug] Process finished in 38ms: /usr/sbin/useradd -oN --uid 501 --gid 20 --home /Users/christiankjaerlaustsen/GitHub/Tehnix/miso-isomorphic-stack/frontend/.stack-work/docker/_home stack
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:48.929360: [debug] Run process: /usr/sbin/groupadd -o --gid 20 group20
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:48.938691: [debug] Process finished in 9ms: /usr/sbin/groupadd -o --gid 20 group20
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:48.938807: [debug] Run process: /usr/sbin/groupadd -o --gid 12 group12
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:48.952149: [debug] Process finished in 13ms: /usr/sbin/groupadd -o --gid 12 group12
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:48.952316: [debug] Run process: /usr/sbin/groupadd -o --gid 61 group61
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:48.977534: [debug] Process finished in 25ms: /usr/sbin/groupadd -o --gid 61 group61
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:48.977670: [debug] Run process: /usr/sbin/groupadd -o --gid 79 group79
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:48.991099: [debug] Process finished in 13ms: /usr/sbin/groupadd -o --gid 79 group79
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:48.991271: [debug] Run process: /usr/sbin/groupadd -o --gid 80 group80
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.006803: [debug] Process finished in 14ms: /usr/sbin/groupadd -o --gid 80 group80
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.006984: [debug] Run process: /usr/sbin/groupadd -o --gid 81 group81
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.020884: [debug] Process finished in 13ms: /usr/sbin/groupadd -o --gid 81 group81
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.021037: [debug] Run process: /usr/sbin/groupadd -o --gid 98 group98
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.030441: [debug] Process finished in 9ms: /usr/sbin/groupadd -o --gid 98 group98
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.030551: [debug] Run process: /usr/sbin/groupadd -o --gid 702 group702
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.040424: [debug] Process finished in 9ms: /usr/sbin/groupadd -o --gid 702 group702
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.040532: [debug] Run process: /usr/sbin/groupadd -o --gid 33 group33
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.051412: [debug] Process finished in 10ms: /usr/sbin/groupadd -o --gid 33 group33
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.051632: [debug] Run process: /usr/sbin/groupadd -o --gid 100 group100
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.061282: [debug] Process finished in 8ms: /usr/sbin/groupadd -o --gid 100 group100
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.061803: [debug] Run process: /usr/sbin/groupadd -o --gid 204 group204
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.074834: [debug] Process finished in 12ms: /usr/sbin/groupadd -o --gid 204 group204
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.075014: [debug] Run process: /usr/sbin/groupadd -o --gid 250 group250
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.085177: [debug] Process finished in 9ms: /usr/sbin/groupadd -o --gid 250 group250
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.085324: [debug] Run process: /usr/sbin/groupadd -o --gid 395 group395
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.093166: [debug] Process finished in 7ms: /usr/sbin/groupadd -o --gid 395 group395
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.093303: [debug] Run process: /usr/sbin/groupadd -o --gid 398 group398
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.101006: [debug] Process finished in 7ms: /usr/sbin/groupadd -o --gid 398 group398
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.101161: [debug] Run process: /usr/sbin/groupadd -o --gid 399 group399
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.109153: [debug] Process finished in 7ms: /usr/sbin/groupadd -o --gid 399 group399
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.109306: [debug] Run process: /usr/sbin/groupadd -o --gid 701 group701
@(System/Process/Log.hs:37:3)
2018-04-24 10:56:49.117319: [debug] Process finished in 7ms: /usr/sbin/groupadd -o --gid 701 group701
@(System/Process/Log.hs:44:3)
2018-04-24 10:56:49.119055: [debug] Decoding build plan from: /Users/christiankjaerlaustsen/.stack/build-plan/lts-9.21.yaml
@(Stack/Snapshot.hs:150:5)
2018-04-24 10:56:49.119212: [debug] Trying to decode /Users/christiankjaerlaustsen/.stack/build-plan-cache/lts-9.21.cache
@(Data/Store/VersionTagged.hs:66:5)
2018-04-24 10:56:49.132586: [debug] Success decoding /Users/christiankjaerlaustsen/.stack/build-plan-cache/lts-9.21.cache
@(Data/Store/VersionTagged.hs:70:13)
2018-04-24 10:56:49.133008: [debug] Getting system compiler version
@(Stack/Setup.hs:387:17)
No information found for ghcjs-0.2.1.9009021_ghc-8.0.2.
Supported versions for OS key 'source': GhcjsVersion 0.1.0.20150924 7.10.2
2018-04-24 12:56:46.033052: [debug] Run process: /usr/local/bin/docker rm -f 791fe386a759de5b23f7bf62a2cca15bdfa540287528024ec9931c4c69b4d913
@(System/Process/Log.hs:37:3)
2018-04-24 12:56:46.109114: [debug] Process finished in 75ms: /usr/local/bin/docker rm -f 791fe386a759de5b23f7bf62a2cca15bdfa540287528024ec9931c4c69b4d913
@(System/Process/Log.hs:44:3)
退一步
如果我们回到基础,我实际上想问的是,堆栈在docker镜像中如何找到GHC,我如何指定GHCJS的路径?
目前,构建此镜像的Dockerfiles相当简单。以构建lts-9.21的GHCJS为例,
FROM fpco/stack-build:lts-11.5
# Install node.js for GHCJS.
RUN curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - \
&& apt-get update \
&& apt-get install -y nodejs \
&& rm -rf /var/lib/apt/lists/*
# Set up GHCJS.
COPY src /tmp/setup-ghcjs
RUN cd /tmp/setup-ghcjs \
&& stack setup --system-ghc \
&& rm -rf /tmp/setup-ghcjs
RUN mkdir -p /src
VOLUME /src
WORKDIR /src
这是做什么的:
- 使用
fpco/stack-build:lts-11.5
作为基础层,因为它包含 cabal、stack 等。 - 然后安装 node.js,因为 GHCJS 需要它。
- 最后,使用一个包含与问题顶部完全相同的 stack.yaml 的项目构建 GHCJS,当然,去掉了 docker/system-ghc 部分。
ghcjs-0.2.1.9009021_ghc-8.0.2
编译器,但似乎并没有发生。镜像本身可以与例如 docker run -v $(pwd):/src -it tehnix/ghcjs-docker:lts-9.21 stack build
一起使用。换句话说:如何使 stack 的 docker 支持能够发现已安装的 GHCJS 编译器?
# 如果为 true(使用本地 Docker 引擎时的默认值),则将 Docker 容器中的进程与主机相同的 UID/GID 一起运行。这确保容器写入的文件在主机上归您所有。当 Docker 引擎是远程的(通过 tcp 访问),默认值为 false。
set-user: false
https://docs.haskellstack.org/en/stable/docker_integration/#configuration - Peter Becich