From a6aa4c6b72f1630d13d286ac53cb4766dd6469c7 Mon Sep 17 00:00:00 2001 From: dxin Date: Tue, 2 Dec 2025 14:22:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Enodejs-email=20=E6=B5=81?= =?UTF-8?q?=E6=B0=B4=E7=BA=BF=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/流水线配置/lessie_nodejs-email.conf | 86 ++++++++++++ jenkins/流水线配置/lessie_official_web.conf | 144 ++++++++++++-------- nginx/s1.jennie.im.conf | 8 ++ 3 files changed, 179 insertions(+), 59 deletions(-) create mode 100644 jenkins/流水线配置/lessie_nodejs-email.conf diff --git a/jenkins/流水线配置/lessie_nodejs-email.conf b/jenkins/流水线配置/lessie_nodejs-email.conf new file mode 100644 index 0000000..3d8076e --- /dev/null +++ b/jenkins/流水线配置/lessie_nodejs-email.conf @@ -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 '部署失败,请检查日志' + } + } +} diff --git a/jenkins/流水线配置/lessie_official_web.conf b/jenkins/流水线配置/lessie_official_web.conf index 54b49f6..71d73fd 100644 --- a/jenkins/流水线配置/lessie_official_web.conf +++ b/jenkins/流水线配置/lessie_official_web.conf @@ -1,64 +1,90 @@ pipeline { - agent any - environment { - DEPLOY_HOST = '49.51.46.148' // 目标机 IP 或域名 - DEPLOY_DIR = '/data/tengine/html/lessie_official' // 目标机部署目录 - } - stages { - stage('Checkout 代码') { - steps { - git branch: 'dev', credentialsId: 'fly_gitlab_auth', url: 'http://172.24.16.20/web/scalelink-frontend.git' - } + agent any + + environment { + // CODE_BRANCH = "dev" + 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" } - stage('Install & Build') { - steps { - sh """ - cd ${WORKSPACE}/projects/lessie' && - npm install --frozen-lockfile && - npm run build - """ - } - } - stage('同步文件') { - 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 """ - scp deploy.tar.gz ${DEPLOY_USER}@${DEPLOY_HOST}:/tmp/ - """ - // 2) 解压、安装依赖、重启 - sh """ - ssh ${DEPLOY_USER}@${DEPLOY_HOST} ' - mkdir -p ${DEPLOY_DIR} && - 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 - ' - """ + + stages { + stage('拉取代码') { + steps { + git branch: "${params.Code_branch}", + credentialsId: 'fly_gitlab_auth', + url: 'http://172.24.16.20/web/scalelink-frontend.git' + } + } + + stage('同步到本地机器') { + steps { + sh """ + ssh ${LOCKHOST_IP} 'rm -rf ${LOCKHOST_PROJECT_PATH}/*' && + rsync -az ${WORKSPACE}/ ${LOCKHOST_IP}:${LOCKHOST_PROJECT_PATH}/ + """ + } + } + + stage('依赖和构建') { + steps { + sh """ + ssh ${LOCKHOST_IP} "bash -lc \\" + cd ${LOCKHOST_PROJECT_PATH}/projects/lessie && + pnpm install --force && pnpm build && + tar -czf output.tar.gz .output + \\"" + """ + } + } + + stage('上传产物到机器1') { + steps { + sh """ + ssh ${LOCKHOST_IP} "bash -lc \\" + scp -r ${LOCKHOST_PROJECT_PATH}/projects/lessie/output.tar.gz ${WEB_HOST_IP_2}:${WEB_HOST_PROJECT_PATH}/ + \\"" + """ + } + } + + 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 '部署失败,请检查日志 ❌' - } - } } diff --git a/nginx/s1.jennie.im.conf b/nginx/s1.jennie.im.conf index 4db7750..8944092 100644 --- a/nginx/s1.jennie.im.conf +++ b/nginx/s1.jennie.im.conf @@ -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; location = /50x.html {