From d9e998d2ff35200faa6f17d818d45db5db2e2459 Mon Sep 17 00:00:00 2001 From: Luc SORIGNET Date: Mon, 9 Feb 2026 12:15:51 +0100 Subject: [PATCH] chore: modification de la ci --- JenkinsFile | 85 ----------------------- ci/build.Jenkinsfile | 91 +++++++++++++++++++++++++ ci/deploy.Jenkinsfile | 42 ++++++++++++ {ci-script => ci/scripts}/makeDocker.sh | 28 ++++---- 4 files changed, 149 insertions(+), 97 deletions(-) delete mode 100644 JenkinsFile create mode 100644 ci/build.Jenkinsfile create mode 100644 ci/deploy.Jenkinsfile rename {ci-script => ci/scripts}/makeDocker.sh (59%) diff --git a/JenkinsFile b/JenkinsFile deleted file mode 100644 index 94ac35e..0000000 --- a/JenkinsFile +++ /dev/null @@ -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' - } - } -} \ No newline at end of file diff --git a/ci/build.Jenkinsfile b/ci/build.Jenkinsfile new file mode 100644 index 0000000..7a5da2e --- /dev/null +++ b/ci/build.Jenkinsfile @@ -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 + """ + } + } +} diff --git a/ci/deploy.Jenkinsfile b/ci/deploy.Jenkinsfile new file mode 100644 index 0000000..022e9c7 --- /dev/null +++ b/ci/deploy.Jenkinsfile @@ -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} <" 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 \ No newline at end of file