diff --git a/config/deploy.yml b/config/deploy.yml index dbe12f3..cec8543 100644 --- a/config/deploy.yml +++ b/config/deploy.yml @@ -51,8 +51,9 @@ env: clear: PORT: 4000 DATABASE_HOST: futureporn-db + MIX_ENV: prod secret: - - DATABASE_PASSWORD + - DATABASE_URL # Aliases are triggered with "bin/kamal ". You can overwrite arguments on invocation: # "bin/kamal logs -r job" will tail logs from the first server in the job section. diff --git a/dockerfiles/bright.dockerfile b/dockerfiles/bright.dockerfile index a4358a9..8d5ce2b 100644 --- a/dockerfiles/bright.dockerfile +++ b/dockerfiles/bright.dockerfile @@ -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 # 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://pkgs.org/ - resource for finding needed packages # - 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 elixir:1.17.3-alpine AS dev -# FROM hexpm/elixir:1.17.3-erlang-27.1.2-debian-bullseye-20241202-slim AS dev +FROM ${BUILDER_IMAGE} as builder # install build dependencies - -RUN \ - 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 +RUN apt-get update -y && apt-get install -y build-essential git \ + && apt-get clean && rm -f /var/lib/apt/lists/*_* # prepare build dir WORKDIR /app @@ -56,21 +32,73 @@ RUN mix local.hex --force && \ mix local.rebar --force # set build ENV -ENV MIX_ENV="dev" -ENV DATABASE_URL="" -ENV PORT="" +ENV MIX_ENV="prod" # 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 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 ./services/bright/config/config.exs ./services/bright/config/${MIX_ENV}.exs config/ -COPY ./services/bright/priv priv -COPY ./services/bright/lib lib -COPY ./services/bright/assets assets +COPY config/config.exs config/${MIX_ENV}.exs config/ +RUN mix deps.compile +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" ] + + +# 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"] diff --git a/services/bright/config/dev.exs b/services/bright/config/dev.exs index a0eae1b..c79c556 100644 --- a/services/bright/config/dev.exs +++ b/services/bright/config/dev.exs @@ -3,8 +3,8 @@ import Config # Configure the database config :bright, Bright.Repo, username: "postgres", - password: "#{System.get_env("DATABASE_PASSWORD")}", - hostname: "#{System.get_env("DATABASE_HOSTNAME")}", + password: "password", + hostname: "db", database: "bright", stacktrace: true, show_sensitive_data_on_connection_error: true,