refactor: rename pool to provider (Data Provider)

This commit is contained in:
tinkle-community
2025-12-13 21:43:43 +08:00
parent c4363f3bc7
commit 4aa612f397
14 changed files with 140 additions and 1794 deletions
+2 -2
View File
@@ -57,8 +57,8 @@ nofx/
│ └── monitor.go # Market data cache
│ └── types.go # market structure
├── pool/ # Coin pool management
│ └── coin_pool.go # AI500 + OI Top merged pool
├── provider/ # Data provider management
│ └── data_provider.go # AI500 + OI Top data provider
├── logger/ # Logging system
│ └── decision_logger.go # Decision recording + performance analysis
+2 -2
View File
@@ -57,8 +57,8 @@ nofx/
│ └── monitor.go # 行情数据缓存
│ └── types.go # market结构体
├── pool/ # 币种池管理
│ └── coin_pool.go # AI500 + OI Top 合并池
├── provider/ # 数据源管理
│ └── data_provider.go # AI500 + OI Top 数据源
├── logger/ # 日志系统
│ └── decision_logger.go # 决策记录 + 性能分析
-473
View File
@@ -1,473 +0,0 @@
# 🐳 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)
> #### Docker Compose Version Notes
>
> **New User Recommendation:**
> - **Use Docker Desktop**: Automatically includes latest Docker Compose, no separate installation needed
> - Simple installation, one-click setup, provides GUI management
> - Supports macOS, Windows, and some Linux distributions
>
> **Upgrading User Note:**
> - **Deprecating standalone docker-compose**: No longer recommended to download the independent Docker Compose binary
> - **Use built-in version**: Docker 20.10+ includes `docker compose` command (with space)
> - If still using old `docker-compose`, please upgrade to new syntax
*Recommended: Use Docker Desktop (if available) or Docker CE with built-in Compose*
```bash
# Install Docker (includes compose)
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Add user to docker group
sudo usermod -aG docker $USER
newgrp docker
# Verify installation (new command)
docker --version
docker compose --version # Docker 24+ includes this, no separate installation needed
```
## 🚀 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
⚠️ **Note**: Basic config.json is still needed for some settings, but ~~trader configurations~~ are now done through the web interface.
```
**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/api/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)~~ (Deprecated)
**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~~ trading.db
# 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~~
*Note: Now using SQLite database for configuration storage, no longer need 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/api/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~~
```
*Note: Now using trading.db database, ensure not to commit sensitive data*
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.
-489
View File
@@ -1,489 +0,0 @@
# 🐳 Docker 一键部署教程
本教程将指导你使用 Docker 快速部署 NOFX AI 交易竞赛系统。
## 📋 前置要求
在开始之前,请确保你的系统已安装:
- **Docker**: 版本 20.10 或更高
- **Docker Compose**: 版本 2.0 或更高
### 安装 Docker
> #### 提示:Docker Compose 版本说明
>
> **新用户建议**
> - **推荐使用 Docker Desktop**:自动包含最新 Docker Compose,无需单独安装
> - 安装简单,一键搞定,提供图形界面管理
> - 支持 macOS、Windows、部分 Linux 发行版
>
> **旧用户提醒**
> - **弃用独立 docker-compose**:不再推荐下载独立的 Docker Compose 二进制文件
> - **使用内置版**Docker 20.10+ 自带 `docker compose` 命令(注意是空格)
> - 如果还在使用旧的 `docker-compose`,请升级到新语法
#### macOS / Windows
下载并安装 [Docker Desktop](https://www.docker.com/products/docker-desktop/)
**安装后验证:**
```bash
docker --version
docker compose --version # 注意:使用空格,不再是连字符
```
#### Linux (Ubuntu/Debian)
**推荐方式:使用 Docker Desktop(如果可用)或 Docker CE**
```bash
# 安装 Docker (自动包含 compose)
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# 将当前用户加入 docker 组
sudo usermod -aG docker $USER
newgrp docker
# 验证安装(新命令)
docker --version
docker compose --version # Docker 24+ 自带,无需单独安装
```
## 🚀 快速开始(3步完成部署)
### 第 1 步:准备配置文件
```bash
# 复制配置文件模板
cp config.json.example config.json
# 编辑配置文件,填入你的 API 密钥
nano config.json # 或使用其他编辑器
```
**必须配置的字段:**
```json
{
"use_default_coins": true,
"api_server_port": 8081,
"jwt_secret": "YOUR_JWT_SECRET_CHANGE_IN_PRODUCTION" // ← 填入一个长随机字符串作为JWT密钥
}
```
> **⚠️ 重要安全提醒**
> - `jwt_secret` 字段是用户认证系统的关键安全配置
> - **必须设置一个长度至少32位的随机字符串**
> - 在生产环境中,建议使用64位以上的随机字符串
> - 可以使用命令生成:`openssl rand -base64 64`
**配置说明:**
- 🔐 **用户认证**:系统现在支持用户注册登录,每个用户都有独立的AI模型和交易所配置
- 🚫 **移除traders配置**:不再需要在config.json中预配置交易员,用户可以通过Web界面创建
- 🔑 **JWT密钥**:用于保护用户会话安全,强烈建议在生产环境中设置复杂密钥
### 第 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/api/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/api/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. **JWT密钥安全配置**
```bash
# 生成强随机JWT密钥
openssl rand -base64 64
# 或者使用其他工具生成
head -c 64 /dev/urandom | base64
```
**JWT密钥要求:**
- 长度至少32位,推荐64位以上
- 使用随机生成的字符串
- 在生产环境中绝不使用默认值
- 定期更换(会使现有用户需要重新登录)
2. ~~**不要将 config.json 提交到 Git**~~
```bash
# ~~确保 config.json 在 .gitignore 中~~
# ~~echo "config.json" >> .gitignore~~
```
*注意:现在使用trading.db数据库,请确保不提交敏感数据*
3. **使用环境变量存储敏感信息**
```yaml
# docker-compose.yml
services:
backend:
environment:
- JWT_SECRET=${JWT_SECRET}
# 用户的API密钥现在通过Web界面配置,不再需要环境变量
```
4. **限制 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。
-472
View File
@@ -1,472 +0,0 @@
# 🐳 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)
> #### Docker Composeバージョンに関する注意
>
> **新規ユーザー推奨:**
> - **Docker Desktopを使用**: 最新のDocker Composeが自動的に含まれ、別途インストールは不要
> - シンプルなインストール、ワンクリックセットアップ、GUI管理を提供
> - macOS、Windows、一部のLinuxディストリビューションをサポート
>
> **既存ユーザー向け注意:**
> - **スタンドアロンdocker-composeの非推奨**: 独立したDocker Composeバイナリのダウンロードは推奨されません
> - **組み込みバージョンを使用**: Docker 20.10+には`docker compose`コマンド(スペース付き)が含まれています
> - 古い`docker-compose`をまだ使用している場合は、新しい構文にアップグレードしてください
*推奨:Docker Desktop(利用可能な場合)またはCompose組み込みのDocker CEを使用*
```bash
# Dockerをインストール(composeを含む)
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# dockerグループにユーザーを追加
sudo usermod -aG docker $USER
newgrp docker
# インストールを確認(新しいコマンド)
docker --version
docker compose --version # Docker 24+にはこれが含まれており、別途インストール不要
```
## 🚀 クイックスタート(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", // ← BinanceのAPIキー
"binance_secret_key": "YOUR_BINANCE_SECRET_KEY", // ← Binanceのシークレットキー
"deepseek_key": "YOUR_DEEPSEEK_API_KEY", // ← DeepSeekのAPIキー
"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`: デタッチモードで実行(バックグラウンド)
### ステップ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" # "your_port:8080"に変更
frontend:
ports:
- "3000:80" # "your_port:80"に変更
```
### リソース制限
`docker-compose.yml`にリソース制限を追加:
```yaml
services:
backend:
deploy:
resources:
limits:
cpus: '2'
memory: 2G
reservations:
cpus: '1'
memory: 1G
```
### 環境変数
`.env`ファイルを作成して環境変数を管理:
```bash
# .env
TZ=Asia/Tokyo
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**: [Issueを提出](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を提出してください。