feat: 增加 pm2部署和sh脚本

This commit is contained in:
helti
2024-12-14 18:11:44 +08:00
parent c9ee406372
commit 38f3f38403
4 changed files with 3006 additions and 0 deletions

View File

@@ -167,6 +167,12 @@ npm run build
npm run start
```
#### pm2 部署
```bash
sh ./deploy.sh
```
成功启动后程序会在控制台输出可访问的地址
### Vercel 部署

35
deploy.sh Normal file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
# 日志文件
LOG_FILE="deploy.log"
# 输出时间戳的日志函数
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a $LOG_FILE
}
# 错误处理函数
handle_error() {
log "错误: $1"
exit 1
}
# 开始拉去代码
log "开始拉取代码..."
git pull
# 开始部署
log "开始部署..."
# 安装依赖
log "正在安装依赖..."
npm install || handle_error "npm install 失败"
# 构建项目
log "正在构建项目..."
npm run build || handle_error "构建失败"
# 使用 pm2 重启或启动项目
log "正在启动/重启服务..."
pm2 restart daily-news || pm2 start ecosystem.config.js || handle_error "PM2 启动失败"
log "部署完成!"

15
ecosystem.config.js Normal file
View File

@@ -0,0 +1,15 @@
module.exports = {
apps: [{
name: 'daily-news',
script: 'npm',
args: 'start',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
PORT: 6688
}
}]
}

2950
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff