diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3f9ed4e..2526bfa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,22 +39,19 @@ lint: exit 0; } -deploy: - stage: deploy - only: - - main - variables: - CI: "true" # Mark this as a CI run - ENVIRONMENT: test # Use test environment settings - PORT: 8081 - script: - - echo "Setting up Python dependencies..." - - source $VIRTUAL_ENV/bin/activate - - pip install -r requirements.txt - - echo "Starting the application to test startup with SSL..." - - cd backend - - python -m main # App will start, validate, and exit - - echo "Application startup validation completed successfully." + deploy: + stage: deploy + variables: + CI: "true" # Mark this as a CI run + ENVIRONMENT: test # Use test environment settings + PORT: 8081 + script: + - echo "Setting up Python dependencies..." + - source $VIRTUAL_ENV/bin/activate + - pip install -r requirements.txt + - echo "Starting the application to test startup with SSL..." + - cd $CI_PROJECT_DIR/backend # Use GitLab-provided dynamic root path + - python -m main # Run the main module dynamically release: stage: release diff --git a/backend/main.py b/backend/main.py index 430ce77..9d4c825 100644 --- a/backend/main.py +++ b/backend/main.py @@ -2,6 +2,7 @@ import sys import os import json +import tomllib from pathlib import Path from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware @@ -25,24 +26,21 @@ from app.database import Base, engine, SessionLocal, load_sample_data # Utility function to fetch metadata from pyproject.toml def get_project_metadata(): - from pathlib import Path - import tomllib + # Start from the current script's directory and search for pyproject.toml + script_dir = Path(__file__).resolve().parent + for parent in script_dir.parents: + pyproject_path = parent / "pyproject.toml" + if pyproject_path.exists(): + with open(pyproject_path, "rb") as f: + pyproject = tomllib.load(f) + name = pyproject["project"]["name"] + version = pyproject["project"]["version"] + return name, version - # Dynamically resolve the project root folder correctly. - # Assume that `pyproject.toml` is located in the heidi-v2 root folder - root_dir = Path(__file__).resolve().parent.parent.parent - pyproject_path = root_dir / "heidi-v2" / "pyproject.toml" - - print(f"Looking for pyproject.toml at: {pyproject_path}") # Debugging output - - if not pyproject_path.exists(): - raise FileNotFoundError(f"{pyproject_path} not found") - - with open(pyproject_path, "rb") as f: - pyproject = tomllib.load(f) - name = pyproject["project"]["name"] - version = pyproject["project"]["version"] - return name, version + # If no pyproject.toml is found, raise FileNotFoundError + raise FileNotFoundError( + f"pyproject.toml not found in any parent directory of {script_dir}" + ) # Get project metadata from pyproject.toml diff --git a/pyproject.toml b/pyproject.toml index 1f4cdb5..48c3a32 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,8 +26,8 @@ dependencies = [ "mysqlclient~=2.1.1", "python-multipart~=0.0.6", "uvicorn==0.23.1", - "python-dateutil~=2.8.2" - + "python-dateutil~=2.8.2", + "tomli>=2.0.1" ] [tool.pytest.ini_options] norecursedirs = ["backend/python-client"]