feat: 移除默认的aria2

This commit is contained in:
dnslin
2025-12-15 16:10:00 +08:00
parent 8d7b2667e1
commit b5983f57bd
3 changed files with 24 additions and 13 deletions

View File

@@ -18,11 +18,9 @@ FROM python:3.13-slim
LABEL maintainer="dnslin"
LABEL description="Aria2 Telegram Bot - 通过 Telegram 控制 aria2 下载"
# 安装 aria2 和必要工具
# 安装必要工具(aria2 通过 /install 命令下载)
RUN apt-get update && \
apt-get install -y --no-install-recommends \
aria2 \
ca-certificates \
apt-get install -y --no-install-recommends ca-certificates \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
@@ -31,13 +29,13 @@ WORKDIR /app
# 从构建阶段复制虚拟环境
COPY --from=builder /app/.venv /app/.venv
# 复制应用代码
# 复制应用代码和入口脚本
COPY src/ ./src/
COPY main.py banner.txt ./
COPY main.py banner.txt docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh
# 创建必要目录和符号链接
RUN mkdir -p /root/.local/bin /root/.config/aria2 /root/downloads && \
ln -s /usr/bin/aria2c /root/.local/bin/aria2c
# 创建必要目录
RUN mkdir -p /root/.local/bin /root/.config/aria2 /root/downloads
# 设置环境变量
ENV PATH="/app/.venv/bin:$PATH"
@@ -51,4 +49,4 @@ VOLUME ["/root/downloads", "/root/.config/aria2"]
EXPOSE 6800
# 启动命令
CMD ["python", "main.py"]
ENTRYPOINT ["./docker-entrypoint.sh"]

8
docker-entrypoint.sh Normal file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
# Docker 容器入口脚本
# 创建必要目录
mkdir -p /root/.local/bin /root/.config/aria2 /root/downloads
# 启动应用
exec python main.py

View File

@@ -257,10 +257,15 @@ class Aria2Installer:
try:
if ARIA2_CONFIG_DIR.exists():
shutil.rmtree(ARIA2_CONFIG_DIR)
logger.info(f"已删除配置目录: {ARIA2_CONFIG_DIR}")
# 删除配置目录中的文件,而不是整个目录(兼容 Docker 挂载卷)
for item in ARIA2_CONFIG_DIR.iterdir():
if item.is_file():
item.unlink()
elif item.is_dir():
shutil.rmtree(item)
logger.info(f"已清空配置目录: {ARIA2_CONFIG_DIR}")
except Exception as exc: # noqa: PERF203
logger.error(f"删除配置目录失败: {exc}")
logger.error(f"清空配置目录失败: {exc}")
errors.append(exc)
try: