Actualiser Jenkinsfile
This commit is contained in:
parent
65f8e584b5
commit
2c7546c67e
63
Jenkinsfile
vendored
63
Jenkinsfile
vendored
|
|
@ -7,66 +7,63 @@ pipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
REGISTRY = 'registry.wk-archi-o24a-15m-g3.fr'
|
APP_NAME = "the-tip-top-backend"
|
||||||
BACK_IMAGE = "${REGISTRY}/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 {
|
stages {
|
||||||
|
|
||||||
stage('Checkout') {
|
stage('Checkout') {
|
||||||
steps {
|
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 {
|
steps {
|
||||||
sh '''
|
echo "📦 Installation des dépendances NPM..."
|
||||||
echo "📦 Installation des dépendances..."
|
sh 'npm ci'
|
||||||
npm install
|
|
||||||
|
|
||||||
echo "🐳 Construction de l’image Docker backend..."
|
|
||||||
docker build -t $BACK_IMAGE:latest .
|
|
||||||
'''
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Push Image to Registry') {
|
stage('Build Docker image') {
|
||||||
steps {
|
steps {
|
||||||
withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
|
echo "🐳 Construction et tag de l’image Docker..."
|
||||||
sh '''
|
sh 'docker build -t ${IMAGE} .'
|
||||||
echo "🔑 Connexion au registre Docker Gitea..."
|
|
||||||
docker login $REGISTRY -u $USER -p $PASS
|
|
||||||
|
|
||||||
echo "📤 Envoi de l’image vers le registre..."
|
|
||||||
docker push $BACK_IMAGE:latest
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Deploy Backend on VPS') {
|
stage('Push to Registry') {
|
||||||
steps {
|
steps {
|
||||||
sshagent(['vps-ssh-key']) {
|
echo "📤 Envoi de l’image vers le registry privé..."
|
||||||
sh '''
|
withCredentials([usernamePassword(credentialsId: 'registry-creds', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
|
||||||
echo "🚀 Déploiement du backend sur le VPS..."
|
sh 'echo $PASS | docker login $REGISTRY -u $USER --password-stdin'
|
||||||
ssh -o StrictHostKeyChecking=no debian@51.75.24.29 "
|
sh 'docker push $IMAGE'
|
||||||
cd /srv/devops/the-tip-top &&
|
|
||||||
docker compose pull backend &&
|
|
||||||
docker compose up -d --build backend
|
|
||||||
"
|
|
||||||
'''
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stage('Deploy') {
|
||||||
|
steps {
|
||||||
|
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 {
|
post {
|
||||||
success {
|
success {
|
||||||
echo "✅ Backend déployé avec succès !"
|
echo "✅ Déploiement du backend réussi !"
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo "❌ Échec du pipeline Backend — vérifier les logs Jenkins."
|
echo "❌ Échec du pipeline backend."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user