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_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/

109
Jenkinsfile vendored
View File

@ -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 {

View File

@ -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
```

View File

@ -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',

View File

@ -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')) {

View File

@ -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',

View File

@ -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)
});