Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .env.docker.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Docker deployment example.
# Copy this file to .env before running docker compose:
# cp .env.docker.example .env

# Flask
DEBUG=True
SECRET_KEY=change-this-secret

# SQLite ORM default inside the container.
# docker-compose.yml persists this file under ./instance on the host.
SQLITE_DATABASE_PATH=/app/instance/stock_cursor.sqlite3

# Redis / Celery inside the Docker Compose network.
# Use the service name "redis" instead of localhost from containers.
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_DB=0
CELERY_BROKER_URL=redis://redis:6379/0
CELERY_RESULT_BACKEND=redis://redis:6379/0
# Data source.
# docker-compose.yml mounts the host ./data directory to /app/data.
# Put the downloaded Parquet data package contents in ./data on the host.
DATA_SOURCE=parquet
DATA_DIR=/app/data
TUSHARE_TOKEN=your_tushare_token

# Runtime mode.
# Docker Compose starts a worker service, so data jobs should use Celery.
DATA_JOB_EXECUTION_MODE=celery

# OpenAI / LLM optional
LLM_PROVIDER=openai
LLM_API_KEY=
LLM_BASE_URL=https://api.deepseek.com
LLM_MODEL=deepseek-v4-flash
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config \
&& rm -rf /var/lib/apt/lists/*

COPY requirements.txt requirements_minimal.txt ./
RUN pip install --no-cache-dir -r requirements_minimal.txt
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

Expand Down
5 changes: 3 additions & 2 deletions app/celery_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ def _decorator(func):

def make_celery(config_name: str = "default"):
cfg = config[config_name]
broker = f"redis://{cfg.REDIS_HOST}:{cfg.REDIS_PORT}/{cfg.REDIS_DB}"
broker = cfg.CELERY_BROKER_URL
backend = cfg.CELERY_RESULT_BACKEND

if Celery is None:
return _LocalCelery()

celery = Celery("quant_data_jobs", broker=broker, backend=broker)
celery = Celery("quant_data_jobs", broker=broker, backend=backend)
celery.conf.update(
task_serializer="json",
accept_content=["json"],
Expand Down
30 changes: 20 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
version: "3.9"

x-app-common: &app-common
build: .
env_file:
- .env
volumes:
- ./data:/app/data
- ./instance:/app/instance
- ./logs:/app/logs
depends_on:
- redis
restart: unless-stopped

services:
web:
build: .
<<: *app-common
command: python run.py
ports:
- "5000:5000"
env_file:
- .env
depends_on:
- redis

worker:
build: .
<<: *app-common
command: celery -A app.celery_app.celery worker -l info -P solo
env_file:
- .env
depends_on:
- redis

redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis_data:/data
restart: unless-stopped

volumes:
redis_data:
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ cvxpy>=1.4.0
#金融数据获取
baostock>=0.8.9
tushare>=1.3.0
pytdx>=1.72