File size: 1,416 Bytes
9c9137b
 
fb2eb9b
2ab2f96
fb2eb9b
 
9c9137b
 
 
 
fb2eb9b
 
9c9137b
 
 
 
 
2ab2f96
9c9137b
 
 
2ab2f96
16552c4
 
 
9c9137b
 
2ab2f96
9c9137b
 
2ab2f96
9c9137b
 
 
 
 
2ab2f96
dc7ccc1
 
9990990
9c9137b
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Use Python 3.11 base image
FROM python:3.11

# Create a non-root user for security
RUN useradd -m -u 1000 user

# Set environment variables and paths
ENV PATH="/home/user/.local/bin:/app/prompt_order_experiment:$PATH"

# Set work directory
WORKDIR /app

# Install necessary tools and dependencies as root
RUN apt-get update -y && apt-get install -y \
    caddy \
    redis-server \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Install Python requirements as root
COPY ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Switch to the non-root user
USER user

# Copy application code
COPY --chown=user . .

# Switch back to root to perform privileged operations
USER root

# Compile frontend assets and move to /srv
RUN reflex export --frontend-only --no-zip && mv .web/_static/* /srv/ && rm -rf .web

# Ensure non-root user has access to /srv
RUN chown -R user:user /srv

# Needed until Reflex properly passes SIGTERM on backend.
STOPSIGNAL SIGKILL

# Ensure the non-root user has ownership of the app directory
RUN chown -R user:user /app

# Revert to non-root user for running the app
USER user

# Apply migrations before starting the backend (if applicable)
RUN [ -d alembic ] && reflex db migrate || true

# Expose the default port
EXPOSE 8080

# Set the entry point for the container
ENTRYPOINT ["reflex", "run", "--env", "dev", "--loglevel", "debug"]