summaryrefslogtreecommitdiff
path: root/Dockerfile
diff options
context:
space:
mode:
authorDawid Rycerz <dawid@rycerz.xyz>2025-03-23 17:11:39 +0100
committerDawid Rycerz <dawid@rycerz.xyz>2025-04-05 21:16:51 +0200
commit0ab2e5ba2b0631b28b5b1405559237b3913c878f (patch)
tree791cea788b0a62bc483d0041fbd0c655d2ad49e8 /Dockerfile
feat: initialize Phoenix application for weather alerts
This commit sets up the initial Silmataivas project structure, including: Phoenix web framework configuration, database models for users and locations, weather polling service, notification system, Docker and deployment configurations, CI/CD pipeline setup
Diffstat (limited to 'Dockerfile')
-rw-r--r--Dockerfile84
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