From 32a77c780abe8c0aa9846843ac81d13e4b8cf73a Mon Sep 17 00:00:00 2001 From: Luc SORIGNET Date: Sat, 15 Feb 2025 15:16:10 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Mise=20=C3=A0=20jour=20des=20Dockerfile?= =?UTF-8?q?=20pr=C3=A9paration=20d'un=20environnement=20de=20d=C3=A9mo=20[?= =?UTF-8?q?#12]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End/Dockerfile | 2 +- Front-End/next.config.mjs | 1 + JenkinsFile | 85 +++++++++++++++++++++++++++++++++++++++ ci-script/makeDocker.sh | 53 ++++++++++++++++++++++++ docker-compose.prod.yml | 44 ++++++++++++++++++++ 5 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 JenkinsFile create mode 100644 ci-script/makeDocker.sh create mode 100644 docker-compose.prod.yml diff --git a/Front-End/Dockerfile b/Front-End/Dockerfile index dcfb896..d6a82ba 100644 --- a/Front-End/Dockerfile +++ b/Front-End/Dockerfile @@ -26,9 +26,9 @@ CMD ["npm", "run", "dev"] FROM node:18-alpine AS production WORKDIR /app ENV NODE_ENV=production -COPY --from=builder /app/public ./public COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/messages ./messages EXPOSE 3000 CMD ["node", "server.js"] diff --git a/Front-End/next.config.mjs b/Front-End/next.config.mjs index 2a18797..4914f53 100644 --- a/Front-End/next.config.mjs +++ b/Front-End/next.config.mjs @@ -5,6 +5,7 @@ const withNextIntl = createNextIntlPlugin(); /** @type {import('next').NextConfig} */ const nextConfig = { + output: "standalone", experimental: { instrumentationHook: true, }, diff --git a/JenkinsFile b/JenkinsFile new file mode 100644 index 0000000..94ac35e --- /dev/null +++ b/JenkinsFile @@ -0,0 +1,85 @@ +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-script/makeDocker.sh b/ci-script/makeDocker.sh new file mode 100644 index 0000000..a41070b --- /dev/null +++ b/ci-script/makeDocker.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Récupération de la version depuis les arguments +VERSION=$1 + +if [ -z "$VERSION" ]; then + echo "Erreur: Version non spécifiée" + echo "Usage: ./makeDocker.sh " + exit 1 +fi +SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $SCRIPT_PATH +# Configuration +DOCKER_REGISTRY="git.v0id.ovh" +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 +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 \ + . + +if [ $? -ne 0 ]; then + echo "Échec de la construction de l'image Frontend" + exit 1 +fi + +# Construction de l'image Backend +echo "Construction de l'image Backend..." +cd ../Back-End +docker build \ + -t ${DOCKER_REGISTRY}/n3wt-innov/${APP_NAME}/backend:${VERSION} \ + -t ${DOCKER_REGISTRY}/n3wt-innov/${APP_NAME}/backend:latest \ + . + +if [ $? -ne 0 ]; then + echo "Échec de la construction de l'image Backend" + exit 1 +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" + +exit 0 \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..cf84c25 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,44 @@ +version: '3' + +services: + redis: + image: 'redis:latest' + expose: + - 6379 + environment: + - TZ=Europe/Paris + + database: + image: 'postgres:latest' + expose: + - 5432 + environment: + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + POSTGRES_DB: school + TZ: Europe/Paris + + backend: + build: + context: ./Back-End + target: production + expose: + - 8080 + environment: + - TZ=Europe/Paris + - TEST_MODE=False + depends_on: + - redis + - database + + frontend: + build: + context: ./Front-End + target: production + ports: + - 3000:3000 + environment: + - TZ=Europe/Paris + - NODE_ENV=production + depends_on: + - backend \ No newline at end of file