Using 2-port build
Browse files- Dockerfile +13 -29
Dockerfile
CHANGED
|
@@ -1,54 +1,38 @@
|
|
| 1 |
-
# This Dockerfile is used to deploy a single-container Reflex app instance
|
| 2 |
-
# to services like Render, Railway, Heroku, GCP, and others.
|
| 3 |
-
|
| 4 |
-
# It uses a reverse proxy to serve the frontend statically and proxy to backend
|
| 5 |
-
# from a single exposed port, expecting TLS termination to be handled at the
|
| 6 |
-
# edge by the given platform.
|
| 7 |
FROM python:3.13
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
ARG API_URL
|
| 13 |
-
ENV PORT=$PORT API_URL=${API_URL:-http://localhost:$PORT} REDIS_URL=redis://localhost PYTHONUNBUFFERED=1
|
| 14 |
-
|
| 15 |
-
# Install Caddy and redis server inside image
|
| 16 |
-
RUN apt-get update -y && apt-get install -y caddy redis-server && rm -rf /var/lib/apt/lists/*
|
| 17 |
|
| 18 |
# Create a non-root user for security
|
| 19 |
RUN useradd -m -u 1000 user
|
| 20 |
|
| 21 |
-
#
|
| 22 |
WORKDIR /app
|
| 23 |
|
| 24 |
# Copy local context to `/app` inside container (see .dockerignore)
|
| 25 |
COPY . .
|
| 26 |
|
| 27 |
-
#
|
| 28 |
RUN chown -R user:user /app
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
# Install app requirements and reflex in the container
|
| 31 |
-
RUN pip install -r requirements.txt
|
| 32 |
|
| 33 |
# Deploy templates and prepare app
|
| 34 |
RUN reflex init
|
| 35 |
|
| 36 |
-
# Setting because lscpu didnt work
|
| 37 |
-
ENV NUM_CPUS=2
|
| 38 |
-
|
| 39 |
# Download all npm dependencies and compile frontend
|
| 40 |
-
RUN reflex export --frontend-only --no-zip
|
| 41 |
-
|
| 42 |
-
# Switch to non-root user
|
| 43 |
-
USER user
|
| 44 |
|
| 45 |
# Needed until Reflex properly passes SIGTERM on backend.
|
| 46 |
STOPSIGNAL SIGKILL
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
# Apply migrations before starting the backend.
|
| 51 |
CMD [ -d alembic ] && reflex db migrate; \
|
| 52 |
-
caddy start && \
|
| 53 |
redis-server --daemonize yes && \
|
| 54 |
-
exec reflex run --env
|
|
|
|
| 1 |
+
# This Dockerfile is used to deploy a simple single-container Reflex app instance.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
FROM python:3.13
|
| 3 |
|
| 4 |
+
# Install Redis and other system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y redis-server && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
ENV REDIS_URL=redis://localhost PYTHONUNBUFFERED=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Create a non-root user for security
|
| 9 |
RUN useradd -m -u 1000 user
|
| 10 |
|
| 11 |
+
# Set the working directory
|
| 12 |
WORKDIR /app
|
| 13 |
|
| 14 |
# Copy local context to `/app` inside container (see .dockerignore)
|
| 15 |
COPY . .
|
| 16 |
|
| 17 |
+
# Set ownership of the application directory to the non-root user
|
| 18 |
RUN chown -R user:user /app
|
| 19 |
|
| 20 |
+
# Switch to the non-root user
|
| 21 |
+
USER user
|
| 22 |
+
|
| 23 |
# Install app requirements and reflex in the container
|
| 24 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 25 |
|
| 26 |
# Deploy templates and prepare app
|
| 27 |
RUN reflex init
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
# Download all npm dependencies and compile frontend
|
| 30 |
+
RUN reflex export --frontend-only --no-zip
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Needed until Reflex properly passes SIGTERM on backend.
|
| 33 |
STOPSIGNAL SIGKILL
|
| 34 |
|
| 35 |
+
# Always apply migrations before starting the backend.
|
|
|
|
|
|
|
| 36 |
CMD [ -d alembic ] && reflex db migrate; \
|
|
|
|
| 37 |
redis-server --daemonize yes && \
|
| 38 |
+
exec reflex run --env prod
|