fixing bugs with ci pipeline
This commit is contained in:
@ -90,6 +90,8 @@ if __name__ == "__main__":
|
||||
else:
|
||||
# Default behavior: Run the FastAPI server
|
||||
import os
|
||||
from multiprocessing import Process
|
||||
from time import sleep
|
||||
|
||||
# Get environment from an environment variable
|
||||
environment = os.getenv("ENVIRONMENT", "dev")
|
||||
@ -98,30 +100,39 @@ if __name__ == "__main__":
|
||||
|
||||
# Paths for SSL certificates
|
||||
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...")
|
||||
host = "127.0.0.1"
|
||||
print("Running in CI mode with self-signed certificates...")
|
||||
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" # In test, bind to all interfaces
|
||||
host = "0.0.0.0"
|
||||
print("Using test SSL certificates...")
|
||||
else:
|
||||
# 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...")
|
||||
host = "127.0.0.1"
|
||||
print("Using development SSL certificates...")
|
||||
|
||||
# Run the application with appropriate SSL setup
|
||||
uvicorn.run(
|
||||
app,
|
||||
host=host,
|
||||
port=port,
|
||||
log_level="debug",
|
||||
ssl_keyfile=key_path,
|
||||
ssl_certfile=cert_path,
|
||||
)
|
||||
def run_server():
|
||||
uvicorn.run(
|
||||
app,
|
||||
host=host,
|
||||
port=port,
|
||||
log_level="debug",
|
||||
ssl_keyfile=key_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()
|
||||
|
Reference in New Issue
Block a user