# cs.money worker: headful Chromium (nodriver) under a virtual display, with noVNC
# so you can open a browser into the container and solve a Cloudflare challenge by hand
# if one ever appears. Build context is the repo root (see docker-compose.yml).
FROM python:3.13-slim

# chromium + a virtual X display + VNC bridge + the fonts/libs Chromium needs.
RUN apt-get update && apt-get install -y --no-install-recommends \
        chromium \
        xvfb \
        x11vnc \
        novnc \
        websockify \
        ca-certificates \
        fonts-liberation \
        dumb-init \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY worker/requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
# blworker/ is the shared package both market scripts import; ship it + the two thin
# market scripts + the entrypoint.
COPY worker/blworker ./blworker
COPY worker/csmoney_worker.py worker/skinland_worker.py worker/entrypoint.sh ./
RUN chmod +x entrypoint.sh

# Which worker this image runs (overridden per service in docker-compose). The cs.money
# worker is the default; the skin.land service sets WORKER_SCRIPT=skinland_worker.py.
ENV BROWSER_PATH=/usr/bin/chromium \
    CHROME_NO_SANDBOX=1 \
    DISPLAY=:99 \
    SOLVE_SECONDS=45 \
    WORKER_SCRIPT=csmoney_worker.py \
    LOG_JSON=1 \
    PYTHONUNBUFFERED=1


# noVNC web UI (browse http://localhost:6080/vnc.html to watch / solve a challenge).
EXPOSE 6080

# dumb-init reaps the Xvfb/x11vnc/websockify children cleanly.
ENTRYPOINT ["dumb-init", "--", "./entrypoint.sh"]
