the-tip-top-backend/Jenkinsfile

113 lines
3.7 KiB
Groovy
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

pipeline {
agent any
environment {
REGISTRY_URL = "registry.wk-archi-o24a-15m-g3.fr"
IMAGE_NAME = "the-tip-top-frontend"
CONTAINER_NAME = "the-tip-top-frontend"
DEPLOY_PATH = "/srv/devops/the-tip-top"
DOMAIN = "dsp5-archi-o24a-15m-g3.fr"
API_URL = "https://api.${DOMAIN}"
}
stages {
stage('Checkout') {
steps {
echo "📦 Récupération du code source depuis Gitea..."
checkout scm
}
}
stage('Install dependencies') {
steps {
echo "📦 Installation des dépendances NPM..."
sh 'npm ci'
}
}
stage('Build Next.js') {
steps {
echo "⚙️ Compilation de lapplication Next.js (production)..."
sh 'npm run build'
}
}
stage('Build Docker image') {
steps {
echo "🐳 Construction de limage Docker frontend..."
sh '''
docker build -t ${REGISTRY_URL}/${IMAGE_NAME}:${BUILD_NUMBER} .
docker tag ${REGISTRY_URL}/${IMAGE_NAME}:${BUILD_NUMBER} ${REGISTRY_URL}/${IMAGE_NAME}:latest
'''
}
}
stage('Push to Registry') {
steps {
echo "📤 Envoi de limage vers le registre privé..."
withCredentials([usernamePassword(credentialsId: 'registry-credentials', usernameVariable: 'REG_USER', passwordVariable: 'REG_PASS')]) {
sh '''
echo "$REG_PASS" | docker login ${REGISTRY_URL} -u "$REG_USER" --password-stdin
docker push ${REGISTRY_URL}/${IMAGE_NAME}:${BUILD_NUMBER}
docker push ${REGISTRY_URL}/${IMAGE_NAME}:latest
'''
}
}
}
stage('Deploy') {
steps {
echo "🚀 Déploiement du frontend..."
sh '''
if [ ! -f ${DEPLOY_PATH}/docker-compose.yml ]; then
echo "❌ Fichier docker-compose.yml introuvable dans ${DEPLOY_PATH}"
exit 1
fi
cd ${DEPLOY_PATH}
docker compose pull frontend
docker compose up -d --force-recreate frontend
'''
}
}
stage('Health Check') {
steps {
echo "🩺 Vérification du frontend après déploiement..."
script {
def maxRetries = 10
def statusCode = "000"
for (int i = 1; i <= maxRetries; i++) {
statusCode = sh(
script: "curl -k -s -o /dev/null -w '%{http_code}' https://${DOMAIN}/ || echo 000",
returnStdout: true
).trim()
if (statusCode == '200') {
echo "✅ Frontend opérationnel (HTTP ${statusCode}) après ${i} essai(s)"
break
} else {
echo "⏳ Tentative ${i}/${maxRetries} → HTTP ${statusCode}"
sleep 5
}
}
if (statusCode != '200') {
error("❌ Health check échoué - code HTTP ${statusCode}")
}
}
}
}
}
post {
success {
echo "✅ Pipeline frontend terminé avec succès !"
}
failure {
echo "❌ Échec du pipeline frontend."
}
}
}