update docker-compose to add healthcheck

This commit is contained in:
2025-10-18 17:00:29 -04:00
parent a79216a889
commit 7813d9d3fe
2 changed files with 13 additions and 0 deletions

View File

@@ -20,5 +20,11 @@ services:
ports: ports:
- "8000:8000" - "8000:8000"
command: ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] command: ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
healthcheck:
test: ["CMD-SHELL", "python -c \"import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/', timeout=2)\""]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
volumes: volumes:
pgdata: pgdata:

View File

@@ -40,6 +40,13 @@ if "API_KEY" in ENV:
else: else:
logger.error("API_KEY not found in .env file... cannot continue.") logger.error("API_KEY not found in .env file... cannot continue.")
exit() exit()
try:
with psycopg.connect(connect_statement) as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1")
except Exception as error:
logger.error("Failed to connect to PostgreSQL: {}", error)
exit()
with psycopg.connect(connect_statement) as conn: with psycopg.connect(connect_statement) as conn:
with conn.cursor() as cur: with conn.cursor() as cur: