trying a more efficient approach
Browse files- Dockerfile +35 -12
Dockerfile
CHANGED
|
@@ -1,22 +1,45 @@
|
|
|
|
|
| 1 |
FROM python:3.11
|
| 2 |
|
|
|
|
| 3 |
RUN useradd -m -u 1000 user
|
| 4 |
-
USER user
|
| 5 |
-
ENV PATH="/home/user/.local/bin:$PATH"
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
WORKDIR /app
|
| 8 |
|
| 9 |
-
# Install
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
ENTRYPOINT ["reflex", "run", "--env", "dev", "--loglevel", "debug"
|
|
|
|
| 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 to ensure permissions for all users
|
| 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 and prepare the app
|
| 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 (requires root permissions)
|
| 33 |
+
RUN reflex export --frontend-only --no-zip && mv .web/_static/* /srv/ && rm -rf .web
|
| 34 |
+
|
| 35 |
+
# Revert to non-root user for running the app
|
| 36 |
+
USER user
|
| 37 |
+
|
| 38 |
+
# Apply migrations before starting the backend (if applicable)
|
| 39 |
+
RUN [ -d alembic ] && reflex db migrate || true
|
| 40 |
|
| 41 |
+
# Expose the default port
|
| 42 |
+
EXPOSE 8080
|
| 43 |
|
| 44 |
+
# Set the entry point for the container
|
| 45 |
+
ENTRYPOINT ["reflex", "run", "--env", "dev", "--loglevel", "debug"]
|