first commit
This commit is contained in:
2
deploy/.env
Normal file
2
deploy/.env
Normal file
@@ -0,0 +1,2 @@
|
||||
OPENAI_API_KEY=your_openai_api_key_here
|
||||
SECRET_KEY=your_secret_key_here
|
||||
120
deploy/compose-without-build.yml
Normal file
120
deploy/compose-without-build.yml
Normal file
@@ -0,0 +1,120 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
# PostgreSQL数据库
|
||||
postgres:
|
||||
image: postgres:14-alpine
|
||||
container_name: algorithm-showcase-postgres
|
||||
environment:
|
||||
POSTGRES_DB: algorithm_db
|
||||
POSTGRES_USER: admin
|
||||
POSTGRES_PASSWORD: password
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U admin -d algorithm_db"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
# Redis缓存
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: algorithm-showcase-redis
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
# MinIO对象存储 (S3兼容)
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
container_name: algorithm-showcase-minio
|
||||
ports:
|
||||
- "9000:9000"
|
||||
- "9001:9001"
|
||||
environment:
|
||||
MINIO_ROOT_USER: minioadmin
|
||||
MINIO_ROOT_PASSWORD: minioadmin
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
command: server /data --console-address ":9001"
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
|
||||
interval: 30s
|
||||
timeout: 20s
|
||||
retries: 3
|
||||
|
||||
# 后端API服务 (使用预构建镜像)
|
||||
backend:
|
||||
image: python:3.9-slim
|
||||
container_name: algorithm-showcase-backend
|
||||
ports:
|
||||
- "8000:8000"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
minio:
|
||||
condition: service_started
|
||||
environment:
|
||||
- DATABASE_URL=postgresql://admin:password@postgres:5432/algorithm_db
|
||||
- REDIS_URL=redis://redis:6379/0
|
||||
- MINIO_ENDPOINT=minio:9000
|
||||
- MINIO_ACCESS_KEY=minioadmin
|
||||
- MINIO_SECRET_KEY=minioadmin
|
||||
- MINIO_BUCKET_NAME=algorithm-data
|
||||
- MINIO_SECURE=false
|
||||
- OPENAI_API_KEY=${OPENAI_API_KEY:-your_openai_api_key_here}
|
||||
- SECRET_KEY=${SECRET_KEY:-your-secret-key-here}
|
||||
- ALGORITHM=HS256
|
||||
- ACCESS_TOKEN_EXPIRE_MINUTES=30
|
||||
volumes:
|
||||
- ../backend:/app
|
||||
working_dir: /app
|
||||
command: >
|
||||
sh -c "pip install --no-cache-dir -r requirements.txt &&
|
||||
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload"
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
# 前端服务 (使用预构建镜像)
|
||||
frontend:
|
||||
image: node:18-alpine
|
||||
container_name: algorithm-showcase-frontend
|
||||
ports:
|
||||
- "3000:3000"
|
||||
depends_on:
|
||||
- backend
|
||||
volumes:
|
||||
- ../frontend:/app
|
||||
working_dir: /app
|
||||
command: >
|
||||
sh -c "npm install &&
|
||||
npm run dev -- --host 0.0.0.0 --port 3000"
|
||||
environment:
|
||||
- NODE_ENV=development
|
||||
- VITE_API_BASE_URL=http://localhost:8000/api
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
minio_data:
|
||||
|
||||
networks:
|
||||
default:
|
||||
driver: bridge
|
||||
name: algorithm-showcase-network
|
||||
115
deploy/custom-docker-compose.yml
Normal file
115
deploy/custom-docker-compose.yml
Normal file
@@ -0,0 +1,115 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
# PostgreSQL数据库
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
container_name: algorithm-showcase-postgres
|
||||
environment:
|
||||
POSTGRES_DB: algorithm_db
|
||||
POSTGRES_USER: admin
|
||||
POSTGRES_PASSWORD: password
|
||||
ports:
|
||||
- "5433:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U admin -d algorithm_db"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
# Redis缓存
|
||||
redis:
|
||||
image: crpi-x2l5uviq1k8hji3c.ap-northeast-1.personal.cr.aliyuncs.com/yipaidocker-images/linux_amd64_redis:latest
|
||||
platform: linux/amd64
|
||||
container_name: algorithm-showcase-redis
|
||||
ports:
|
||||
- "6381:6379"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
# MinIO对象存储 (S3兼容)
|
||||
minio:
|
||||
image: crpi-x2l5uviq1k8hji3c.ap-northeast-1.personal.cr.aliyuncs.com/yipaidocker-images/linux_amd64_minio:latest
|
||||
platform: linux/amd64
|
||||
container_name: algorithm-showcase-minio
|
||||
ports:
|
||||
- "9000:9000"
|
||||
- "9001:9001"
|
||||
environment:
|
||||
MINIO_ROOT_USER: minioadmin
|
||||
MINIO_ROOT_PASSWORD: minioadmin
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
command: server /data --console-address ":9001"
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
|
||||
interval: 30s
|
||||
timeout: 20s
|
||||
retries: 3
|
||||
|
||||
# 后端API服务
|
||||
backend:
|
||||
build:
|
||||
context: ../backend
|
||||
dockerfile: Dockerfile.custom
|
||||
container_name: algorithm-showcase-backend
|
||||
ports:
|
||||
- "8000:8000"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
minio:
|
||||
condition: service_started
|
||||
environment:
|
||||
- DATABASE_URL=postgresql://admin:password@postgres:5432/algorithm_db
|
||||
- REDIS_URL=redis://redis:6379/0
|
||||
- MINIO_ENDPOINT=minio:9000
|
||||
- MINIO_ACCESS_KEY=minioadmin
|
||||
- MINIO_SECRET_KEY=minioadmin
|
||||
- MINIO_BUCKET_NAME=algorithm-data
|
||||
- MINIO_SECURE=false
|
||||
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
||||
- SECRET_KEY=${SECRET_KEY:-your-secret-key-here}
|
||||
- ALGORITHM=HS256
|
||||
- ACCESS_TOKEN_EXPIRE_MINUTES=30
|
||||
volumes:
|
||||
- ../backend:/app
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
# 前端服务
|
||||
frontend:
|
||||
build:
|
||||
context: ../frontend
|
||||
dockerfile: Dockerfile.prod.simple
|
||||
container_name: algorithm-showcase-frontend
|
||||
ports:
|
||||
- "3000:80"
|
||||
depends_on:
|
||||
- backend
|
||||
environment:
|
||||
- VITE_API_BASE_URL=http://localhost:8000/api
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
minio_data:
|
||||
|
||||
networks:
|
||||
default:
|
||||
driver: bridge
|
||||
name: algorithm-showcase-network
|
||||
85
deploy/deploy.sh
Executable file
85
deploy/deploy.sh
Executable file
@@ -0,0 +1,85 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 智能算法展示平台部署脚本
|
||||
|
||||
set -e # 遇到错误立即退出
|
||||
|
||||
echo "开始部署智能算法展示平台..."
|
||||
|
||||
# 检查必要的命令
|
||||
command -v docker >/dev/null 2>&1 || { echo >&2 "Docker is required but not installed. Aborting."; exit 1; }
|
||||
command -v docker-compose >/dev/null 2>&1 || { echo >&2 "Docker Compose is required but not installed. Aborting."; exit 1; }
|
||||
|
||||
# 检查Docker守护进程是否运行
|
||||
if ! docker info >/dev/null 2>&1; then
|
||||
echo >&2 "Docker daemon is not running. Please start Docker and try again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查环境变量文件
|
||||
if [ ! -f ".env" ]; then
|
||||
echo "警告: .env 文件不存在,将使用默认配置"
|
||||
echo "请参考 .env.example 创建 .env 文件"
|
||||
echo "OPENAI_API_KEY=your_openai_api_key_here" > .env
|
||||
echo "SECRET_KEY=your_secret_key_here" >> .env
|
||||
fi
|
||||
|
||||
# 加载环境变量
|
||||
export $(grep -v '^#' .env | xargs)
|
||||
|
||||
# 检查Docker镜像是否存在,如果不存在则尝试拉取
|
||||
IMAGES=("postgres:14-alpine" "redis:7-alpine" "minio/minio:latest" "nginx:alpine")
|
||||
|
||||
for image in "${IMAGES[@]}"; do
|
||||
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "$(echo $image | sed 's/:.*//'):$(echo $image | sed 's/.*://')"; then
|
||||
echo "拉取镜像: $image"
|
||||
if ! docker pull "$image"; then
|
||||
echo "警告: 无法拉取镜像 $image,这可能导致后续构建失败"
|
||||
echo "您可以尝试配置Docker镜像加速器或检查网络连接"
|
||||
fi
|
||||
else
|
||||
echo "镜像已存在: $image"
|
||||
fi
|
||||
done
|
||||
|
||||
# 构建并启动服务
|
||||
echo "构建并启动服务..."
|
||||
docker-compose -f docker-compose-full.yml up -d --build
|
||||
|
||||
# 等待服务启动
|
||||
echo "等待服务启动..."
|
||||
sleep 15
|
||||
|
||||
# 检查服务状态
|
||||
echo "检查服务状态..."
|
||||
docker-compose -f docker-compose-full.yml ps
|
||||
|
||||
echo ""
|
||||
echo "检查服务健康状态..."
|
||||
SERVICES=("postgres" "redis" "minio" "backend" "frontend")
|
||||
|
||||
for service in "${SERVICES[@]}"; do
|
||||
sleep 3
|
||||
if [ "$(docker-compose -f docker-compose-full.yml ps $service --format json 2>/dev/null | jq -r '.State' 2>/dev/null || echo 'unknown')" = "running" ]; then
|
||||
echo "✓ $service 服务正在运行"
|
||||
else
|
||||
echo "✗ $service 服务未运行或存在问题"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "部署完成!"
|
||||
echo ""
|
||||
echo "服务地址:"
|
||||
echo "- 前端: http://localhost:3000"
|
||||
echo "- 后端API: http://localhost:8000"
|
||||
echo "- MinIO控制台: http://localhost:9001 (admin/minioadmin)"
|
||||
echo ""
|
||||
echo "要查看日志,请运行: docker-compose -f docker-compose-full.yml logs -f"
|
||||
|
||||
# 提供额外的故障排除信息
|
||||
echo ""
|
||||
echo "如遇问题,可尝试以下操作:"
|
||||
echo "1. 检查Docker是否正常运行"
|
||||
echo "2. 检查端口8000, 3000, 5432, 6379, 9000, 9001是否已被占用"
|
||||
echo "3. 运行 'docker-compose -f docker-compose-full.yml logs' 查看详细日志"
|
||||
128
deploy/docker-compose-full.yml
Normal file
128
deploy/docker-compose-full.yml
Normal file
@@ -0,0 +1,128 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
# PostgreSQL数据库
|
||||
postgres:
|
||||
image: postgres:14-alpine
|
||||
container_name: algorithm-showcase-postgres
|
||||
environment:
|
||||
POSTGRES_DB: algorithm_db
|
||||
POSTGRES_USER: admin
|
||||
POSTGRES_PASSWORD: password
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U admin -d algorithm_db"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
# Redis缓存
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: algorithm-showcase-redis
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
# MinIO对象存储 (S3兼容)
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
container_name: algorithm-showcase-minio
|
||||
ports:
|
||||
- "9000:9000"
|
||||
- "9001:9001"
|
||||
environment:
|
||||
MINIO_ROOT_USER: minioadmin
|
||||
MINIO_ROOT_PASSWORD: minioadmin
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
command: server /data --console-address ":9001"
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
|
||||
interval: 30s
|
||||
timeout: 20s
|
||||
retries: 3
|
||||
|
||||
# 后端API服务
|
||||
backend:
|
||||
build:
|
||||
context: ../backend
|
||||
dockerfile: Dockerfile
|
||||
container_name: algorithm-showcase-backend
|
||||
ports:
|
||||
- "8000:8000"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
minio:
|
||||
condition: service_started
|
||||
environment:
|
||||
- DATABASE_URL=postgresql://admin:password@postgres:5432/algorithm_db
|
||||
- REDIS_URL=redis://redis:6379/0
|
||||
- MINIO_ENDPOINT=minio:9000
|
||||
- MINIO_ACCESS_KEY=minioadmin
|
||||
- MINIO_SECRET_KEY=minioadmin
|
||||
- MINIO_BUCKET_NAME=algorithm-data
|
||||
- MINIO_SECURE=false
|
||||
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
||||
- SECRET_KEY=${SECRET_KEY:-your-secret-key-here}
|
||||
- ALGORITHM=HS256
|
||||
- ACCESS_TOKEN_EXPIRE_MINUTES=30
|
||||
volumes:
|
||||
- ../backend:/app
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
|
||||
# 前端服务
|
||||
frontend:
|
||||
build:
|
||||
context: ../frontend
|
||||
dockerfile: Dockerfile.prod
|
||||
container_name: algorithm-showcase-frontend
|
||||
ports:
|
||||
- "3000:80"
|
||||
depends_on:
|
||||
- backend
|
||||
environment:
|
||||
- VITE_API_BASE_URL=http://localhost:8000/api
|
||||
restart: unless-stopped
|
||||
|
||||
# Nginx反向代理 (可选)
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
container_name: algorithm-showcase-nginx
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/nginx.conf
|
||||
- ./ssl:/etc/nginx/ssl
|
||||
depends_on:
|
||||
- frontend
|
||||
- backend
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
minio_data:
|
||||
|
||||
networks:
|
||||
default:
|
||||
driver: bridge
|
||||
name: algorithm-showcase-network
|
||||
28
deploy/nginx.conf
Normal file
28
deploy/nginx.conf
Normal file
@@ -0,0 +1,28 @@
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
upstream backend {
|
||||
server backend:8000;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
# 前端静态文件
|
||||
location / {
|
||||
root /usr/share/nginx/html;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# API请求代理到后端
|
||||
location /api {
|
||||
proxy_pass http://backend;
|
||||
proxy_set_header Host $host;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user