From bd4746004efa8553c67de2af59d9dee288221e6e Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Fri, 27 Mar 2026 07:05:56 +0100 Subject: [PATCH] Docker image for headless proxy (#289) --- .dockerignore | 28 ++++++++++++++++++++++++++++ Dockerfile | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2b5f4d8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,28 @@ +.git +.github +.gitignore +__pycache__/ +*.py[cod] +*.pyo +*.egg-info/ +.pytest_cache/ +.mypy_cache/ +.ruff_cache/ +.venv/ +venv/ +dist/ +build/ +packaging/ +windows.py +icon.ico +*.spec +*.spec.bak +*.manifest +*.log +.vscode/ +.idea/ +*.swp +*.swo +.DS_Store +Thumbs.db +Desktop.ini diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dae44d2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +# syntax=docker/dockerfile:1.7 + +FROM python:3.12-slim AS builder + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + PIP_NO_CACHE_DIR=1 \ + VIRTUAL_ENV=/opt/venv + +RUN apt-get update \ + && apt-get install -y --no-install-recommends build-essential cargo libffi-dev libssl-dev \ + && python -m venv "$VIRTUAL_ENV" \ + && "$VIRTUAL_ENV/bin/pip" install --upgrade pip setuptools wheel \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app +RUN "$VIRTUAL_ENV/bin/pip" install cryptography==46.0.5 + +FROM python:3.12-slim AS runtime + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PATH=/opt/venv/bin:$PATH \ + TG_WS_PROXY_HOST=0.0.0.0 \ + TG_WS_PROXY_PORT=1080 \ + TG_WS_PROXY_DC_IPS="2:149.154.167.220 4:149.154.167.220" + +RUN apt-get update \ + && apt-get install -y --no-install-recommends tini ca-certificates \ + && rm -rf /var/lib/apt/lists/* \ + && groupadd --system app \ + && useradd --system --gid app --create-home --home-dir /home/app app + +WORKDIR /app +COPY --from=builder /opt/venv /opt/venv +COPY proxy ./proxy +COPY README.md LICENSE ./ + +USER app + +EXPOSE 1080/tcp + +ENTRYPOINT ["/usr/bin/tini", "--", "/bin/sh", "-lc", "set -eu; args=\"--host ${TG_WS_PROXY_HOST} --port ${TG_WS_PROXY_PORT}\"; for dc in ${TG_WS_PROXY_DC_IPS}; do args=\"$args --dc-ip $dc\"; done; exec python -u proxy/tg_ws_proxy.py $args \"$@\"", "--"] +CMD []