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