-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (35 loc) · 1.47 KB
/
Copy pathDockerfile
File metadata and controls
51 lines (35 loc) · 1.47 KB
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
# This docker file is intended to be used with docker compose to deploy a production
# instance of a Reflex app.
# Stage 1: builder
FROM ghcr.io/astral-sh/uv:debian AS builder
# Copy local context to `/app` inside container (see .dockerignore)
WORKDIR /app
COPY . .
# Create virtual environment and install dependencies
RUN uv venv
RUN uv sync --frozen
ENV UV_NO_SYNC=1
# Deploy templates and prepare app
RUN uv run reflex init
# Install pre-cached frontend dependencies (if exist)
RUN if [ -f .web/bun.lockb ]; then cd .web && ~/.local/share/reflex/bun/bin/bun install --frozen-lockfile; fi
# Export static copy of frontend to /srv
RUN uv run reflex export --loglevel debug --frontend-only --no-zip && mv .web/build/client/* /srv/ && rm -rf .web
# Stage 2: final image
FROM ghcr.io/astral-sh/uv:debian-slim
WORKDIR /app
ENV UV_NO_SYNC=1
# Install libpq-dev for psycopg (skip if not using postgres)
RUN apt-get update -y && apt-get install -y caddy libpq-dev && rm -rf /var/lib/apt/lists/*
# Copy application and virtual environment from builder
COPY --from=builder /app /app
COPY --from=builder /srv /srv
# Create data directories
RUN mkdir -p /app/data /app/uploaded_files
ENV PYTHONUNBUFFERED=1
# Needed until Reflex properly passes SIGTERM on backend.
STOPSIGNAL SIGKILL
RUN uv sync --frozen
# has to match the port specified in the Caddyfile
EXPOSE 8080
CMD ["sh", "-c", "[ -d alembic ] && uv run reflex db migrate; caddy start && exec uv run reflex run --env prod --backend-only"]