【问题标题】:How to fix "<stdin>: hGetLine: end of file" when running stack build --file-watch in a docker-compose command如何在 docker-compose 命令中运行 stack build --file-watch 时修复“<stdin>: hGetLine: end of file”
【发布时间】:2019-10-21 08:09:07
【问题描述】:

我尝试在 docker-compose 服务中为我的 haskell RPC 服务器代码进行自动重建和重新执行设置。该命令是一个带有 stack build --file-watch 的 bash 脚本(以及另一个在二进制文件更改时启动二进制文件的命令,但这有效)。问题是,无论我尝试什么,stack build --file-watch 命令都会失败,并出现一个神秘的错误&lt;stdin&gt;: hGetLine: end of file

我不明白为什么会出现此错误,尤其是因为如果我使用 docker-compose run bd-service bash -l -c "./bd-service/compile_hs_and_run.sh" 运行相同的命令,它会按预期工作。我认为这是执行 docker-compose up 时如何处理 bash 的问题,而不是堆栈本身的问题,但我承认我一无所知。

还要注意:

  • 删除 --file-watch 选项使脚本工作
  • 将 --file-watch 替换为 --file-watch-poll 不会改变任何内容

这是服务定义:

  # this is my service definition in docker-compose.yml
  bd-service:
    build:
      context: '.'
      dockerfile: 'dockerfiles/bd_heroku_service.Dockerfile'
      args:
        UID: "$UID"
    command:  bash -l -c "./bd-service/compile_hs_and_run.sh"
    user: "$UID"
    volumes:
      - .:/app/user

这是相关的dockerfile:

# Inherit from bd_heroku_node image
FROM bd_heroku_node

ENV LANG en_US.UTF-8
# Stack stores binaries in /root/.local/bin
ENV PATH /root/.local/bin:$PATH

# Heroku assumes we'll put everything in /app/user
RUN mkdir -p /app/user/bd-service
WORKDIR /app/user

USER root

ARG STACK_VERSION=2.1.3
RUN wget -qO- https://github.com/commercialhaskell/stack/releases/download/v$STACK_VERSION/stack-$STACK_VERSION-linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C /usr/local/bin '*/stack'
USER appuser
# . here means the entire bd-bootstrap repo, context should be set accordingly (to bd-bootstrap)
RUN stack setup --resolver lts-14.10;

USER appuser
RUN mkdir -p /app/user/bd-common
RUN mkdir -p /app/user/bd-service

COPY bd-common/*.yaml /app/user/bd-common/

RUN cd /app/user/bd-common; stack build --only-dependencies;

RUN stack install fswatcher;

然后是我的 bash 文件 compile_hs_and_run:

#! /bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

cd $DIR
echo "We are at "
pwd
echo "start";

stack build --verbose --file-watch

# The next command is commented because it works :
# /app/.local/bin/fswatcher --path /app/user/bd-service/.stack-work/install stack run bd-service-exe &


echo "it's over"

当以docker-compose up bd-service 开始时,它会因以下日志而失败:

bd-service_1       | We are at 
bd-service_1       | /app/user/bd-service
bd-service_1       | start
bd-service_1       | Version 2.1.3, Git revision 0fa51b9925decd937e4a993ad90cb686f88fa282 (7739 commits) x86_64 hpack-0.31.2
bd-service_1       | 2019-10-21 07:23:02.631167: [debug] Checking for project config at: /app/user/bd-service/stack.yaml
bd-service_1       | 2019-10-21 07:23:02.634794: [debug] Loading project config file stack.yaml
bd-service_1       | 2019-10-21 07:23:02.641395: [error] <stdin>: hGetLine: end of file
bd-service_1       | it's over

【问题讨论】:

    标签: bash docker haskell docker-compose haskell-stack


    【解决方案1】:

    我的问题的一个简单解决方法是将 cat 通过管道传输到堆栈构建 --file-watch。 我受到堆栈交换的这个线程的启发:https://unix.stackexchange.com/a/103893.

    因此将stack build --verbose --file-watch 替换为cat | stack build --verbose --file-watch 就像一个魅力。我确实觉得这在某种程度上不“正常”,但无论如何......

    使它工作的东西实际上是 docker-compose.yml 中的 stdin_open: true 选项,管道 cat 命令没有做任何事情......

    【讨论】:

    • 如果有人不使用 docker-compose。我也遇到了这个错误,解决方法是添加 -it 标志。例如docker container run -it ...
    猜你喜欢
    • 2015-10-15
    • 1970-01-01
    • 2018-05-20
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-10
    • 2021-03-27
    相关资源
    最近更新 更多