Compare commits

...

2 Commits

Author SHA1 Message Date
dxin
d42ab824bc Merge branch 'main' of http://8.134.11.35:3000/dxin/Work-configuration-file 2025-12-02 14:22:19 +08:00
dxin
a6aa4c6b72 新增nodejs-email 流水线脚本 2025-12-02 14:22:15 +08:00
3 changed files with 179 additions and 59 deletions

View File

@@ -0,0 +1,86 @@
pipeline {
agent any
parameters {
gitParameter(
branchFilter: 'origin/(.*)',
defaultValue: 'main',
name: 'GIT_BRANCH',
type: 'PT_BRANCH_TAG',
selectedValue: 'DEFAULT',
sortMode: 'NONE',
description: '选择代码分支: ',
quickFilterEnabled: true,
tagFilter: '*',
listSize: "5"
)
}
environment {
REMOTE_HOST = '43.130.56.138'
REMOTE_PROJECT_PATH = '/data/webapps/nodejs-email'
}
stages {
stage('Checkout 代码') {
steps {
git branch: "${params.GIT_BRANCH}", credentialsId: 'fly_gitlab_auth', url: 'http://172.24.16.20/nodejs/nodejs-email.git'
}
}
stage('生成 .env 文件') {
steps {
sh """
cd ${WORKSPACE}
# 清空或创建文件
cat << 'EOF' > .env
GOOGLE_CLIENT_ID=184829050868-h21pf2mj6c51e1hveop30arbt5mqqr0v.apps.googleusercontent.com
GOOGLE_SECRET_ID=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
PORT=3005
DATABASE_URL="mysql://system:System8888!@10.0.0.10:3306/creator_contact_record?charset=utf8mb4&parseTime=true&loc=Local"
EOF
echo '查看 .env 文件内容'
cat .env
"""
}
}
stage('同步文件') {
steps {
sh """
ssh ${REMOTE_HOST} 'mkdir -p ${REMOTE_PROJECT_PATH}'
rsync -avz --delete --exclude='node_modules' ${WORKSPACE}/ ${REMOTE_HOST}:${REMOTE_PROJECT_PATH}/
"""
}
}
stage('安装 & 启动服务') {
steps {
sh """
ssh ${REMOTE_HOST} '
cd ${REMOTE_PROJECT_PATH} &&
pm2 delete index || true &&
pm2 list &&
nvm use 20.19.6 &&
npm install &&
npx prisma generate &&
pm2 start index.js &&
pm2 save
'
"""
}
}
}
post {
success {
echo '部署成功'
}
failure {
echo '部署失败,请检查日志'
}
}
}

View File

@@ -1,64 +1,90 @@
pipeline { pipeline {
agent any agent any
environment {
DEPLOY_HOST = '49.51.46.148' // 目标机 IP 或域名 environment {
DEPLOY_DIR = '/data/tengine/html/lessie_official' // 目标机部署目录 // CODE_BRANCH = "dev"
} LOCKHOST_IP = "192.168.70.15"
stages { LOCKHOST_PROJECT_PATH = "/root/cdx/scalelink-frontend"
stage('Checkout 代码') { WEB_HOST_IP_1 = "43.130.56.138"
steps { WEB_HOST_IP_2 = "43.153.21.64"
git branch: 'dev', credentialsId: 'fly_gitlab_auth', url: 'http://172.24.16.20/web/scalelink-frontend.git' WEB_HOST_PROJECT_PATH = "/data/webapps/lessie_official_web"
}
} }
stage('Install & Build') {
steps { stages {
sh """ stage('拉取代码') {
cd ${WORKSPACE}/projects/lessie' && steps {
npm install --frozen-lockfile && git branch: "${params.Code_branch}",
npm run build credentialsId: 'fly_gitlab_auth',
""" url: 'http://172.24.16.20/web/scalelink-frontend.git'
} }
} }
stage('同步文件') {
steps { stage('同步到本地机器') {
// 打包必要文件:.output、package.json、pnpm-lock.yaml steps {
# sh ''' sh """
# rm -rf deploy.tar.gz ssh ${LOCKHOST_IP} 'rm -rf ${LOCKHOST_PROJECT_PATH}/*' &&
# tar czf deploy.tar.gz \ rsync -az ${WORKSPACE}/ ${LOCKHOST_IP}:${LOCKHOST_PROJECT_PATH}/
# .output package.json pnpm-lock.yaml """
# ''' }
# archiveArtifacts artifacts: 'deploy.tar.gz' }
}
} stage('依赖和构建') {
stage('Deploy to Target') { steps {
steps { sh """
sshagent([SSH_CRED]) { ssh ${LOCKHOST_IP} "bash -lc \\"
// 1) 传输压缩包 cd ${LOCKHOST_PROJECT_PATH}/projects/lessie &&
sh """ pnpm install --force && pnpm build &&
scp deploy.tar.gz ${DEPLOY_USER}@${DEPLOY_HOST}:/tmp/ tar -czf output.tar.gz .output
""" \\""
// 2) 解压、安装依赖、重启 """
sh """ }
ssh ${DEPLOY_USER}@${DEPLOY_HOST} ' }
mkdir -p ${DEPLOY_DIR} &&
tar xzf /tmp/deploy.tar.gz -C ${DEPLOY_DIR} && stage('上传产物到机器1') {
cd ${DEPLOY_DIR} && steps {
# 安装生产依赖 sh """
npm install --production && ssh ${LOCKHOST_IP} "bash -lc \\"
# 重启 pm2 服务 scp -r ${LOCKHOST_PROJECT_PATH}/projects/lessie/output.tar.gz ${WEB_HOST_IP_2}:${WEB_HOST_PROJECT_PATH}/
pm2 reload nuxt-app || pm2 start .output/server/index.mjs --name nuxt-app \\""
' """
""" }
}
stage('启动机器1') {
steps {
sh """
ssh ${WEB_HOST_IP_2} '
cd ${WEB_HOST_PROJECT_PATH} && pm2 list &&
pm2 delete lessie-official-web --silent || true &&
tar -zxf output.tar.gz &&
pm2 start .output/server/index.mjs --name lessie-official-web --output ./nuxt-out.log --error ./nuxt-error.log
'
"""
}
}
stage('上传产物到机器2') {
steps {
sh """
ssh ${LOCKHOST_IP} "bash -lc \\"
scp -r ${LOCKHOST_PROJECT_PATH}/projects/lessie/output.tar.gz ${WEB_HOST_IP_1}:${WEB_HOST_PROJECT_PATH}/
\\""
"""
}
}
stage('启动机器2') {
steps {
sh """
ssh ${WEB_HOST_IP_1} '
bash &&
cd ${WEB_HOST_PROJECT_PATH} && pm2 list &&
pm2 delete lessie-official-web --silent || true &&
tar -zxf output.tar.gz &&
pm2 start .output/server/index.mjs --name lessie-official-web --output ./nuxt-out.log --error ./nuxt-error.log
'
"""
}
} }
}
} }
}
post {
success {
echo '部署成功 🎉'
}
failure {
echo '部署失败,请检查日志 ❌'
}
}
} }

View File

@@ -883,6 +883,14 @@ server {
} }
} }
location /api/gmail {
proxy_pass http://10.0.0.10:3005;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
# 错误页面 # 错误页面
error_page 500 502 503 504 /50x.html; error_page 500 502 503 504 /50x.html;
location = /50x.html { location = /50x.html {