jenkins, automation tst1

This commit is contained in:
vriti 2025-06-12 14:40:23 +05:30
parent acbc52e946
commit 567da81bbe
7 changed files with 56 additions and 82 deletions

View File

@ -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_ACCESS_TOKEN_EXPIRY=5h
JWT_REFRESH_TOKEN_EXPIRY=7d JWT_REFRESH_TOKEN_EXPIRY=7d
# BACK_URL = https://backend.spurrinai.com/ # BACK_URL = http://localhost:3000/
BACK_URL = http://localhost:3000/ BACK_URL = http://localhost:3000/
DOMAIN_url = http://localhost:3000/ DOMAIN_url = http://localhost:3000/
FLASK_BASE_URL = http://localhost:5000/ FLASK_BASE_URL = http://localhost:5000/

61
Jenkinsfile vendored
View File

@ -2,17 +2,17 @@ pipeline {
agent any agent any
environment { environment {
SSH_CREDENTIALS = 'spurrin-backend-dev' SSH_CREDENTIALS = 'hookpilot'
GIT_CREDENTIALS = 'gitea-cred' GIT_CREDENTIALS = 'gitea-cred'
REMOTE_SERVER = 'ubuntu@160.187.166.67' REMOTE_SERVER = 'ubuntu@160.187.167.213'
REPO_HTTPS_URL = 'https://git.tech4biz.wiki/rohit/spurrin-backend.git' REPO_HTTPS_URL = 'https://git.tech4biz.wiki/rohit/spurrin-cleaned-backend-dev.git'
BRANCH = 'main' BRANCH = 'main'
REMOTE_DIR = '/home/ubuntu/spurrin-cleaned-node' REMOTE_DIR = '/home/ubuntu/spurrin-cleaned-backend-dev'
BACKUP_UPLOADS_DIR = '/home/ubuntu/uploads_backup' BACKUP_UPLOADS_DIR = '/home/ubuntu/uploads_backup'
VENV_PYTHON = '../venv/bin/python' 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' NOTIFY_EMAIL = 'jassim.mohammed@tech4biz.io'
} }
@ -29,7 +29,7 @@ pipeline {
} }
} }
stage('Update Repo on Remote') { stage('Update Repo on Remote') {
steps { steps {
echo '🔄 Pulling latest code on remote server with conditional restore and fresh backup...' echo '🔄 Pulling latest code on remote server with conditional restore and fresh backup...'
withCredentials([usernamePassword(credentialsId: "${GIT_CREDENTIALS}", usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) { withCredentials([usernamePassword(credentialsId: "${GIT_CREDENTIALS}", usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
@ -38,29 +38,16 @@ stage('Update Repo on Remote') {
ssh ${REMOTE_SERVER} ' ssh ${REMOTE_SERVER} '
set -e set -e
# Clean old backup folder
echo "🗑️ Removing old backups..." echo "🗑️ Removing old backups..."
rm -rf ${BACKUP_UPLOADS_DIR} rm -rf ${BACKUP_UPLOADS_DIR}
mkdir -p ${BACKUP_UPLOADS_DIR} mkdir -p ${BACKUP_UPLOADS_DIR}
echo "📦 Backing up existing data..." echo "📦 Backing up existing data..."
if [ -d ${REMOTE_DIR}/uploads ]; then [ -d ${REMOTE_DIR}/uploads ] && cp -a ${REMOTE_DIR}/uploads ${BACKUP_UPLOADS_DIR}/
cp -a ${REMOTE_DIR}/uploads ${BACKUP_UPLOADS_DIR}/ [ -d ${REMOTE_DIR}/hospital_data ] && cp -a ${REMOTE_DIR}/hospital_data ${BACKUP_UPLOADS_DIR}/
fi [ -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 [ -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 if [ -d ${REMOTE_DIR}/.git ]; then
echo "🔁 Repo exists. Pulling latest changes..." echo "🔁 Repo exists. Pulling latest changes..."
cd ${REMOTE_DIR} cd ${REMOTE_DIR}
@ -70,35 +57,19 @@ stage('Update Repo on Remote') {
else else
echo "📥 Repo not found. Cloning fresh and restoring backup..." echo "📥 Repo not found. Cloning fresh and restoring backup..."
rm -rf ${REMOTE_DIR} rm -rf ${REMOTE_DIR}
git clone -b ${BRANCH} https://${GIT_USER}:${GIT_PASS}@git.tech4biz.wiki/rohit/spurrin-backend.git ${REMOTE_DIR} git clone -b ${BRANCH} https://${GIT_USER}:${GIT_PASS}@${REPO_HTTPS_URL#https://} ${REMOTE_DIR}
# Restore backups only on fresh clone... [ -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}/
# Restore backup only on fresh clone [ -f ${BACKUP_UPLOADS_DIR}/.env ] && cp ${BACKUP_UPLOADS_DIR}/.env ${REMOTE_DIR}/.env
if [ -d ${BACKUP_UPLOADS_DIR}/uploads ]; then [ -d ${BACKUP_UPLOADS_DIR}/certificates ] && cp -a ${BACKUP_UPLOADS_DIR}/certificates ${REMOTE_DIR}/
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 fi
' '
""" """
} }
} }
} }
} }
stage('Install & Start Services') { stage('Install & Start Services') {
steps { steps {

View File

@ -32,7 +32,7 @@ project-root/
1. Clone the repository: 1. Clone the repository:
```bash ```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 cd spurrinai-backend
``` ```

View File

@ -1,13 +1,15 @@
console.log('Loading configuration...');
console.log('Current environment:', process.env.NODE_ENV);
require('dotenv').config();
const config = { const config = {
development: { development: {
database: { database: {
host: process.env.DB_HOST, host: process.env.DB_HOST,
user: process.env.DB_USER , user: process.env.DB_USER,
password: process.env.DB_PASSWORD , password: process.env.DB_PASSWORD,
database: process.env.DB_NAME, database: process.env.DB_NAME,
waitForConnections: true, waitForConnections: true,
connectionLimit: 10, connectionLimit: 10,
@ -23,8 +25,9 @@ const config = {
port: process.env.PORT, port: process.env.PORT,
cors: { cors: {
origin: [ origin: [
'http://localhost:5173',
'http://localhost:5174', 'http://localhost:5174',
'http://192.168.1.25:5174',
'http://localhost:3000',
'http://localhost:3000', 'http://localhost:3000',
'http://localhost:8081', 'http://localhost:8081',
'http://testhospital.localhost:5174', 'http://testhospital.localhost:5174',
@ -57,7 +60,9 @@ const config = {
port: process.env.PORT || 3000, port: process.env.PORT || 3000,
cors: { cors: {
origin: [ origin: [
'http://localhost:5174',
'https://spurrinai.com', 'https://spurrinai.com',
'http://192.168.1.25:5174',
'https://www.spurrinai.com', 'https://www.spurrinai.com',
'https://spurrinai.info', 'https://spurrinai.info',
'https://www.spurrinai.info', 'https://www.spurrinai.info',

View File

@ -4,7 +4,7 @@ exports.getOnboardingSteps = async (req, res) => {
try { try {
const { userId } = req.params; const { userId } = req.params;
const result = await onboardingService.getOnboardingSteps(userId, req.user.role, req.user.id); const result = await onboardingService.getOnboardingSteps(userId, req.user.role, req.user.id);
res.status(200).json(result); res.status(404).json(result);
} catch (error) { } catch (error) {
console.error('Error fetching onboarding steps:', error.message); console.error('Error fetching onboarding steps:', error.message);
if (error.message.includes('not authorized')) { if (error.message.includes('not authorized')) {

View File

@ -71,8 +71,8 @@ const corsOptions = {
const allowedOrigins = [ const allowedOrigins = [
'http://192.168.1.19:8081', 'http://192.168.1.19:8081',
'http://localhost:5173',
'http://localhost:5174', 'http://localhost:5174',
'http://localhost:3000',
'https://spurrinai.com', 'https://spurrinai.com',
'https://www.spurrinai.com', 'https://www.spurrinai.com',
'http://localhost:3000', 'http://localhost:3000',

View File

@ -7,11 +7,9 @@ const db = require("../config/database");
const base_url = process.env.back_url; const base_url = process.env.back_url;
const server = https.createServer({ const server = https.createServer({
// cert: fs.readFileSync(process.env.SSL_CERT), cert: fs.readFileSync(process.env.SSL_CERT),
// key: fs.readFileSync(process.env.SSL_KEY) key: fs.readFileSync(process.env.SSL_KEY)
}); });