File size: 1,283 Bytes
aed647b
 
e6459b9
 
 
 
 
 
 
 
 
 
aed647b
 
e6459b9
 
 
 
aed647b
 
e6459b9
 
aed647b
 
 
 
50194ae
e6459b9
 
 
aed647b
e6459b9
 
 
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
FROM python:3.11-slim

ENV PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    HOME=/tmp \
    XDG_CACHE_HOME=/tmp/.cache \
    SELENIUM_MANAGER_CACHE_DIR=/tmp/selenium \
    TMPDIR=/tmp \
    CHROME_BINARY=/usr/bin/chromium \
    CHROMEDRIVER=/usr/bin/chromedriver \
    CHROME_EXTRA_ARGS="--no-sandbox --disable-dev-shm-usage --disable-gpu --window-size=1920,1080 --headless=new"

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        chromium chromium-driver \
        fonts-liberation \
        libgbm1 libnss3 libxss1 libasound2 libxshmfence1 \
        ca-certificates && \
    rm -rf /var/lib/apt/lists/*

RUN mkdir -p /app/downloaded_files /tmp/.cache /tmp/selenium && \
    chmod -R 777 /app/downloaded_files /tmp/.cache /tmp/selenium

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

RUN python -c "import os, sysconfig, pathlib; site=pathlib.Path(sysconfig.get_paths()['purelib']); p=site/'seleniumbase'/'drivers'; print('Fixing perms under:', p); p.mkdir(parents=True, exist_ok=True); os.system(f'chmod -R a+rwX {p}')"

RUN chmod a+rx /usr/bin/chromium /usr/bin/chromedriver

WORKDIR /app
COPY . /app

CMD ["gunicorn","-w","1","--threads","1","-k","uvicorn.workers.UvicornWorker","--bind","0.0.0.0:8080","app.main:app"]