the-tip-top-frontend/Jenkinsfile
2025-10-30 14:55:29 +00:00

85 lines
2.2 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 {
docker {
image 'node:20'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
environment {
APP_NAME = "the-tip-top-frontend"
REGISTRY = "registry.wk-archi-o24a-15m-g3.fr"
IMAGE = "${REGISTRY}/${APP_NAME}:${BUILD_NUMBER}"
DEPLOY_PATH = "/srv/devops/the-tip-top"
}
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 "⚙️ Build de lapplication Next.js (production)..."
sh 'npm run build'
}
}
stage('Build Docker image') {
steps {
echo "🐳 Construction de limage Docker frontend..."
sh 'docker build -t ${IMAGE} .'
}
}
stage('Push to Registry') {
steps {
echo "📤 Envoi de limage vers le registry privé..."
withCredentials([usernamePassword(credentialsId: 'registry-creds', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh 'echo $PASS | docker login $REGISTRY -u $USER --password-stdin'
sh 'docker push $IMAGE'
// Tag stable
sh 'docker tag ${IMAGE} ${REGISTRY}/${APP_NAME}:latest'
sh 'docker push ${REGISTRY}/${APP_NAME}:latest'
}
}
}
stage('Deploy') {
steps {
echo "🚀 Déploiement du frontend via Docker Compose..."
sh """
cd ${DEPLOY_PATH}
docker compose pull frontend
docker compose up -d --no-deps --build frontend
"""
}
}
stage('Health Check') {
steps {
echo "🩺 Vérification de la disponibilité du frontend..."
script {
def code = sh(script: "curl -k -s -o /dev/null -w '%{http_code}' https://dsp5-archi-o24a-15m-g3.fr", returnStdout: true).trim()
if (code != '200') { error "Le frontend ne répond pas correctement (HTTP ${code})" }
}
}
}
}
post {
success { echo "✅ Déploiement du frontend réussi !" }
failure { echo "❌ Échec du pipeline frontend." }
}
}