feat: 添加生产环境部署和监控配置

- 新增生产环境部署脚本和文档
- 添加监控系统配置(Alertmanager, Prometheus, Grafana)
- 更新e2e测试用例以适配新环境
- 添加.env.production配置文件
- 优化Sentry初始化逻辑为动态加载
- 新增全局设置脚本以支持不同环境
This commit is contained in:
张翔
2026-03-09 16:37:23 +08:00
parent 261c45b4d9
commit 4ece85a9c3
14 changed files with 950 additions and 356 deletions
+51
View File
@@ -0,0 +1,51 @@
#!/bin/bash
set -e
echo "🚀 开始部署到生产环境..."
# 加载生产环境变量
export NODE_ENV=production
# 检查是否已安装依赖
if [ ! -d "node_modules" ]; then
echo "📦 安装依赖..."
npm ci --production=false
fi
# 运行测试
echo "🧪 运行测试..."
cd e2e
TEST_ENV=development npx playwright test --reporter=list
cd ..
# 构建生产版本
echo "🔨 构建生产版本..."
npm run build
# 备份当前版本(如果存在)
if [ -d "dist_backup" ]; then
rm -rf dist_backup
fi
if [ -d "dist" ]; then
echo "💾 备份当前版本..."
mv dist dist_backup
fi
# 启动生产服务器
echo "🌟 启动生产服务器..."
npm start &
# 等待服务器启动
echo "⏳ 等待服务器启动..."
sleep 10
# 健康检查
echo "🏥 健康检查..."
curl -f http://localhost:3000/api/health || {
echo "❌ 健康检查失败!"
exit 1
}
echo "✅ 部署成功!"
echo "📊 访问 http://localhost:3000"
+94
View File
@@ -0,0 +1,94 @@
#!/bin/bash
set -e
echo "🔍 配置监控和告警..."
# 创建监控配置目录
mkdir -p monitoring
# 创建Prometheus配置
cat > monitoring/prometheus.yml << 'EOF'
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'novalon-website'
static_configs:
- targets: ['localhost:3000']
metrics_path: '/api/health'
EOF
# 创建Grafana仪表板配置
cat > monitoring/grafana-dashboard.json << 'EOF'
{
"dashboard": {
"title": "Novalon Website Monitoring",
"panels": [
{
"title": "HTTP Requests",
"targets": [
{
"expr": "rate(http_requests_total[5m])"
}
]
},
{
"title": "Response Time",
"targets": [
{
"expr": "histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))"
}
]
},
{
"title": "Error Rate",
"targets": [
{
"expr": "rate(http_requests_total{status=~\"5..\"}[5m])"
}
]
}
]
}
}
EOF
# 创建告警规则
cat > monitoring/alerts.yml << 'EOF'
groups:
- name: novalon-website
rules:
- alert: HighErrorRate
expr: rate(http_requests_total{status=~\"5..\"}[5m]) > 0.05
for: 5m
labels:
severity: critical
annotations:
summary: "High error rate detected"
description: "Error rate is {{ $value }}"
- alert: HighResponseTime
expr: histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m])) > 1
for: 5m
labels:
severity: warning
annotations:
summary: "High response time detected"
description: "95th percentile response time is {{ $value }}s"
- alert: ServiceDown
expr: up{job=\"novalon-website\"} == 0
for: 1m
labels:
severity: critical
annotations:
summary: "Service is down"
description: "Novalon website service is not responding"
EOF
echo "✅ 监控和告警配置完成!"
echo "📊 Prometheus配置: monitoring/prometheus.yml"
echo "📈 Grafana仪表板: monitoring/grafana-dashboard.json"
echo "🚨 告警规则: monitoring/alerts.yml"