From 567da81bbed6b55ab4f999826de59b3f62ee5c46 Mon Sep 17 00:00:00 2001 From: vriti Date: Thu, 12 Jun 2025 14:40:23 +0530 Subject: [PATCH] jenkins, automation tst1 --- .env.example | 2 +- Jenkinsfile | 111 +++++++++--------------- readme.md | 2 +- src/config/index.js | 13 ++- src/controllers/onboardingController.js | 2 +- src/middlewares/security.js | 2 +- src/services/secondaryWebsocket.js | 6 +- 7 files changed, 56 insertions(+), 82 deletions(-) diff --git a/.env.example b/.env.example index d50ac15..590eaed 100644 --- a/.env.example +++ b/.env.example @@ -15,7 +15,7 @@ JWT_REFRESH_TOKEN_SECRET=Lx$Z7#T2^d&n9!Y4%K8@Fcg*m#qX5p@wL JWT_ACCESS_TOKEN_EXPIRY=5h JWT_REFRESH_TOKEN_EXPIRY=7d -# BACK_URL = https://backend.spurrinai.com/ +# BACK_URL = http://localhost:3000/ BACK_URL = http://localhost:3000/ DOMAIN_url = http://localhost:3000/ FLASK_BASE_URL = http://localhost:5000/ diff --git a/Jenkinsfile b/Jenkinsfile index be62b5d..f15e4d4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,17 +2,17 @@ pipeline { agent any environment { - SSH_CREDENTIALS = 'spurrin-backend-dev' + SSH_CREDENTIALS = 'hookpilot' GIT_CREDENTIALS = 'gitea-cred' - REMOTE_SERVER = 'ubuntu@160.187.166.67' - REPO_HTTPS_URL = 'https://git.tech4biz.wiki/rohit/spurrin-backend.git' + REMOTE_SERVER = 'ubuntu@160.187.167.213' + REPO_HTTPS_URL = 'https://git.tech4biz.wiki/rohit/spurrin-cleaned-backend-dev.git' BRANCH = 'main' - REMOTE_DIR = '/home/ubuntu/spurrin-cleaned-node' + REMOTE_DIR = '/home/ubuntu/spurrin-cleaned-backend-dev' BACKUP_UPLOADS_DIR = '/home/ubuntu/uploads_backup' VENV_PYTHON = '../venv/bin/python' - NODE_BIN_PATH = '/home/ubuntu/.nvm/versions/node/v22.12.0/bin' + NODE_BIN_PATH = '/home/ubuntu/.nvm/versions/node/v22.15.0/bin' NOTIFY_EMAIL = 'jassim.mohammed@tech4biz.io' } @@ -29,76 +29,47 @@ pipeline { } } -stage('Update Repo on Remote') { - steps { - echo '🔄 Pulling latest code on remote server with conditional restore and fresh backup...' - withCredentials([usernamePassword(credentialsId: "${GIT_CREDENTIALS}", usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) { - sshagent(credentials: [SSH_CREDENTIALS]) { - sh """ - ssh ${REMOTE_SERVER} ' - set -e + stage('Update Repo on Remote') { + steps { + echo '🔄 Pulling latest code on remote server with conditional restore and fresh backup...' + withCredentials([usernamePassword(credentialsId: "${GIT_CREDENTIALS}", usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) { + sshagent(credentials: [SSH_CREDENTIALS]) { + sh """ + ssh ${REMOTE_SERVER} ' + set -e - # Clean old backup folder - echo "🗑️ Removing old backups..." - rm -rf ${BACKUP_UPLOADS_DIR} - mkdir -p ${BACKUP_UPLOADS_DIR} + echo "🗑️ Removing old backups..." + rm -rf ${BACKUP_UPLOADS_DIR} + mkdir -p ${BACKUP_UPLOADS_DIR} - echo "📦 Backing up existing data..." - if [ -d ${REMOTE_DIR}/uploads ]; then - cp -a ${REMOTE_DIR}/uploads ${BACKUP_UPLOADS_DIR}/ - fi + echo "📦 Backing up existing data..." + [ -d ${REMOTE_DIR}/uploads ] && cp -a ${REMOTE_DIR}/uploads ${BACKUP_UPLOADS_DIR}/ + [ -d ${REMOTE_DIR}/hospital_data ] && cp -a ${REMOTE_DIR}/hospital_data ${BACKUP_UPLOADS_DIR}/ + [ -f ${REMOTE_DIR}/.env ] && cp ${REMOTE_DIR}/.env ${BACKUP_UPLOADS_DIR}/.env + [ -d ${REMOTE_DIR}/certificates ] && cp -a ${REMOTE_DIR}/certificates ${BACKUP_UPLOADS_DIR}/ - if [ -d ${REMOTE_DIR}/hospital_data ]; then - cp -a ${REMOTE_DIR}/hospital_data ${BACKUP_UPLOADS_DIR}/ - fi + if [ -d ${REMOTE_DIR}/.git ]; then + echo "🔁 Repo exists. Pulling latest changes..." + cd ${REMOTE_DIR} + git stash push --include-untracked --message "temp-backup-before-pull" || true + git pull origin ${BRANCH} + git stash pop || true + else + echo "📥 Repo not found. Cloning fresh and restoring backup..." + rm -rf ${REMOTE_DIR} + git clone -b ${BRANCH} https://${GIT_USER}:${GIT_PASS}@${REPO_HTTPS_URL#https://} ${REMOTE_DIR} - if [ -f ${REMOTE_DIR}/.env ]; then - cp ${REMOTE_DIR}/.env ${BACKUP_UPLOADS_DIR}/.env - fi - - if [ -d ${REMOTE_DIR}/certificates ]; then - cp -a ${REMOTE_DIR}/certificates ${BACKUP_UPLOADS_DIR}/ - fi - - # Pull latest changes without deleting local files/folders - if [ -d ${REMOTE_DIR}/.git ]; then - echo "🔁 Repo exists. Pulling latest changes..." - cd ${REMOTE_DIR} - git stash push --include-untracked --message "temp-backup-before-pull" || true - git pull origin ${BRANCH} - git stash pop || true - else - echo "📥 Repo not found. Cloning fresh and restoring backup..." - rm -rf ${REMOTE_DIR} - git clone -b ${BRANCH} https://${GIT_USER}:${GIT_PASS}@git.tech4biz.wiki/rohit/spurrin-backend.git ${REMOTE_DIR} - - # Restore backups only on fresh clone... - - # Restore backup only on fresh clone - if [ -d ${BACKUP_UPLOADS_DIR}/uploads ]; then - cp -a ${BACKUP_UPLOADS_DIR}/uploads ${REMOTE_DIR}/ - fi - - if [ -d ${BACKUP_UPLOADS_DIR}/hospital_data ]; then - cp -a ${BACKUP_UPLOADS_DIR}/hospital_data ${REMOTE_DIR}/ - fi - - if [ -f ${BACKUP_UPLOADS_DIR}/.env ]; then - cp ${BACKUP_UPLOADS_DIR}/.env ${REMOTE_DIR}/.env - fi - - if [ -d ${BACKUP_UPLOADS_DIR}/certificates ]; then - cp -a ${BACKUP_UPLOADS_DIR}/certificates ${REMOTE_DIR}/ - fi - fi - ' - """ + [ -d ${BACKUP_UPLOADS_DIR}/uploads ] && cp -a ${BACKUP_UPLOADS_DIR}/uploads ${REMOTE_DIR}/ + [ -d ${BACKUP_UPLOADS_DIR}/hospital_data ] && cp -a ${BACKUP_UPLOADS_DIR}/hospital_data ${REMOTE_DIR}/ + [ -f ${BACKUP_UPLOADS_DIR}/.env ] && cp ${BACKUP_UPLOADS_DIR}/.env ${REMOTE_DIR}/.env + [ -d ${BACKUP_UPLOADS_DIR}/certificates ] && cp -a ${BACKUP_UPLOADS_DIR}/certificates ${REMOTE_DIR}/ + fi + ' + """ + } + } } } - } -} - - stage('Install & Start Services') { steps { @@ -143,4 +114,4 @@ stage('Update Repo on Remote') { body: "The deployment of spurrin-cleaned-node to ${REMOTE_SERVER} failed. Please check Jenkins logs.\n\nRegards,\nJenkins" } } -} \ No newline at end of file +} diff --git a/readme.md b/readme.md index 12cc417..186c922 100644 --- a/readme.md +++ b/readme.md @@ -32,7 +32,7 @@ project-root/ 1. Clone the repository: ```bash -git clone -b dev https://git.tech4biz.wiki/Tech4Biz-Services/spurrin-cleaned-node.git +git clone https://git.tech4biz.wiki/rohit/spurrin-cleaned-backend-dev.git cd spurrinai-backend ``` diff --git a/src/config/index.js b/src/config/index.js index f4f4dc9..0a0b33b 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -1,13 +1,15 @@ - +console.log('Loading configuration...'); +console.log('Current environment:', process.env.NODE_ENV); +require('dotenv').config(); const config = { development: { database: { host: process.env.DB_HOST, - user: process.env.DB_USER , - password: process.env.DB_PASSWORD , + user: process.env.DB_USER, + password: process.env.DB_PASSWORD, database: process.env.DB_NAME, waitForConnections: true, connectionLimit: 10, @@ -23,8 +25,9 @@ const config = { port: process.env.PORT, cors: { origin: [ - 'http://localhost:5173', 'http://localhost:5174', + 'http://192.168.1.25:5174', + 'http://localhost:3000', 'http://localhost:3000', 'http://localhost:8081', 'http://testhospital.localhost:5174', @@ -57,7 +60,9 @@ const config = { port: process.env.PORT || 3000, cors: { origin: [ + 'http://localhost:5174', 'https://spurrinai.com', + 'http://192.168.1.25:5174', 'https://www.spurrinai.com', 'https://spurrinai.info', 'https://www.spurrinai.info', diff --git a/src/controllers/onboardingController.js b/src/controllers/onboardingController.js index 957a06c..7751a3c 100644 --- a/src/controllers/onboardingController.js +++ b/src/controllers/onboardingController.js @@ -4,7 +4,7 @@ exports.getOnboardingSteps = async (req, res) => { try { const { userId } = req.params; const result = await onboardingService.getOnboardingSteps(userId, req.user.role, req.user.id); - res.status(200).json(result); + res.status(404).json(result); } catch (error) { console.error('Error fetching onboarding steps:', error.message); if (error.message.includes('not authorized')) { diff --git a/src/middlewares/security.js b/src/middlewares/security.js index 25b8d99..bbd8b0a 100644 --- a/src/middlewares/security.js +++ b/src/middlewares/security.js @@ -71,8 +71,8 @@ const corsOptions = { const allowedOrigins = [ 'http://192.168.1.19:8081', - 'http://localhost:5173', 'http://localhost:5174', + 'http://localhost:3000', 'https://spurrinai.com', 'https://www.spurrinai.com', 'http://localhost:3000', diff --git a/src/services/secondaryWebsocket.js b/src/services/secondaryWebsocket.js index af25485..0f28310 100644 --- a/src/services/secondaryWebsocket.js +++ b/src/services/secondaryWebsocket.js @@ -7,11 +7,9 @@ const db = require("../config/database"); const base_url = process.env.back_url; - - const server = https.createServer({ - // cert: fs.readFileSync(process.env.SSL_CERT), - // key: fs.readFileSync(process.env.SSL_KEY) + cert: fs.readFileSync(process.env.SSL_CERT), + key: fs.readFileSync(process.env.SSL_KEY) });