mirror of
https://github.com/zhinianboke/xianyu-auto-reply.git
synced 2025-08-30 01:27:35 +08:00
支持国内镜像构建项目
增加一个国内网络环境使用的Dockerfile,加速国内网络环境构建镜像
This commit is contained in:
commit
549e7ab32f
124
Dockerfile-cn
Normal file
124
Dockerfile-cn
Normal file
@ -0,0 +1,124 @@
|
||||
# 使用Python 3.11作为基础镜像
|
||||
FROM python:3.11-slim
|
||||
|
||||
# 设置标签信息
|
||||
LABEL maintainer="zhinianboke"
|
||||
LABEL version="2.1.0"
|
||||
LABEL description="闲鱼自动回复系统 - 企业级多用户版本,支持自动发货和免拼发货"
|
||||
LABEL repository="https://github.com/zhinianboke/xianyu-auto-reply"
|
||||
LABEL license="仅供学习使用,禁止商业用途"
|
||||
LABEL author="zhinianboke"
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 设置环境变量
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV DOCKER_ENV=true
|
||||
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
||||
|
||||
#更换中科大源
|
||||
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources
|
||||
|
||||
# 安装系统依赖(包括Playwright浏览器依赖)
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
# 基础工具
|
||||
nodejs \
|
||||
npm \
|
||||
tzdata \
|
||||
curl \
|
||||
ca-certificates \
|
||||
# 图像处理依赖
|
||||
libjpeg-dev \
|
||||
libpng-dev \
|
||||
libfreetype6-dev \
|
||||
fonts-dejavu-core \
|
||||
fonts-liberation \
|
||||
# Playwright浏览器依赖
|
||||
libnss3 \
|
||||
libnspr4 \
|
||||
libatk-bridge2.0-0 \
|
||||
libdrm2 \
|
||||
libxkbcommon0 \
|
||||
libxcomposite1 \
|
||||
libxdamage1 \
|
||||
libxrandr2 \
|
||||
libgbm1 \
|
||||
libxss1 \
|
||||
libasound2 \
|
||||
libatspi2.0-0 \
|
||||
libgtk-3-0 \
|
||||
libgdk-pixbuf2.0-0 \
|
||||
libxcursor1 \
|
||||
libxi6 \
|
||||
libxrender1 \
|
||||
libxext6 \
|
||||
libx11-6 \
|
||||
libxft2 \
|
||||
libxinerama1 \
|
||||
libxtst6 \
|
||||
libappindicator3-1 \
|
||||
libx11-xcb1 \
|
||||
libxfixes3 \
|
||||
xdg-utils \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& rm -rf /tmp/* \
|
||||
&& rm -rf /var/tmp/*
|
||||
|
||||
# 设置时区
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
# 验证Node.js安装并设置环境变量
|
||||
RUN node --version && npm --version
|
||||
ENV NODE_PATH=/usr/lib/node_modules
|
||||
|
||||
# 复制requirements.txt并安装Python依赖
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple&& \
|
||||
pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
|
||||
# 复制项目文件
|
||||
COPY . .
|
||||
|
||||
# 安装Playwright浏览器(必须在复制项目文件之后)
|
||||
RUN playwright install chromium && \
|
||||
playwright install-deps chromium
|
||||
|
||||
# 创建必要的目录并设置权限
|
||||
RUN mkdir -p /app/logs /app/data /app/backups && \
|
||||
chmod 777 /app/logs /app/data /app/backups
|
||||
|
||||
# 注意: 为了简化权限问题,使用root用户运行
|
||||
# 在生产环境中,建议配置适当的用户映射
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 8080
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD curl -f http://localhost:8080/health || exit 1
|
||||
|
||||
# 创建启动脚本
|
||||
COPY <<EOF /app/entrypoint.sh
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "🚀 启动闲鱼自动回复系统..."
|
||||
echo "📊 数据库将在应用启动时自动初始化..."
|
||||
echo "🎯 启动主应用..."
|
||||
|
||||
# 确保数据目录存在
|
||||
mkdir -p /app/data /app/logs /app/backups
|
||||
|
||||
# 启动主应用
|
||||
exec python Start.py
|
||||
EOF
|
||||
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
|
||||
# 启动命令
|
||||
CMD ["/app/entrypoint.sh"]
|
107
docker-compose-cn.yml
Normal file
107
docker-compose-cn.yml
Normal file
@ -0,0 +1,107 @@
|
||||
services:
|
||||
xianyu-app:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile-cn
|
||||
image: xianyu-auto-reply:latest
|
||||
container_name: xianyu-auto-reply
|
||||
restart: unless-stopped
|
||||
# 使用root用户避免权限问题
|
||||
user: "0:0"
|
||||
ports:
|
||||
- "${WEB_PORT:-8080}:8080"
|
||||
volumes:
|
||||
# 数据持久化
|
||||
- ./data:/app/data:rw
|
||||
- ./logs:/app/logs:rw
|
||||
- ./global_config.yml:/app/global_config.yml:ro
|
||||
# 可选:如果需要自定义配置
|
||||
# - ./custom_config.yml:/app/global_config.yml:ro
|
||||
# 可选:备份目录
|
||||
- ./backups:/app/backups:rw
|
||||
environment:
|
||||
- PYTHONUNBUFFERED=${PYTHONUNBUFFERED:-1}
|
||||
- PYTHONDONTWRITEBYTECODE=${PYTHONDONTWRITEBYTECODE:-1}
|
||||
- TZ=${TZ:-Asia/Shanghai}
|
||||
- DB_PATH=${DB_PATH:-/app/data/xianyu_data.db}
|
||||
- LOG_LEVEL=${LOG_LEVEL:-INFO}
|
||||
- DEBUG=${DEBUG:-false}
|
||||
- RELOAD=${RELOAD:-false}
|
||||
# SQL日志配置(默认启用,可通过环境变量覆盖)
|
||||
- SQL_LOG_ENABLED=${SQL_LOG_ENABLED:-true}
|
||||
- SQL_LOG_LEVEL=${SQL_LOG_LEVEL:-INFO}
|
||||
- ADMIN_USERNAME=${ADMIN_USERNAME:-admin}
|
||||
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin123}
|
||||
- JWT_SECRET_KEY=${JWT_SECRET_KEY:-default-secret-key}
|
||||
- SESSION_TIMEOUT=${SESSION_TIMEOUT:-3600}
|
||||
# 多用户系统配置
|
||||
- MULTIUSER_ENABLED=${MULTIUSER_ENABLED:-true}
|
||||
- USER_REGISTRATION_ENABLED=${USER_REGISTRATION_ENABLED:-true}
|
||||
- EMAIL_VERIFICATION_ENABLED=${EMAIL_VERIFICATION_ENABLED:-true}
|
||||
- CAPTCHA_ENABLED=${CAPTCHA_ENABLED:-true}
|
||||
- TOKEN_EXPIRE_TIME=${TOKEN_EXPIRE_TIME:-86400}
|
||||
- AUTO_REPLY_ENABLED=${AUTO_REPLY_ENABLED:-true}
|
||||
- AUTO_DELIVERY_ENABLED=${AUTO_DELIVERY_ENABLED:-true}
|
||||
- AUTO_DELIVERY_TIMEOUT=${AUTO_DELIVERY_TIMEOUT:-30}
|
||||
- API_CARD_TIMEOUT=${API_CARD_TIMEOUT:-10}
|
||||
- BATCH_DATA_LOCK_TIMEOUT=${BATCH_DATA_LOCK_TIMEOUT:-5}
|
||||
# AI回复相关配置
|
||||
- AI_REPLY_ENABLED=${AI_REPLY_ENABLED:-false}
|
||||
- DEFAULT_AI_MODEL=${DEFAULT_AI_MODEL:-qwen-plus}
|
||||
- DEFAULT_AI_BASE_URL=${DEFAULT_AI_BASE_URL:-https://dashscope.aliyuncs.com/compatible-mode/v1}
|
||||
- AI_REQUEST_TIMEOUT=${AI_REQUEST_TIMEOUT:-30}
|
||||
- AI_MAX_TOKENS=${AI_MAX_TOKENS:-100}
|
||||
- WEBSOCKET_URL=${WEBSOCKET_URL:-wss://wss-goofish.dingtalk.com/}
|
||||
- HEARTBEAT_INTERVAL=${HEARTBEAT_INTERVAL:-15}
|
||||
- HEARTBEAT_TIMEOUT=${HEARTBEAT_TIMEOUT:-5}
|
||||
- TOKEN_REFRESH_INTERVAL=${TOKEN_REFRESH_INTERVAL:-3600}
|
||||
- TOKEN_RETRY_INTERVAL=${TOKEN_RETRY_INTERVAL:-300}
|
||||
- MESSAGE_EXPIRE_TIME=${MESSAGE_EXPIRE_TIME:-300000}
|
||||
env_file:
|
||||
- path: .env
|
||||
required: false
|
||||
networks:
|
||||
- xianyu-network
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
# 资源限制
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: ${MEMORY_LIMIT:-512}M
|
||||
cpus: '${CPU_LIMIT:-0.5}'
|
||||
reservations:
|
||||
memory: ${MEMORY_RESERVATION:-256}M
|
||||
cpus: '${CPU_RESERVATION:-0.25}'
|
||||
|
||||
# 可选:添加Nginx反向代理
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
container_name: xianyu-nginx
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
- ./nginx/ssl:/etc/nginx/ssl:ro
|
||||
depends_on:
|
||||
- xianyu-app
|
||||
networks:
|
||||
- xianyu-network
|
||||
profiles:
|
||||
- with-nginx
|
||||
|
||||
networks:
|
||||
xianyu-network:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
xianyu-data:
|
||||
driver: local
|
||||
xianyu-logs:
|
||||
driver: local
|
@ -70,7 +70,12 @@ init_config() {
|
||||
# 构建镜像
|
||||
build_image() {
|
||||
print_info "构建 Docker 镜像..."
|
||||
docker-compose build --no-cache
|
||||
echo "是否需要使用国内镜像(y/n): " && read iscn
|
||||
if [[ $iscn == "y" ]]; then
|
||||
docker-compose -f docker-compose-cn.yml build --no-cache
|
||||
else
|
||||
docker-compose build --no-cache
|
||||
fi
|
||||
print_success "镜像构建完成"
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user