Update Jenkinsfile

This commit is contained in:
jose-rZM
2025-12-15 13:55:47 +01:00
parent 1085b42e54
commit 741fc78b96

109
Jenkinsfile vendored
View File

@@ -8,8 +8,8 @@ pipeline {
environment {
CI = 'true'
NODE_OPTIONS = '--max_old_space_size=2048'
APP_VERSION = "1.0.${BUILD_NUMBER}"
DOCKER_BUILDKIT = '1'
}
stages {
@@ -28,41 +28,13 @@ pipeline {
returnStdout: true
).trim()
}
echo "Last commit: ${env.COMMIT_AUTHOR}"
}
}
/* =========================
BACKEND (Python)
========================= */
stage('Backend: deps') {
agent {
docker {
image 'python:3.12'
args '-u root'
}
}
steps {
dir('backend') {
sh '''
set -e
python --version
python -m venv .venv
. .venv/bin/activate
pip install --upgrade pip
pip install -r requirements-dev.txt
'''
}
}
}
stage('Backend: lint & test') {
agent {
docker {
image 'python:3.12'
image 'python:3.11-slim'
args '-u root'
}
}
@@ -70,7 +42,10 @@ pipeline {
dir('backend') {
sh '''
set -e
python -m venv .venv
. .venv/bin/activate
pip install --upgrade pip
pip install -r requirements-dev.txt
ruff check app tests
pytest
'''
@@ -78,86 +53,43 @@ pipeline {
}
}
/* =========================
FRONTEND (Node)
========================= */
stage('Frontend: deps') {
stage('Frontend: check & build') {
agent {
docker {
image 'node:20'
image 'node:20-slim'
}
}
steps {
dir('frontend') {
sh '''
set -e
node --version
npm --version
npm install --no-progress --no-audit --prefer-offline
'''
}
}
}
stage('Frontend: check & test') {
agent {
docker {
image 'node:20'
}
}
steps {
dir('frontend') {
sh '''
set -e
npm run check
'''
}
}
}
stage('Frontend: build') {
agent {
docker {
image 'node:20'
}
}
steps {
dir('frontend') {
sh '''
set -e
npm run build
'''
}
}
}
/* =========================
DOCKER
========================= */
stage('Docker: build images') {
when {
expression {
fileExists('backend/Dockerfile') &&
fileExists('frontend/Dockerfile')
}
}
agent any
steps {
sh '''
set -e
docker version
docker build \
--build-arg APP_VERSION=${APP_VERSION} \
--build-arg GIT_COMMIT=${COMMIT_SHORT} \
--build-arg COMMIT_AUTHOR="${COMMIT_AUTHOR}" \
--build-arg BUILD_NUMBER=${BUILD_NUMBER} \
-t cafeteria-backend:${BUILD_NUMBER} ./backend
-t cafeteria-backend:latest \
-t cafeteria-backend:${BUILD_NUMBER} \
./backend
docker build \
-t cafeteria-frontend:${BUILD_NUMBER} ./frontend
-t cafeteria-frontend:latest \
-t cafeteria-frontend:${BUILD_NUMBER} \
./frontend
'''
}
}
@@ -168,20 +100,17 @@ pipeline {
sh '''
set -e
echo "Deploying build ${BUILD_NUMBER}"
docker rm -f cafeteria-backend cafeteria-frontend 2>/dev/null || true
docker run -d \
--name cafeteria-backend \
-p 8000:8000 \
cafeteria-backend:${BUILD_NUMBER}
cafeteria-backend:latest
docker run -d \
--name cafeteria-frontend \
-p 3000:80 \
cafeteria-frontend:${BUILD_NUMBER}
cafeteria-frontend:latest
'''
}
}
@@ -189,11 +118,11 @@ pipeline {
post {
always {
script {
node {
sh '''
docker image prune -a -f || true
docker builder prune -a -f || true
'''
cleanWs()
}
}
}
}
}