Skip to content

Commit a0be6aa

Browse files
committed
Code for step 3
1 parent cbb3db3 commit a0be6aa

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

Dockerfile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# ---- Build Stage ----
2+
FROM erlang:21 AS app_builder
3+
4+
# Set environment variables for building the application
5+
ENV MIX_ENV=prod \
6+
TEST=1 \
7+
LANG=C.UTF-8
8+
9+
# Fetch the latest version of Elixir (once the 1.9 docker image is available you won't have to do this)
10+
RUN set -xe \
11+
&& ELIXIR_DOWNLOAD_URL="https://github.com/elixir-lang/elixir/archive/v1.9.0-rc.0.tar.gz" \
12+
&& ELIXIR_DOWNLOAD_SHA256="fa019ba18556f53bfb77840b0970afd116517764251704b55e419becb0b384cf" \
13+
&& curl -fSL -o elixir-src.tar.gz $ELIXIR_DOWNLOAD_URL \
14+
&& echo "$ELIXIR_DOWNLOAD_SHA256 elixir-src.tar.gz" | sha256sum -c - \
15+
&& mkdir -p /usr/local/src/elixir \
16+
&& tar -xzC /usr/local/src/elixir --strip-components=1 -f elixir-src.tar.gz \
17+
&& rm elixir-src.tar.gz \
18+
&& cd /usr/local/src/elixir \
19+
&& make install clean
20+
21+
# Install hex and rebar
22+
RUN mix local.hex --force && \
23+
mix local.rebar --force
24+
25+
# Create the application build directory
26+
RUN mkdir /app
27+
WORKDIR /app
28+
29+
# Copy over all the necessary application files and directories
30+
COPY config ./config
31+
COPY lib ./lib
32+
COPY priv ./priv
33+
COPY mix.exs .
34+
COPY mix.lock .
35+
36+
# Fetch the application dependencies and build the application
37+
RUN mix deps.get
38+
RUN mix deps.compile
39+
RUN mix phx.digest
40+
RUN mix release
41+
42+
# ---- Application Stage ----
43+
FROM debian:stretch AS app
44+
45+
ENV LANG=C.UTF-8
46+
47+
# Install openssl
48+
RUN apt-get update && apt-get install -y openssl
49+
50+
# Copy over the build artifact from the previous step and create a non root user
51+
RUN useradd --create-home app
52+
WORKDIR /home/app
53+
COPY --from=app_builder /app/_build .
54+
RUN chown -R app: ./prod
55+
USER app
56+
57+
# Run the Phoenix app
58+
CMD ["./prod/rel/docker_elixir_19_release/bin/docker_elixir_19_release", "start"]

0 commit comments

Comments
 (0)