Compare commits
2 Commits
b07b715392
...
d42ab824bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d42ab824bc | ||
|
|
a6aa4c6b72 |
86
jenkins/流水线配置/lessie_nodejs-email.conf
Normal file
86
jenkins/流水线配置/lessie_nodejs-email.conf
Normal 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 '部署失败,请检查日志'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,64 +1,90 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
DEPLOY_HOST = '49.51.46.148' // 目标机 IP 或域名
|
// CODE_BRANCH = "dev"
|
||||||
DEPLOY_DIR = '/data/tengine/html/lessie_official' // 目标机部署目录
|
LOCKHOST_IP = "192.168.70.15"
|
||||||
|
LOCKHOST_PROJECT_PATH = "/root/cdx/scalelink-frontend"
|
||||||
|
WEB_HOST_IP_1 = "43.130.56.138"
|
||||||
|
WEB_HOST_IP_2 = "43.153.21.64"
|
||||||
|
WEB_HOST_PROJECT_PATH = "/data/webapps/lessie_official_web"
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout 代码') {
|
stage('拉取代码') {
|
||||||
steps {
|
steps {
|
||||||
git branch: 'dev', credentialsId: 'fly_gitlab_auth', url: 'http://172.24.16.20/web/scalelink-frontend.git'
|
git branch: "${params.Code_branch}",
|
||||||
|
credentialsId: 'fly_gitlab_auth',
|
||||||
|
url: 'http://172.24.16.20/web/scalelink-frontend.git'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Install & Build') {
|
|
||||||
|
stage('同步到本地机器') {
|
||||||
steps {
|
steps {
|
||||||
sh """
|
sh """
|
||||||
cd ${WORKSPACE}/projects/lessie' &&
|
ssh ${LOCKHOST_IP} 'rm -rf ${LOCKHOST_PROJECT_PATH}/*' &&
|
||||||
npm install --frozen-lockfile &&
|
rsync -az ${WORKSPACE}/ ${LOCKHOST_IP}:${LOCKHOST_PROJECT_PATH}/
|
||||||
npm run build
|
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('同步文件') {
|
|
||||||
|
stage('依赖和构建') {
|
||||||
steps {
|
steps {
|
||||||
// 打包必要文件:.output、package.json、pnpm-lock.yaml
|
|
||||||
# sh '''
|
|
||||||
# rm -rf deploy.tar.gz
|
|
||||||
# tar czf deploy.tar.gz \
|
|
||||||
# .output package.json pnpm-lock.yaml
|
|
||||||
# '''
|
|
||||||
# archiveArtifacts artifacts: 'deploy.tar.gz'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('Deploy to Target') {
|
|
||||||
steps {
|
|
||||||
sshagent([SSH_CRED]) {
|
|
||||||
// 1) 传输压缩包
|
|
||||||
sh """
|
sh """
|
||||||
scp deploy.tar.gz ${DEPLOY_USER}@${DEPLOY_HOST}:/tmp/
|
ssh ${LOCKHOST_IP} "bash -lc \\"
|
||||||
|
cd ${LOCKHOST_PROJECT_PATH}/projects/lessie &&
|
||||||
|
pnpm install --force && pnpm build &&
|
||||||
|
tar -czf output.tar.gz .output
|
||||||
|
\\""
|
||||||
"""
|
"""
|
||||||
// 2) 解压、安装依赖、重启
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('上传产物到机器1') {
|
||||||
|
steps {
|
||||||
sh """
|
sh """
|
||||||
ssh ${DEPLOY_USER}@${DEPLOY_HOST} '
|
ssh ${LOCKHOST_IP} "bash -lc \\"
|
||||||
mkdir -p ${DEPLOY_DIR} &&
|
scp -r ${LOCKHOST_PROJECT_PATH}/projects/lessie/output.tar.gz ${WEB_HOST_IP_2}:${WEB_HOST_PROJECT_PATH}/
|
||||||
tar xzf /tmp/deploy.tar.gz -C ${DEPLOY_DIR} &&
|
\\""
|
||||||
cd ${DEPLOY_DIR} &&
|
"""
|
||||||
# 安装生产依赖
|
}
|
||||||
npm install --production &&
|
}
|
||||||
# 重启 pm2 服务
|
|
||||||
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 '部署失败,请检查日志 ❌'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user