|
| 1 | +FROM ghcr.io/astral-sh/uv:bookworm-slim AS builder |
| 2 | + |
| 3 | +ARG VNC_PASSWORD=browser-use |
| 4 | + |
| 5 | +ENV UV_COMPILE_BYTECODE=1 \ |
| 6 | + UV_LINK_MODE=copy \ |
| 7 | + UV_PYTHON_INSTALL_DIR=/python \ |
| 8 | + UV_PYTHON_PREFERENCE=only-managed |
| 9 | + |
| 10 | +# Install build dependencies and clean up in the same layer |
| 11 | +RUN apt-get update -y && \ |
| 12 | + apt-get install --no-install-recommends -y clang && \ |
| 13 | + rm -rf /var/lib/apt/lists/* |
| 14 | + |
| 15 | +# Install Python before the project for caching |
| 16 | +RUN uv python install 3.13 |
| 17 | + |
| 18 | +WORKDIR /app |
| 19 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 20 | + --mount=type=bind,source=uv.lock,target=uv.lock \ |
| 21 | + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ |
| 22 | + uv sync --frozen --no-install-project --no-dev |
| 23 | +ADD . /app |
| 24 | +RUN --mount=type=cache,target=/root/.cache/uv \ |
| 25 | + uv sync --frozen --no-dev |
| 26 | + |
| 27 | +FROM debian:bookworm-slim AS runtime |
| 28 | + |
| 29 | +# Install required packages including Chromium and clean up in the same layer |
| 30 | +RUN apt-get update && \ |
| 31 | + apt-get install --no-install-recommends -y \ |
| 32 | + xfce4 \ |
| 33 | + dbus-x11 \ |
| 34 | + tigervnc-standalone-server \ |
| 35 | + tigervnc-tools \ |
| 36 | + nodejs \ |
| 37 | + npm \ |
| 38 | + chromium \ |
| 39 | + chromium-driver \ |
| 40 | + fonts-freefont-ttf \ |
| 41 | + fonts-ipafont-gothic \ |
| 42 | + fonts-wqy-zenhei \ |
| 43 | + fonts-thai-tlwg \ |
| 44 | + fonts-kacst \ |
| 45 | + fonts-symbola \ |
| 46 | + fonts-noto-color-emoji && \ |
| 47 | + npm i -g proxy-login-automator && \ |
| 48 | + apt-get clean && \ |
| 49 | + rm -rf /var/lib/apt/lists/* && \ |
| 50 | + rm -rf /var/cache/apt/* |
| 51 | + |
| 52 | +# Copy only necessary files from builder |
| 53 | +COPY --from=builder --chown=python:python /python /python |
| 54 | +COPY --from=builder --chown=app:app /app /app |
| 55 | + |
| 56 | +ENV PATH="/app/.venv/bin:$PATH" \ |
| 57 | + DISPLAY=:0 \ |
| 58 | + CHROME_BIN=/usr/bin/chromium \ |
| 59 | + CHROMIUM_FLAGS="--no-sandbox --headless --disable-gpu --disable-software-rasterizer --disable-dev-shm-usage" |
| 60 | + |
| 61 | +# Combine VNC setup commands to reduce layers |
| 62 | +RUN mkdir -p ~/.vnc && \ |
| 63 | + echo ${VNC_PASSWORD} | vncpasswd -f > /root/.vnc/passwd && \ |
| 64 | + chmod 600 /root/.vnc/passwd && \ |
| 65 | + printf '#!/bin/sh\nunset SESSION_MANAGER\nunset DBUS_SESSION_BUS_ADDRESS\nstartxfce4' > /root/.vnc/xstartup && \ |
| 66 | + chmod +x /root/.vnc/xstartup && \ |
| 67 | + printf '#!/bin/bash\nvncserver -depth 24 -geometry 1920x1080 -localhost no -PasswordFile /root/.vnc/passwd :0\nproxy-login-automator\npython /app/main.py' > /app/boot.sh && \ |
| 68 | + chmod +x /app/boot.sh |
| 69 | + |
| 70 | +ENTRYPOINT ["/bin/bash", "/app/boot.sh"] |
0 commit comments