From 7042079eb3008e4c4a54c2329fbb6c2861f6efc1 Mon Sep 17 00:00:00 2001 From: Nikolai Papin Date: Wed, 27 Nov 2024 13:39:12 +0300 Subject: [PATCH] Minimal compose file, healthcheck, redis and loki requirements --- .gitignore | 2 ++ Backend/app/main.py | 6 ++++ Backend/requirements.txt | 4 ++- docker-compose.yml | 70 ++++++++++++++++++++++++++++++++++++++++ loki-config.yaml | 0 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yml create mode 100644 loki-config.yaml diff --git a/.gitignore b/.gitignore index 7594f94..d706088 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.env + # Kate *.kate-swp diff --git a/Backend/app/main.py b/Backend/app/main.py index efa4340..66ef7d7 100644 --- a/Backend/app/main.py +++ b/Backend/app/main.py @@ -5,6 +5,12 @@ app = FastAPI() +@app.get("/healthcheck") +def healthcheck(): + """ + Health check endpoint + """ + return {"status": "healthy"} def main(): """ diff --git a/Backend/requirements.txt b/Backend/requirements.txt index 0bf49d2..36ab45d 100644 --- a/Backend/requirements.txt +++ b/Backend/requirements.txt @@ -1,4 +1,6 @@ fastapi[standard] peewee pendulum -python-dotenv \ No newline at end of file +python-dotenv +python-logging-loki +redis[hiredis] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a66f857 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,70 @@ +services: + postgres: + image: postgres:latest + environment: + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + volumes: + - postgres_data:/var/lib/postgresql/data + networks: + - my_network + + redis: + image: redis:latest + environment: + - REDIS_PASSWORD=${REDIS_PASSWORD} + command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}"] + networks: + - my_network + + # loki: + # image: grafana/loki:latest + # command: -config.file=/etc/loki/local-config.yaml + # volumes: + # - ./loki-config.yaml:/etc/loki/local-config.yaml + # networks: + # - my_network + + # grafana: + # image: grafana/grafana:latest + # environment: + # GF_SECURITY_ADMIN_PASSWORD: ${GF_SECURITY_ADMIN_PASSWORD} + # ports: + # - "3000:3000" + # networks: + # - my_network + # depends_on: + # - loki + + fastapi: + build: + context: ./Backend + dockerfile: Dockerfile + environment: + POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + JWT_KEY: ${JWT_KEY} + JWT_ACCESS_EXPIRE_MINUTES: ${JWT_ACCESS_EXPIRE_MINUTES} + JWT_REFRESH_EXPIRE_MINUTES: ${JWT_REFRESH_EXPIRE_MINUTES} + JWT_ISSUER: ${JWT_ISSUER} + JWT_AUDIENCE: ${JWT_AUDIENCE} + ports: + - "8000:8000" + networks: + - my_network + depends_on: + - postgres + - redis + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8000/healthcheck"] + interval: 10s + timeout: 5s + retries: 3 + +volumes: + postgres_data: + +networks: + my_network: diff --git a/loki-config.yaml b/loki-config.yaml new file mode 100644 index 0000000..e69de29