Trying with reflex dockerfile
Browse files- Dockerfile +35 -35
Dockerfile
CHANGED
@@ -1,51 +1,51 @@
|
|
1 |
-
#
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Create a non-root user for security
|
5 |
RUN useradd -m -u 1000 user
|
6 |
|
7 |
-
#
|
8 |
-
ENV PATH="/home/user/.local/bin:/app/prompt_order_experiment:$PATH"
|
9 |
-
|
10 |
-
# Set work directory
|
11 |
WORKDIR /app
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
caddy \
|
16 |
-
redis-server \
|
17 |
-
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
22 |
-
|
23 |
-
# Switch to the non-root user
|
24 |
-
USER user
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
|
29 |
-
#
|
30 |
-
|
31 |
|
32 |
-
#
|
33 |
RUN reflex export --frontend-only --no-zip && mv .web/_static/* /srv/ && rm -rf .web
|
34 |
|
35 |
-
#
|
36 |
-
STOPSIGNAL SIGKILL
|
37 |
-
|
38 |
-
# Ensure the non-root user has ownership of the app directory
|
39 |
-
RUN chown -R user:user /app
|
40 |
-
|
41 |
-
# Revert to non-root user for running the app
|
42 |
USER user
|
43 |
|
44 |
-
#
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
EXPOSE 8080
|
49 |
|
50 |
-
#
|
51 |
-
|
|
|
|
|
|
|
|
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 |
+
# If the service expects a different port, provide it here (f.e Render expects port 10000)
|
10 |
+
ARG PORT=8080
|
11 |
+
# Only set for local/direct access. When TLS is used, the API_URL is assumed to be the same as the frontend.
|
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 |
+
# Switch to the app directory
|
|
|
|
|
|
|
22 |
WORKDIR /app
|
23 |
|
24 |
+
# Copy local context to `/app` inside container (see .dockerignore)
|
25 |
+
COPY . .
|
|
|
|
|
|
|
26 |
|
27 |
+
# Adjust permissions for the app directory to allow the non-root user to access it
|
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 |
+
# Download all npm dependencies and compile frontend
|
37 |
RUN reflex export --frontend-only --no-zip && mv .web/_static/* /srv/ && rm -rf .web
|
38 |
|
39 |
+
# Switch to non-root user
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
USER user
|
41 |
|
42 |
+
# Needed until Reflex properly passes SIGTERM on backend.
|
43 |
+
STOPSIGNAL SIGKILL
|
44 |
|
45 |
+
EXPOSE $PORT
|
|
|
46 |
|
47 |
+
# Apply migrations before starting the backend.
|
48 |
+
CMD [ -d alembic ] && reflex db migrate; \
|
49 |
+
caddy start && \
|
50 |
+
redis-server --daemonize yes && \
|
51 |
+
exec reflex run --env prod --backend-only
|