Actualiser Jenkinsfile
This commit is contained in:
parent
65f8e584b5
commit
2c7546c67e
61
Jenkinsfile
vendored
61
Jenkinsfile
vendored
|
|
@ -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."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user