From 02b12877d5eb623b4334072ccd112457ded1b666 Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Thu, 26 Feb 2026 07:35:31 -0600 Subject: [PATCH] Update Dockerfile from LogRocket example --- Dockerfile | 86 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 31f95e2..b73b739 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,37 +1,87 @@ +# Dockerfile is modified from the example given on the LogRocket blog +# https://blog.logrocket.com/run-phoenix-application-docker/ + ARG ELIXIR_VERSION=1.17.3 ARG OTP_VERSION=27.3.4.7 ARG DEBIAN_VERSION=trixie-20260202-slim +ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" +ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" -FROM "docker.io/hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" +FROM ${BUILDER_IMAGE} as builder # Set the locale ENV LANG=en_US.UTF-8 ENV LANGUAGE=en_US:en ENV LC_ALL=en_US.UTF-8 -# Install dependencies -RUN apt-get update \ - && apt-get install -y --no-install-recommends build-essential make gcc erlang-dev git autoconf automake libtool pkg-config \ - && rm -rf /var/lib/apt/lists/* +# Install dependencies, including C build tools for libsecp256k1 +RUN apt-get update && \ + apt-get install -y --no-install-recommends erlang-dev build-essential make gcc git autoconf automake libtool pkg-config && \ + apt-get clean && \ + rm -f /var/lib/apt/lists/*_* # Create a build directory and copy in the project files WORKDIR /app -COPY . . -# Compile the application -RUN mix local.hex --force && mix local.rebar --force -RUN mix deps.get --only prod -RUN MIX_ENV=prod mix compile +# Install Hex and Rebar +RUN mix local.hex --force && \ + mix local.rebar --force + +# Configure for prod build +ENV MIX_ENV="prod" -# Update the static Swagger documentation -RUN MIX_ENV=prod mix phx.swagger.generate +# Install Elixir application dependencies +COPY mix.exs mix.lock ./ +RUN mix deps.get --only ${MIX_ENV} -# Run as the isidore-dev user -USER 1008 -RUN mix local.hex --force && mix local.rebar --force +# Copy in config files before compiling dependencies. +# This ensures config changes will force recompilation of dependencies. +RUN mkdir config +COPY config/config.exs config/${MIX_ENV}.exs config/ + +# Compile Elixir application dependencies +RUN mix deps.compile + +# Copy in static assets and source code +# Note: Swagger docs must be generated before deployment; this image does not generate them. +COPY priv priv +COPY lib lib + +# Compile the app for production +RUN mix compile + +# Copy in runtime config files. +# Other config files are baked into the compilation, but runtime config is applied at runtime. +COPY config/runtime.exs config/ + +# Copy in any release files and create a release +COPY rel rel +RUN mix release + +# Lean runtime stage +FROM ${RUNNER_IMAGE} +RUN apt-get update && \ + apt-get install -y libstdc++6 openssl libncurses5 locales && \ + apt-get clean && \ + rm -f /var/lib/apt/lists/*_* + +# Set the runtime 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 + +# Transfer ownership of the app directory to the runtime user +WORKDIR "/app" +RUN chown 1008:1008 /app -# Set environment variables for the application -ENV PORT=4000 ENV MIX_ENV="prod" -CMD ["mix", "phx.server"] +# Copy the final compiled release into the runtime stage +COPY --from=builder --chown=1008:1008 /app/_build/${MIX_ENV}/rel/gc_index_relay ./ + +USER 1008 + +# Run the compiled binary +CMD ["/app/bin/server"]