Skip to content

Commit

Permalink
Configure Application for Initial Live Deployment (#34)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dhruv-ahuja authored Sep 22, 2024
1 parent 67c548e commit f4487a7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 14 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/config/constants/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
]
9 changes: 7 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f4487a7

Please sign in to comment.