chore: modification de la ci

This commit is contained in:
Luc SORIGNET
2026-02-09 12:15:51 +01:00
parent abb4b525b2
commit d9e998d2ff
4 changed files with 149 additions and 97 deletions

View File

@ -1,85 +0,0 @@
pipeline {
agent any
environment {
DOCKER_REGISTRY = 'git.v0id.ovh'
ORGANIZATION = "n3wt-innov"
APP_NAME = 'n3wt-school'
}
// Déclencher uniquement sur les tags
triggers {
issueCommentTrigger('.*deploy.*')
}
stages {
stage('Vérification du Tag') {
when {
expression { env.TAG_NAME != null }
}
steps {
script {
// Extraire la version du tag
env.VERSION = env.TAG_NAME
echo "Version détectée: ${env.VERSION}"
}
}
}
stage('Build Docker Images') {
when {
expression { env.TAG_NAME != null }
}
steps {
script {
// Donner les permissions d'exécution au script
sh 'chmod +x ./ci-scripts/makeDocker.sh'
// Exécuter le script avec la version
sh """
./ci-scripts/makeDocker.sh ${env.VERSION}
"""
}
}
}
stage('Push sur Registry') {
when {
expression { env.TAG_NAME != null }
}
steps {
script {
withCredentials([usernamePassword(
credentialsId: 'docker-registry-credentials',
usernameVariable: 'REGISTRY_USER',
passwordVariable: 'REGISTRY_PASS'
)]) {
// Login au registry
sh "docker login ${DOCKER_REGISTRY} -u ${REGISTRY_USER} -p ${REGISTRY_PASS}"
// Push des images
sh """
docker push ${DOCKER_REGISTRY}/${ORGANIZATION}/${APP_NAME}/frontend:${env.VERSION}
docker push ${DOCKER_REGISTRY}/${ORGANIZATION}/${APP_NAME}/backend:${env.VERSION}
docker push ${DOCKER_REGISTRY}/${ORGANIZATION}/${APP_NAME}/frontend:latest
docker push ${DOCKER_REGISTRY}/${ORGANIZATION}/${APP_NAME}/backend:latest
"""
}
}
}
}
}
post {
success {
echo "Build et push des images Docker réussis pour la version ${env.VERSION}"
}
failure {
echo "Échec du build ou du push des images Docker"
}
always {
// Nettoyage
sh 'docker system prune -f'
}
}
}

91
ci/build.Jenkinsfile Normal file
View File

@ -0,0 +1,91 @@
pipeline {
agent {
label "SLAVE-N3WT"
}
options {
disableConcurrentBuilds()
timestamps()
}
environment {
DOCKER_REGISTRY = "git.v0id.ovh"
ORG_NAME = "n3wt-innov"
APP_NAME = "n3wt-school"
IMAGE_FRONT = "${DOCKER_REGISTRY}/${ORG_NAME}/${APP_NAME}/frontend"
IMAGE_BACK = "${DOCKER_REGISTRY}/${ORG_NAME}/${APP_NAME}/backend"
}
stages {
stage("Clean Workspace") {
steps {
cleanWs()
}
}
stage("Only Tags Build") {
when {
buildingTag()
}
steps {
echo "Build déclenché par tag : ${TAG_NAME}"
}
}
stage("Build Docker Images") {
when {
buildingTag()
}
steps {
sh """
chmod +x ./ci/scripts/makeDocker.sh
./ci/scripts/makeDocker.sh ${TAG_NAME}
"""
}
}
stage("Push Images to Registry") {
when {
buildingTag()
}
steps {
withCredentials([usernamePassword(
credentialsId: "gitea-jenkins",
usernameVariable: "REGISTRY_USER",
passwordVariable: "REGISTRY_PASS"
)]) {
sh """
echo "Login registry..."
docker login ${DOCKER_REGISTRY} \
-u ${REGISTRY_USER} \
-p ${REGISTRY_PASS}
echo "Push version images..."
docker push ${IMAGE_FRONT}:${TAG_NAME}
docker push ${IMAGE_BACK}:${TAG_NAME}
echo "Tag latest..."
docker tag ${IMAGE_FRONT}:${TAG_NAME} ${IMAGE_FRONT}:latest
docker tag ${IMAGE_BACK}:${TAG_NAME} ${IMAGE_BACK}:latest
docker push ${IMAGE_FRONT}:latest
docker push ${IMAGE_BACK}:latest
"""
}
}
}
}
post {
always {
sh """
docker builder prune -f
docker image prune -f
"""
}
}
}

42
ci/deploy.Jenkinsfile Normal file
View File

@ -0,0 +1,42 @@
pipeline {
agent { label "SLAVE-N3WT" }
parameters {
choice(name: 'ENVIRONMENT', choices: ['demo', 'prod'], description: 'Choisir environnement')
string(name: 'VERSION', defaultValue: 'v1.0.0', description: 'Version Docker à déployer')
}
environment {
PLATEFORME_DEMO = 'demo.n3wtschool.com'
PLATEFORME_PROD = 'vps.n3wtschool.com'
DEPLOY_DIR = '~/n3wtschool'
}
stages {
stage('Deploy') {
steps {
script {
def targetHost = params.ENVIRONMENT == 'prod' ? env.PLATEFORME_PROD : env.PLATEFORME_DEMO
def deployDir = env.DEPLOY_DIR
// Le credential id Jenkins qui contient la clé SSH
def sshCredentialId = params.ENVIRONMENT == 'prod' ? 'vps_n3wt_prod' : 'demo_n3wt'
// Le user SSH que tu passes dans la commande ssh
def sshUser = params.ENVIRONMENT == 'prod' ? 'root' : 'demo'
sshagent([sshCredentialId]) {
sh """
ssh -o StrictHostKeyChecking=no ${sshUser}@${targetHost} <<EOF
cd ${deployDir}
docker compose down
docker compose pull
docker compose up -d
EOF
"""
}
}
}
}
}
}

View File

@ -1,5 +1,8 @@
#!/bin/bash
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Récupération de la version depuis les arguments
VERSION=$1
@ -8,21 +11,22 @@ if [ -z "$VERSION" ]; then
echo "Usage: ./makeDocker.sh <version>"
exit 1
fi
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $SCRIPT_PATH
# Configuration
DOCKER_REGISTRY="git.v0id.ovh"
ORG_NAME="n3wt-innov"
APP_NAME="n3wt-school"
echo "Début de la construction des images Docker pour la version ${VERSION}"
# Construction de l'image Frontend
echo "Construction de l'image Frontend..."
cd ../Front-End
cd $SCRIPT_PATH/../../Front-End
docker build \
--build-arg BUILD_MODE=production \
-t ${DOCKER_REGISTRY}/n3wt-innov/${APP_NAME}/frontend:${VERSION} \
-t ${DOCKER_REGISTRY}/n3wt-innov/${APP_NAME}/frontend:latest \
-t ${DOCKER_REGISTRY}/${ORG_NAME}/${APP_NAME}/frontend:${VERSION} \
-t ${DOCKER_REGISTRY}/${ORG_NAME}/${APP_NAME}/frontend:latest \
.
if [ $? -ne 0 ]; then
@ -32,10 +36,10 @@ fi
# Construction de l'image Backend
echo "Construction de l'image Backend..."
cd ../Back-End
cd $SCRIPT_PATH/../../Back-End
docker build \
-t ${DOCKER_REGISTRY}/n3wt-innov/${APP_NAME}/backend:${VERSION} \
-t ${DOCKER_REGISTRY}/n3wt-innov/${APP_NAME}/backend:latest \
-t ${DOCKER_REGISTRY}/${ORG_NAME}/${APP_NAME}/backend:${VERSION} \
-t ${DOCKER_REGISTRY}/${ORG_NAME}/${APP_NAME}/backend:latest \
.
if [ $? -ne 0 ]; then
@ -45,9 +49,9 @@ fi
echo "Construction des images Docker terminée avec succès"
echo "Images créées :"
echo "- ${DOCKER_REGISTRY}/${APP_NAME}/frontend:${VERSION}"
echo "- ${DOCKER_REGISTRY}/${APP_NAME}/frontend:latest"
echo "- ${DOCKER_REGISTRY}/${APP_NAME}/backend:${VERSION}"
echo "- ${DOCKER_REGISTRY}/${APP_NAME}/backend:latest"
echo "- ${DOCKER_REGISTRY}/${ORG_NAME}/${APP_NAME}/frontend:${VERSION}"
echo "- ${DOCKER_REGISTRY}/${ORG_NAME}/${APP_NAME}/frontend:latest"
echo "- ${DOCKER_REGISTRY}/${ORG_NAME}/${APP_NAME}/backend:${VERSION}"
echo "- ${DOCKER_REGISTRY}/${ORG_NAME}/${APP_NAME}/backend:latest"
exit 0