Deployment Guide
This document explains how to deploy the AI Stock Analysis System to a server.
Deployment Options Comparison
Section titled “Deployment Options Comparison”| Option | Pros | Cons | Recommended For |
|---|---|---|---|
| Docker Compose ⭐ | One-click deploy, isolated environment, easy migration, easy upgrade | Requires Docker installation | Recommended: Most scenarios |
| Direct Deployment | Simple, no extra dependencies | Environment dependencies, migration difficulties | Temporary testing |
| Systemd Service | System-level management, auto-start on boot | Complex configuration | Long-term stable operation |
| Supervisor | Process management, auto-restart | Requires additional installation | Multi-process management |
Conclusion: Docker Compose is recommended for the fastest and most convenient migration!
Option 1: Docker Compose Deployment (Recommended)
Section titled “Option 1: Docker Compose Deployment (Recommended)”1. Install Docker
Section titled “1. Install Docker”# Ubuntu/Debiancurl -fsSL https://get.docker.com | shsudo usermod -aG docker $USER
# CentOSsudo yum install -y docker docker-composesudo systemctl start dockersudo systemctl enable docker2. Prepare Configuration Files
Section titled “2. Prepare Configuration Files”# Clone code (or upload code to server)git clone <your-repo-url> /opt/stock-analyzercd /opt/stock-analyzer
# Copy and edit configuration filecp .env.example .envvim .env # Fill in real API Keys and configuration3. One-Click Start
Section titled “3. One-Click Start”# Build and startdocker-compose -f ./docker/docker-compose.yml up -d
# View logsdocker-compose -f ./docker/docker-compose.yml logs -f
# View running statusdocker-compose -f ./docker/docker-compose.yml ps3.1 Resource Recommendations
Section titled “3.1 Resource Recommendations”The default docker/docker-compose.yml sets limits.memory: 1G and reservations.memory: 512M for each service. Treat this as the recommended starting point for full analysis workloads.
- Minimum trial:
512M, only for lightweight Web/API usage, single-stock runs, and low concurrency. SetMAX_WORKERS=1. - Recommended:
1G, suitable for normal analysis when running eitherserveroranalyzer. - Heavy workloads:
2G+, suitable when runningserver + analyzertogether, multi-stock analysis, defaultMAX_WORKERS=3, market review, news expansion, image reports, or screening.
If you can only use 512M, avoid starting both server and analyzer, and disable non-essential market review, news expansion, and image report features.
3.2 Avoid Duplicate Scheduled Notifications
Section titled “3.2 Avoid Duplicate Scheduled Notifications”Prefer one automatic scheduler: either the standalone analyzer, or server with SCHEDULE_ENABLED=true. Check for old NAS --schedule containers and duplicate deployments. Instances with separate databases cannot deduplicate each other.
Daily CLI and Web/API jobs atomically claim their due occurrence in the same SQLite file configured by DATABASE_PATH. The same due instant, watchlist/portfolio source, analysis/delivery options, and report settings dispatch once, including when a second process triggers after the first finishes. Different slots, watchlists, or analysis/delivery options remain independent. Due times use the scheduler process’s timezone and are normalized to UTC; keep TZ consistent within a deployment. Both official Compose services share data/ by default, including the claim records.
This is at-most-once automatic dispatch, not automatic failure retry or guaranteed notification delivery. A crash, timeout, or analysis failure after claiming (possibly after partial notification delivery) does not cause another scheduler to repeat the whole run. Inspect the outcome, then use the Web “Run now” action to retry manually. Claiming happens at the actual execution boundary and freezes the watchlist snapshot, avoiding races with settings edits during asynchronous startup. Web dispatches rejected as busy never acquire a claim. Immediate startup runs, manual CLI/API analysis, and “Run now” bypass this deduplication. Records are retained for approximately seven days. An unwritable/busy database logs an error and skips that occurrence; Web scheduler status reports claim errors.
This relies on reliable SQLite file locking and covers same-host processes and containers sharing one local bind mount. It does not promise distributed deduplication across separate databases, NFS, or multiple hosts. No new setting or historical analysis-data migration is required.
4. Common Management Commands
Section titled “4. Common Management Commands”# Stop servicesdocker-compose -f ./docker/docker-compose.yml down
# Restart servicesdocker-compose -f ./docker/docker-compose.yml restart
# Redeploy after code updategit pulldocker-compose -f ./docker/docker-compose.yml build --no-cachedocker-compose -f ./docker/docker-compose.yml up -d
# Enter container for debuggingdocker-compose -f ./docker/docker-compose.yml exec -u dsa stock-analyzer bash
# Manually run analysis oncedocker-compose -f ./docker/docker-compose.yml exec -u dsa stock-analyzer python main.py --no-notify5. Data Persistence
Section titled “5. Data Persistence”Data is automatically saved to host directories:
./data/- Database files./logs/- Log files./reports/- Analysis reports
6. Permissions
Section titled “6. Permissions”The Docker image startup entrypoint automatically creates and fixes ownership for the mounted ./data, ./logs, and ./reports directories, then drops privileges to the non-root dsa user (UID 1000). Normal deployments do not require manual host-side chown / chmod.
If you explicitly set --user / Compose user:, or use read-only mounts, rootless Docker, NFS, or another environment that prevents the container from fixing ownership, make sure the actual runtime user can write to these directories.
Option 2: Direct Deployment
Section titled “Option 2: Direct Deployment”1. Install Python Environment
Section titled “1. Install Python Environment”# Install Python 3.10+sudo apt updatesudo apt install -y python3.10 python3.10-venv python3-pip
# Create virtual environmentpython3.10 -m venv /opt/stock-analyzer/venvsource /opt/stock-analyzer/venv/bin/activate2. Install Dependencies
Section titled “2. Install Dependencies”cd /opt/stock-analyzerpip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple3. Configure Environment Variables
Section titled “3. Configure Environment Variables”cp .env.example .envvim .env # Fill in configuration4. Run
Section titled “4. Run”# Single runpython main.py
# Scheduled task mode (foreground)python main.py --schedule
# Background run (using nohup)nohup python main.py --schedule > /dev/null 2>&1 &Option 3: Systemd Service
Section titled “Option 3: Systemd Service”Create systemd service file for auto-start on boot and auto-restart:
1. Create Service File
Section titled “1. Create Service File”sudo vim /etc/systemd/system/stock-analyzer.serviceContents:
[Unit]Description=AI Stock Analysis SystemAfter=network.target
[Service]Type=simpleUser=rootWorkingDirectory=/opt/stock-analyzerEnvironment="PATH=/opt/stock-analyzer/venv/bin"ExecStart=/opt/stock-analyzer/venv/bin/python main.py --scheduleRestart=alwaysRestartSec=30
[Install]WantedBy=multi-user.target2. Start Service
Section titled “2. Start Service”# Reload configurationsudo systemctl daemon-reload
# Start servicesudo systemctl start stock-analyzer
# Enable auto-start on bootsudo systemctl enable stock-analyzer
# View statussudo systemctl status stock-analyzer
# View logsjournalctl -u stock-analyzer -fConfiguration Guide
Section titled “Configuration Guide”Required Configuration
Section titled “Required Configuration”| Config Item | Description | How to Get |
|---|---|---|
MODELFLARE_KEY / GEMINI_API_KEY / ANTHROPIC_API_KEY / OPENAI_API_KEY / AIHUBMIX_KEY / ANSPIRE_API_KEYS |
Configure at least one AI model key; choose a provider as needed | Provider console |
STOCK_LIST |
Watchlist | Comma-separated stock codes; registered-index explicit forms (e.g. sh000016, 930606.CSI, sz399365) are supported via the one-shot --stocks argument or the GitHub Actions entry (local .env/Docker no-arg default runs keep stock semantics; use --stocks there for indices) — see Index watchlist configuration |
| Notification channel | Configure at least one, such as WeChat Work, Feishu, Telegram, or email | Notification provider |
Optional Configuration
Section titled “Optional Configuration”| Config Item | Default | Description |
|---|---|---|
SCHEDULE_ENABLED |
false |
Enable scheduled tasks |
SCHEDULE_TIME |
18:00 |
Daily execution time |
MARKET_REVIEW_ENABLED |
true |
Enable market review |
SERPAPI_API_KEYS |
- | SerpAPI realtime financial news search (recommended) |
AIHUBMIX_KEY |
- | AIHubMix API key (optional) |
ANSPIRE_API_KEYS |
- | Anspire API key (optional; shared by LLM and search; availability depends on account permissions) |
TAVILY_API_KEYS |
- | Tavily news search (optional) |
MINIMAX_API_KEYS |
- | MiniMax search (optional) |
Proxy Configuration
Section titled “Proxy Configuration”If server is in mainland China, accessing Gemini API requires proxy:
Docker Method
Section titled “Docker Method”Edit docker-compose.yml:
environment: - http_proxy=http://your-proxy:port - https_proxy=http://your-proxy:portDirect Deployment Method
Section titled “Direct Deployment Method”Edit top of main.py:
os.environ["http_proxy"] = "http://your-proxy:port"os.environ["https_proxy"] = "http://your-proxy:port"Monitoring & Maintenance
Section titled “Monitoring & Maintenance”View Logs
Section titled “View Logs”# Docker methoddocker-compose -f ./docker/docker-compose.yml logs -f --tail=100
# Direct deploymenttail -f /opt/stock-analyzer/logs/stock_analysis_*.logHealth Check
Section titled “Health Check”# Check processps aux | grep main.py
# Check recent reportsls -la /opt/stock-analyzer/reports/Routine Maintenance
Section titled “Routine Maintenance”# Clean old logs (keep 7 days)find /opt/stock-analyzer/logs -mtime +7 -delete
# Clean old reports (keep 30 days)find /opt/stock-analyzer/reports -mtime +30 -delete1. Docker build failed
Section titled “1. Docker build failed”# Clear cache and rebuilddocker-compose -f ./docker/docker-compose.yml build --no-cache2. API access timeout
Section titled “2. API access timeout”Check proxy configuration, ensure server can access Gemini API.
3. Database locked
Section titled “3. Database locked”# Stop service then delete lock filerm /opt/stock-analyzer/data/*.lock4. Insufficient memory
Section titled “4. Insufficient memory”The default Compose recommendation is already 1G. If the container still hits OOM or is killed by the platform, raise the memory limit in docker-compose.yml; use 2G+ when running server + analyzer together, multi-stock analysis, market review, image reports, or screening:
deploy: resources: limits: memory: 1G reservations: memory: 512MFor a constrained 512M deployment, set MAX_WORKERS=1, start only one of server or analyzer, and reduce non-essential market review, news expansion, and image report tasks.
5. Exited (132) or Illegal instruction on Apple Silicon / ARM64 Linux VMs
Section titled “5. Exited (132) or Illegal instruction on Apple Silicon / ARM64 Linux VMs”Symptom: On newer-kernel aarch64 Linux VMs running on Apple Silicon (e.g. M4 Ubuntu 26.04 VM), containers exit immediately with Exited (132) or docker build fails with Illegal instruction (core dumped).
Root Cause: Newer ARM64 VM kernels expose HWCAP2_SME, causing NumPy’s bundled OpenBLAS dynamic dispatch to execute SME instructions unsupported in non-streaming mode.
Resolution:
- Docker deployment: Current
Dockerfileandentrypoint.shautomatically defaultOPENBLAS_CORETYPE=ARMV8onaarch64/arm64(leavingx86_64untouched). If using an older image or running commands viadocker-compose exec, addOPENBLAS_CORETYPE=ARMV8to.env(or pass-e OPENBLAS_CORETYPE=ARMV8todocker run). - Direct deployment (pip + python): On bleeding-edge Linux distributions that default to Python 3.14 (such as Ubuntu 26.04), create your virtual environment with Python 3.11 or 3.12 so pinned dependencies resolve prebuilt
aarch64wheels instead of compiling C/Rust extensions from source, andexport OPENBLAS_CORETYPE=ARMV8before starting ifIllegal instructionoccurs.
Quick Migration
Section titled “Quick Migration”Migrate from one server to another:
# Source server: Packagecd /opt/stock-analyzertar -czvf stock-analyzer-backup.tar.gz .env data/ logs/ reports/
# Target server: Deploymkdir -p /opt/stock-analyzercd /opt/stock-analyzergit clone <your-repo-url> .tar -xzvf stock-analyzer-backup.tar.gzdocker-compose -f ./docker/docker-compose.yml up -dOption 4: GitHub Actions Deployment (Serverless)
Section titled “Option 4: GitHub Actions Deployment (Serverless)”The simplest option! No server needed, leverages GitHub’s free compute resources.
Advantages
Section titled “Advantages”- ✅ Completely free (2000 minutes/month)
- ✅ No server needed
- ✅ Auto-scheduled execution
- ✅ Zero maintenance cost
Limitations
Section titled “Limitations”- ⚠️ Stateless (fresh environment each run)
- ⚠️ Scheduled timing may have few minutes delay
- ⚠️ Cannot provide HTTP API
Deployment Steps
Section titled “Deployment Steps”1. Create GitHub Repository
Section titled “1. Create GitHub Repository”# Initialize git (if not already)cd /path/to/daily_stock_analysisgit initgit add .git commit -m "Initial commit"
# Create GitHub repo and push# After creating new repo on GitHub web:git remote add origin https://github.com/your-username/daily_stock_analysis.gitgit branch -M maingit push -u origin main2. Configure Secrets (Important!)
Section titled “2. Configure Secrets (Important!)”Go to repo page → Settings → Secrets and variables → Actions → New repository secret
Add these Secrets:
| Secret Name | Description | Required |
|---|---|---|
ANTHROPIC_API_KEY |
Anthropic API Key | Optional |
GEMINI_API_KEY |
Gemini AI API Key | Optional |
OPENAI_API_KEY |
OpenAI-compatible API Key | Optional |
AIHUBMIX_KEY |
AIHubMix API key | Optional |
WECHAT_WEBHOOK_URL |
WeChat Work Bot Webhook | Optional* |
FEISHU_WEBHOOK_URL |
Feishu Bot Webhook | Optional* |
TELEGRAM_BOT_TOKEN |
Telegram Bot Token | Optional* |
TELEGRAM_CHAT_ID |
Telegram Chat ID | Optional* |
TELEGRAM_MESSAGE_THREAD_ID |
Telegram Topic ID | Optional* |
EMAIL_SENDER |
Sender email | Optional* |
EMAIL_PASSWORD |
Email authorization code | Optional* |
SERVERCHAN3_SENDKEY |
ServerChan v3 Sendkey | Optional* |
CUSTOM_WEBHOOK_URLS |
Custom Webhook (comma-separated for multiple) | Optional* |
STOCK_LIST |
Watchlist, e.g., 600519,300750 |
✅ |
SERPAPI_API_KEYS |
SerpAPI Key | Recommended |
ANSPIRE_API_KEYS |
Anspire API key (optional; shared by LLM and search; availability depends on account permissions) | Optional |
TAVILY_API_KEYS |
Tavily Search API Key | Optional |
BOCHA_API_KEYS |
Bocha Search API Key | Optional |
BRAVE_API_KEYS |
Brave Search API Key | Optional |
MINIMAX_API_KEYS |
MiniMax Coding Plan Web Search | Optional |
TUSHARE_TOKEN |
Tushare Token | Optional |
GEMINI_MODEL |
Model name (default gemini-3.6-flash) | Optional |
*Note: Configure at least one notification channel, multiple channels supported for simultaneous push
3. Verify Workflow File
Section titled “3. Verify Workflow File”Ensure .github/workflows/00-daily-analysis.yml file exists and is committed:
git add .github/workflows/00-daily-analysis.ymlgit commit -m "Add GitHub Actions workflow"git push4. Manual Test Run
Section titled “4. Manual Test Run”- Go to repo page → Actions tab
- Select “Daily Stock Analysis” workflow
- Click “Run workflow” button
- Select run mode:
full- Full analysis (stocks + market)market-only- Market review onlystocks-only- Stock analysis only
- Click green “Run workflow” button
5. View Execution Logs
Section titled “5. View Execution Logs”- Actions page shows run history
- Click specific run record to view detailed logs
- Analysis reports are saved as Artifacts for 30 days
Schedule Details
Section titled “Schedule Details”Default configuration: Monday to Friday, 18:00 Beijing Time auto-execution
Modify time: Edit cron expression in .github/workflows/00-daily-analysis.yml:
schedule: - cron: '0 10 * * 1-5' # UTC time, +8 = Beijing timeCommon cron examples:
| Expression | Description |
|---|---|
'0 10 * * 1-5' |
Mon-Fri 18:00 (Beijing) |
'30 7 * * 1-5' |
Mon-Fri 15:30 (Beijing) |
'0 10 * * *' |
Daily 18:00 (Beijing) |
'0 2 * * 1-5' |
Mon-Fri 10:00 (Beijing) |
Modify Watchlist
Section titled “Modify Watchlist”Method 1: Modify repo Secret STOCK_LIST
Method 2: Modify code directly then push:
# Modify .env.example or set default value in codegit commit -am "Update stock list"git pushQ: Why isn’t the scheduled task running? A: GitHub Actions scheduled tasks may have 5-15 minute delays, and only trigger when repo has activity. Long periods without commits may cause workflow to be disabled.
Q: How to view historical reports?
A: Actions → Select run record → Artifacts → Download analysis-reports-xxx
Q: Is the free quota enough? A: Each run takes about 2-5 minutes, 22 workdays per month = 44-110 minutes, well below the 2000 minute limit.
Wishing you a smooth deployment!