From 57d3924469c5a23f25ed033c8eae46989d17e7ee Mon Sep 17 00:00:00 2001 From: aa243527 Date: Sat, 8 Mar 2025 10:22:11 +0100 Subject: [PATCH 1/4] feat: moving pytest dependency to requirements file --- backend/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index af4eb8b..33a52a2 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -12,7 +12,6 @@ COPY requirements.txt . # Installer les dépendances et ajouter pytest RUN pip install --no-cache-dir -r requirements.txt -RUN pip install --no-cache-dir pytest # Copier le reste du code (y compris les tests) COPY . /app -- GitLab From 942d6765c517ec6fe8edc6a11d6bcbd6d8a92f88 Mon Sep 17 00:00:00 2001 From: aa243527 Date: Sat, 8 Mar 2025 10:24:40 +0100 Subject: [PATCH 2/4] fix: moving pytest dependency to requirements file --- backend/requirements.txt | Bin 416 -> 450 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index 5d52d94c6c3b4e58915e291a51dab9134dc20897..e80e8e1653f09a58cd393eef99f529d6273f3f31 100644 GIT binary patch delta 42 rcmZ3$e296&0!F0*hDwGKhE#@PAZZJP77Tg}#z1V!pa6ut3|tHV*2D)= delta 7 OcmX@aynuPb0!9D} Date: Sat, 8 Mar 2025 10:25:24 +0100 Subject: [PATCH 3/4] feat :adding ci pipeline --- .gitlab-ci.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..65fdf7d --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,17 @@ +stages: + - test + +test_backend: + stage: test + image: python:3.11 + services: + - name: redis:alpine + alias: redis + before_script: + - pip install --upgrade pip + - pip install -r backend/requirements.txt + - pip install pytest + script: + - pytest backend/test_app.py + only: + - merge_requests # Exécute les tests uniquement sur un Merge Request -- GitLab From aaa89ccdc4d801d94fb5b79ead8367ef9388b7ae Mon Sep 17 00:00:00 2001 From: aa243527 Date: Sat, 8 Mar 2025 10:35:20 +0100 Subject: [PATCH 4/4] Fix REDIS_PORT parsing for GitLab CI and Docker --- backend/app.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/app.py b/backend/app.py index 29f571c..7747c76 100644 --- a/backend/app.py +++ b/backend/app.py @@ -4,6 +4,7 @@ import hashlib import itertools import logging import subprocess +import re # <-- Import pour extraire le numéro du port from flask import Flask, request, jsonify from flask_cors import CORS # Import pour activer CORS @@ -16,7 +17,13 @@ CORS(app) # Activation de CORS pour toutes les routes # Configuration de Redis redis_host = os.getenv("REDIS_HOST", "redis") # "redis" correspond au service Redis dans Docker -redis_port = int(os.getenv("REDIS_PORT", 6379)) +redis_url = os.getenv("REDIS_PORT", "6379") # Valeur par défaut + +# Extraction du numéro de port de Redis (compatible avec GitLab CI/CD et Docker) +redis_port_match = re.search(r":(\d+)", redis_url) +redis_port = int(redis_port_match.group(1)) if redis_port_match else 6379 + +# Connexion à Redis redis_client = redis.StrictRedis(host=redis_host, port=redis_port, db=0, decode_responses=True) # Clé pour le compteur de requêtes reçues -- GitLab