1616# This should match the version of Alpine that the `elixir:1.14-alpine` image uses
1717ARG ALPINE_VERSION=3.17
1818ARG SECRET_KEY_BASE
19+ ARG COMPONENT=core
20+ ARG MIX_ENV=prod
1921
2022FROM elixir:1.14-alpine AS builder
2123
22- ARG MIX_ENV=prod
24+ ARG MIX_ENV
25+ ARG COMPONENT
2326
2427ENV MIX_ENV=${MIX_ENV} \
2528 SECRET_KEY_BASE=${SECRET_KEY_BASE}
@@ -37,14 +40,16 @@ RUN apk update && \
3740# This copies our app source code into the build container
3841COPY . .
3942
40- RUN mix deps.get --only $ MIX_ENV
43+ RUN mix deps.get --only "${ MIX_ENV}"
4144RUN mix compile
42- RUN mix release core
45+ RUN echo "Building FunLess ${COMPONENT} in env ${MIX_ENV}"
46+ RUN MIX_ENV=${MIX_ENV} mix release ${COMPONENT}
4347
4448# From this line onwards, we're in a new image, which will be the image used in production
4549FROM alpine:${ALPINE_VERSION}
4650
47- ARG MIX_ENV=prod
51+ ARG MIX_ENV
52+ ARG COMPONENT
4853ARG SECRET_KEY_BASE
4954ARG PORT=4000
5055ARG NODE_IP=""
@@ -58,6 +63,7 @@ RUN apk update && \
5863ENV REPLACE_OS_VARS=true \
5964 USER=funless \
6065 MIX_ENV=${MIX_ENV} \
66+ COMPONENT=${COMPONENT}\
6167 SECRET_KEY_BASE=${SECRET_KEY_BASE} \
6268 PORT=${PORT} \
6369 NODE_IP=${NODE_IP} \
@@ -70,19 +76,15 @@ ENV REPLACE_OS_VARS=true \
7076
7177
7278WORKDIR "/home/${USER}/app"
79+
7380# Creates an unprivileged user to be used exclusively to run the Phoenix app
7481RUN addgroup -g 1000 -S "${USER}" && adduser -s /bin/sh -u 1000 -G "${USER}" \
7582 -h "/home/${USER}" -D "${USER}" && su "${USER}"
7683
7784# Everything from this line onwards will run in the context of the unprivileged user.
7885USER "${USER}"
7986
80- COPY --chown="${USER}":"${USER}" --from=builder /opt/app/_build/${MIX_ENV}/rel/core / .
87+ COPY --chown="${USER}" :"${USER}" --from=builder /opt/app/_build/${MIX_ENV}/rel/${COMPONENT} / .
8188
82- # # Usage:
83- # # * build: sudo docker image build -t elixir/my_app .
84- # # * shell: sudo docker container run --rm -it --entrypoint "" -p 127.0.0.1:4000:4000 elixir/my_app sh
85- # # * run: sudo docker container run --rm -it -p 127.0.0.1:4000:4000 --name my_app elixir/my_app
86- # # * exec: sudo docker container exec -it my_app sh
87- # # * logs: sudo docker container logs --follow --tail 100 my_app
88- CMD ["sh", "-c", "bin/migrate && bin/seed && bin/server"]
89+ RUN echo "Command: FunLess ${COMPONENT} in env ${MIX_ENV}"
90+ CMD ["sh" , "-c" , "bin/run" ]
0 commit comments