diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2564db..6cebd32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ on: branches: [main, develop] push: branches: - - 'feature/**' + - '*' jobs: test-api: @@ -15,17 +15,28 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: "3.10" + # Installer Miniconda + - name: Installer Miniconda + run: | + wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh + bash miniconda.sh -b -p $HOME/miniconda + echo "$HOME/miniconda/bin" >> $GITHUB_PATH + + # Créer l'environnement Conda et installer lightfm + - name: Configurer Conda et installer lightfm + run: | + conda create -y -n lightfm_env python=3.9 + conda install -y -n lightfm_env -c conda-forge lightfm numpy scipy tqdm pymysql pandas scikit-learn - - name: Installer les dépendances + # Installer les dépendances Python via pip dans l'environnement Conda + - name: Installer les dépendances Python run: | - pip install fastapi uvicorn pymysql pandas numpy \ - lightfm pytest httpx python-dotenv + conda run -n lightfm_env pip install fastapi uvicorn pymysql pandas numpy httpx==0.25.0 python-dotenv pytest haversine + # Lancer les tests dans l'environnement Conda - name: Lancer les tests - run: pytest tests/ -v + run: | + conda run -n lightfm_env pytest tests_api/ -v env: MYSQL_HOST: ${{ secrets.MYSQL_HOST }} MYSQL_USER: ${{ secrets.MYSQL_USER }} @@ -35,8 +46,7 @@ jobs: build-images: name: Build Docker Images runs-on: ubuntu-latest - needs: test-api - + #needs: test-api strategy: matrix: include: @@ -52,11 +62,20 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Debug matrix + run: | + echo "SERVICE=${{ matrix.service }}" + echo "DOCKERFILE=${{ matrix.dockerfile }}" + - name: Debug repository + run: | + pwd + ls -la + find . -type f | sort - name: Build ${{ matrix.service }} uses: docker/build-push-action@v5 with: context: . - dockerfile: ${{ matrix.dockerfile }} + file: ${{ matrix.dockerfile }} push: false tags: ${{ matrix.service }}:test \ No newline at end of file diff --git a/api.py b/api.py index 736ecdf..9a7d112 100644 --- a/api.py +++ b/api.py @@ -34,8 +34,14 @@ def connect_mysql(): with open("lightfm_model_hist.pkl", "rb") as f: model = pickle.load(f) -with open("models/dataset.pkl", "rb") as f: - dataset = pickle.load(f) +dataset = None +try: + + with open("dataset.pkl", "rb") as f: + dataset = pickle.load(f) +except : + with open("models/dataset.pkl", "rb") as f: + dataset = pickle.load(f) print("Modèle LightFM et dataset chargés avec succès")