Heroku Container 多阶段构建找不到文件

Heroku Container multi-stage build failing to find file

我有一个 docker 文件,其中包含两个阶段,可以在本地成功构建。当我尝试将它推送到 heroku 的容器服务时,它无法构建并出现文件不可用的错误。

错误

** (Mix.Config.LoadError) could not load config config/prod.exs
    ** (ArgumentError) argument error
    :erlang.binary_to_integer("")
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:878: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:236: :erl_eval.expr/5

Dockerfile

FROM bitwalker/alpine-elixir-phoenix:1.5.2 as builder

ARG CLOAK_ENCRYPTION_KEY
ARG DATABASE_URL


ENV MIX_ENV=prod PORT=$PORT DATABASE_URL=$DATABASE_URL CLOAK_ENCRYPTION_KEY=$CLOAK_ENCRYPTION_KEY

WORKDIR /app

# Cache elixir deps
ADD mix.exs mix.lock /app/
RUN mix do deps.get, deps.compile

# Same with npm deps
ADD client/package.json client/package-lock.json /app/client/
RUN cd client && \
    npm install

ADD . .

# Run frontend build, compile, and digest assets
RUN cd /app/client/ && \
    npm run build && \
    cd /app && \
    mix do compile

RUN MIX_ENV=prod mix release --env=prod --verbose --no-tar

### Release

FROM alpine:3.8

# We need bash and openssl for Phoenix
RUN apk upgrade --no-cache && \
    apk add --no-cache bash openssl

ENV SHELL=/bin/bash

COPY --from=builder /app/_build/prod/rel/myapp/app

ENTRYPOINT ["/app/bin/myapp"]

CMD ["foreground"]

第二次出现错误mix do compile

是什么原因导致它在本地工作,但在 Heroku 上失败?

想通了。在执行 heroku push 时,我正在为每个参数做一个 --arg 参数(Docker --build-arg 是 1 到 1)。 Heroku 实际上只想要一个 --arg,所有参数都用逗号连接。

heroku 相当于

docker build -t myapp --build-arg DATABASE_URL=someurl --build-arg CLOAK_ENCRYPTION_KEY=somekey 

heroku container:push web --arg DATABASE_URL=someurl,CLOAK_ENCRYPTION_KEY=somekey