summaryrefslogtreecommitdiff
path: root/Dockerfile
blob: d54e6e9ef2fc880b3d4500dd2d4ff24df058e7db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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"]