1- FROM elixir:1.13.1-slim AS build
1+ # Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of
2+ # Alpine to avoid DNS resolution issues in production.
3+ #
4+ # https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
5+ # https://hub.docker.com/_/ubuntu?tab=tags
6+ #
7+ #
8+ # This file is based on these images:
9+ #
10+ # - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
11+ # - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20210902-slim - for the release image
12+ # - https://pkgs.org/ - resource for finding needed packages
13+ # - Ex: hexpm/elixir:1.13.2-erlang-24.1.1-debian-bullseye-20210902-slim
14+ #
15+ ARG BUILDER_IMAGE="hexpm/elixir:1.13.2-erlang-24.1.1-debian-bullseye-20210902-slim"
16+ ARG RUNNER_IMAGE="debian:bullseye-20210902-slim"
17+
18+ FROM ${BUILDER_IMAGE} as builder
219
320# install build dependencies
4- RUN apt update && apt install -y build-essential git
21+ RUN apt-get update -y && apt-get install -y build-essential git apt-transport-https curl \
22+ && apt-get clean && rm -f /var/lib/apt/lists/*_*
23+
24+ # add node deb
25+ RUN curl -fsSL https://deb.nodesource.com/setup_lts.x -o /tmp/setup_node.sh && bash /tmp/setup_node.sh && apt-get install -y nodejs \
26+ && apt-get clean && rm -f /var/lib/apt/lists/*_* \
27+ && corepack enable
528
629# prepare build dir
730WORKDIR /app
@@ -11,41 +34,68 @@ RUN mix local.hex --force && \
1134 mix local.rebar --force
1235
1336# set build ENV
14- ENV MIX_ENV=prod
37+ ENV MIX_ENV=" prod"
1538
1639# install mix dependencies
1740COPY mix.exs mix.lock ./
18- COPY config config
19- RUN mix do deps.get, deps.compile
41+ RUN mix deps.get --only $MIX_ENV
42+ RUN mkdir config
2043
21- # build assets
22- # COPY assets/package.json assets/package-lock.json ./assets/
23- # RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
44+ # copy compile-time config files before we compile dependencies
45+ # to ensure any relevant config change will trigger the dependencies
46+ # to be re-compiled.
47+ COPY config/config.exs config/${MIX_ENV}.exs config/
48+ RUN mix deps.compile
2449
2550COPY priv priv
26- # COPY assets assets
27- # RUN npm run --prefix ./assets deploy
28- RUN mix phx.digest
2951
30- # compile and build release
52+ # note: if your project uses a tool like https://purgecss.com/,
53+ # which customizes asset compilation based on what it finds in
54+ # your Elixir templates, you will need to move the asset compilation
55+ # step down so that `lib` is available.
56+ COPY assets assets
57+ ADD openapi.json package.json yarn.lock ./
58+ # compile assets
59+ RUN yarn install --frozen-lockfile
3160COPY lib lib
32- COPY openapi.json openapi.json
33- # uncomment COPY if rel/ exists
34- # COPY rel rel
35- RUN mix do compile, release
61+ RUN mix assets.deploy
62+ # Compile the release
3663
37- # prepare release image
38- FROM debian:buster AS app
39- RUN apt update && apt install -y openssl
64+ RUN mix compile
4065
41- WORKDIR /app
66+ # Changes to config/runtime.exs don't require recompiling the code
67+ COPY config/runtime.exs config/
68+
69+ COPY rel rel
70+ RUN mix release
71+
72+ # start a new build stage so that the final image will only contain
73+ # the compiled release and other runtime necessities
74+ FROM ${RUNNER_IMAGE}
75+
76+ RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales apt-transport-https curl \
77+ && apt-get clean && rm -f /var/lib/apt/lists/*_*
78+
79+ # add node deb
80+ RUN curl -fsSL https://deb.nodesource.com/setup_lts.x -o /tmp/setup_node.sh && bash /tmp/setup_node.sh && apt-get install -y nodejs --no-install-recommends \
81+ && apt-get clean && rm -f /var/lib/apt/lists/*_* \
82+ && corepack enable
83+
84+ # Set the locale
85+ RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
4286
43- # RUN chown nobody:nobody /app
87+ ENV LANG en_US.UTF-8
88+ ENV LANGUAGE en_US:en
89+ ENV LC_ALL en_US.UTF-8
4490
45- # USER nobody:nobody
91+ WORKDIR "/app"
92+ RUN chown nobody /app
4693
47- COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/librecov ./
94+ # Only copy the final release from the build stage
95+ COPY --from=builder --chown=nobody:root /app/_build/prod/rel/librecov ./
96+ ADD openapi.json package.json yarn.lock /app/bin/
97+ RUN cd bin && yarn install --production --frozen-lockfile
4898
49- ENV HOME=/app
99+ USER nobody
50100
51- CMD ["bin/librecov" , "start " ]
101+ CMD ["/app/ bin/server " ]
0 commit comments