Compare commits

9 Commits

Author SHA1 Message Date
9bb9ab8e51 Merge branch 'develop'
All checks were successful
Tests / Backend - Tests passed: 8
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-08-10 19:26:39 +00:00
b15d8458c8 refactor: centralize server IP configuration
All checks were successful
Tests / Backend - Tests passed: 8
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-08-10 19:23:52 +00:00
100b75a05a ci: publish JUnit and coverage reports
All checks were successful
Tests / Backend - Tests passed: 8
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-08-08 01:07:31 +00:00
d57b26c8c8 test: generate JUnit reports for Jenkins
All checks were successful
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-08-08 00:24:43 +00:00
d071f737bb Merge pull request 'develop' (#2) from develop into main
All checks were successful
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
Reviewed-on: http://gitea.furious.local/andil/THE-TIP-TOP/pulls/2
2026-08-04 21:38:40 +00:00
803a78cd71 refactor: align branches with dev preprod and production
All checks were successful
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-08-04 20:43:14 +00:00
466655f52d feat: add production deployment flow
All checks were successful
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-08-04 17:54:09 +00:00
ac702c8835 feat: route branches to dev and preproduction
All checks were successful
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-08-04 16:13:53 +00:00
92dfcbe61e feat: add preproduction environment
All checks were successful
THE-TIP-TOP-MULTIBRANCH/pipeline/head This commit looks good
2026-08-04 16:01:02 +00:00
6 changed files with 400 additions and 47 deletions

207
Jenkinsfile vendored
View File

@@ -8,16 +8,16 @@ pipeline {
} }
environment { environment {
CI_NETWORK = "tiptop-ci-${BUILD_NUMBER}"
CI_DATABASE = "tiptop-ci-db-${BUILD_NUMBER}"
DATABASE_URL = "postgresql://tiptop_ci:tiptop_ci_password@${CI_DATABASE}:5432/the_tip_top_ci"
REGISTRY = "localhost:5000" REGISTRY = "localhost:5000"
IMAGE_TAG = "${BUILD_NUMBER}" SERVER_IP = "192.168.1.95"
BACKEND_IMAGE = "${REGISTRY}/the-tip-top/backend" BACKEND_IMAGE = "${REGISTRY}/the-tip-top/backend"
FRONTEND_IMAGE = "${REGISTRY}/the-tip-top/frontend" FRONTEND_IMAGE = "${REGISTRY}/the-tip-top/frontend"
CI_NETWORK = "tiptop-ci-${JOB_BASE_NAME}-${BUILD_NUMBER}"
CI_DATABASE = "tiptop-ci-db-${JOB_BASE_NAME}-${BUILD_NUMBER}"
DATABASE_URL = "postgresql://tiptop_ci:tiptop_ci_password@${CI_DATABASE}:5432/the_tip_top_ci"
} }
stages { stages {
@@ -27,6 +27,70 @@ pipeline {
} }
} }
stage('Préparer environnement') {
steps {
script {
env.IMAGE_TAG = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
/*
* Stratégie de branches :
*
* feature/* -> CI uniquement
* develop -> DEV automatique
* release-* -> PREPROD automatique
* main -> PROD avec validation manuelle
*/
if (env.BRANCH_NAME == 'develop') {
env.DEPLOY_ENABLED = 'true'
env.DEPLOY_ENV = 'DEV'
env.COMPOSE_FILE = 'deploy/dev/docker-compose.yml'
env.COMPOSE_PROJECT = 'tiptop-dev'
env.DEPLOY_NETWORK = 'tiptop-dev'
env.FRONTEND_API_URL = "http://${SERVER_IP}:5001"
} else if (env.BRANCH_NAME.startsWith('release-')) {
env.DEPLOY_ENABLED = 'true'
env.DEPLOY_ENV = 'PREPROD'
env.COMPOSE_FILE = 'deploy/preprod/docker-compose.yml'
env.COMPOSE_PROJECT = 'tiptop-preprod'
env.DEPLOY_NETWORK = 'tiptop-preprod'
env.FRONTEND_API_URL = "http://${SERVER_IP}:5002"
} else if (env.BRANCH_NAME == 'main') {
env.DEPLOY_ENABLED = 'true'
env.DEPLOY_ENV = 'PROD'
env.COMPOSE_FILE = 'deploy/prod/docker-compose.yml'
env.COMPOSE_PROJECT = 'tiptop-prod'
env.DEPLOY_NETWORK = 'tiptop-prod'
env.FRONTEND_API_URL = "http://${SERVER_IP}:5003"
} else {
env.DEPLOY_ENABLED = 'false'
env.DEPLOY_ENV = 'CI uniquement'
env.COMPOSE_FILE = ''
env.COMPOSE_PROJECT = ''
env.DEPLOY_NETWORK = ''
env.FRONTEND_API_URL = ''
}
echo "Branche : ${env.BRANCH_NAME}"
echo "Tag Docker : ${env.IMAGE_TAG}"
echo "Environnement : ${env.DEPLOY_ENV}"
echo "Déploiement activé : ${env.DEPLOY_ENABLED}"
echo "Serveur : ${env.SERVER_IP}"
echo "API frontend : ${env.FRONTEND_API_URL}"
}
}
}
stage('Vérification du workspace') { stage('Vérification du workspace') {
steps { steps {
sh ''' sh '''
@@ -34,9 +98,10 @@ pipeline {
test -f backend/package-lock.json test -f backend/package-lock.json
test -f frontend/package.json test -f frontend/package.json
test -f frontend/package-lock.json test -f frontend/package-lock.json
test -f deploy/dev/docker-compose.yml
echo "Tag Docker : ${IMAGE_TAG}" if [ "${DEPLOY_ENABLED}" = "true" ]; then
test -f "${COMPOSE_FILE}"
fi
''' '''
} }
} }
@@ -54,16 +119,20 @@ pipeline {
-e POSTGRES_DB=the_tip_top_ci \ -e POSTGRES_DB=the_tip_top_ci \
postgres:16-alpine postgres:16-alpine
echo "Attente de PostgreSQL..." echo "Attente de PostgreSQL CI..."
for i in $(seq 1 30); do for i in $(seq 1 30); do
if docker exec "${CI_DATABASE}" \ if docker exec "${CI_DATABASE}" \
pg_isready -U tiptop_ci -d the_tip_top_ci; then pg_isready \
echo "PostgreSQL est prêt." -U tiptop_ci \
-d the_tip_top_ci; then
echo "PostgreSQL CI est prêt."
break break
fi fi
if [ "$i" -eq 30 ]; then if [ "$i" -eq 30 ]; then
echo "PostgreSQL CI ne répond pas."
docker logs "${CI_DATABASE}" docker logs "${CI_DATABASE}"
exit 1 exit 1
fi fi
@@ -96,6 +165,21 @@ pipeline {
" "
''' '''
} }
post {
always {
junit(
testResults: 'backend/test-results/*.xml',
allowEmptyResults: true
)
archiveArtifacts(
artifacts: 'backend/coverage/**',
fingerprint: true,
allowEmptyArchive: true
)
}
}
} }
stage('Frontend - Lint et Build') { stage('Frontend - Lint et Build') {
@@ -124,70 +208,108 @@ pipeline {
} }
stage('Construction des images Docker') { stage('Construction des images Docker') {
when {
expression {
env.DEPLOY_ENABLED == 'true'
}
}
steps { steps {
sh ''' sh '''
docker build \ docker build \
-t "${BACKEND_IMAGE}:${IMAGE_TAG}" \ -t "${BACKEND_IMAGE}:${IMAGE_TAG}" \
-t "${BACKEND_IMAGE}:latest" \
backend backend
docker build \ docker build \
--build-arg VITE_API_URL=http://192.168.1.23:5001 \ --build-arg VITE_API_URL="${FRONTEND_API_URL}" \
-t "${FRONTEND_IMAGE}:${IMAGE_TAG}" \ -t "${FRONTEND_IMAGE}:${IMAGE_TAG}" \
-t "${FRONTEND_IMAGE}:latest" \
frontend frontend
''' '''
} }
} }
stage('Publication dans le Registry') { stage('Publication dans le Registry') {
when {
expression {
env.DEPLOY_ENABLED == 'true'
}
}
steps { steps {
sh ''' sh '''
docker push "${BACKEND_IMAGE}:${IMAGE_TAG}" docker push "${BACKEND_IMAGE}:${IMAGE_TAG}"
docker push "${BACKEND_IMAGE}:latest"
docker push "${FRONTEND_IMAGE}:${IMAGE_TAG}" docker push "${FRONTEND_IMAGE}:${IMAGE_TAG}"
docker push "${FRONTEND_IMAGE}:latest"
''' '''
} }
} }
stage('Déploiement DEV') { stage('Validation production') {
when {
expression {
env.DEPLOY_ENV == 'PROD'
}
}
steps {
timeout(time: 15, unit: 'MINUTES') {
input(
message: "Déployer ${IMAGE_TAG} en production ?",
ok: "Déployer"
)
}
}
}
stage('Déploiement') {
when {
expression {
env.DEPLOY_ENABLED == 'true'
}
}
steps { steps {
sh ''' sh '''
echo "Déploiement de ${BRANCH_NAME} vers ${DEPLOY_ENV}"
echo "Image backend : ${BACKEND_IMAGE}:${IMAGE_TAG}"
echo "Image frontend : ${FRONTEND_IMAGE}:${IMAGE_TAG}"
echo "Compose : ${COMPOSE_FILE}"
REGISTRY="${REGISTRY}" \ REGISTRY="${REGISTRY}" \
IMAGE_TAG="${IMAGE_TAG}" \ IMAGE_TAG="${IMAGE_TAG}" \
docker compose \ docker compose \
-p tiptop-dev \ -p "${COMPOSE_PROJECT}" \
-f deploy/dev/docker-compose.yml \ -f "${COMPOSE_FILE}" \
up -d \ up -d \
--pull always \ --pull always \
--remove-orphans --remove-orphans
echo "Attente du backend DEV..." echo "Attente du backend ${DEPLOY_ENV}..."
for i in $(seq 1 30); do for i in $(seq 1 30); do
if docker run --rm \ if docker run --rm \
--network tiptop-dev \ --network "${DEPLOY_NETWORK}" \
curlimages/curl:8.12.1 \ curlimages/curl:8.12.1 \
-fsS http://backend:5000/ >/dev/null; then -fsS \
http://backend:5000/ \
>/dev/null; then
echo "Backend DEV opérationnel." echo "Backend ${DEPLOY_ENV} opérationnel."
break break
fi fi
if [ "$i" -eq 30 ]; then if [ "$i" -eq 30 ]; then
echo "Le backend DEV ne répond pas." echo "Le backend ${DEPLOY_ENV} ne répond pas."
docker compose \ docker compose \
-p tiptop-dev \ -p "${COMPOSE_PROJECT}" \
-f deploy/dev/docker-compose.yml \ -f "${COMPOSE_FILE}" \
ps ps
docker compose \ docker compose \
-p tiptop-dev \ -p "${COMPOSE_PROJECT}" \
-f deploy/dev/docker-compose.yml \ -f "${COMPOSE_FILE}" \
logs --tail=100 logs \
--tail=150
exit 1 exit 1
fi fi
@@ -195,14 +317,16 @@ pipeline {
sleep 5 sleep 5
done done
echo "Vérification du frontend DEV..." echo "Vérification du frontend ${DEPLOY_ENV}..."
docker run --rm \ docker run --rm \
--network tiptop-dev \ --network "${DEPLOY_NETWORK}" \
curlimages/curl:8.12.1 \ curlimages/curl:8.12.1 \
-fsS http://frontend/ >/dev/null -fsS \
http://frontend/ \
>/dev/null
echo "Frontend DEV opérationnel." echo "Frontend ${DEPLOY_ENV} opérationnel."
''' '''
} }
} }
@@ -217,11 +341,22 @@ pipeline {
} }
success { success {
echo "Pipeline CI/CD réussi. Version DEV déployée : ${IMAGE_TAG}" echo """
Pipeline réussi.
Branche : ${BRANCH_NAME}
Environnement : ${DEPLOY_ENV}
Version : ${IMAGE_TAG}
"""
} }
failure { failure {
echo "Pipeline CI/CD en échec. Consulte la Console Output." echo """
Pipeline en échec.
Branche : ${BRANCH_NAME}
Environnement : ${DEPLOY_ENV}
"""
} }
} }
} }

View File

@@ -1,26 +1,33 @@
module.exports = { module.exports = {
testEnvironment: "node", testEnvironment: "node",
// Dossier des tests
testMatch: ["**/tests/**/*.test.js"], testMatch: ["**/tests/**/*.test.js"],
// Nettoyage des mocks entre les tests
clearMocks: true, clearMocks: true,
// Timeout (utile pour Prisma / DB)
testTimeout: 10000, testTimeout: 10000,
// Affichage des logs de test verbose: true,
verbose: true,
// Couverture de code (optionnel mais bon pour soutenance)
collectCoverage: true, collectCoverage: true,
coverageDirectory: "coverage", coverageDirectory: "coverage",
coverageReporters: [
"text",
"lcov",
"html"
],
// Fichiers à ignorer reporters: [
testPathIgnorePatterns: ["/node_modules/"], "default",
[
"jest-junit",
{
outputDirectory: "./test-results",
outputName: "junit.xml"
}
]
],
// Configuration pour Jest avec Supertest testPathIgnorePatterns: ["/node_modules/"]
//setupFilesAfterEnv: ["<rootDir>/tests/setup.js"]
}; };

View File

@@ -25,6 +25,7 @@
"cross-env": "^10.1.0", "cross-env": "^10.1.0",
"dotenv": "^17.4.2", "dotenv": "^17.4.2",
"jest": "^30.4.2", "jest": "^30.4.2",
"jest-junit": "^17.0.0",
"nodemon": "^3.1.14", "nodemon": "^3.1.14",
"supertest": "^7.2.2" "supertest": "^7.2.2"
} }
@@ -4457,6 +4458,22 @@
"url": "https://github.com/sponsors/jonschlinkert" "url": "https://github.com/sponsors/jonschlinkert"
} }
}, },
"node_modules/jest-junit": {
"version": "17.0.0",
"resolved": "https://registry.npmjs.org/jest-junit/-/jest-junit-17.0.0.tgz",
"integrity": "sha512-RYWCkq4j59gUXj5DsgbIE7xFBZzu1gtibPhyjSjMmGaOTLnqlXhg7x9zuGCwgbCuMAyoyvk0Mi8wSrRR5uOeLA==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"mkdirp": "^1.0.4",
"strip-ansi": "^6.0.1",
"uuid": "^14.0.0",
"xml": "^1.0.1"
},
"engines": {
"node": ">=20.0.0"
}
},
"node_modules/jest-leak-detector": { "node_modules/jest-leak-detector": {
"version": "30.4.1", "version": "30.4.1",
"resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-30.4.1.tgz", "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-30.4.1.tgz",
@@ -5375,6 +5392,19 @@
"node": ">=16 || 14 >=14.17" "node": ">=16 || 14 >=14.17"
} }
}, },
"node_modules/mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
"dev": true,
"license": "MIT",
"bin": {
"mkdirp": "bin/cmd.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/ms": { "node_modules/ms": {
"version": "2.1.3", "version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
@@ -6836,6 +6866,20 @@
"browserslist": ">= 4.21.0" "browserslist": ">= 4.21.0"
} }
}, },
"node_modules/uuid": {
"version": "14.0.1",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-14.0.1.tgz",
"integrity": "sha512-6ZxzVpzDXDa3bJWaHilVayA+BH/1zmxCJoVgvmqJnid/gPoKHxUrS/aC/T6LGQtNHT+XHG9fXPJB4d+IrU30Ew==",
"dev": true,
"funding": [
"https://github.com/sponsors/broofa",
"https://github.com/sponsors/ctavan"
],
"license": "MIT",
"bin": {
"uuid": "dist-node/bin/uuid"
}
},
"node_modules/v8-to-istanbul": { "node_modules/v8-to-istanbul": {
"version": "9.3.0", "version": "9.3.0",
"resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz",
@@ -6942,6 +6986,13 @@
"node": "^14.17.0 || ^16.13.0 || >=18.0.0" "node": "^14.17.0 || ^16.13.0 || >=18.0.0"
} }
}, },
"node_modules/xml": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz",
"integrity": "sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==",
"dev": true,
"license": "MIT"
},
"node_modules/y18n": { "node_modules/y18n": {
"version": "5.0.8", "version": "5.0.8",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",

View File

@@ -32,6 +32,7 @@
"cross-env": "^10.1.0", "cross-env": "^10.1.0",
"dotenv": "^17.4.2", "dotenv": "^17.4.2",
"jest": "^30.4.2", "jest": "^30.4.2",
"jest-junit": "^17.0.0",
"nodemon": "^3.1.14", "nodemon": "^3.1.14",
"supertest": "^7.2.2" "supertest": "^7.2.2"
}, },

View File

@@ -0,0 +1,79 @@
services:
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: tiptop_preprod
POSTGRES_PASSWORD: tiptop_preprod_password
POSTGRES_DB: the_tip_top_preprod
volumes:
- tiptop_preprod_postgres_data:/var/lib/postgresql/data
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -U tiptop_preprod -d the_tip_top_preprod"
]
interval: 10s
timeout: 5s
retries: 10
networks:
- tiptop-preprod
backend:
image: ${REGISTRY}/the-tip-top/backend:${IMAGE_TAG}
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment:
PORT: 5000
NODE_ENV: preproduction
DATABASE_URL: postgresql://tiptop_preprod:tiptop_preprod_password@postgres:5432/the_tip_top_preprod
JWT_SECRET: preprod_secret_change_me
APP_URL: http://192.168.1.23:5002
MAIL_HOST: smtp.gmail.com
MAIL_PORT: 587
MAIL_USER: ""
MAIL_PASS: ""
MAIL_FROM: "The Tip Top Preprod <no-reply@tiptop.local>"
command: >
sh -c "
npx prisma migrate deploy &&
npm run init:db &&
npm start
"
ports:
- "5002:5000"
networks:
- tiptop-preprod
frontend:
image: ${REGISTRY}/the-tip-top/frontend:${IMAGE_TAG}
restart: unless-stopped
depends_on:
- backend
ports:
- "5174:80"
networks:
- tiptop-preprod
volumes:
tiptop_preprod_postgres_data:
name: tiptop_preprod_postgres_data
networks:
tiptop-preprod:
name: tiptop-preprod

View File

@@ -0,0 +1,80 @@
services:
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: tiptop_prod
POSTGRES_PASSWORD: tiptop_prod_password
POSTGRES_DB: the_tip_top_prod
volumes:
- tiptop_prod_postgres_data:/var/lib/postgresql/data
healthcheck:
test:
[
"CMD-SHELL",
"pg_isready -U tiptop_prod -d the_tip_top_prod"
]
interval: 10s
timeout: 5s
retries: 10
networks:
- tiptop-prod
backend:
image: ${REGISTRY}/the-tip-top/backend:${IMAGE_TAG}
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment:
PORT: 5000
NODE_ENV: production
DATABASE_URL: postgresql://tiptop_prod:tiptop_prod_password@postgres:5432/the_tip_top_prod
JWT_SECRET: prod_secret_change_me
APP_URL: http://192.168.1.23:5003
MAIL_HOST: smtp.gmail.com
MAIL_PORT: 587
MAIL_USER: ""
MAIL_PASS: ""
MAIL_FROM: "The Tip Top <no-reply@tiptop.local>"
command: >
sh -c "
npx prisma migrate deploy &&
npm run init:db &&
npm start
"
ports:
- "5003:5000"
networks:
- tiptop-prod
frontend:
image: ${REGISTRY}/the-tip-top/frontend:${IMAGE_TAG}
restart: unless-stopped
depends_on:
- backend
ports:
- "5175:80"
networks:
- tiptop-prod
volumes:
tiptop_prod_postgres_data:
name: tiptop_prod_postgres_data
networks:
tiptop-prod:
name: tiptop-prod