✅ Fix Jenkinsfile: force recreate + health check
This commit is contained in:
parent
246f154793
commit
bfa10dc890
51
Jenkinsfile
vendored
51
Jenkinsfile
vendored
|
|
@ -1,19 +1,15 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
agent {
|
agent any
|
||||||
docker {
|
|
||||||
image 'node:20'
|
|
||||||
args '-v /var/run/docker.sock:/var/run/docker.sock'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
APP_NAME = "the-tip-top-frontend"
|
REGISTRY_URL = 'registry.wk-archi-o24a-15m-g3.fr'
|
||||||
REGISTRY = "registry.wk-archi-o24a-15m-g3.fr"
|
IMAGE_NAME = 'the-tip-top-frontend'
|
||||||
IMAGE = "${REGISTRY}/${APP_NAME}:${BUILD_NUMBER}"
|
DEPLOY_PATH = '/srv/devops/the-tip-top'
|
||||||
DEPLOY_PATH = "/srv/devops/the-tip-top"
|
DEPLOY_HOST = 'https://dsp5-archi-o24a-15m-g3.fr'
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
|
||||||
stage('Checkout') {
|
stage('Checkout') {
|
||||||
steps {
|
steps {
|
||||||
echo "📦 Récupération du code source depuis Gitea..."
|
echo "📦 Récupération du code source depuis Gitea..."
|
||||||
|
|
@ -30,7 +26,7 @@ pipeline {
|
||||||
|
|
||||||
stage('Build Next.js') {
|
stage('Build Next.js') {
|
||||||
steps {
|
steps {
|
||||||
echo "⚙️ Build de l’application Next.js (production)..."
|
echo "⚙️ Compilation de l’application Next.js (production)..."
|
||||||
sh 'npm run build'
|
sh 'npm run build'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -38,18 +34,22 @@ pipeline {
|
||||||
stage('Build Docker image') {
|
stage('Build Docker image') {
|
||||||
steps {
|
steps {
|
||||||
echo "🐳 Construction de l’image Docker frontend..."
|
echo "🐳 Construction de l’image Docker frontend..."
|
||||||
sh 'docker build -t ${IMAGE} .'
|
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') {
|
stage('Push to Registry') {
|
||||||
steps {
|
steps {
|
||||||
echo "📤 Envoi de l’image vers le registry privé..."
|
echo "📤 Envoi de l’image vers le registre privé..."
|
||||||
withCredentials([usernamePassword(credentialsId: 'registry-creds', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
|
withCredentials([usernamePassword(credentialsId: 'registry-credentials', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
|
||||||
sh 'echo $PASS | docker login $REGISTRY -u $USER --password-stdin'
|
sh """
|
||||||
sh 'docker push ${IMAGE}'
|
echo "$PASS" | docker login ${REGISTRY_URL} -u "$USER" --password-stdin
|
||||||
sh 'docker tag ${IMAGE} ${REGISTRY}/${APP_NAME}:latest'
|
docker push ${REGISTRY_URL}/${IMAGE_NAME}:${BUILD_NUMBER}
|
||||||
sh 'docker push ${REGISTRY}/${APP_NAME}:latest'
|
docker push ${REGISTRY_URL}/${IMAGE_NAME}:latest
|
||||||
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -59,8 +59,7 @@ pipeline {
|
||||||
echo "🚀 Déploiement du frontend via Docker Compose..."
|
echo "🚀 Déploiement du frontend via Docker Compose..."
|
||||||
sh """
|
sh """
|
||||||
cd ${DEPLOY_PATH}
|
cd ${DEPLOY_PATH}
|
||||||
docker compose pull frontend || true
|
docker compose pull frontend # récupère la dernière image 'latest'
|
||||||
docker compose rm -sf frontend || true
|
|
||||||
docker compose up -d --no-deps --force-recreate frontend
|
docker compose up -d --no-deps --force-recreate frontend
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
@ -71,20 +70,16 @@ pipeline {
|
||||||
echo "🩺 Vérification de la disponibilité du frontend..."
|
echo "🩺 Vérification de la disponibilité du frontend..."
|
||||||
script {
|
script {
|
||||||
def success = false
|
def success = false
|
||||||
for (int i = 1; i <= 5; i++) {
|
for (int i = 1; i <= 3; i++) {
|
||||||
echo "⏳ Tentative #${i} (attente ${i * 10}s)..."
|
echo "⏳ Tentative #${i} (attente ${i * 10}s)..."
|
||||||
sh "sleep ${i * 10}"
|
sh "sleep ${i * 10}"
|
||||||
|
def code = sh(script: "curl -k -s -o /dev/null -w '%{http_code}' ${DEPLOY_HOST} || echo 000", returnStdout: true).trim()
|
||||||
// ✅ Test via Jenkins lui-même (pas le conteneur node)
|
echo "➡️ Réponse HTTP : ${code}"
|
||||||
def code = sh(script: "docker exec jenkins curl --insecure -s -o /dev/null -w '%{http_code}' https://dsp5-archi-o24a-15m-g3.fr", returnStdout: true).trim()
|
|
||||||
echo "Réponse HTTP : ${code}"
|
|
||||||
|
|
||||||
if (code == '200' || code == '301' || code == '302') {
|
if (code == '200' || code == '301' || code == '302') {
|
||||||
success = true
|
success = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
error("❌ Le frontend ne répond pas après plusieurs tentatives.")
|
error("❌ Le frontend ne répond pas après plusieurs tentatives.")
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +90,7 @@ pipeline {
|
||||||
|
|
||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
echo "✅ Déploiement du frontend réussi !"
|
echo "✅ Déploiement réussi du frontend !"
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo "❌ Échec du pipeline frontend."
|
echo "❌ Échec du pipeline frontend."
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user