factorstudios commited on
Commit
edea27f
·
verified ·
1 Parent(s): 3fe0ae5

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -25
Dockerfile CHANGED
@@ -1,34 +1,29 @@
1
  FROM python:3.11-slim
2
 
3
- # Set working directory
4
  WORKDIR /app
5
 
6
- # Install system dependencies
7
- RUN apt-get update && apt-get install -y \
8
-
9
- build-essential \
10
- python3-dev \
11
- && rm -rf /var/lib/apt/lists/*
12
 
 
 
 
 
 
13
 
14
- # Copy requirements and install Python dependencies
15
- COPY requirements.txt .
16
- RUN pip install --no-cache-dir -r requirements.txt
17
 
18
- # Copy application files
19
- COPY . .
20
-
21
- RUN useradd -m -u 1000 user
 
22
 
23
- RUN chmod -R 777 /app
24
 
25
- # Set environment variables
26
- ENV FLASK_APP=app.py
27
- ENV FLASK_ENV=production
28
- ENV PORT=7860
29
-
30
- # Expose port
31
- EXPOSE 7860
32
-
33
- # Run the application
34
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.11-slim
2
 
 
3
  WORKDIR /app
4
 
5
+ # Playwright saves browsers here during the image build. The same path is then
6
+ # available to the non-root FastAPI process at runtime.
7
+ ENV PYTHONUNBUFFERED=1 \
8
+ PORT=7860 \
9
+ PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
 
10
 
11
+ # Install the application dependencies first so Docker can cache this layer.
12
+ COPY requirements.txt ./
13
+ RUN pip install --no-cache-dir -r requirements.txt \
14
+ && python -m playwright install --with-deps chromium \
15
+ && rm -rf /var/lib/apt/lists/* /root/.cache/pip
16
 
17
+ # Copy the FastAPI application after dependency installation.
18
+ COPY . ./
 
19
 
20
+ # Avoid running the web app as root. The installed browser path is readable by
21
+ # this user and /tmp remains writable for temporary MP4 output.
22
+ RUN useradd --create-home --uid 1000 appuser \
23
+ && chown -R appuser:appuser /app /ms-playwright
24
+ USER appuser
25
 
26
+ EXPOSE 7860
27
 
28
+ # Uses $PORT when a host injects it, and otherwise listens on 7860.
29
+ CMD ["sh", "-c", "uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860}"]