From 2c7546c67ecd0a8bccad8da82ee73317fc675962 Mon Sep 17 00:00:00 2001 From: wkadmin Date: Thu, 30 Oct 2025 14:30:50 +0000 Subject: [PATCH] Actualiser Jenkinsfile --- Jenkinsfile | 61 +++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ec2f9716..5fe81719 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,66 +7,63 @@ pipeline { } environment { - REGISTRY = 'registry.wk-archi-o24a-15m-g3.fr' - BACK_IMAGE = "${REGISTRY}/the-tip-top-backend" + APP_NAME = "the-tip-top-backend" + 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 { - git branch: 'main', url: 'https://gitea.wk-archi-o24a-15m-g3.fr/wkadmin/the-tip-top-backend.git' + echo "📦 Récupération du code source depuis Gitea..." + checkout scm } } - stage('Build Backend Image') { + stage('Install dependencies') { steps { - sh ''' - echo "📦 Installation des dépendances..." - npm install - - echo "🐳 Construction de l’image Docker backend..." - docker build -t $BACK_IMAGE:latest . - ''' + echo "📦 Installation des dépendances NPM..." + sh 'npm ci' } } - stage('Push Image to Registry') { + stage('Build Docker image') { steps { - withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USER', passwordVariable: 'PASS')]) { - sh ''' - echo "🔑 Connexion au registre Docker Gitea..." - docker login $REGISTRY -u $USER -p $PASS + echo "🐳 Construction et tag de l’image Docker..." + sh 'docker build -t ${IMAGE} .' + } + } - echo "📤 Envoi de l’image vers le registre..." - docker push $BACK_IMAGE:latest - ''' + stage('Push to Registry') { + steps { + echo "📤 Envoi de l’image 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' } } } - stage('Deploy Backend on VPS') { + stage('Deploy') { steps { - sshagent(['vps-ssh-key']) { - sh ''' - echo "🚀 Déploiement du backend sur le VPS..." - ssh -o StrictHostKeyChecking=no debian@51.75.24.29 " - cd /srv/devops/the-tip-top && - docker compose pull backend && - docker compose up -d --build backend - " - ''' - } + echo "🚀 Déploiement du backend via Docker Compose..." + sh """ + cd ${DEPLOY_PATH} + docker compose pull backend + docker compose up -d --no-deps --build backend + """ } } } post { success { - echo "✅ Backend déployé avec succès !" + echo "✅ Déploiement du backend réussi !" } failure { - echo "❌ Échec du pipeline Backend — vérifier les logs Jenkins." + echo "❌ Échec du pipeline backend." } } }