refactor the code structure
This commit is contained in:
parent
f19beaa263
commit
d176fb9d9a
@ -1,19 +0,0 @@
|
|||||||
# Dockerfile for Python Service
|
|
||||||
FROM python:3.10-slim
|
|
||||||
|
|
||||||
# Set the working directory inside the container
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy the requirements.txt to the working directory and install dependencies
|
|
||||||
COPY requirements.txt ./
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
|
||||||
|
|
||||||
# Copy the application code to the working directory
|
|
||||||
COPY . /app
|
|
||||||
|
|
||||||
# Expose the port used by the FastAPI app
|
|
||||||
EXPOSE 8005
|
|
||||||
|
|
||||||
|
|
||||||
# Run the application using the start script
|
|
||||||
CMD ["uvicorn", "app.central_storage.webapi.main:app", "--reload", "--port=8005", "--host=0.0.0.0"]
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
from infra.config.app_settings import app_settings
|
|
||||||
from beanie import init_beanie
|
|
||||||
from motor.motor_asyncio import AsyncIOMotorClient
|
|
||||||
from app.central_storage.backend.models import backend_models
|
|
||||||
|
|
||||||
|
|
||||||
def register(app):
|
|
||||||
app.debug = "mongo_debug"
|
|
||||||
app.title = "mongo_name"
|
|
||||||
|
|
||||||
@app.on_event("startup")
|
|
||||||
async def start_database():
|
|
||||||
await initiate_database()
|
|
||||||
|
|
||||||
|
|
||||||
async def initiate_database():
|
|
||||||
client = AsyncIOMotorClient(
|
|
||||||
app_settings.MONGODB_URI,
|
|
||||||
serverSelectionTimeoutMS=60000,
|
|
||||||
minPoolSize=5, # Minimum number of connections in the pool
|
|
||||||
maxPoolSize=20, # Maximum number of connections in the pool
|
|
||||||
)
|
|
||||||
await init_beanie(
|
|
||||||
database=client[app_settings.MONGODB_NAME], document_models=backend_models
|
|
||||||
)
|
|
||||||
24
apps/central_storage/.env
Normal file
24
apps/central_storage/.env
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
APP_NAME=central_storage
|
||||||
|
export SERVICE_API_ACCESS_HOST=0.0.0.0
|
||||||
|
export SERVICE_API_ACCESS_PORT=8005
|
||||||
|
export CONTAINER_APP_ROOT=/app
|
||||||
|
export AZURE_STORAGE_DOCUMENT_API_KEY=xbiFtFeQ6v5dozgVM99fZ9huUomL7QcLu6s0y8zYHtIXZ8XdneKDMcg4liQr/9oNlVoRFcZhWjLY+ASt9cjICQ==
|
||||||
|
export AZURE_STORAGE_DOCUMENT_API_ENDPOINT="https://freeleaps1document.blob.core.windows.net/"
|
||||||
|
export LOG_BASE_PATH=$CONTAINER_APP_ROOT/log/$APP_NAME
|
||||||
|
export BACKEND_LOG_FILE_NAME=$APP_NAME
|
||||||
|
export APPLICATION_ACTIVITY_LOG=$APP_NAME-activity
|
||||||
|
export MONGODB_NAME=freeleaps2
|
||||||
|
export MONGODB_PORT=27017
|
||||||
|
GIT_REPO_ROOT=/mnt/freeleaps/freeleaps-service-hub
|
||||||
|
CODEBASE_ROOT=/mnt/freeleaps/freeleaps-service-hub/app/central_storage
|
||||||
|
SITE_DEPLOY_FOLDER=/mnt/freeleaps/freeleaps-service-hub/sites/central_storage/deploy
|
||||||
|
#!/bin/bash
|
||||||
|
export VENV_DIR=venv_t
|
||||||
|
export VENV_ACTIVATE=venv_t/bin/activate
|
||||||
|
export DOCKER_HOME=/var/lib/docker
|
||||||
|
export DOCKER_APP_HOME=$DOCKER_HOME/app
|
||||||
|
export DOCKER_BACKEND_HOME=$DOCKER_APP_HOME/$APP_NAME
|
||||||
|
export DOCKER_BACKEND_LOG_HOME=$DOCKER_BACKEND_HOME/log
|
||||||
|
export MONGODB_URI=mongodb://localhost:27017/
|
||||||
|
export FREELEAPS_ENV=local
|
||||||
|
|
||||||
38
apps/central_storage/Dockerfile
Normal file
38
apps/central_storage/Dockerfile
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
FROM python:3.10-slim-buster
|
||||||
|
|
||||||
|
# docker settings
|
||||||
|
ARG CONTAINER_APP_ROOT=
|
||||||
|
ENV APP_NAME=
|
||||||
|
|
||||||
|
ENV AZURE_STORAGE_DOCUMENT_API_KEY=""
|
||||||
|
ENV AZURE_STORAGE_DOCUMENT_API_ENDPOINT=""
|
||||||
|
|
||||||
|
#site_settings
|
||||||
|
ENV SERVICE_API_ACCESS_HOST=0.0.0.0
|
||||||
|
ENV SERVICE_API_ACCESS_PORT=8005
|
||||||
|
ENV MONGODB_NAME=
|
||||||
|
ENV MONGODB_PORT=
|
||||||
|
ENV MONGODB_URI=
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#log_settings
|
||||||
|
ENV LOG_BASE_PATH=
|
||||||
|
ENV BACKEND_LOG_FILE_NAME=
|
||||||
|
ENV APPLICATION_ACTIVITY_LOG=
|
||||||
|
|
||||||
|
|
||||||
|
WORKDIR ${CONTAINER_APP_ROOT}
|
||||||
|
COPY requirements.txt .
|
||||||
|
|
||||||
|
RUN pip install --upgrade pip
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . ${CONTAINER_APP_ROOT}
|
||||||
|
|
||||||
|
RUN apt update
|
||||||
|
RUN apt install -y netcat
|
||||||
|
RUN ln -s /bin/bash /usr/bin/bash
|
||||||
|
|
||||||
|
EXPOSE ${SERVICE_API_ACCESS_PORT}
|
||||||
|
CMD ["uvicorn", "webapi.main:app", "--reload", "--port=${SERVICE_API_ACCESS_PORT}", "--host=${SERVICE_API_ACCESS_HOST}"]
|
||||||
@ -1,4 +1,4 @@
|
|||||||
from app.central_storage.backend.business.document_manager import (
|
from backend.business.document_manager import (
|
||||||
DocumentManager,
|
DocumentManager,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
from app.central_storage.backend.services.document_service import DocumentService
|
from backend.services.document_service import DocumentService
|
||||||
from app.central_storage.backend.models.models import MediaType, DataFormat
|
from backend.models.models import MediaType, DataFormat
|
||||||
|
|
||||||
|
|
||||||
class DocumentManager:
|
class DocumentManager:
|
||||||
@ -1,4 +1,4 @@
|
|||||||
from app.central_storage.common.config.app_settings import app_settings
|
from common.config.app_settings import app_settings
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
@ -1,9 +1,9 @@
|
|||||||
from datetime import datetime as dt, timezone as tz
|
from datetime import datetime as dt, timezone as tz
|
||||||
from app.central_storage.backend.models.models import DocumentDoc
|
from backend.models.models import DocumentDoc
|
||||||
from app.central_storage.backend.models.constants import MediaType, DataFormat
|
from backend.models.constants import MediaType, DataFormat
|
||||||
|
|
||||||
from infra.exception.exceptions import DoesNotExistError
|
from common.exception.exceptions import DoesNotExistError
|
||||||
from app.central_storage.backend.infra.azure_storage.blob_handler import (
|
from backend.infra.azure_storage.blob_handler import (
|
||||||
AzureBlobHandler,
|
AzureBlobHandler,
|
||||||
)
|
)
|
||||||
import base64
|
import base64
|
||||||
@ -5,9 +5,8 @@ from pydantic_settings import BaseSettings
|
|||||||
class AppSettings(BaseSettings):
|
class AppSettings(BaseSettings):
|
||||||
NAME: str = "central_storage"
|
NAME: str = "central_storage"
|
||||||
|
|
||||||
AZURE_STORAGE_DOCUMENT_API_ENDPOINT: str = (
|
AZURE_STORAGE_DOCUMENT_API_ENDPOINT: str = ""
|
||||||
"https://freeleaps1document.blob.core.windows.net/"
|
|
||||||
)
|
|
||||||
AZURE_STORAGE_DOCUMENT_API_KEY: str = ""
|
AZURE_STORAGE_DOCUMENT_API_KEY: str = ""
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
40
apps/central_storage/start_fastapi.sh
Executable file
40
apps/central_storage/start_fastapi.sh
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
rp=$(dirname "$(realpath '$1'))")
|
||||||
|
pushd $rp
|
||||||
|
|
||||||
|
APP_NAME=central_storage
|
||||||
|
APP_PARENT_FOLDER=apps
|
||||||
|
|
||||||
|
GIT_REPO_ROOT=$(git rev-parse --show-toplevel)
|
||||||
|
CODEBASE_ROOT=$GIT_REPO_ROOT/$APP_PARENT_FOLDER/$APP_NAME
|
||||||
|
SITE_DEPLOY_FOLDER=$GIT_REPO_ROOT/sites/$APP_NAME/deploy
|
||||||
|
|
||||||
|
|
||||||
|
echo APP_NAME=$APP_NAME > .env
|
||||||
|
cat $SITE_DEPLOY_FOLDER/common/.env >> .env
|
||||||
|
echo GIT_REPO_ROOT=$(git rev-parse --show-toplevel) >> .env
|
||||||
|
echo CODEBASE_ROOT=$GIT_REPO_ROOT/$APP_PARENT_FOLDER/$APP_NAME >> .env
|
||||||
|
echo SITE_DEPLOY_FOLDER=$GIT_REPO_ROOT/sites/$APP_NAME/deploy >> .env
|
||||||
|
cat $SITE_DEPLOY_FOLDER/common/.host.env >> .env
|
||||||
|
cat $SITE_DEPLOY_FOLDER/local/.env >> .env
|
||||||
|
|
||||||
|
. .env
|
||||||
|
|
||||||
|
if [ -d "$VENV_DIR" ]
|
||||||
|
then
|
||||||
|
echo "Folder $VENV_DIR exists. Proceed to next steps"
|
||||||
|
else
|
||||||
|
echo "Folder $VENV_DIR dosen't exist. create it"
|
||||||
|
sudo apt install python3-pip
|
||||||
|
python3 -m pip install virtualenv
|
||||||
|
python3 -m virtualenv $VENV_DIR
|
||||||
|
fi
|
||||||
|
|
||||||
|
source $VENV_DIR/bin/activate
|
||||||
|
pip install --upgrade pip
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
uvicorn webapi.main:app --reload --host 0.0.0.0 --port $SERVICE_API_ACCESS_PORT
|
||||||
|
|
||||||
|
|
||||||
|
popd
|
||||||
@ -2,12 +2,12 @@ import logging
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.openapi.utils import get_openapi
|
from fastapi.openapi.utils import get_openapi
|
||||||
|
|
||||||
from app.central_storage.webapi.providers import common
|
from webapi.providers import common
|
||||||
from app.central_storage.webapi.providers import logger
|
from webapi.providers import logger
|
||||||
from app.central_storage.webapi.providers import router
|
from webapi.providers import router
|
||||||
from app.central_storage.webapi.providers import database
|
from webapi.providers import database
|
||||||
from app.central_storage.webapi.providers import scheduler
|
from webapi.providers import scheduler
|
||||||
from app.central_storage.webapi.providers import exception_handler
|
from webapi.providers import exception_handler
|
||||||
from .freeleaps_app import FreeleapsApp
|
from .freeleaps_app import FreeleapsApp
|
||||||
|
|
||||||
|
|
||||||
@ -16,6 +16,8 @@ class SiteSettings(BaseSettings):
|
|||||||
TIME_ZONE: str = "UTC"
|
TIME_ZONE: str = "UTC"
|
||||||
|
|
||||||
BASE_PATH: str = os.path.dirname(os.path.dirname((os.path.abspath(__file__))))
|
BASE_PATH: str = os.path.dirname(os.path.dirname((os.path.abspath(__file__))))
|
||||||
|
MONGODB_NAME: str = os.environ["MONGODB_NAME"]
|
||||||
|
MONGODB_URI: str = os.environ["MONGODB_URI"]
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
env_file = ".devbase-webapi.env"
|
env_file = ".devbase-webapi.env"
|
||||||
@ -1,5 +1,5 @@
|
|||||||
from app.central_storage.webapi.bootstrap.application import create_app
|
from webapi.bootstrap.application import create_app
|
||||||
from app.central_storage.webapi.config.site_settings import site_settings
|
from webapi.config.site_settings import site_settings
|
||||||
from fastapi.responses import RedirectResponse
|
from fastapi.responses import RedirectResponse
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
import uvicorn
|
import uvicorn
|
||||||
20
apps/central_storage/webapi/providers/database.py
Normal file
20
apps/central_storage/webapi/providers/database.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from webapi.config.site_settings import site_settings
|
||||||
|
from beanie import init_beanie
|
||||||
|
from motor.motor_asyncio import AsyncIOMotorClient
|
||||||
|
from backend.models import backend_models
|
||||||
|
|
||||||
|
|
||||||
|
def register(app):
|
||||||
|
app.debug = "mongo_debug"
|
||||||
|
app.title = "mongo_name"
|
||||||
|
|
||||||
|
@app.on_event("startup")
|
||||||
|
async def start_database():
|
||||||
|
await initiate_database()
|
||||||
|
|
||||||
|
|
||||||
|
async def initiate_database():
|
||||||
|
client = AsyncIOMotorClient(site_settings.MONGODB_URI, serverSelectionTimeoutMS=60000)
|
||||||
|
await init_beanie(
|
||||||
|
database=client[site_settings.MONGODB_NAME], document_models=backend_models
|
||||||
|
)
|
||||||
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from infra.config.log_settings import log_settings
|
from common.config.log_settings import log_settings
|
||||||
|
|
||||||
|
|
||||||
def register(app=None):
|
def register(app=None):
|
||||||
@ -1,5 +1,4 @@
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
from infra.token.token_manager import TokenManager
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
@ -7,8 +6,7 @@ from fastapi import Depends, HTTPException
|
|||||||
from starlette.status import HTTP_401_UNAUTHORIZED
|
from starlette.status import HTTP_401_UNAUTHORIZED
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from infra.token.token_manager import TokenManager
|
from backend.application.document_hub import DocumentHub
|
||||||
from app.central_storage.backend.application.document_hub import DocumentHub
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
from infra.token.token_manager import TokenManager
|
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
@ -7,11 +6,9 @@ from fastapi import Depends, HTTPException
|
|||||||
from starlette.status import HTTP_401_UNAUTHORIZED
|
from starlette.status import HTTP_401_UNAUTHORIZED
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from infra.token.token_manager import TokenManager
|
from backend.application.document_hub import DocumentHub
|
||||||
from app.central_storage.backend.application.document_hub import DocumentHub
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
token_manager = TokenManager()
|
|
||||||
|
|
||||||
|
|
||||||
# Web API
|
# Web API
|
||||||
@ -1,10 +1,9 @@
|
|||||||
from fastapi import APIRouter, UploadFile, File, Form, HTTPException
|
from fastapi import APIRouter, UploadFile, File, Form, HTTPException
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
from infra.token.token_manager import TokenManager
|
|
||||||
from starlette.status import HTTP_401_UNAUTHORIZED
|
from starlette.status import HTTP_401_UNAUTHORIZED
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from app.central_storage.backend.application.document_hub import DocumentHub
|
from backend.application.document_hub import DocumentHub
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@ -4,7 +4,7 @@ from infra.token.token_manager import TokenManager
|
|||||||
from starlette.status import HTTP_401_UNAUTHORIZED
|
from starlette.status import HTTP_401_UNAUTHORIZED
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from app.central_storage.backend.application.document_hub import DocumentHub
|
from backend.application.document_hub import DocumentHub
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user