From 1ecbe97955a10a479bc3e37c505f3cdd670aedf6 Mon Sep 17 00:00:00 2001 From: GotthardG <51994228+GotthardG@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:23:10 +0100 Subject: [PATCH] fixing bugs with ci pipeline --- .gitlab-ci.yml | 18 +++++++++--------- backend/main.py | 22 ++++++++++++++++------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 00506d6..012485c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -43,18 +43,18 @@ deploy: only: - main variables: - PORT: 8081 # Set the port to run the application on - ENVIRONMENT: test # Set the environment to test + CI: "true" # Mark this as a CI run + ENVIRONMENT: dev # Use dev environment settings + PORT: 8081 # Set the port for the application script: - - echo "Updating repository..." - - git pull origin main # Update the repository with the latest code - - echo "Setting up Python dependencies..." + - echo "Setting up dependencies..." - source $VIRTUAL_ENV/bin/activate - - pip install -r requirements.txt # Install the required Python dependencies - - bash ./make_openapi_client.sh # Re-generate OpenAPI client library - - echo "Running the application on port $PORT..." + - pip install -r requirements.txt + - echo "Verifying SSL files..." + - ls ssl/ # Ensure dev SSL certificates are present + - echo "Running the application with dev SSL certificates on port $PORT..." - cd backend - - python3.8 -m main # The app will now use $PORT for binding + - python3.8 -m main release: stage: release diff --git a/backend/main.py b/backend/main.py index 7308901..23e9f47 100644 --- a/backend/main.py +++ b/backend/main.py @@ -93,18 +93,28 @@ if __name__ == "__main__": # Get environment from an environment variable environment = os.getenv("ENVIRONMENT", "dev") + is_ci = os.getenv("CI", "false").lower() == "true" # Check if running in CI port = int(os.getenv("PORT", 8000)) # Default to 8000 if PORT is not set # Paths for SSL certificates - cert_path = "ssl/cert.pem" - key_path = "ssl/key.pem" - - if environment == "test": + if is_ci: + # Use self-signed certificates for CI + cert_path = "ssl/cert.pem" + key_path = "ssl/key.pem" + host = "127.0.0.1" # In CI, bind to localhost + print("Using self-signed SSL certificates for CI...") + elif environment == "test": + # Use proper test certificates cert_path = "ssl/mx-aare-test.psi.ch.pem" key_path = "ssl/mx-aare-test.psi.ch.key" - host = "0.0.0.0" # Bind to all interfaces + host = "0.0.0.0" # In test, bind to all interfaces + print("Using test SSL certificates...") else: - host = "127.0.0.1" # Default for other environments + # Use development self-signed certificates + cert_path = "ssl/cert.pem" + key_path = "ssl/key.pem" + host = "127.0.0.1" # Bind to localhost for dev + print("Using self-signed SSL certificates for development...") # Run the application with appropriate SSL setup uvicorn.run( -- GitLab