ex_trainer/Dockerfile
Joao P Dubas 9be7566cbb
All checks were successful
continuous-integration/drone/push Build is passing
feat: execute service as distributed erlang (#96)
To create a cluster with distributed nodes, the following changes were made:

* Use [`dns_cluster`][0] to execute distributed nodes
* Add _script_ to execute distributed nodes locally

Also, improve local execution by:

* Use [`mix release`][1] to make easier [deploy `phoenix`][2]
* Use [`compose watch`][3] to synchronize code from the host with the service

Some minor improvements:

* Ignore files and folders in git and docker
* Remove boilerplate comments

[0]: https://github.com/phoenixframework/dns_cluster
[1]: https://hexdocs.pm/mix/Mix.Tasks.Release.html
[2]: https://hexdocs.pm/phoenix/releases.html
[3]: https://docs.docker.com/compose/how-tos/file-watch/

Co-authored-by: Joao P Dubas <joao.dubas@gmail.com>
Reviewed-on: #96
Co-authored-by: Joao P Dubas <joao.dubas+gitea@gmail.com>
Co-committed-by: Joao P Dubas <joao.dubas+gitea@gmail.com>
2024-09-22 18:56:27 +00:00

71 lines
2.0 KiB
Docker

ARG ELIXIR_VERSION=1.17.3
ARG OTP_VERSION=27.1
ARG DEBIAN_VERSION=bookworm-20240904-slim
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"
FROM ${BUILDER_IMAGE} AS builder
RUN apt-get update \
&& apt-get -y install \
build-essential \
git \
make \
&& apt-get clean \
&& rm -rf /var/lib/ap/lists/*_*
WORKDIR /opt/app
# install hex + rebar
RUN mix do local.hex --force, local.rebar --force
# set build ENV
ARG BUILD_MIX_ENV=prod
ENV MIX_ENV=${BUILD_MIX_ENV}
# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only ${MIX_ENV}
RUN mkdir config
# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${BUILD_MIX_ENV}.exs config/
RUN mix deps.compile
COPY priv priv
COPY lib lib
# Compile the release
RUN mix compile
# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/
COPY rel rel
RUN mix release
COPY ./mix.exs ./
EXPOSE 4000
ENTRYPOINT ["./priv/docker/service/docker-entrypoint.sh"]
CMD ["sample-cookie"]
# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}
RUN apt-get update -y \
&& apt-get install -y \
ca-certificates \
libncurses5 \
libstdc++6 \
locales \
openssl \
tini \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
WORKDIR /opt/app
RUN chown nobody /opt/app
# set runner ENV
ARG BUILD_MIX_ENV=prod
ENV MIX_ENV=${BUILD_MIX_ENV}
# Only copy the final release from the build stage
COPY --from=builder --chown=nobody:root /app/_build/${BUILD_MIX_ENV}/rel/wabanex ./
USER nobody
EXPOSE 4000
ENTRYPOINT ["tini", "--"]
CMD ["/app/bin/server"]