From 590be070764d4a6921ce9e8baa91c9a00644c543 Mon Sep 17 00:00:00 2001 From: James Greenwood Date: Mon, 17 Nov 2025 08:38:37 +0000 Subject: [PATCH] Dockerfile for building --- Dockerfile | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..60e4fab --- /dev/null +++ b/Dockerfile @@ -0,0 +1,72 @@ +# syntax=docker/dockerfile:1.7 + +# Use the official Alpine Elixir image; keep the version in sync with mix.exs +ARG ELIXIR_VERSION=1.15 +FROM elixir:${ELIXIR_VERSION}-alpine AS build + +ENV LANG="en_US.UTF-8" \ + MIX_ENV="prod" \ + HOME="/app" + +WORKDIR /app + +RUN apk update && \ + apk add --no-cache \ + build-base \ + sqlite-dev \ + openssl-dev \ + ca-certificates + +RUN mix do local.hex --force, local.rebar --force + +# Only copy files necessary to download deps to maximize layer caching +COPY mix.exs mix.lock ./ +COPY config config + +RUN mix deps.get --only ${MIX_ENV} && \ + mix deps.compile + +# Copy the rest of the application source +COPY lib lib +COPY priv priv +COPY assets assets + +RUN mix compile +RUN mix assets.deploy +RUN mix release + +# Minimal runtime image +FROM alpine:3.19 AS app + +ENV LANG="en_US.UTF-8" \ + MIX_ENV="prod" \ + PORT="4000" \ + PHX_SERVER="true" \ + DATABASE_PATH="/app/data/action_requests_demo.db" + +WORKDIR /app + +RUN apk add --no-cache \ + openssl \ + ncurses-libs \ + libstdc++ \ + sqlite \ + ca-certificates + +# Keep SQLite data outside of the release directory so it can persist as a volume +RUN install -d -m 0755 /app/data + +COPY --from=build /app/_build/prod/rel/action_requests_demo ./ + +RUN addgroup -S app && \ + adduser -S app -G app && \ + chown -R app:app /app + +USER app + +EXPOSE 4000 +VOLUME ["/app/data"] + +ENTRYPOINT ["./bin/action_requests_demo"] +CMD ["start"] +