Skip to content

Commit 736fa0b

Browse files
authored
Merge pull request #62 from KarlRaphel/main
Add docker support
2 parents 0190ac0 + 9213785 commit 736fa0b

File tree

4 files changed

+222
-1
lines changed

4 files changed

+222
-1
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ wheels/
1010

1111
# Virtual environments
1212
.venv
13-
test.ipynb
13+
test.ipynb
14+
15+
logs
16+
models
17+
test-compose.yml

Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# 使用官方Python镜像作为基础
2+
FROM python:3.11-slim
3+
4+
# 设置python镜像
5+
ENV UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
6+
ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
7+
ENV PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn
8+
9+
# 设置工作目录
10+
WORKDIR /app
11+
12+
# 跳过安全更新,加快构建速度
13+
RUN echo 'APT::Get::AllowUnauthenticated "true";' > /etc/apt/apt.conf.d/99allow-unauthenticated
14+
RUN echo 'Acquire::AllowReleaseInfoChange::Suite "true";' > /etc/apt/apt.conf.d/99allow-releaseinfo-change
15+
16+
# 设置debian镜像
17+
RUN rm -f /etc/apt/sources.list /etc/apt/sources.list.d/*
18+
RUN echo "\
19+
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free\n\
20+
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free\n\
21+
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free\n\
22+
deb https://security.debian.org/debian-security bookworm-security main contrib non-free" > /etc/apt/sources.list
23+
24+
# 安装系统依赖(包括cron)
25+
RUN apt-get update && apt-get install -y \
26+
build-essential \
27+
cmake \
28+
git \
29+
cron \
30+
&& rm -rf /var/lib/apt/lists/*
31+
32+
# 复制项目文件
33+
COPY . .
34+
35+
# 升级cmake
36+
RUN pip install --upgrade cmake
37+
ENV CC=/usr/bin/gcc
38+
ENV CXX=/usr/bin/g++
39+
40+
# 安装Python依赖
41+
RUN pip install uv
42+
RUN uv sync
43+
44+
# 创建日志目录和模型目录
45+
RUN mkdir -p /var/log/cron
46+
47+
# 下载LLM模型 (如果使用本地LLM)
48+
RUN if [ "$USE_LLM_API" = "0" ]; then \
49+
mkdir -p /app/models \
50+
wget https://huggingface.co/Qwen/Qwen1.5-3B-Instruct-GGUF/resolve/main/qwen1.5-3b-instruct-q4_k_m.gguf -O /app/models/qwen.gguf; \
51+
fi
52+
53+
# 设置容器启动命令(由compose覆盖)
54+
CMD ["cd /app && /usr/local/bin/uv run main.py"]

assets/use_docker.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
## 🐳 Docker Deployment
2+
3+
For users who prefer containerized deployment, we now provide Docker deployment options. This is particularly useful for:
4+
5+
- Running the service on your own server instead of GitHub Actions
6+
- Better resource control (CPU/RAM allocation)
7+
- Easier environment management
8+
- Persistent logging and model caching
9+
- **Prerequisites**:
10+
- Docker installed ([Installation Guide](https://docs.docker.com/engine/install/))
11+
- Docker Compose (usually included with Docker Desktop)
12+
- Configured Docker image registry mirror (for faster builds in some regions)
13+
14+
### Quick Start with Docker
15+
16+
1. Clone the repository:
17+
```bash
18+
git clone https://github.com/TideDra/zotero-arxiv-daily.git
19+
cd zotero-arxiv-daily
20+
```
21+
22+
2. Build the Docker image (recommended for customization):
23+
```bash
24+
docker build . -t local/zotero-arxiv-daily:latest
25+
```
26+
27+
3. Create necessary directories:
28+
```bash
29+
mkdir -p logs models
30+
```
31+
32+
4. Edit the `docker-compose.yml` file to configure your environment variables:
33+
```yaml
34+
environment:
35+
environment:
36+
# 必填参数(示例值)
37+
- ZOTERO_ID=1234567
38+
- ZOTERO_KEY=AbCdEfGhIjKlMnOpQrStUvWx
39+
- SMTP_SERVER=smtp.example.com
40+
- SMTP_PORT=465
41+
42+
- SENDER_PASSWORD=your_email_password
43+
44+
45+
# 可选参数(带默认值)
46+
- ZOTERO_IGNORE=already_read_papers
47+
- ARXIV_QUERY=cs.AI+cs.CV+cs.LG+cs.CL
48+
- SEND_EMPTY=False
49+
- MAX_PAPER_NUM=5
50+
- USE_LLM_API=1
51+
- OPENAI_API_KEY=sk-your-openai-key-here
52+
- OPENAI_API_BASE=https://api.openai.com/v1
53+
- MODEL_NAME=Qwen/Qwen1.5-7B-Instruct
54+
- LANGUAGE=English
55+
56+
# 新增配置
57+
- HF_ENDPOINT=https://hf-mirror.com
58+
# - TZ=Asia/Shanghai # 时区设置
59+
# - http_proxy=http://proxy.example.com:8080 # HTTP代理(可选)
60+
# - https_proxy=http://proxy.example.com:8080 # HTTPS代理(可选)
61+
# - no_proxy=localhost,127.0.0.1,.internal # 代理排除项
62+
```
63+
64+
5. Start the service:
65+
```bash
66+
docker compose up -d
67+
```
68+
69+
### Key Features of Docker Deployment
70+
71+
- **Scheduled Execution**: By default runs daily at 8:00 AM (configurable in `command` section)
72+
- **Log Persistence**: All logs are saved in the `logs/` directory
73+
- **Model Caching**: Local LLM models can be cached in `models/` directory
74+
- **Resource Isolation**: Runs in a contained environment with all dependencies included
75+
- **Easy Updates**: Simply rebuild the image when updating the service
76+
77+
### Configuration Options
78+
79+
You can customize the deployment by:
80+
81+
1. **Changing schedule time**: Edit the cron expression in `command` section (default: `0 8 * * *` means 8:00 AM daily)
82+
2. **Using local LLM**: Set `USE_LLM_API=0` and uncomment the models volume
83+
3. **Proxy settings**: Uncomment and configure proxy environment variables if needed
84+
4. **Timezone**: Uncomment `TZ` variable to set specific timezone (you may also need to comment `- /etc/localtime:/etc/localtime:ro`)
85+
86+
### Monitoring and Maintenance
87+
88+
- View logs:
89+
```bash
90+
docker logs zotero-arxiv-daily
91+
```
92+
93+
- Stop the service:
94+
```bash
95+
docker compose down
96+
```
97+
98+
- Update the service:
99+
```bash
100+
git pull origin main
101+
docker compose down
102+
docker compose up -d --build
103+
```
104+
105+
### Why Choose Docker Deployment?
106+
107+
1. **Consistent Environment**: Eliminates "works on my machine" problems
108+
2. **Resource Control**: Allocate specific CPU/RAM resources as needed
109+
3. **Isolation**: Runs separately from your host system
110+
4. **Portability**: Easy to move between different servers
111+
5. **Persistent Storage**: Logs and models persist between container restarts

docker-compose.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
services:
2+
zotero-arxiv-daily:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
image: local/zotero-arxiv-daily:latest
7+
container_name: zotero-arxiv-daily
8+
network_mode: bridge
9+
restart: unless-stopped
10+
environment:
11+
# 必填参数(示例值)
12+
- ZOTERO_ID=1234567
13+
- ZOTERO_KEY=AbCdEfGhIjKlMnOpQrStUvWx
14+
- SMTP_SERVER=smtp.example.com
15+
- SMTP_PORT=465
16+
17+
- SENDER_PASSWORD=your_email_password
18+
19+
20+
# 可选参数(带默认值)
21+
- ZOTERO_IGNORE=already_read_papers
22+
- ARXIV_QUERY=cs.AI+cs.CV+cs.LG+cs.CL
23+
- SEND_EMPTY=False
24+
- MAX_PAPER_NUM=5
25+
- USE_LLM_API=1
26+
- OPENAI_API_KEY=sk-your-openai-key-here
27+
- OPENAI_API_BASE=https://api.openai.com/v1
28+
- MODEL_NAME=Qwen/Qwen1.5-7B-Instruct
29+
- LANGUAGE=English
30+
31+
# 新增配置
32+
- HF_ENDPOINT=https://hf-mirror.com
33+
# - TZ=Asia/Shanghai # 时区设置
34+
# - http_proxy=http://proxy.example.com:8080 # HTTP代理(可选)
35+
# - https_proxy=http://proxy.example.com:8080 # HTTPS代理(可选)
36+
# - no_proxy=localhost,127.0.0.1,.internal # 代理排除项
37+
38+
volumes:
39+
- ./logs:/var/log/cron # 日志持久化
40+
# - ./models:/app/models # LLM模型缓存,如果你使用本地推理的话
41+
- /etc/localtime:/etc/localtime:ro # 同步主机时区
42+
43+
command: >
44+
bash -c "
45+
rm -f /var/run/crond.pid /var/run/cron.pid &&
46+
printenv | grep -v 'no_proxy' >> /etc/environment &&
47+
echo '0 8 * * * root cd /app && /usr/local/bin/uv run main.py >> /var/log/cron/corn.log 2>&1' > /etc/cron.d/zotero-job &&
48+
chmod 0644 /etc/cron.d/zotero-job &&
49+
touch /var/log/cron/corn.log &&
50+
cron -f &&
51+
tail -f /var/log/cron/cron.log
52+
"

0 commit comments

Comments
 (0)