Reverting to old state and owning srv
Browse files- Dockerfile +37 -21
Dockerfile
CHANGED
|
@@ -1,38 +1,54 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM python:3.
|
| 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
|
|
|
|
|
|
|
|
|
|
| 12 |
WORKDIR /app
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
# Switch to the non-root user
|
| 21 |
USER user
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
RUN reflex export --frontend-only --no-zip
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# Needed until Reflex properly passes SIGTERM on backend.
|
| 33 |
STOPSIGNAL SIGKILL
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Python 3.11 base image
|
| 2 |
+
FROM python:3.11
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Create a non-root user for security
|
| 5 |
RUN useradd -m -u 1000 user
|
| 6 |
|
| 7 |
+
# Set environment variables and paths
|
| 8 |
+
ENV PATH="/home/user/.local/bin:/app/prompt_order_experiment:$PATH"
|
| 9 |
+
|
| 10 |
+
# Set work directory
|
| 11 |
WORKDIR /app
|
| 12 |
|
| 13 |
+
# Install necessary tools and dependencies as root
|
| 14 |
+
RUN apt-get update -y && apt-get install -y \
|
| 15 |
+
caddy \
|
| 16 |
+
redis-server \
|
| 17 |
+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
+
# Install Python requirements as root
|
| 20 |
+
COPY ./requirements.txt requirements.txt
|
| 21 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 22 |
|
| 23 |
# Switch to the non-root user
|
| 24 |
USER user
|
| 25 |
|
| 26 |
+
# Copy application code
|
| 27 |
+
COPY --chown=user . .
|
| 28 |
|
| 29 |
+
# Switch back to root to perform privileged operations
|
| 30 |
+
USER root
|
| 31 |
|
| 32 |
+
# Compile frontend assets and move to /srv
|
| 33 |
+
RUN reflex export --frontend-only --no-zip && mv .web/_static/* /srv/ && rm -rf .web
|
| 34 |
+
|
| 35 |
+
# Ensure non-root user has access to /srv
|
| 36 |
+
RUN chown -R user:user /srv
|
| 37 |
|
| 38 |
# Needed until Reflex properly passes SIGTERM on backend.
|
| 39 |
STOPSIGNAL SIGKILL
|
| 40 |
|
| 41 |
+
# Ensure the non-root user has ownership of the app directory
|
| 42 |
+
RUN chown -R user:user /app
|
| 43 |
+
|
| 44 |
+
# Revert to non-root user for running the app
|
| 45 |
+
USER user
|
| 46 |
+
|
| 47 |
+
# Apply migrations before starting the backend (if applicable)
|
| 48 |
+
RUN [ -d alembic ] && reflex db migrate || true
|
| 49 |
+
|
| 50 |
+
# Expose the default port
|
| 51 |
+
EXPOSE 8080
|
| 52 |
+
|
| 53 |
+
# Set the entry point for the container
|
| 54 |
+
ENTRYPOINT ["reflex", "run", "--env", "dev", "--loglevel", "debug"]
|