feat: Mise à jour des Dockerfile préparation d'un environnement de démo [#12]

This commit is contained in:
Luc SORIGNET
2025-02-15 15:16:10 +01:00
parent aef6c193b1
commit 32a77c780a
5 changed files with 184 additions and 1 deletions

View File

@ -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"]

View File

@ -5,6 +5,7 @@ const withNextIntl = createNextIntlPlugin();
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "standalone",
experimental: {
instrumentationHook: true,
},

85
JenkinsFile Normal file
View File

@ -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'
}
}
}

53
ci-script/makeDocker.sh Normal file
View File

@ -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 <version>"
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

44
docker-compose.prod.yml Normal file
View File

@ -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