From c0005f38d5a22a28800f54727ef52a7005a70f39 Mon Sep 17 00:00:00 2001 From: H4CK3R-01 Date: Mon, 13 Mar 2023 13:37:23 +0100 Subject: [PATCH] Added healthchecks --- backend/Dockerfile | 4 +++- backend/app.py | 2 ++ backend/routes/health.py | 10 ++++++++++ frontend/Dockerfile | 4 +++- 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 backend/routes/health.py diff --git a/backend/Dockerfile b/backend/Dockerfile index 9fef8fb..c21de60 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -9,4 +9,6 @@ EXPOSE 8080 COPY ./ /app -CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8080"] \ No newline at end of file +CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8080"] + +HEALTHCHECK --interval=1m --timeout=3s CMD curl --fail http://localhost:8080/health || exit 1 \ No newline at end of file diff --git a/backend/app.py b/backend/app.py index 468341c..e674718 100644 --- a/backend/app.py +++ b/backend/app.py @@ -2,6 +2,7 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from config.config import initiate_database +from routes.health import router as HealthRouter from routes.request import router as RequestRouter from routes.admin import router as AdminRouter from config import Settings @@ -24,6 +25,7 @@ app.add_middleware( app.include_router(RequestRouter, tags=["Requests"]) +app.include_router(HealthRouter, tags=["Health"]) if Settings().ENV == "dev": app.include_router(AdminRouter, tags=["Admin"]) \ No newline at end of file diff --git a/backend/routes/health.py b/backend/routes/health.py new file mode 100644 index 0000000..7c35326 --- /dev/null +++ b/backend/routes/health.py @@ -0,0 +1,10 @@ +from fastapi import APIRouter + +from database.database import * +from models.request import * + +router = APIRouter() + +@router.get("/health", response_description="Returns 200") +async def healthcheck(): + return \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile index dfc5cd4..df5cb54 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -2,4 +2,6 @@ FROM nginx:latest COPY ./index.html /usr/share/nginx/html/index.html COPY ./index.css /usr/share/nginx/html/index.css -COPY ./index.js /usr/share/nginx/html/index.js \ No newline at end of file +COPY ./index.js /usr/share/nginx/html/index.js + +HEALTHCHECK --interval=1m --timeout=3s CMD curl --fail http://localhost/ || exit 1 \ No newline at end of file