darnahsan
Phoenix Docker build fails on npm ci
Setting up a phoneix project in a container , works fine on the cli
Dockerfile
FROM hexpm/elixir:1.11.2-erlang-23.1.3-debian-buster-20201012 AS base
# install build dependencies
RUN apt-get -qq update && \
apt-get -qq -y install build-essential npm git python --fix-missing --no-install-recommends
# prepare build dir
WORKDIR /app
ARG MIX_ENV
ARG RELEASE_LEVEL
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
# Update timezone
ENV TZ=Asia/Singapore
# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
# set build ENV
ENV MIX_ENV=$MIX_ENV
# install mix dependencies
COPY mix.exs mix.lock ./
COPY config config
RUN mix deps.get --only $MIX_ENV
RUN mix deps.compile
# build assets
COPY assets/package.json assets/package-lock.json ./assets/
RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
COPY priv priv
COPY assets assets
RUN npm run --prefix ./assets deploy
RUN mix phx.digest
# compile and build release
COPY lib lib
# uncomment COPY if rel/ exists
# COPY rel rel
RUN mix do compile, release
FROM debian:buster-slim AS app
RUN apk add --no-cache openssl ncurses-libs
WORKDIR /app
ARG MIX_ENV
ARG RELEASE_LEVEL
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
# Update timezone
ENV TZ=Asia/Singapore
# Exposes port to the host machine
EXPOSE 8080
# Install stable dependencies that don't change often
RUN apt-get update && \
apt-get install -y --no-install-recommends \
apt-utils \
openssl \
curl \
wget && \
rm -rf /var/lib/apt/lists/*
RUN chown nobody:nobody /app
USER nobody:nobody
COPY --from=build --chown=nobody:nobody /app/_build/${MIX_ENV}/rel/ghost_rider ./
ENV HOME=/app
CMD ["bin/ghost_rider", "start"]
fails with following error
Step 15/35 : RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
---> Running in 2b08ff3a7d3a
npm ERR! (intermediate value)(intermediate value)(intermediate value).then is not a function
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-12-02T02_23_33_826Z-debug.log
ERROR: Service 'ghost-rider' failed to build : The command '/bin/sh -c npm --prefix ./assets ci --progress=false --no-audit --loglevel=error' returned a non-zero code: 1
it works fine on the project via cli
npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
.....
......
........
added 948 packages in 12.791s
deps
[
{:phoenix, "~> 1.5.7"},
{:phoenix_ecto, "~> 4.1"},
{:ecto_sql, "~> 3.4"},
{:ecto_psql_extras, "~> 0.2"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.11"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_dashboard, "~> 0.3 or ~> 0.2.9"},
{:telemetry_metrics, "~> 0.4"},
{:telemetry_poller, "~> 0.4"},
{:gettext, "~> 0.11"},
{:jason, "~> 1.0"},
{:plug_cowboy, "~> 2.0"},
{:finch, "~> 0.5.2"},
{:recaptcha, "~> 3.0"},
{:ink, "~> 1.0"},
{:credo, "~> 1.5", only: [:dev, :test], runtime: false},
{:sentry, "8.0.3"},
{:hackney, "~> 1.8"}
]
Marked As Solved
darnahsan
Thanks for sharing your input
got it to work finally with some changes ![]()
# https://forum.elixirforum.com/t/could-use-some-feedback-on-this-multistage-dockerfile-1st-elixir-phoenix-deployment/30862/10?
########################
### Dependency stage ###
########################
FROM hexpm/elixir:1.11.2-erlang-23.1.3-debian-buster-20201012 AS deps
# install build dependencies
RUN apt-get -qq update && \
apt-get -qq -y install build-essential npm git python --fix-missing --no-install-recommends
# prepare build dir
WORKDIR /app
ARG MIX_ENV
ARG RELEASE_LEVEL
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
# Update timezone
ENV TZ=Asia/Singapore
# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
# set build ENV
ENV MIX_ENV=${MIX_ENV}
ENV RELEASE_LEVEL=${RELEASE_LEVEL}
COPY mix.exs mix.lock ./
COPY config config
# install mix dependencies
RUN mix deps.get --only ${MIX_ENV}
RUN mix deps.compile
########################
# Build Phoenix assets #
########################
# Using stretch for now because it includes Python
# Otherwise you get errors, could use a smaller image though
FROM node:14.15.1-stretch AS assets
WORKDIR /app/assets
COPY --from=deps /app/deps /app/deps/
COPY assets/package.json assets/package-lock.json ./
RUN npm ci --progress=false --no-audit --loglevel=error
COPY assets/ ./
RUN npm run deploy
#########################
# Create Phoenix digest #
#########################
FROM deps AS digest
COPY priv priv
RUN mix phx.digest
#######################
#### Create release ###
#######################
FROM digest AS release
ARG MIX_ENV
ENV MIX_ENV=${MIX_ENV}
COPY lib ./lib
RUN mix do compile, release
#################################################
# Create the actual image that will be deployed #
#################################################
FROM debian:buster-slim AS deploy
# Install stable dependencies that don't change often
RUN apt-get update && \
apt-get install -y --no-install-recommends \
apt-utils \
openssl \
curl \
wget && \
rm -rf /var/lib/apt/lists/*
# Set WORKDIR after setting user to nobody so it automatically gets the right permissions
# When the app starts it will need to be able to create a tmp directory in /app
WORKDIR /app
ARG MIX_ENV
ARG RELEASE_LEVEL
ENV MIX_ENV=${MIX_ENV}
ENV RELEASE_LEVEL=${RELEASE_LEVEL}
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
# Update timezone
ENV TZ=Asia/Singapore
COPY --from=release /app/_build/${MIX_ENV}/rel/ghost_rider ./
ENV HOME=/app
# Exposes port to the host machine
EXPOSE 8080
CMD ["bin/ghost_rider", "start"]
I will try to submit to the official hex docs for deployment as the recipe there is incomplete in my view and not so convenient for 1st time users of phoenix
1
Popular in Questions
How to bind a phoenix app to a specific ip address?
could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equa...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Other popular topics
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
Got a question about when to concat vs. prepending items to list then reversing to achieve appending.
So i know lists boil down to [1 | ...
New
I would like to know what is the best IDE for elixir development?
New
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)?
Would
mix ecto.rollback -v 200809061...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









