diff options
Diffstat (limited to 'Dockerfile')
| -rw-r--r-- | Dockerfile | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d54e6e9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,84 @@ +# Stage 1: Build the application +FROM hexpm/elixir:1.18.3-erlang-25.0.4-debian-bookworm-20250317-slim AS build + +# Install build dependencies +RUN apt-get update -y && \ + apt-get install -y --no-install-recommends build-essential git && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Set environment variables +ENV MIX_ENV=prod + +# Prepare build directory +WORKDIR /app + +# Install hex and rebar +RUN mix local.hex --force && \ + mix local.rebar --force + +# Copy configuration files first to cache dependencies +COPY mix.exs mix.lock ./ +COPY config config + +# Get dependencies +RUN mix deps.get --only prod + +# Copy the rest of the application code +COPY lib lib +COPY priv priv +# No rel directory yet +# COPY rel rel + +# Compile the application and create release +RUN mix deps.compile +RUN mix compile +RUN mix release + +# Stage 2: Create the minimal runtime image +FROM debian:bookworm-slim AS app + +# Install runtime dependencies +RUN apt-get update -y && \ + apt-get install -y --no-install-recommends \ + libstdc++6 \ + openssl \ + ca-certificates \ + ncurses-bin \ + sqlite3 \ + libsqlite3-dev \ + curl && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Set environment variables +ENV LANG=C.UTF-8 \ + PHX_SERVER=true \ + DB_ADAPTER=sqlite \ + DATABASE_URL=sqlite3:/app/data/silmataivas.db + +WORKDIR /app + +# Copy the release from the build stage +COPY --from=build /app/_build/prod/rel/silmataivas ./ + +# Create data directory and non-root user with proper permissions +RUN mkdir -p /app/data && \ + useradd -m silmataivas && \ + chown -R silmataivas:silmataivas /app && \ + chmod -R 750 /app/data + +USER silmataivas + +# Document which ports the application uses +EXPOSE 4000 + +# Define volumes for persistence +VOLUME ["/app/data"] + +# Add health check +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ + CMD curl -f http://localhost:4000/health || exit 1 + +# Set the command to start the app +CMD ["/app/bin/silmataivas", "start"]
\ No newline at end of file |
