From dfe86fc47f1b7192411a6425e10c4a1bcffd2e1c Mon Sep 17 00:00:00 2001 From: Victor Mylle Date: Mon, 20 Feb 2023 13:39:44 +0100 Subject: [PATCH] Added docker-compose file --- backend/src/routers/signs.py | 16 ++++++++++++---- docker-compose.yml | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 docker-compose.yml diff --git a/backend/src/routers/signs.py b/backend/src/routers/signs.py index 8eb7f18..3b5aaaf 100644 --- a/backend/src/routers/signs.py +++ b/backend/src/routers/signs.py @@ -1,8 +1,9 @@ +import asyncio import datetime import os import zipfile -from fastapi import APIRouter, Depends, status +from fastapi import APIRouter, BackgroundTasks, Depends, status from fastapi.responses import FileResponse from fastapi_jwt_auth import AuthJWT from pydantic import BaseModel @@ -97,7 +98,7 @@ async def delete_sign(id: int, Authorize: AuthJWT = Depends(), session: AsyncSes return {"message": "Sign deleted"} @router.get("/download/all", status_code=status.HTTP_200_OK) -async def download_all(Authorize: AuthJWT = Depends(), session: AsyncSession = Depends(get_session)): +async def download_all(background_tasks: BackgroundTasks, Authorize: AuthJWT = Depends(), session: AsyncSession = Depends(get_session)): Authorize.jwt_required() user = Authorize.get_jwt_subject() @@ -120,5 +121,12 @@ async def download_all(Authorize: AuthJWT = Depends(), session: AsyncSession = D for path in paths: zip_file.write(f"{settings.DATA_PATH}/{path}", os.path.basename(path)) - # return the zip file and delete it after the request is done - return FileResponse(zip_path, media_type="application/zip", filename="signs.zip", delete_after_request=True) \ No newline at end of file + background_tasks.add_task(delete_zip_file, zip_path) + # serve the zip file as the response + response = FileResponse(zip_path, media_type="application/zip", filename="signs.zip") + + return response + +# define a function to delete the zip file +async def delete_zip_file(zip_path): + os.remove(zip_path) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e5f60da --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: "3" + +services: + backend: + build: ./backend + ports: + - "8000:8000" + volumes: + - ./data:/data + + environment: + DB_USE_SQLITE: "true" + DB_SQLITE_PATH: "/data/sqlite.db" + DATA_PATH: "/data/videos" + + JWT_SECRET_KEY: "e8ae5c5d5cd7f0f1bec2303ad04a7c80f09f759d480a7a5faff5a6bbaa4078d0" + + DEFAULT_USER_ENABLED: "true" + DEFAULT_USER_EMAIL: "signlanuage@tool.com" + DEFAULT_USER_PASSWORD: "SignLanguageTool123!" + + frontend: + build: ./frontend + ports: + - "3000:3000" + environment: + REACT_APP_BACKEND_URL: "http://192.168.1.171:8000"