jenkinsfile

This commit is contained in:
Araozu 2023-11-04 10:05:47 -05:00
parent 3c334093de
commit 31d7e8d3da

View File

@ -1,29 +1,25 @@
pipeline { pipeline {
agent any agent any
stages { stages {
stage('Build backend') { stage('Build backend') {
agent { environment {
docker { PATH = "/var/lib/jenkins/.cargo/bin:${env.PATH}"
image 'rust:buster'
// args '-v /srv/jenkins/.cargo:/root/.cargo'
// reuseNode true
} }
}
steps { steps {
sh "sh cargo install"
sh "sh cargo --version"
sh "cd ${env.WORKSPACE}/backend" sh "cd ${env.WORKSPACE}/backend"
sh "touch .env"
sh "echo DATABASE_URL=mysql://educa7ls_user:123456789a*@md-89.webhostbox.net:3306/educa7ls_plataforma >> .env"
sh "echo RENIEC_API=apis-token-1.aTSI1U7KEuT-6bbbCguH-4Y8TI6KS73N >> .env"
sh "cargo build --release" sh "cargo build --release"
} }
} }
stage('Build frontend') { stage('Build frontend') {
agent { environment {
docker { image 'node:18.18.0-alpine3.18' } PATH = "/var/lib/jenkins/.nvm/versions/node/v18.18.0/bin:${env.PATH}"
} }
steps { steps {
sh "cd ${env.WORKSPACE}/frontend" sh "cd ${env.WORKSPACE}/frontend"
sh "echo VITE_BACKEND_URL=https://system.eegsac.com >> .env.production"
sh "pnpm i" sh "pnpm i"
sh "pnpm build" sh "pnpm build"
} }
@ -34,9 +30,16 @@ pipeline {
sh "touch .env" sh "touch .env"
sh "echo DATABASE_URL=mysql://educa7ls_user:123456789a*@md-89.webhostbox.net:3306/educa7ls_plataforma >> .env" sh "echo DATABASE_URL=mysql://educa7ls_user:123456789a*@md-89.webhostbox.net:3306/educa7ls_plataforma >> .env"
sh "echo RENIEC_API=apis-token-1.aTSI1U7KEuT-6bbbCguH-4Y8TI6KS73N >> .env" sh "echo RENIEC_API=apis-token-1.aTSI1U7KEuT-6bbbCguH-4Y8TI6KS73N >> .env"
sh "echo CLASSROOM_URL=https://aulavirtual.eegsac.com >> .env"
sh "echo CLASSROOM_USER=admin >> .env"
sh "echo CLASSROOM_PASSWORD=YVL1@N4_PaL0-93\\$ >> .env"
sh "echo RUST_LOG=info >> .env"
} }
} }
stage("Stop old PM2 processes") { stage("Stop old PM2 processes") {
environment {
PATH = "/var/lib/jenkins/.local/share/pnpm:${env.PATH}"
}
steps { steps {
sh "pm2 stop ${env.JOB_BASE_NAME} || true" sh "pm2 stop ${env.JOB_BASE_NAME} || true"
sh "pm2 delete ${env.JOB_BASE_NAME} || true" sh "pm2 delete ${env.JOB_BASE_NAME} || true"
@ -49,20 +52,25 @@ pipeline {
} }
stage("Copy deploy files") { stage("Copy deploy files") {
steps { steps {
sh "mkdir -p /var/deploys/${env.JOB_BASE_NAME}/${env.BUILD_TAG}/static" sh "mkdir -p /var/deploys/${env.JOB_BASE_NAME}/static"
// Copy backend binary // Copy backend binary
sh "cp ${env.WORKSPACE}/backend/target/release/backend /var/deploys/${env.JOB_BASE_NAME}/${env.BUILD_TAG}/" sh "cp ${env.WORKSPACE}/backend/target/release/backend /var/deploys/${env.JOB_BASE_NAME}/"
// Copy frontend static files // Copy frontend static files
sh "cp -r ${env.WORKSPACE}/frontend/dist/* /var/deploys/${env.JOB_BASE_NAME}/${env.BUILD_TAG}/static/" sh "cp -r ${env.WORKSPACE}/frontend/dist/* /var/deploys/${env.JOB_BASE_NAME}/static/"
// Copy ENV file // Copy ENV file for RUST
sh "cp ${env.WORKSPACE}/.env /var/deploys/${env.JOB_BASE_NAME}/${env.BUILD_TAG}/" sh "cp ${env.WORKSPACE}/.env /var/deploys/${env.JOB_BASE_NAME}/"
// Make log dir
sh "mkdir -p /var/deploys/${env.JOB_BASE_NAME}/request-logs/"
} }
} }
stage('Start app with PM2') { stage('Start app with PM2') {
environment {
PATH = "/var/lib/jenkins/.local/share/pnpm:${env.PATH}"
}
steps { steps {
sh "cd /var/deploys/${env.JOB_BASE_NAME}/${env.BUILD_TAG}/" sh "cd /var/deploys/${env.JOB_BASE_NAME}/"
// ROCKET_PORT=3333 sh "ROCKET_PORT=3333 pm2 start backend --name ${env.JOB_BASE_NAME}"
sh "pm2 start backend --name ${env.JOB_BASE_NAME}" sh "pm2 save"
} }
} }
} }