derek-thomas HF staff commited on
Commit
9c9137b
·
verified ·
1 Parent(s): 4508180

Reverting to old state and owning srv

Browse files
Files changed (1) hide show
  1. Dockerfile +37 -21
Dockerfile CHANGED
@@ -1,38 +1,54 @@
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
 
 
 
 
 
 
 
 
 
 
 
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"]