fixing bugs with ci pipeline
This commit is contained in:
parent
8f79e5a430
commit
6b493757c1
@ -44,16 +44,16 @@ deploy:
|
|||||||
- main
|
- main
|
||||||
variables:
|
variables:
|
||||||
CI: "true" # Mark this as a CI run
|
CI: "true" # Mark this as a CI run
|
||||||
ENVIRONMENT: dev # Use dev environment settings
|
ENVIRONMENT: test # Use test environment settings
|
||||||
PORT: 8081 # Set the port for the application
|
PORT: 8081
|
||||||
script:
|
script:
|
||||||
- echo "Setting up dependencies..."
|
- echo "Setting up Python dependencies..."
|
||||||
- source $VIRTUAL_ENV/bin/activate
|
- source $VIRTUAL_ENV/bin/activate
|
||||||
- pip install -r requirements.txt
|
- pip install -r requirements.txt
|
||||||
- echo "Verifying SSL files..."
|
- echo "Starting the application to test startup with SSL..."
|
||||||
- echo "Running the application with dev SSL certificates on port $PORT..."
|
|
||||||
- cd backend
|
- cd backend
|
||||||
- python3.8 -m main
|
- python3.8 -m main # App will start, validate, and exit
|
||||||
|
- echo "Application startup validation completed successfully."
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
|
@ -90,6 +90,8 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
# Default behavior: Run the FastAPI server
|
# Default behavior: Run the FastAPI server
|
||||||
import os
|
import os
|
||||||
|
from multiprocessing import Process
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
# Get environment from an environment variable
|
# Get environment from an environment variable
|
||||||
environment = os.getenv("ENVIRONMENT", "dev")
|
environment = os.getenv("ENVIRONMENT", "dev")
|
||||||
@ -98,25 +100,22 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# Paths for SSL certificates
|
# Paths for SSL certificates
|
||||||
if is_ci:
|
if is_ci:
|
||||||
# Use self-signed certificates for CI
|
|
||||||
cert_path = "ssl/cert.pem"
|
cert_path = "ssl/cert.pem"
|
||||||
key_path = "ssl/key.pem"
|
key_path = "ssl/key.pem"
|
||||||
host = "127.0.0.1" # In CI, bind to localhost
|
host = "127.0.0.1"
|
||||||
print("Using self-signed SSL certificates for CI...")
|
print("Running in CI mode with self-signed certificates...")
|
||||||
elif environment == "test":
|
elif environment == "test":
|
||||||
# Use proper test certificates
|
|
||||||
cert_path = "ssl/mx-aare-test.psi.ch.pem"
|
cert_path = "ssl/mx-aare-test.psi.ch.pem"
|
||||||
key_path = "ssl/mx-aare-test.psi.ch.key"
|
key_path = "ssl/mx-aare-test.psi.ch.key"
|
||||||
host = "0.0.0.0" # In test, bind to all interfaces
|
host = "0.0.0.0"
|
||||||
print("Using test SSL certificates...")
|
print("Using test SSL certificates...")
|
||||||
else:
|
else:
|
||||||
# Use development self-signed certificates
|
|
||||||
cert_path = "ssl/cert.pem"
|
cert_path = "ssl/cert.pem"
|
||||||
key_path = "ssl/key.pem"
|
key_path = "ssl/key.pem"
|
||||||
host = "127.0.0.1" # Bind to localhost for dev
|
host = "127.0.0.1"
|
||||||
print("Using self-signed SSL certificates for development...")
|
print("Using development SSL certificates...")
|
||||||
|
|
||||||
# Run the application with appropriate SSL setup
|
def run_server():
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
app,
|
app,
|
||||||
host=host,
|
host=host,
|
||||||
@ -125,3 +124,15 @@ if __name__ == "__main__":
|
|||||||
ssl_keyfile=key_path,
|
ssl_keyfile=key_path,
|
||||||
ssl_certfile=cert_path,
|
ssl_certfile=cert_path,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if is_ci:
|
||||||
|
# In CI, start server in a subprocess and exit after a short delay
|
||||||
|
server_process = Process(target=run_server)
|
||||||
|
server_process.start()
|
||||||
|
sleep(5) # Wait for 5 seconds to ensure the server starts without errors
|
||||||
|
server_process.terminate() # Terminate the server process
|
||||||
|
server_process.join() # Clean up the process
|
||||||
|
print("CI: Server started successfully and exited.")
|
||||||
|
else:
|
||||||
|
# Normal behavior for running the FastAPI server
|
||||||
|
run_server()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user