File size: 1,093 Bytes
de68d43
 
 
6f8bc75
de68d43
 
6f8bc75
de68d43
 
 
 
 
 
 
 
 
 
6f8bc75
de68d43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Stage 1: Build
FROM python:3.11-slim as builder

WORKDIR /app

# Copy requirements.txt
COPY requirements.txt .

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy everything 
COPY app app

# Stage 2: Production
FROM python:3.11-slim as production

WORKDIR /app

# Copy installed modules from the builder stage
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages

# Install playwright dependencies
RUN python -m playwright install-deps && \
    # Clean up
    rm -f /usr/lib/x86_64-linux-gnu/libmfxhw* /usr/lib/x86_64-linux-gnu/mfx/* && \
    # Create non-root user
    useradd --home-dir /app --shell /bin/sh zaws && \
    chown -R zaws:zaws .

# Switch to non-root user
USER zaws

# Installfirefox inside non-root
# Do not install firefox in root to avoid permission error otherwise you need to give zaws permission to access installation path
RUN python -m playwright install firefox

# Copy application code from the builder stage
COPY --from=builder /app /app

# Run application
CMD ["python", "app/main.py"]