From f4487a73ad836e46f14f50ba2df6bcf25c07eb15 Mon Sep 17 00:00:00 2001 From: Dhruv <83733638+dhruv-ahuja@users.noreply.github.com> Date: Mon, 23 Sep 2024 00:04:04 +0530 Subject: [PATCH] Configure Application for Initial Live Deployment (#34) * fix: correct docker compose env vars * chore: cache requirements for faster docker builds * chore: update requirements * chore: update cors list * fix: use utc datetime for created and updated common db fields * chore: update documentation config - update app name and set current version - disable docs access for prod environment --- Dockerfile | 4 ++-- docker-compose.yml | 3 ++- requirements.txt | 27 ++++++++++++++------------- src/config/constants/app.py | 9 ++++++++- src/main.py | 9 +++++++-- src/models/common.py | 4 ++-- 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3a3ab2a..d254151 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,8 +12,8 @@ RUN apt-get update && apt-get install -y curl libcurl4-openssl-dev build-essenti # copying and installing requirements first will avoid a re-install of all dependencies when re-building the image COPY requirements.txt . -RUN pip3 install --no-cache-dir wheel -RUN pip3 install --no-cache-dir -r requirements.txt +RUN pip3 install wheel +RUN pip3 install -r requirements.txt # now starting the next layer, the one that runs the program # FROM ubuntu:22.04 AS runner-image diff --git a/docker-compose.yml b/docker-compose.yml index 78efc7e..421aa85 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -49,8 +49,9 @@ services: - NEW_RELIC_LICENSE_KEY=${NEW_RELIC_LICENSE_KEY} - NEW_RELIC_APP_NAME=${NEW_RELIC_APP_NAME} - NEW_RELIC_APP_NAME=backend_burger_docker - - ENV NEW_RELIC_LOG=/home/myuser/log/newrelic.log + - NEW_RELIC_LOG=/home/myuser/log/newrelic.log - REDIS_HOST=redis_burger + - REDIS_PASSWORD=${REDIS_PASSWORD} - APP_ENVIRONMENT=prod - LOGFIRE_PYDANTIC_PLUGIN_RECORD=${LOGFIRE_PYDANTIC_PLUGIN_RECORD} env_file: diff --git a/requirements.txt b/requirements.txt index 0d58602..cccb860 100644 --- a/requirements.txt +++ b/requirements.txt @@ -42,7 +42,7 @@ jmespath==1.0.1 joblib==1.4.2 kombu==5.3.4 lazy-model==0.2.0 -logfire==0.51.0 +logfire==0.53.0 loguru==0.7.2 markdown-it-py==3.0.0 MarkupSafe==2.1.5 @@ -61,18 +61,19 @@ mypy-boto3-sqs==1.28.82 mypy-extensions==1.0.0 newrelic==9.3.0 numpy==2.0.0 -opentelemetry-api==1.26.0 -opentelemetry-exporter-otlp-proto-common==1.26.0 -opentelemetry-exporter-otlp-proto-http==1.26.0 -opentelemetry-instrumentation==0.47b0 -opentelemetry-instrumentation-asgi==0.47b0 -opentelemetry-instrumentation-fastapi==0.47b0 -opentelemetry-instrumentation-pymongo==0.47b0 -opentelemetry-instrumentation-redis==0.47b0 -opentelemetry-proto==1.26.0 -opentelemetry-sdk==1.26.0 -opentelemetry-semantic-conventions==0.47b0 -opentelemetry-util-http==0.47b0 +opentelemetry-api==1.27.0 +opentelemetry-exporter-otlp-proto-common==1.27.0 +opentelemetry-exporter-otlp-proto-http==1.27.0 +opentelemetry-instrumentation==0.48b0 +opentelemetry-instrumentation-asgi==0.48b0 +opentelemetry-instrumentation-fastapi==0.48b0 +opentelemetry-instrumentation-pymongo==0.48b0 +opentelemetry-instrumentation-redis==0.48b0 +opentelemetry-instrumentation-system-metrics==0.48b0 +opentelemetry-proto==1.27.0 +opentelemetry-sdk==1.27.0 +opentelemetry-semantic-conventions==0.48b0 +opentelemetry-util-http==0.48b0 orjson==3.9.15 packaging==23.2 pandas==2.2.2 diff --git a/src/config/constants/app.py b/src/config/constants/app.py index 472f59c..9dd464b 100644 --- a/src/config/constants/app.py +++ b/src/config/constants/app.py @@ -50,4 +50,11 @@ "<=": "$lte", } -CORS_ALLOWED_HOSTS = ["http://localhost:5173", "http://127.0.0.1:5173", "http://0.0.0.0:5173"] +CORS_ALLOWED_HOSTS = [ + "http://localhost:5173", + "http://127.0.0.1:5173", + "http://0.0.0.0:5173", + "https://winter-orb.vercel.app", + "https://winter-orb.vercel.app/", + "winter-orb.vercel.app/", +] diff --git a/src/main.py b/src/main.py index 0d164f0..7decd4f 100644 --- a/src/main.py +++ b/src/main.py @@ -16,7 +16,7 @@ handle_auth_exception, ) from src.config.middleware import ExceptionHandlerMiddleware, LoggingMiddleware -from src.config.services import setup_services, initialize_logfire_services +from src.config.services import setup_services, initialize_logfire_services, settings from src.routers import poe, users, auth from src.schemas.responses import BaseResponse @@ -26,7 +26,12 @@ app = FastAPI( - lifespan=setup_services, redirect_slashes=False, default_response_class=ORJSONResponse, title="Backend Burger" + lifespan=setup_services, + redirect_slashes=False, + default_response_class=ORJSONResponse, + title="Winter Orb", + version="0.1.0", + openapi_url=None if settings.app_environment == "prod" else "/openapi.json", ) initialize_logfire_services(app) diff --git a/src/models/common.py b/src/models/common.py index d752013..efdde9e 100644 --- a/src/models/common.py +++ b/src/models/common.py @@ -8,8 +8,8 @@ class DateMetadataDocument(Document): """DateMetadataDocument provides created and updated time fields, and sets the correct `updated_time` each time the model instance is modified.""" - created_time: dt.datetime = Field(default_factory=dt.datetime.now) - updated_time: dt.datetime = Field(default_factory=dt.datetime.now) + created_time: dt.datetime = Field(default_factory=dt.datetime.utcnow) + updated_time: dt.datetime = Field(default_factory=dt.datetime.utcnow) @after_event(Update, Replace, SaveChanges, ValidateOnSave) def update_document_time(self) -> None: