feat: 完成docker部署和测试

This commit is contained in:
chuan
2026-05-27 09:50:38 +08:00
Unverified
parent 03574805aa
commit 136e9dd1fc
6 changed files with 92 additions and 35 deletions
+28
View File
@@ -0,0 +1,28 @@
.git
.gitignore
.dockerignore
.venv
venv
env
__pycache__
*.py[cod]
*.pyo
*.pyd
.pytest_cache
.ruff_cache
.mypy_cache
.pyre
.coverage
htmlcov
data
.v2rayA
*.tmp
*.log
Dockerfile
docs
tests
+26 -19
View File
@@ -2,12 +2,14 @@ FROM ghcr.io/astral-sh/uv:python3.14-bookworm-slim
WORKDIR /app
ARG XRAY_VERSION=""
ARG TARGETARCH
ARG APT_MIRROR="https://mirrors.ustc.edu.cn/debian"
ARG UV_INDEX_URL="https://pypi.mirrors.ustc.edu.cn/simple/"
ENV UV_INDEX_URL="${UV_INDEX_URL}"
ENV UV_INDEX_URL="${UV_INDEX_URL}" \
PYTHONUNBUFFERED=1 \
PYXRAY_HOST=0.0.0.0 \
PYXRAY_PORT=8080 \
PYXRAY_XRAY_DIR=/config/xray
RUN if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
sed -i "s|http://deb.debian.org/debian|${APT_MIRROR}|g; s|http://deb.debian.org/debian-security|${APT_MIRROR}-security|g" /etc/apt/sources.list.d/debian.sources; \
@@ -16,29 +18,34 @@ RUN if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
sed -i "s|http://deb.debian.org/debian|${APT_MIRROR}|g; s|http://security.debian.org/debian-security|${APT_MIRROR}-security|g" /etc/apt/sources.list; \
fi \
&& apt-get update \
&& apt-get install -y --no-install-recommends iproute2 iptables ca-certificates curl unzip \
&& apt-get install -y --no-install-recommends \
ca-certificates \
curl \
iproute2 \
iptables \
nftables \
unzip \
&& rm -rf /var/lib/apt/lists/*
RUN if [ -n "$XRAY_VERSION" ]; then \
case "$TARGETARCH" in \
amd64|"") XRAY_ARCH="64" ;; \
arm64) XRAY_ARCH="arm64-v8a" ;; \
arm) XRAY_ARCH="arm32-v7a" ;; \
*) echo "unsupported TARGETARCH: $TARGETARCH" >&2; exit 1 ;; \
esac; \
curl -fsSL "https://github.com/XTLS/Xray-core/releases/download/${XRAY_VERSION}/Xray-linux-${XRAY_ARCH}.zip" -o /tmp/xray.zip; \
unzip /tmp/xray.zip xray geoip.dat geosite.dat -d /usr/local/share/xray; \
install -m 0755 /usr/local/share/xray/xray /usr/local/bin/xray; \
rm -f /tmp/xray.zip; \
fi
COPY pyproject.toml uv.lock README.md ./
COPY pyxray ./pyxray
RUN uv sync --frozen --no-dev
RUN uv sync --frozen --no-dev \
&& uv pip install --python /app/.venv/bin/python gunicorn==23.0.0
RUN printf '%s\n' \
'#!/bin/sh' \
'set -eu' \
'mkdir -p "$PYXRAY_XRAY_DIR"' \
'exec /app/.venv/bin/gunicorn --bind "$PYXRAY_HOST:$PYXRAY_PORT" --workers 1 --threads 8 --timeout 120 --access-logfile - --error-logfile - "pyxray.web.server:create_app(\"$PYXRAY_XRAY_DIR\")"' \
> /usr/local/bin/pyxray-entrypoint \
&& chmod 0755 /usr/local/bin/pyxray-entrypoint
VOLUME ["/config"]
EXPOSE 8080
CMD ["/app/.venv/bin/pyxray", "--nodes-file", "/config/nodes.toml", "--state-file", "/config/state.toml", "--runtime-file", "/config/runtime.toml", "web", "--host", "0.0.0.0", "--port", "8080", "--config-file", "/config/config.json", "--log-file", "/config/xray.log"]
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -fsS "http://127.0.0.1:${PYXRAY_PORT}/" >/dev/null || exit 1
CMD ["/usr/local/bin/pyxray-entrypoint"]
-15
View File
@@ -1,15 +0,0 @@
1. Xray 自动下载 / 检查
2. 节点链接导入与标准化
3. 节点管理与选择
4. Xray 配置生成
- [x] 定义 `settings.toml` 结构:core / inbounds / routing / transparent / dns / outbound settings。
- [x] 实现设置读写与默认值:使用 TOML 保存所有配置生成相关参数。
- [x] 实现基础配置模型:log / inbounds / outbounds / routing / dns。
- [x] 实现选中节点到 Xray outbound 的转换。
- [x] 实现 inbound 生成:socks / http / rule socks / rule http / custom inbounds / sniffing。
- [x] 实现 routing 生成:proxy / direct / whitelist / gfwlist / custom / RoutingA。
- [x] 实现 DNS 生成:dns rules / dns hosts / dns outbound / dns routing。
- [x] 实现透明代理配置生成:close / proxy / whitelist / gfwlist / pacredirect / tproxy / system_proxy / tun。
- [x] 实现 mux / tcpFastOpen / logLevel 等 outbound sockopt 和运行参数。
- [x] 增加完整配置生成测试:最小配置、规则端口、DNS、透明代理、各协议节点。
5. Xray 运行控制
+19
View File
@@ -0,0 +1,19 @@
services:
pyxray:
image: pyxray:latest
build:
context: .
dockerfile: Dockerfile
container_name: pyxray
restart: unless-stopped
privileged: true
network_mode: host
environment:
PYXRAY_HOST: 127.0.0.1
PYXRAY_PORT: 13999
PYXRAY_XRAY_DIR: /config/xray
volumes:
- ./data:/config
- /lib/modules:/lib/modules:ro
- /etc/resolv.conf:/etc/resolv.conf
stop_grace_period: 15s
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "pyxray"
version = "0.1.0"
version = "1.0.0"
description = "A lightweight Linux xray control plane."
readme = "README.md"
requires-python = ">=3.14"
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
set -eu
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
PROJECT_DIR=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)
IMAGE_NAME=${IMAGE_NAME:-pyxray}
IMAGE_TAG=${IMAGE_TAG:-latest}
APT_MIRROR=${APT_MIRROR:-https://mirrors.ustc.edu.cn/debian}
UV_INDEX_URL=${UV_INDEX_URL:-https://pypi.mirrors.ustc.edu.cn/simple/}
cd "$PROJECT_DIR"
docker build \
--build-arg "APT_MIRROR=$APT_MIRROR" \
--build-arg "UV_INDEX_URL=$UV_INDEX_URL" \
-t "$IMAGE_NAME:$IMAGE_TAG" \
.