mirror of
https://github.com/dnslin/aria2bot.git
synced 2026-01-11 12:12:19 +08:00
feat: add ci and docker file
This commit is contained in:
34
.dockerignore
Normal file
34
.dockerignore
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# Git
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# Python
|
||||||
|
.venv
|
||||||
|
__pycache__
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.egg-info
|
||||||
|
.eggs
|
||||||
|
|
||||||
|
# 环境配置
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
|
||||||
|
# 缓存和临时文件
|
||||||
|
.cache
|
||||||
|
temp
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# 文档和计划
|
||||||
|
*.md
|
||||||
|
!README.md
|
||||||
|
|
||||||
|
# 测试
|
||||||
|
tests
|
||||||
|
.pytest_cache
|
||||||
|
.coverage
|
||||||
64
.github/workflows/docker.yml
vendored
Normal file
64
.github/workflows/docker.yml
vendored
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
name: Docker Build and Push
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
DOCKERHUB_IMAGE: dnslin/aria2bot
|
||||||
|
GHCR_IMAGE: ghcr.io/${{ github.repository }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: |
|
||||||
|
${{ env.DOCKERHUB_IMAGE }}
|
||||||
|
${{ env.GHCR_IMAGE }}
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=sha,prefix=sha-
|
||||||
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
54
Dockerfile
Normal file
54
Dockerfile
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# 阶段1: 构建依赖
|
||||||
|
FROM python:3.13-slim AS builder
|
||||||
|
|
||||||
|
# 安装 uv
|
||||||
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 复制依赖文件
|
||||||
|
COPY pyproject.toml uv.lock ./
|
||||||
|
|
||||||
|
# 安装依赖到虚拟环境
|
||||||
|
RUN uv sync --frozen --no-dev --no-install-project
|
||||||
|
|
||||||
|
# 阶段2: 运行环境
|
||||||
|
FROM python:3.13-slim
|
||||||
|
|
||||||
|
LABEL maintainer="dnslin"
|
||||||
|
LABEL description="Aria2 Telegram Bot - 通过 Telegram 控制 aria2 下载"
|
||||||
|
|
||||||
|
# 安装 aria2 和必要工具
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
|
aria2 \
|
||||||
|
ca-certificates \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
&& apt-get clean
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 从构建阶段复制虚拟环境
|
||||||
|
COPY --from=builder /app/.venv /app/.venv
|
||||||
|
|
||||||
|
# 复制应用代码
|
||||||
|
COPY src/ ./src/
|
||||||
|
COPY main.py banner.txt ./
|
||||||
|
|
||||||
|
# 创建必要目录和符号链接
|
||||||
|
RUN mkdir -p /root/.local/bin /root/.config/aria2 /root/downloads && \
|
||||||
|
ln -s /usr/bin/aria2c /root/.local/bin/aria2c
|
||||||
|
|
||||||
|
# 设置环境变量
|
||||||
|
ENV PATH="/app/.venv/bin:$PATH"
|
||||||
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|
||||||
|
# 声明数据卷
|
||||||
|
VOLUME ["/root/downloads", "/root/.config/aria2"]
|
||||||
|
|
||||||
|
# 暴露 aria2 RPC 端口
|
||||||
|
EXPOSE 6800
|
||||||
|
|
||||||
|
# 启动命令
|
||||||
|
CMD ["python", "main.py"]
|
||||||
16
docker-compose.yml
Normal file
16
docker-compose.yml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
services:
|
||||||
|
aria2bot:
|
||||||
|
build: .
|
||||||
|
image: dnslin/aria2bot:latest
|
||||||
|
container_name: aria2bot
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
# 下载目录
|
||||||
|
- ./downloads:/root/downloads
|
||||||
|
# aria2 配置目录(包含配置文件、会话、云存储令牌)
|
||||||
|
- ./config:/root/.config/aria2
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
# 可选:暴露 aria2 RPC 端口(如需外部访问)
|
||||||
|
# ports:
|
||||||
|
# - "6800:6800"
|
||||||
Reference in New Issue
Block a user