use phoenix dockerfile
This commit is contained in:
parent
670f8c7a53
commit
9c7bf85f36
|
@ -51,8 +51,9 @@ env:
|
||||||
clear:
|
clear:
|
||||||
PORT: 4000
|
PORT: 4000
|
||||||
DATABASE_HOST: futureporn-db
|
DATABASE_HOST: futureporn-db
|
||||||
|
MIX_ENV: prod
|
||||||
secret:
|
secret:
|
||||||
- DATABASE_PASSWORD
|
- DATABASE_URL
|
||||||
|
|
||||||
# Aliases are triggered with "bin/kamal <alias>". You can overwrite arguments on invocation:
|
# Aliases are triggered with "bin/kamal <alias>". You can overwrite arguments on invocation:
|
||||||
# "bin/kamal logs -r job" will tail logs from the first server in the job section.
|
# "bin/kamal logs -r job" will tail logs from the first server in the job section.
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
## 2024-12-26 -- file created using `mix phx.gen.release --docker`
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
|
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian
|
||||||
# instead of Alpine to avoid DNS resolution issues in production.
|
# instead of Alpine to avoid DNS resolution issues in production.
|
||||||
#
|
#
|
||||||
|
@ -16,37 +10,19 @@
|
||||||
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20241202-slim - for the release image
|
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20241202-slim - for the release image
|
||||||
# - https://pkgs.org/ - resource for finding needed packages
|
# - https://pkgs.org/ - resource for finding needed packages
|
||||||
# - Ex: hexpm/elixir:1.17.3-erlang-27.1.2-debian-bullseye-20241202-slim
|
# - Ex: hexpm/elixir:1.17.3-erlang-27.1.2-debian-bullseye-20241202-slim
|
||||||
# - https://gitlab.com/ericlathrop/dockerize_elixir/-/blob/main/priv/templates/Dockerfile?ref_type=heads
|
#
|
||||||
|
ARG ELIXIR_VERSION=1.17.3
|
||||||
|
ARG OTP_VERSION=27.1.2
|
||||||
|
ARG DEBIAN_VERSION=bullseye-20241202-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
|
||||||
|
|
||||||
|
|
||||||
FROM elixir:1.17.3-alpine AS dev
|
|
||||||
# FROM hexpm/elixir:1.17.3-erlang-27.1.2-debian-bullseye-20241202-slim AS dev
|
|
||||||
|
|
||||||
# install build dependencies
|
# install build dependencies
|
||||||
|
RUN apt-get update -y && apt-get install -y build-essential git \
|
||||||
RUN \
|
&& apt-get clean && rm -f /var/lib/apt/lists/*_*
|
||||||
apk add --no-cache \
|
|
||||||
build-base \
|
|
||||||
npm \
|
|
||||||
git \
|
|
||||||
python3 \
|
|
||||||
make \
|
|
||||||
cmake \
|
|
||||||
openssl-dev \
|
|
||||||
libsrtp-dev \
|
|
||||||
ffmpeg-dev \
|
|
||||||
clang-dev \
|
|
||||||
inotify-tools
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
mkdir /home/user \
|
|
||||||
&& chown 1000.1000 /home/user
|
|
||||||
|
|
||||||
ENV HOME=/home/user
|
|
||||||
USER 1000:1000
|
|
||||||
|
|
||||||
# prepare build dir
|
# prepare build dir
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
@ -56,21 +32,73 @@ RUN mix local.hex --force && \
|
||||||
mix local.rebar --force
|
mix local.rebar --force
|
||||||
|
|
||||||
# set build ENV
|
# set build ENV
|
||||||
ENV MIX_ENV="dev"
|
ENV MIX_ENV="prod"
|
||||||
ENV DATABASE_URL=""
|
|
||||||
ENV PORT=""
|
|
||||||
|
|
||||||
# install mix dependencies
|
# install mix dependencies
|
||||||
COPY ./services/bright/mix.exs ./services/bright/mix.lock ./
|
COPY mix.exs mix.lock ./
|
||||||
RUN mix deps.get --only $MIX_ENV
|
RUN mix deps.get --only $MIX_ENV
|
||||||
RUN mkdir config
|
RUN mkdir config
|
||||||
|
|
||||||
# copy compile-time config files before we compile dependencies
|
# copy compile-time config files before we compile dependencies
|
||||||
# to ensure any relevant config change will trigger the dependencies
|
# to ensure any relevant config change will trigger the dependencies
|
||||||
# to be re-compiled.
|
# to be re-compiled.
|
||||||
COPY ./services/bright/config/config.exs ./services/bright/config/${MIX_ENV}.exs config/
|
COPY config/config.exs config/${MIX_ENV}.exs config/
|
||||||
COPY ./services/bright/priv priv
|
RUN mix deps.compile
|
||||||
COPY ./services/bright/lib lib
|
|
||||||
COPY ./services/bright/assets assets
|
|
||||||
|
|
||||||
|
COPY priv priv
|
||||||
|
|
||||||
|
COPY lib lib
|
||||||
|
|
||||||
|
COPY assets assets
|
||||||
|
|
||||||
|
# compile assets
|
||||||
|
RUN mix assets.deploy
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
|
||||||
|
## dev target
|
||||||
|
FROM builder AS dev
|
||||||
|
WORKDIR "/app"
|
||||||
CMD [ "mix", "ecto.setup", "&&", "mix", "phx.server" ]
|
CMD [ "mix", "ecto.setup", "&&", "mix", "phx.server" ]
|
||||||
|
|
||||||
|
|
||||||
|
# start a new build stage so that the final image will only contain
|
||||||
|
# the compiled release and other runtime necessities
|
||||||
|
FROM ${RUNNER_IMAGE} AS prod
|
||||||
|
|
||||||
|
RUN apt-get update -y && \
|
||||||
|
apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
|
||||||
|
&& 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 "/app"
|
||||||
|
RUN chown nobody /app
|
||||||
|
|
||||||
|
# set runner ENV
|
||||||
|
ENV MIX_ENV="prod"
|
||||||
|
|
||||||
|
# Only copy the final release from the build stage
|
||||||
|
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/bright ./
|
||||||
|
|
||||||
|
USER nobody
|
||||||
|
|
||||||
|
# If using an environment that doesn't automatically reap zombie processes, it is
|
||||||
|
# advised to add an init process such as tini via `apt-get install`
|
||||||
|
# above and adding an entrypoint. See https://github.com/krallin/tini for details
|
||||||
|
# ENTRYPOINT ["/tini", "--"]
|
||||||
|
|
||||||
|
CMD ["/app/bin/server"]
|
||||||
|
|
|
@ -3,8 +3,8 @@ import Config
|
||||||
# Configure the database
|
# Configure the database
|
||||||
config :bright, Bright.Repo,
|
config :bright, Bright.Repo,
|
||||||
username: "postgres",
|
username: "postgres",
|
||||||
password: "#{System.get_env("DATABASE_PASSWORD")}",
|
password: "password",
|
||||||
hostname: "#{System.get_env("DATABASE_HOSTNAME")}",
|
hostname: "db",
|
||||||
database: "bright",
|
database: "bright",
|
||||||
stacktrace: true,
|
stacktrace: true,
|
||||||
show_sensitive_data_on_connection_error: true,
|
show_sensitive_data_on_connection_error: true,
|
||||||
|
|
Loading…
Reference in New Issue