mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
Docs: Add Docker one-click deployment support for all languages
Complete Docker deployment solution with beginner-friendly documentation: **New Docker Files:** - `Dockerfile` - Multi-stage Go backend build with health checks - `web/Dockerfile` - Frontend build with Nginx and API proxy - `docker-compose.yml` - Full orchestration with service dependencies - `.dockerignore` & `web/.dockerignore` - Build optimization - `start.sh` - Convenient management script (start/stop/logs/status) **Comprehensive Documentation:** - `DOCKER_DEPLOY.md` (中文) - Complete Chinese deployment guide - `DOCKER_DEPLOY.en.md` (English) - Complete English deployment guide - Prerequisites & Docker installation (macOS/Windows/Linux) - 3-step quick start (config → start → access) - Service management commands - Advanced configuration (ports, resources, env vars) - Data persistence & backups - Comprehensive troubleshooting - Security recommendations - Production deployment (Nginx, HTTPS, Docker Swarm) - Monitoring & logging setup **README Updates (All 4 Languages):** - README.md (English) - README.zh-CN.md (中文) - README.uk.md (Українська) - README.ru.md (Русский) Added prominent "Option A: Docker One-Click Deployment" section at the beginning of Quick Start in all languages. Clearly marked as EASIEST method for beginners. Shows 3 simple steps with command examples and links to detailed DOCKER_DEPLOY docs. **Key Features:** - One-command deployment: `./start.sh start --build` - Auto-handles all dependencies (Go, Node.js, TA-Lib) - Health checks for both services - Data persistence (logs, cache, config) - Log rotation (10MB × 3 files) - Easy service management - Beginner-friendly for complete newcomers **User Benefits:** - No need to install Go, Node.js, or TA-Lib manually - Works on macOS, Windows, Linux - Perfect for non-developers - Production-ready with best practices This makes NOFX truly accessible to beginners as requested: "真就让小白都能一键开始" Co-Authored-By: tinkle-community <tinklefund@gmail.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
|||||||
|
# Git
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
.github
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
Dockerfile
|
||||||
|
docker-compose.yml
|
||||||
|
.dockerignore
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
|
||||||
|
# Build artifacts
|
||||||
|
nofx
|
||||||
|
nofx_test
|
||||||
|
*.exe
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test files
|
||||||
|
*_test.go
|
||||||
|
test_*
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
*.md
|
||||||
|
!README.md
|
||||||
|
docs/
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
decision_logs/
|
||||||
|
coin_pool_cache/
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Config files (should be mounted)
|
||||||
|
config.json
|
||||||
|
|
||||||
|
# Web directory (has its own Dockerfile)
|
||||||
|
web/
|
||||||
|
|
||||||
|
# Temporary files
|
||||||
|
tmp/
|
||||||
|
temp/
|
||||||
|
*.tmp
|
||||||
@@ -0,0 +1,456 @@
|
|||||||
|
# 🐳 Docker One-Click Deployment Guide
|
||||||
|
|
||||||
|
This guide will help you quickly deploy the NOFX AI Trading Competition System using Docker.
|
||||||
|
|
||||||
|
## 📋 Prerequisites
|
||||||
|
|
||||||
|
Before you begin, ensure your system has:
|
||||||
|
|
||||||
|
- **Docker**: Version 20.10 or higher
|
||||||
|
- **Docker Compose**: Version 2.0 or higher
|
||||||
|
|
||||||
|
### Installing Docker
|
||||||
|
|
||||||
|
#### macOS / Windows
|
||||||
|
Download and install [Docker Desktop](https://www.docker.com/products/docker-desktop/)
|
||||||
|
|
||||||
|
#### Linux (Ubuntu/Debian)
|
||||||
|
```bash
|
||||||
|
# Install Docker
|
||||||
|
curl -fsSL https://get.docker.com -o get-docker.sh
|
||||||
|
sudo sh get-docker.sh
|
||||||
|
|
||||||
|
# Install Docker Compose
|
||||||
|
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||||
|
sudo chmod +x /usr/local/bin/docker-compose
|
||||||
|
|
||||||
|
# Add current user to docker group
|
||||||
|
sudo usermod -aG docker $USER
|
||||||
|
newgrp docker
|
||||||
|
|
||||||
|
# Verify installation
|
||||||
|
docker --version
|
||||||
|
docker-compose --version
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🚀 Quick Start (3 Steps)
|
||||||
|
|
||||||
|
### Step 1: Prepare Configuration File
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Copy configuration template
|
||||||
|
cp config.json.example config.json
|
||||||
|
|
||||||
|
# Edit configuration file with your API keys
|
||||||
|
nano config.json # or use any other editor
|
||||||
|
```
|
||||||
|
|
||||||
|
**Required fields:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"traders": [
|
||||||
|
{
|
||||||
|
"id": "my_trader",
|
||||||
|
"name": "My AI Trader",
|
||||||
|
"ai_model": "deepseek",
|
||||||
|
"binance_api_key": "YOUR_BINANCE_API_KEY", // ← Your Binance API Key
|
||||||
|
"binance_secret_key": "YOUR_BINANCE_SECRET_KEY", // ← Your Binance Secret Key
|
||||||
|
"deepseek_key": "YOUR_DEEPSEEK_API_KEY", // ← Your DeepSeek API Key
|
||||||
|
"initial_balance": 1000.0,
|
||||||
|
"scan_interval_minutes": 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"use_default_coins": true,
|
||||||
|
"api_server_port": 8080
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Step 2: One-Click Start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build and start all services (first run)
|
||||||
|
docker-compose up -d --build
|
||||||
|
|
||||||
|
# Subsequent starts (without rebuilding)
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
**Startup options:**
|
||||||
|
- `--build`: Build Docker images (use on first run or after code updates)
|
||||||
|
- `-d`: Run in detached mode (background)
|
||||||
|
|
||||||
|
### Step 3: Access the System
|
||||||
|
|
||||||
|
Once deployed, open your browser and visit:
|
||||||
|
|
||||||
|
- **Web Interface**: http://localhost:3000
|
||||||
|
- **API Health Check**: http://localhost:8080/health
|
||||||
|
|
||||||
|
## 📊 Service Management
|
||||||
|
|
||||||
|
### View Running Status
|
||||||
|
```bash
|
||||||
|
# View all container status
|
||||||
|
docker-compose ps
|
||||||
|
|
||||||
|
# View service health status
|
||||||
|
docker-compose ps --format json | jq
|
||||||
|
```
|
||||||
|
|
||||||
|
### View Logs
|
||||||
|
```bash
|
||||||
|
# View all service logs
|
||||||
|
docker-compose logs -f
|
||||||
|
|
||||||
|
# View backend logs only
|
||||||
|
docker-compose logs -f backend
|
||||||
|
|
||||||
|
# View frontend logs only
|
||||||
|
docker-compose logs -f frontend
|
||||||
|
|
||||||
|
# View last 100 lines
|
||||||
|
docker-compose logs --tail=100
|
||||||
|
```
|
||||||
|
|
||||||
|
### Stop Services
|
||||||
|
```bash
|
||||||
|
# Stop all services (keep data)
|
||||||
|
docker-compose stop
|
||||||
|
|
||||||
|
# Stop and remove containers (keep data)
|
||||||
|
docker-compose down
|
||||||
|
|
||||||
|
# Stop and remove containers and volumes (clear all data)
|
||||||
|
docker-compose down -v
|
||||||
|
```
|
||||||
|
|
||||||
|
### Restart Services
|
||||||
|
```bash
|
||||||
|
# Restart all services
|
||||||
|
docker-compose restart
|
||||||
|
|
||||||
|
# Restart backend only
|
||||||
|
docker-compose restart backend
|
||||||
|
|
||||||
|
# Restart frontend only
|
||||||
|
docker-compose restart frontend
|
||||||
|
```
|
||||||
|
|
||||||
|
### Update Services
|
||||||
|
```bash
|
||||||
|
# Pull latest code
|
||||||
|
git pull
|
||||||
|
|
||||||
|
# Rebuild and restart
|
||||||
|
docker-compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 Advanced Configuration
|
||||||
|
|
||||||
|
### Change Ports
|
||||||
|
|
||||||
|
Edit `docker-compose.yml` to modify port mappings:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
ports:
|
||||||
|
- "8080:8080" # Change to "your_port:8080"
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
ports:
|
||||||
|
- "3000:80" # Change to "your_port:80"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Resource Limits
|
||||||
|
|
||||||
|
Add resource limits in `docker-compose.yml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '2'
|
||||||
|
memory: 2G
|
||||||
|
reservations:
|
||||||
|
cpus: '1'
|
||||||
|
memory: 1G
|
||||||
|
```
|
||||||
|
|
||||||
|
### Environment Variables
|
||||||
|
|
||||||
|
Create `.env` file to manage environment variables:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# .env
|
||||||
|
TZ=Asia/Shanghai
|
||||||
|
BACKEND_PORT=8080
|
||||||
|
FRONTEND_PORT=3000
|
||||||
|
```
|
||||||
|
|
||||||
|
Then use in `docker-compose.yml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
ports:
|
||||||
|
- "${BACKEND_PORT}:8080"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📁 Data Persistence
|
||||||
|
|
||||||
|
The system automatically persists data to local directories:
|
||||||
|
|
||||||
|
- `./decision_logs/`: AI decision logs
|
||||||
|
- `./coin_pool_cache/`: Coin pool cache
|
||||||
|
- `./config.json`: Configuration file (mounted)
|
||||||
|
|
||||||
|
**Data locations:**
|
||||||
|
```bash
|
||||||
|
# View data directories
|
||||||
|
ls -la decision_logs/
|
||||||
|
ls -la coin_pool_cache/
|
||||||
|
|
||||||
|
# Backup data
|
||||||
|
tar -czf backup_$(date +%Y%m%d).tar.gz decision_logs/ coin_pool_cache/ config.json
|
||||||
|
|
||||||
|
# Restore data
|
||||||
|
tar -xzf backup_20241029.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🐛 Troubleshooting
|
||||||
|
|
||||||
|
### Container Won't Start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# View detailed error messages
|
||||||
|
docker-compose logs backend
|
||||||
|
docker-compose logs frontend
|
||||||
|
|
||||||
|
# Check container status
|
||||||
|
docker-compose ps -a
|
||||||
|
|
||||||
|
# Rebuild (clear cache)
|
||||||
|
docker-compose build --no-cache
|
||||||
|
```
|
||||||
|
|
||||||
|
### Port Already in Use
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Find process using the port
|
||||||
|
lsof -i :8080 # backend port
|
||||||
|
lsof -i :3000 # frontend port
|
||||||
|
|
||||||
|
# Kill the process
|
||||||
|
kill -9 <PID>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configuration File Not Found
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ensure config.json exists
|
||||||
|
ls -la config.json
|
||||||
|
|
||||||
|
# If not exists, copy template
|
||||||
|
cp config.json.example config.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### Health Check Failing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Check health status
|
||||||
|
docker inspect nofx-backend | jq '.[0].State.Health'
|
||||||
|
docker inspect nofx-frontend | jq '.[0].State.Health'
|
||||||
|
|
||||||
|
# Manually test health endpoints
|
||||||
|
curl http://localhost:8080/health
|
||||||
|
curl http://localhost:3000/health
|
||||||
|
```
|
||||||
|
|
||||||
|
### Frontend Can't Connect to Backend
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Check network connectivity
|
||||||
|
docker-compose exec frontend ping backend
|
||||||
|
|
||||||
|
# Check if backend service is running
|
||||||
|
docker-compose exec frontend wget -O- http://backend:8080/health
|
||||||
|
```
|
||||||
|
|
||||||
|
### Clean Docker Resources
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Clean unused images
|
||||||
|
docker image prune -a
|
||||||
|
|
||||||
|
# Clean unused volumes
|
||||||
|
docker volume prune
|
||||||
|
|
||||||
|
# Clean all unused resources (use with caution)
|
||||||
|
docker system prune -a --volumes
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔐 Security Recommendations
|
||||||
|
|
||||||
|
1. **Don't commit config.json to Git**
|
||||||
|
```bash
|
||||||
|
# Ensure config.json is in .gitignore
|
||||||
|
echo "config.json" >> .gitignore
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Use environment variables for sensitive data**
|
||||||
|
```yaml
|
||||||
|
# docker-compose.yml
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
environment:
|
||||||
|
- BINANCE_API_KEY=${BINANCE_API_KEY}
|
||||||
|
- BINANCE_SECRET_KEY=${BINANCE_SECRET_KEY}
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Restrict API access**
|
||||||
|
```yaml
|
||||||
|
# Only allow local access
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8080:8080"
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Regularly update images**
|
||||||
|
```bash
|
||||||
|
docker-compose pull
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🌐 Production Deployment
|
||||||
|
|
||||||
|
### Using Nginx Reverse Proxy
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
# /etc/nginx/sites-available/nofx
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name your-domain.com;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:3000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://localhost:8080/api/;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configure HTTPS (Let's Encrypt)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install Certbot
|
||||||
|
sudo apt-get install certbot python3-certbot-nginx
|
||||||
|
|
||||||
|
# Get SSL certificate
|
||||||
|
sudo certbot --nginx -d your-domain.com
|
||||||
|
|
||||||
|
# Auto-renewal
|
||||||
|
sudo certbot renew --dry-run
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using Docker Swarm (Cluster Deployment)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Initialize Swarm
|
||||||
|
docker swarm init
|
||||||
|
|
||||||
|
# Deploy stack
|
||||||
|
docker stack deploy -c docker-compose.yml nofx
|
||||||
|
|
||||||
|
# View service status
|
||||||
|
docker stack services nofx
|
||||||
|
|
||||||
|
# Scale services
|
||||||
|
docker service scale nofx_backend=3
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📈 Monitoring & Logging
|
||||||
|
|
||||||
|
### Log Management
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Configure log rotation (already configured in docker-compose.yml)
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
|
||||||
|
# View log statistics
|
||||||
|
docker-compose logs --timestamps | wc -l
|
||||||
|
```
|
||||||
|
|
||||||
|
### Monitoring Tool Integration
|
||||||
|
|
||||||
|
Integrate Prometheus + Grafana for monitoring:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# docker-compose.yml (add monitoring services)
|
||||||
|
services:
|
||||||
|
prometheus:
|
||||||
|
image: prom/prometheus
|
||||||
|
ports:
|
||||||
|
- "9090:9090"
|
||||||
|
volumes:
|
||||||
|
- ./prometheus.yml:/etc/prometheus/prometheus.yml
|
||||||
|
|
||||||
|
grafana:
|
||||||
|
image: grafana/grafana
|
||||||
|
ports:
|
||||||
|
- "3001:3000"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🆘 Get Help
|
||||||
|
|
||||||
|
- **GitHub Issues**: [Submit an issue](https://github.com/yourusername/open-nofx/issues)
|
||||||
|
- **Documentation**: Check [README.md](README.md)
|
||||||
|
- **Community**: Join our Discord/Telegram group
|
||||||
|
|
||||||
|
## 📝 Command Cheat Sheet
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Start
|
||||||
|
docker-compose up -d --build # Build and start
|
||||||
|
docker-compose up -d # Start (without rebuilding)
|
||||||
|
|
||||||
|
# Stop
|
||||||
|
docker-compose stop # Stop services
|
||||||
|
docker-compose down # Stop and remove containers
|
||||||
|
docker-compose down -v # Stop and remove containers and data
|
||||||
|
|
||||||
|
# View
|
||||||
|
docker-compose ps # View status
|
||||||
|
docker-compose logs -f # View logs
|
||||||
|
docker-compose top # View processes
|
||||||
|
|
||||||
|
# Restart
|
||||||
|
docker-compose restart # Restart all services
|
||||||
|
docker-compose restart backend # Restart backend
|
||||||
|
|
||||||
|
# Update
|
||||||
|
git pull && docker-compose up -d --build
|
||||||
|
|
||||||
|
# Clean
|
||||||
|
docker-compose down -v # Clear all data
|
||||||
|
docker system prune -a # Clean Docker resources
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
🎉 Congratulations! You've successfully deployed the NOFX AI Trading Competition System!
|
||||||
|
|
||||||
|
If you encounter any issues, please check the [Troubleshooting](#-troubleshooting) section or submit an issue.
|
||||||
@@ -0,0 +1,456 @@
|
|||||||
|
# 🐳 Docker 一键部署教程
|
||||||
|
|
||||||
|
本教程将指导你使用 Docker 快速部署 NOFX AI 交易竞赛系统。
|
||||||
|
|
||||||
|
## 📋 前置要求
|
||||||
|
|
||||||
|
在开始之前,请确保你的系统已安装:
|
||||||
|
|
||||||
|
- **Docker**: 版本 20.10 或更高
|
||||||
|
- **Docker Compose**: 版本 2.0 或更高
|
||||||
|
|
||||||
|
### 安装 Docker
|
||||||
|
|
||||||
|
#### macOS / Windows
|
||||||
|
下载并安装 [Docker Desktop](https://www.docker.com/products/docker-desktop/)
|
||||||
|
|
||||||
|
#### Linux (Ubuntu/Debian)
|
||||||
|
```bash
|
||||||
|
# 安装 Docker
|
||||||
|
curl -fsSL https://get.docker.com -o get-docker.sh
|
||||||
|
sudo sh get-docker.sh
|
||||||
|
|
||||||
|
# 安装 Docker Compose
|
||||||
|
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||||
|
sudo chmod +x /usr/local/bin/docker-compose
|
||||||
|
|
||||||
|
# 将当前用户加入 docker 组
|
||||||
|
sudo usermod -aG docker $USER
|
||||||
|
newgrp docker
|
||||||
|
|
||||||
|
# 验证安装
|
||||||
|
docker --version
|
||||||
|
docker-compose --version
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🚀 快速开始(3步完成部署)
|
||||||
|
|
||||||
|
### 第 1 步:准备配置文件
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 复制配置文件模板
|
||||||
|
cp config.json.example config.json
|
||||||
|
|
||||||
|
# 编辑配置文件,填入你的 API 密钥
|
||||||
|
nano config.json # 或使用其他编辑器
|
||||||
|
```
|
||||||
|
|
||||||
|
**必须配置的字段:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"traders": [
|
||||||
|
{
|
||||||
|
"id": "my_trader",
|
||||||
|
"name": "My AI Trader",
|
||||||
|
"ai_model": "deepseek",
|
||||||
|
"binance_api_key": "YOUR_BINANCE_API_KEY", // ← 填入你的币安 API Key
|
||||||
|
"binance_secret_key": "YOUR_BINANCE_SECRET_KEY", // ← 填入你的币安 Secret Key
|
||||||
|
"deepseek_key": "YOUR_DEEPSEEK_API_KEY", // ← 填入你的 DeepSeek API Key
|
||||||
|
"initial_balance": 1000.0,
|
||||||
|
"scan_interval_minutes": 3
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"use_default_coins": true,
|
||||||
|
"api_server_port": 8080
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 第 2 步:一键启动
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 构建并启动所有服务(首次运行)
|
||||||
|
docker-compose up -d --build
|
||||||
|
|
||||||
|
# 后续启动(不重新构建)
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
**启动过程说明:**
|
||||||
|
- `--build`: 构建 Docker 镜像(首次运行或代码更新后使用)
|
||||||
|
- `-d`: 后台运行(detached mode)
|
||||||
|
|
||||||
|
### 第 3 步:访问系统
|
||||||
|
|
||||||
|
部署成功后,打开浏览器访问:
|
||||||
|
|
||||||
|
- **Web 界面**: http://localhost:3000
|
||||||
|
- **API 文档**: http://localhost:8080/health
|
||||||
|
|
||||||
|
## 📊 服务管理
|
||||||
|
|
||||||
|
### 查看运行状态
|
||||||
|
```bash
|
||||||
|
# 查看所有容器状态
|
||||||
|
docker-compose ps
|
||||||
|
|
||||||
|
# 查看服务健康状态
|
||||||
|
docker-compose ps --format json | jq
|
||||||
|
```
|
||||||
|
|
||||||
|
### 查看日志
|
||||||
|
```bash
|
||||||
|
# 查看所有服务日志
|
||||||
|
docker-compose logs -f
|
||||||
|
|
||||||
|
# 只查看后端日志
|
||||||
|
docker-compose logs -f backend
|
||||||
|
|
||||||
|
# 只查看前端日志
|
||||||
|
docker-compose logs -f frontend
|
||||||
|
|
||||||
|
# 查看最近 100 行日志
|
||||||
|
docker-compose logs --tail=100
|
||||||
|
```
|
||||||
|
|
||||||
|
### 停止服务
|
||||||
|
```bash
|
||||||
|
# 停止所有服务(保留数据)
|
||||||
|
docker-compose stop
|
||||||
|
|
||||||
|
# 停止并删除容器(保留数据)
|
||||||
|
docker-compose down
|
||||||
|
|
||||||
|
# 停止并删除容器和卷(清除所有数据)
|
||||||
|
docker-compose down -v
|
||||||
|
```
|
||||||
|
|
||||||
|
### 重启服务
|
||||||
|
```bash
|
||||||
|
# 重启所有服务
|
||||||
|
docker-compose restart
|
||||||
|
|
||||||
|
# 只重启后端
|
||||||
|
docker-compose restart backend
|
||||||
|
|
||||||
|
# 只重启前端
|
||||||
|
docker-compose restart frontend
|
||||||
|
```
|
||||||
|
|
||||||
|
### 更新服务
|
||||||
|
```bash
|
||||||
|
# 拉取最新代码
|
||||||
|
git pull
|
||||||
|
|
||||||
|
# 重新构建并重启
|
||||||
|
docker-compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 高级配置
|
||||||
|
|
||||||
|
### 修改端口
|
||||||
|
|
||||||
|
编辑 `docker-compose.yml`,修改端口映射:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
ports:
|
||||||
|
- "8080:8080" # 改为 "你的端口:8080"
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
ports:
|
||||||
|
- "3000:80" # 改为 "你的端口:80"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 资源限制
|
||||||
|
|
||||||
|
在 `docker-compose.yml` 中添加资源限制:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
deploy:
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpus: '2'
|
||||||
|
memory: 2G
|
||||||
|
reservations:
|
||||||
|
cpus: '1'
|
||||||
|
memory: 1G
|
||||||
|
```
|
||||||
|
|
||||||
|
### 环境变量
|
||||||
|
|
||||||
|
创建 `.env` 文件来管理环境变量:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# .env
|
||||||
|
TZ=Asia/Shanghai
|
||||||
|
BACKEND_PORT=8080
|
||||||
|
FRONTEND_PORT=3000
|
||||||
|
```
|
||||||
|
|
||||||
|
然后在 `docker-compose.yml` 中使用:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
ports:
|
||||||
|
- "${BACKEND_PORT}:8080"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📁 数据持久化
|
||||||
|
|
||||||
|
系统会自动持久化以下数据到本地目录:
|
||||||
|
|
||||||
|
- `./decision_logs/`: AI 决策日志
|
||||||
|
- `./coin_pool_cache/`: 币种池缓存
|
||||||
|
- `./config.json`: 配置文件(挂载)
|
||||||
|
|
||||||
|
**数据位置:**
|
||||||
|
```bash
|
||||||
|
# 查看数据目录
|
||||||
|
ls -la decision_logs/
|
||||||
|
ls -la coin_pool_cache/
|
||||||
|
|
||||||
|
# 备份数据
|
||||||
|
tar -czf backup_$(date +%Y%m%d).tar.gz decision_logs/ coin_pool_cache/ config.json
|
||||||
|
|
||||||
|
# 恢复数据
|
||||||
|
tar -xzf backup_20241029.tar.gz
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🐛 故障排查
|
||||||
|
|
||||||
|
### 容器无法启动
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查看详细错误信息
|
||||||
|
docker-compose logs backend
|
||||||
|
docker-compose logs frontend
|
||||||
|
|
||||||
|
# 检查容器状态
|
||||||
|
docker-compose ps -a
|
||||||
|
|
||||||
|
# 重新构建(清除缓存)
|
||||||
|
docker-compose build --no-cache
|
||||||
|
```
|
||||||
|
|
||||||
|
### 端口被占用
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 查找占用端口的进程
|
||||||
|
lsof -i :8080 # 后端端口
|
||||||
|
lsof -i :3000 # 前端端口
|
||||||
|
|
||||||
|
# 杀死占用端口的进程
|
||||||
|
kill -9 <PID>
|
||||||
|
```
|
||||||
|
|
||||||
|
### 配置文件未找到
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 确保 config.json 存在
|
||||||
|
ls -la config.json
|
||||||
|
|
||||||
|
# 如果不存在,复制模板
|
||||||
|
cp config.json.example config.json
|
||||||
|
```
|
||||||
|
|
||||||
|
### 健康检查失败
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 检查健康状态
|
||||||
|
docker inspect nofx-backend | jq '.[0].State.Health'
|
||||||
|
docker inspect nofx-frontend | jq '.[0].State.Health'
|
||||||
|
|
||||||
|
# 手动测试健康端点
|
||||||
|
curl http://localhost:8080/health
|
||||||
|
curl http://localhost:3000/health
|
||||||
|
```
|
||||||
|
|
||||||
|
### 前端无法连接后端
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 检查网络连接
|
||||||
|
docker-compose exec frontend ping backend
|
||||||
|
|
||||||
|
# 检查后端服务是否正常
|
||||||
|
docker-compose exec frontend wget -O- http://backend:8080/health
|
||||||
|
```
|
||||||
|
|
||||||
|
### 清理 Docker 资源
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 清理未使用的镜像
|
||||||
|
docker image prune -a
|
||||||
|
|
||||||
|
# 清理未使用的卷
|
||||||
|
docker volume prune
|
||||||
|
|
||||||
|
# 清理所有未使用的资源(慎用)
|
||||||
|
docker system prune -a --volumes
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔐 安全建议
|
||||||
|
|
||||||
|
1. **不要将 config.json 提交到 Git**
|
||||||
|
```bash
|
||||||
|
# 确保 config.json 在 .gitignore 中
|
||||||
|
echo "config.json" >> .gitignore
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **使用环境变量存储敏感信息**
|
||||||
|
```yaml
|
||||||
|
# docker-compose.yml
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
environment:
|
||||||
|
- BINANCE_API_KEY=${BINANCE_API_KEY}
|
||||||
|
- BINANCE_SECRET_KEY=${BINANCE_SECRET_KEY}
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **限制 API 访问**
|
||||||
|
```yaml
|
||||||
|
# 只允许本地访问
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:8080:8080"
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **定期更新镜像**
|
||||||
|
```bash
|
||||||
|
docker-compose pull
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🌐 生产环境部署
|
||||||
|
|
||||||
|
### 使用 Nginx 反向代理
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
# /etc/nginx/sites-available/nofx
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name your-domain.com;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:3000;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://localhost:8080/api/;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 配置 HTTPS (Let's Encrypt)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 安装 Certbot
|
||||||
|
sudo apt-get install certbot python3-certbot-nginx
|
||||||
|
|
||||||
|
# 获取 SSL 证书
|
||||||
|
sudo certbot --nginx -d your-domain.com
|
||||||
|
|
||||||
|
# 自动续期
|
||||||
|
sudo certbot renew --dry-run
|
||||||
|
```
|
||||||
|
|
||||||
|
### 使用 Docker Swarm (集群部署)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 初始化 Swarm
|
||||||
|
docker swarm init
|
||||||
|
|
||||||
|
# 部署堆栈
|
||||||
|
docker stack deploy -c docker-compose.yml nofx
|
||||||
|
|
||||||
|
# 查看服务状态
|
||||||
|
docker stack services nofx
|
||||||
|
|
||||||
|
# 扩展服务
|
||||||
|
docker service scale nofx_backend=3
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📈 监控与日志
|
||||||
|
|
||||||
|
### 日志管理
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 配置日志轮转(已在 docker-compose.yml 中配置)
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
|
||||||
|
# 查看日志统计
|
||||||
|
docker-compose logs --timestamps | wc -l
|
||||||
|
```
|
||||||
|
|
||||||
|
### 监控工具集成
|
||||||
|
|
||||||
|
可以集成 Prometheus + Grafana 进行监控:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# docker-compose.yml (添加监控服务)
|
||||||
|
services:
|
||||||
|
prometheus:
|
||||||
|
image: prom/prometheus
|
||||||
|
ports:
|
||||||
|
- "9090:9090"
|
||||||
|
volumes:
|
||||||
|
- ./prometheus.yml:/etc/prometheus/prometheus.yml
|
||||||
|
|
||||||
|
grafana:
|
||||||
|
image: grafana/grafana
|
||||||
|
ports:
|
||||||
|
- "3001:3000"
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🆘 获取帮助
|
||||||
|
|
||||||
|
- **GitHub Issues**: [提交问题](https://github.com/yourusername/open-nofx/issues)
|
||||||
|
- **文档**: 查看 [README.md](README.md)
|
||||||
|
- **社区**: 加入我们的 Discord/Telegram 群组
|
||||||
|
|
||||||
|
## 📝 常用命令速查表
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 启动
|
||||||
|
docker-compose up -d --build # 构建并启动
|
||||||
|
docker-compose up -d # 启动(不重新构建)
|
||||||
|
|
||||||
|
# 停止
|
||||||
|
docker-compose stop # 停止服务
|
||||||
|
docker-compose down # 停止并删除容器
|
||||||
|
docker-compose down -v # 停止并删除容器和数据
|
||||||
|
|
||||||
|
# 查看
|
||||||
|
docker-compose ps # 查看状态
|
||||||
|
docker-compose logs -f # 查看日志
|
||||||
|
docker-compose top # 查看进程
|
||||||
|
|
||||||
|
# 重启
|
||||||
|
docker-compose restart # 重启所有服务
|
||||||
|
docker-compose restart backend # 重启后端
|
||||||
|
|
||||||
|
# 更新
|
||||||
|
git pull && docker-compose up -d --build
|
||||||
|
|
||||||
|
# 清理
|
||||||
|
docker-compose down -v # 清除所有数据
|
||||||
|
docker system prune -a # 清理 Docker 资源
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
🎉 恭喜!你已经成功部署了 NOFX AI 交易竞赛系统!
|
||||||
|
|
||||||
|
如有问题,请查看[故障排查](#-故障排查)部分或提交 Issue。
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
# 构建阶段
|
||||||
|
FROM golang:1.21-alpine AS builder
|
||||||
|
|
||||||
|
# 安装必要的构建工具
|
||||||
|
RUN apk add --no-cache git gcc musl-dev
|
||||||
|
|
||||||
|
# 设置工作目录
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 复制 go mod 文件
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
|
||||||
|
# 下载依赖
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# 复制源代码
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# 构建应用
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o nofx .
|
||||||
|
|
||||||
|
# 运行阶段
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
# 安装 ca-certificates(HTTPS 请求需要)
|
||||||
|
RUN apk --no-cache add ca-certificates tzdata
|
||||||
|
|
||||||
|
# 设置时区为上海
|
||||||
|
ENV TZ=Asia/Shanghai
|
||||||
|
|
||||||
|
# 创建非 root 用户
|
||||||
|
RUN addgroup -g 1000 nofx && \
|
||||||
|
adduser -D -u 1000 -G nofx nofx
|
||||||
|
|
||||||
|
# 设置工作目录
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 从构建阶段复制二进制文件
|
||||||
|
COPY --from=builder /app/nofx .
|
||||||
|
|
||||||
|
# 复制配置文件示例
|
||||||
|
COPY config.json.example ./config.json.example
|
||||||
|
|
||||||
|
# 创建必要的目录
|
||||||
|
RUN mkdir -p decision_logs coin_pool_cache && \
|
||||||
|
chown -R nofx:nofx /app
|
||||||
|
|
||||||
|
# 切换到非 root 用户
|
||||||
|
USER nofx
|
||||||
|
|
||||||
|
# 暴露 API 端口
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# 健康检查
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||||
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
|
||||||
|
|
||||||
|
# 启动应用
|
||||||
|
CMD ["./nofx"]
|
||||||
@@ -166,6 +166,54 @@ Before using this system, you need a Binance Futures account. **Use our referral
|
|||||||
|
|
||||||
## 🚀 Quick Start
|
## 🚀 Quick Start
|
||||||
|
|
||||||
|
### 🐳 Option A: Docker One-Click Deployment (EASIEST - Recommended for Beginners!)
|
||||||
|
|
||||||
|
**⚡ Start trading in 3 simple steps with Docker - No installation needed!**
|
||||||
|
|
||||||
|
Docker automatically handles all dependencies (Go, Node.js, TA-Lib) and environment setup. Perfect for beginners!
|
||||||
|
|
||||||
|
#### Step 1: Prepare Configuration
|
||||||
|
```bash
|
||||||
|
# Copy configuration template
|
||||||
|
cp config.json.example config.json
|
||||||
|
|
||||||
|
# Edit and fill in your API keys
|
||||||
|
nano config.json # or use any editor
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 2: One-Click Start
|
||||||
|
```bash
|
||||||
|
# Option 1: Use convenience script (Recommended)
|
||||||
|
chmod +x start.sh
|
||||||
|
./start.sh start --build
|
||||||
|
|
||||||
|
# Option 2: Use docker-compose directly
|
||||||
|
docker-compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Step 3: Access Dashboard
|
||||||
|
Open your browser and visit: **http://localhost:3000**
|
||||||
|
|
||||||
|
**That's it! 🎉** Your AI trading system is now running!
|
||||||
|
|
||||||
|
#### Manage Your System
|
||||||
|
```bash
|
||||||
|
./start.sh logs # View logs
|
||||||
|
./start.sh status # Check status
|
||||||
|
./start.sh stop # Stop services
|
||||||
|
./start.sh restart # Restart services
|
||||||
|
```
|
||||||
|
|
||||||
|
**📖 For detailed Docker deployment guide, troubleshooting, and advanced configuration:**
|
||||||
|
- **English**: See [DOCKER_DEPLOY.en.md](DOCKER_DEPLOY.en.md)
|
||||||
|
- **中文**: 查看 [DOCKER_DEPLOY.md](DOCKER_DEPLOY.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 📦 Option B: Manual Installation (For Developers)
|
||||||
|
|
||||||
|
**Note**: If you used Docker deployment above, skip this section. Manual installation is only needed if you want to modify the code or run without Docker.
|
||||||
|
|
||||||
### 1. Environment Requirements
|
### 1. Environment Requirements
|
||||||
|
|
||||||
- **Go 1.21+**
|
- **Go 1.21+**
|
||||||
|
|||||||
@@ -102,6 +102,55 @@
|
|||||||
|
|
||||||
## 🚀 Быстрый старт
|
## 🚀 Быстрый старт
|
||||||
|
|
||||||
|
### 🐳 Вариант A: Docker развертывание в один клик (ПРОЩЕ ВСЕГО - Рекомендуется для новичков!)
|
||||||
|
|
||||||
|
**⚡ Начните торговать за 3 простых шага с Docker - Не нужно ничего устанавливать!**
|
||||||
|
|
||||||
|
Docker автоматически обрабатывает все зависимости (Go, Node.js, TA-Lib) и настройку среды. Идеально для новичков!
|
||||||
|
|
||||||
|
#### Шаг 1: Подготовьте конфигурацию
|
||||||
|
```bash
|
||||||
|
# Скопируйте шаблон конфигурации
|
||||||
|
cp config.json.example config.json
|
||||||
|
|
||||||
|
# Отредактируйте и заполните ваши API ключи
|
||||||
|
nano config.json # или используйте любой редактор
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Шаг 2: Запуск в один клик
|
||||||
|
```bash
|
||||||
|
# Вариант 1: Используйте удобный скрипт (Рекомендуется)
|
||||||
|
chmod +x start.sh
|
||||||
|
./start.sh start --build
|
||||||
|
|
||||||
|
# Вариант 2: Используйте docker-compose напрямую
|
||||||
|
docker-compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Шаг 3: Доступ к панели
|
||||||
|
Откройте в браузере: **http://localhost:3000**
|
||||||
|
|
||||||
|
**Вот и все! 🎉** Ваша AI торговая система теперь работает!
|
||||||
|
|
||||||
|
#### Управление вашей системой
|
||||||
|
```bash
|
||||||
|
./start.sh logs # Просмотреть логи
|
||||||
|
./start.sh status # Проверить статус
|
||||||
|
./start.sh stop # Остановить сервисы
|
||||||
|
./start.sh restart # Перезапустить сервисы
|
||||||
|
```
|
||||||
|
|
||||||
|
**📖 Подробное руководство по развертыванию Docker, устранению неполадок и расширенной конфигурации:**
|
||||||
|
- **Русский**: См. документацию Docker (скоро будет доступно)
|
||||||
|
- **English**: See [DOCKER_DEPLOY.en.md](DOCKER_DEPLOY.en.md)
|
||||||
|
- **中文**: 查看 [DOCKER_DEPLOY.md](DOCKER_DEPLOY.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 📦 Вариант B: Ручная установка (Для разработчиков)
|
||||||
|
|
||||||
|
**Примечание**: Если вы использовали развертывание Docker выше, пропустите этот раздел. Ручная установка нужна только если вы хотите изменить код или запустить без Docker.
|
||||||
|
|
||||||
### 1. Требования к среде
|
### 1. Требования к среде
|
||||||
|
|
||||||
- **Go 1.21+**
|
- **Go 1.21+**
|
||||||
|
|||||||
@@ -102,6 +102,55 @@
|
|||||||
|
|
||||||
## 🚀 Швидкий старт
|
## 🚀 Швидкий старт
|
||||||
|
|
||||||
|
### 🐳 Варіант A: Docker розгортання в один клік (НАЙПРОСТІШЕ - Рекомендується для новачків!)
|
||||||
|
|
||||||
|
**⚡ Почніть торгувати за 3 прості кроки з Docker - Не потрібно нічого встановлювати!**
|
||||||
|
|
||||||
|
Docker автоматично обробляє всі залежності (Go, Node.js, TA-Lib) та налаштування середовища. Ідеально для новачків!
|
||||||
|
|
||||||
|
#### Крок 1: Підготуйте конфігурацію
|
||||||
|
```bash
|
||||||
|
# Скопіюйте шаблон конфігурації
|
||||||
|
cp config.json.example config.json
|
||||||
|
|
||||||
|
# Відредагуйте та заповніть ваші API ключі
|
||||||
|
nano config.json # або використайте будь-який редактор
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Крок 2: Запуск в один клік
|
||||||
|
```bash
|
||||||
|
# Варіант 1: Використайте зручний скрипт (Рекомендується)
|
||||||
|
chmod +x start.sh
|
||||||
|
./start.sh start --build
|
||||||
|
|
||||||
|
# Варіант 2: Використайте docker-compose безпосередньо
|
||||||
|
docker-compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Крок 3: Доступ до панелі
|
||||||
|
Відкрийте у браузері: **http://localhost:3000**
|
||||||
|
|
||||||
|
**От і все! 🎉** Ваша AI торгова система зараз працює!
|
||||||
|
|
||||||
|
#### Керування вашою системою
|
||||||
|
```bash
|
||||||
|
./start.sh logs # Переглянути логи
|
||||||
|
./start.sh status # Перевірити статус
|
||||||
|
./start.sh stop # Зупинити сервіси
|
||||||
|
./start.sh restart # Перезапустити сервіси
|
||||||
|
```
|
||||||
|
|
||||||
|
**📖 Детальний посібник з розгортання Docker, усунення несправностей та розширеної конфігурації:**
|
||||||
|
- **Українська**: Дивіться документацію Docker (скоро буде доступно)
|
||||||
|
- **English**: See [DOCKER_DEPLOY.en.md](DOCKER_DEPLOY.en.md)
|
||||||
|
- **中文**: 查看 [DOCKER_DEPLOY.md](DOCKER_DEPLOY.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 📦 Варіант B: Ручне встановлення (Для розробників)
|
||||||
|
|
||||||
|
**Примітка**: Якщо ви використали розгортання Docker вище, пропустіть цей розділ. Ручне встановлення потрібне лише якщо ви хочете змінити код або запустити без Docker.
|
||||||
|
|
||||||
### 1. Вимоги до середовища
|
### 1. Вимоги до середовища
|
||||||
|
|
||||||
- **Go 1.21+**
|
- **Go 1.21+**
|
||||||
|
|||||||
@@ -166,6 +166,54 @@ nofx/
|
|||||||
|
|
||||||
## 🚀 快速开始
|
## 🚀 快速开始
|
||||||
|
|
||||||
|
### 🐳 方式A:Docker 一键部署(最简单 - 新手推荐!)
|
||||||
|
|
||||||
|
**⚡ 使用Docker只需3步即可开始交易 - 无需安装任何环境!**
|
||||||
|
|
||||||
|
Docker会自动处理所有依赖(Go、Node.js、TA-Lib)和环境配置,完美适合新手!
|
||||||
|
|
||||||
|
#### 步骤1:准备配置文件
|
||||||
|
```bash
|
||||||
|
# 复制配置文件模板
|
||||||
|
cp config.json.example config.json
|
||||||
|
|
||||||
|
# 编辑并填入你的API密钥
|
||||||
|
nano config.json # 或使用其他编辑器
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 步骤2:一键启动
|
||||||
|
```bash
|
||||||
|
# 方式1:使用便捷脚本(推荐)
|
||||||
|
chmod +x start.sh
|
||||||
|
./start.sh start --build
|
||||||
|
|
||||||
|
# 方式2:直接使用docker-compose
|
||||||
|
docker-compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 步骤3:访问控制台
|
||||||
|
在浏览器中打开:**http://localhost:3000**
|
||||||
|
|
||||||
|
**就是这么简单!🎉** 你的AI交易系统已经运行起来了!
|
||||||
|
|
||||||
|
#### 管理你的系统
|
||||||
|
```bash
|
||||||
|
./start.sh logs # 查看日志
|
||||||
|
./start.sh status # 检查状态
|
||||||
|
./start.sh stop # 停止服务
|
||||||
|
./start.sh restart # 重启服务
|
||||||
|
```
|
||||||
|
|
||||||
|
**📖 详细的Docker部署教程、故障排查和高级配置:**
|
||||||
|
- **中文**: 查看 [DOCKER_DEPLOY.md](DOCKER_DEPLOY.md)
|
||||||
|
- **English**: See [DOCKER_DEPLOY.en.md](DOCKER_DEPLOY.en.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 📦 方式B:手动安装(开发者)
|
||||||
|
|
||||||
|
**注意**:如果你使用了上面的Docker部署,请跳过本节。手动安装仅在你需要修改代码或不想使用Docker时需要。
|
||||||
|
|
||||||
### 1. 环境要求
|
### 1. 环境要求
|
||||||
|
|
||||||
- **Go 1.21+**
|
- **Go 1.21+**
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
# 后端服务
|
||||||
|
backend:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: nofx-backend
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
volumes:
|
||||||
|
# 挂载配置文件(必须)
|
||||||
|
- ./config.json:/app/config.json:ro
|
||||||
|
# 持久化决策日志
|
||||||
|
- ./decision_logs:/app/decision_logs
|
||||||
|
# 持久化币种池缓存
|
||||||
|
- ./coin_pool_cache:/app/coin_pool_cache
|
||||||
|
environment:
|
||||||
|
- TZ=Asia/Shanghai
|
||||||
|
networks:
|
||||||
|
- nofx-network
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 10s
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
|
||||||
|
# 前端服务
|
||||||
|
frontend:
|
||||||
|
build:
|
||||||
|
context: ./web
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: nofx-frontend
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "3000:80"
|
||||||
|
depends_on:
|
||||||
|
backend:
|
||||||
|
condition: service_healthy
|
||||||
|
networks:
|
||||||
|
- nofx-network
|
||||||
|
environment:
|
||||||
|
- TZ=Asia/Shanghai
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 5s
|
||||||
|
logging:
|
||||||
|
driver: "json-file"
|
||||||
|
options:
|
||||||
|
max-size: "10m"
|
||||||
|
max-file: "3"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
nofx-network:
|
||||||
|
driver: bridge
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
decision_logs:
|
||||||
|
coin_pool_cache:
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# NOFX AI Trading System - Docker Quick Start Script
|
||||||
|
# 使用方法: ./start.sh [command]
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# 颜色定义
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# 打印带颜色的消息
|
||||||
|
print_info() {
|
||||||
|
echo -e "${BLUE}[INFO]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_success() {
|
||||||
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_warning() {
|
||||||
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_error() {
|
||||||
|
echo -e "${RED}[ERROR]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 检查 Docker 是否安装
|
||||||
|
check_docker() {
|
||||||
|
if ! command -v docker &> /dev/null; then
|
||||||
|
print_error "Docker 未安装!请先安装 Docker: https://docs.docker.com/get-docker/"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v docker-compose &> /dev/null; then
|
||||||
|
print_error "Docker Compose 未安装!请先安装 Docker Compose"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_success "Docker 和 Docker Compose 已安装"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 检查配置文件
|
||||||
|
check_config() {
|
||||||
|
if [ ! -f "config.json" ]; then
|
||||||
|
print_warning "config.json 不存在,从模板复制..."
|
||||||
|
cp config.json.example config.json
|
||||||
|
print_info "请编辑 config.json 填入你的 API 密钥"
|
||||||
|
print_info "运行: nano config.json 或使用其他编辑器"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
print_success "配置文件存在"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 启动服务
|
||||||
|
start() {
|
||||||
|
print_info "正在启动 NOFX AI Trading System..."
|
||||||
|
|
||||||
|
if [ "$1" == "--build" ]; then
|
||||||
|
print_info "重新构建镜像..."
|
||||||
|
docker-compose up -d --build
|
||||||
|
else
|
||||||
|
docker-compose up -d
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_success "服务已启动!"
|
||||||
|
print_info "Web 界面: http://localhost:3000"
|
||||||
|
print_info "API 端点: http://localhost:8080"
|
||||||
|
print_info ""
|
||||||
|
print_info "查看日志: ./start.sh logs"
|
||||||
|
print_info "停止服务: ./start.sh stop"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 停止服务
|
||||||
|
stop() {
|
||||||
|
print_info "正在停止服务..."
|
||||||
|
docker-compose stop
|
||||||
|
print_success "服务已停止"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 重启服务
|
||||||
|
restart() {
|
||||||
|
print_info "正在重启服务..."
|
||||||
|
docker-compose restart
|
||||||
|
print_success "服务已重启"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 查看日志
|
||||||
|
logs() {
|
||||||
|
if [ -z "$2" ]; then
|
||||||
|
docker-compose logs -f
|
||||||
|
else
|
||||||
|
docker-compose logs -f "$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# 查看状态
|
||||||
|
status() {
|
||||||
|
print_info "服务状态:"
|
||||||
|
docker-compose ps
|
||||||
|
echo ""
|
||||||
|
print_info "健康检查:"
|
||||||
|
curl -s http://localhost:8080/health | jq '.' || echo "后端未响应"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 清理
|
||||||
|
clean() {
|
||||||
|
print_warning "这将删除所有容器和数据!"
|
||||||
|
read -p "确认删除?(yes/no): " confirm
|
||||||
|
if [ "$confirm" == "yes" ]; then
|
||||||
|
print_info "正在清理..."
|
||||||
|
docker-compose down -v
|
||||||
|
print_success "清理完成"
|
||||||
|
else
|
||||||
|
print_info "已取消"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# 更新
|
||||||
|
update() {
|
||||||
|
print_info "正在更新..."
|
||||||
|
git pull
|
||||||
|
docker-compose up -d --build
|
||||||
|
print_success "更新完成"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 显示帮助
|
||||||
|
show_help() {
|
||||||
|
echo "NOFX AI Trading System - Docker 管理脚本"
|
||||||
|
echo ""
|
||||||
|
echo "用法: ./start.sh [command] [options]"
|
||||||
|
echo ""
|
||||||
|
echo "命令:"
|
||||||
|
echo " start [--build] 启动服务(可选:重新构建)"
|
||||||
|
echo " stop 停止服务"
|
||||||
|
echo " restart 重启服务"
|
||||||
|
echo " logs [service] 查看日志(可选:指定服务名 backend/frontend)"
|
||||||
|
echo " status 查看服务状态"
|
||||||
|
echo " clean 清理所有容器和数据"
|
||||||
|
echo " update 更新代码并重启"
|
||||||
|
echo " help 显示此帮助信息"
|
||||||
|
echo ""
|
||||||
|
echo "示例:"
|
||||||
|
echo " ./start.sh start --build # 构建并启动"
|
||||||
|
echo " ./start.sh logs backend # 查看后端日志"
|
||||||
|
echo " ./start.sh status # 查看状态"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 主函数
|
||||||
|
main() {
|
||||||
|
check_docker
|
||||||
|
|
||||||
|
case "${1:-start}" in
|
||||||
|
start)
|
||||||
|
check_config
|
||||||
|
start "$2"
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
stop
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
restart
|
||||||
|
;;
|
||||||
|
logs)
|
||||||
|
logs "$@"
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
status
|
||||||
|
;;
|
||||||
|
clean)
|
||||||
|
clean
|
||||||
|
;;
|
||||||
|
update)
|
||||||
|
update
|
||||||
|
;;
|
||||||
|
help|--help|-h)
|
||||||
|
show_help
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
print_error "未知命令: $1"
|
||||||
|
show_help
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# 运行主函数
|
||||||
|
main "$@"
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
package-lock.json
|
||||||
|
yarn.lock
|
||||||
|
pnpm-lock.yaml
|
||||||
|
|
||||||
|
# Build output (will be regenerated)
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Development files
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
# Testing
|
||||||
|
coverage/
|
||||||
|
.nyc_output/
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
|
||||||
|
# Git
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
*.md
|
||||||
|
!README.md
|
||||||
|
CHANGELOG.md
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs/
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Temporary files
|
||||||
|
.cache/
|
||||||
|
.temp/
|
||||||
|
.tmp/
|
||||||
|
*.tmp
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
# 构建阶段
|
||||||
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
|
# 设置工作目录
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# 复制 package 文件
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# 安装依赖
|
||||||
|
RUN npm ci --only=production=false
|
||||||
|
|
||||||
|
# 复制源代码
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# 构建应用
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# 运行阶段
|
||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
# 复制自定义 nginx 配置
|
||||||
|
COPY <<EOF /etc/nginx/conf.d/default.conf
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
# 启用 gzip 压缩
|
||||||
|
gzip on;
|
||||||
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||||
|
gzip_min_length 1000;
|
||||||
|
|
||||||
|
# SPA 路由支持
|
||||||
|
location / {
|
||||||
|
try_files \$uri \$uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
# API 代理到后端
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://backend:8080/api/;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade \$http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Host \$host;
|
||||||
|
proxy_cache_bypass \$http_upgrade;
|
||||||
|
proxy_set_header X-Real-IP \$remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto \$scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
# 健康检查端点
|
||||||
|
location /health {
|
||||||
|
proxy_pass http://backend:8080/health;
|
||||||
|
access_log off;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# 从构建阶段复制构建产物
|
||||||
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
|
# 暴露端口
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
# 健康检查
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||||
|
CMD wget --no-verbose --tries=1 --spider http://localhost/health || exit 1
|
||||||
|
|
||||||
|
# 启动 nginx
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
Reference in New Issue
Block a user