Skip to content

Commit

Permalink
update k8s files, create docshow ai organization on prod, change app_…
Browse files Browse the repository at this point in the history
…env=development to app_env=dev
  • Loading branch information
liberty-rising committed Jan 5, 2024
1 parent 3a30937 commit 5cb277c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
16 changes: 16 additions & 0 deletions backend/envs/prod/initialization/setup_prod_environment.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
from database.database_manager import DatabaseManager
from database.organization_manager import OrganizationManager
from database.user_manager import UserManager
from models.organization import Organization
from models.user import User, UserRole
from security import get_password_hash
from utils.utils import get_app_logger

logger = get_app_logger(__name__)


def create_docshow_ai_organization():
"""Creates the DocShow AI organization if it doesn't already exist."""
organization = Organization(name="DocShow AI")

with DatabaseManager() as session:
org_manager = OrganizationManager(session)
existing_org = org_manager.get_organization_by_name(organization.name)
if not existing_org:
org_manager.create_organization(organization)
logger.debug("DocShow AI organization created.")
else:
logger.debug("DocShow AI organization already exists.")


def create_admin_user():
"""Creates an admin user if it doesn't already exist."""
admin_user = User(
Expand Down
4 changes: 3 additions & 1 deletion backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

DATABASE_URL = config("DATABASE_URL")

EMAIL_VERIFICATION_EXPIRE_MINUTES = int(config("EMAIL_VERIFICATION_EXPIRE_MINUTES"))
EMAIL_VERIFICATION_EXPIRE_MINUTES = int(
config("EMAIL_VERIFICATION_EXPIRE_MINUTES", default=15)
)

OPENAI_API_KEY = config("OPENAI_API_KEY")

Expand Down
6 changes: 4 additions & 2 deletions backend/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from envs.prod.initialization.setup_prod_environment import (
create_admin_user as prod_create_admin_user,
create_docshow_ai_organization,
)
from envs.dev.utils import seed_db
from settings import APP_ENV, JWT_SECRET_KEY
Expand All @@ -28,19 +29,20 @@
def run_startup_routines():
check_jwt_secret_key()

if APP_ENV == "development":
if APP_ENV == "dev":
create_sample_organization()
dev_create_admin_user()
seed_db()
create_sample_dashboard()
create_sample_dataprofile()

if APP_ENV == "prod":
create_docshow_ai_organization()
prod_create_admin_user()


def check_jwt_secret_key():
if APP_ENV != "development" and JWT_SECRET_KEY == "mysecretkey":
if APP_ENV != "dev" and JWT_SECRET_KEY == "mysecretkey":
raise EnvironmentError(
"JWT_SECRET_KEY must be set in non-development environments"
)
4 changes: 2 additions & 2 deletions backend/utils/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def send_password_reset_email_with_sendgrid(email: List[str], token: str):
html_content=f'Click on the link to reset your password: <a href="https://{APP_HOST}/reset-password?token={token}">https://{APP_HOST}/reset-password</a>',
)
# Disable click tracking in development
if APP_ENV == "development":
if APP_ENV == "dev":
message.tracking_settings = TrackingSettings()
message.tracking_settings.click_tracking = ClickTracking(False, False)
try:
Expand All @@ -34,7 +34,7 @@ async def send_verification_email_with_sendgrid(email: List[str], token: str):
html_content=f'Click on the link to verify your email: <a href="https://{APP_HOST}/verify-email?token={token}">https://{APP_HOST}/verify-email</a>',
)
# Disable click tracking in development
if APP_ENV == "development":
if APP_ENV == "dev":
message.tracking_settings = TrackingSettings()
message.tracking_settings.click_tracking = ClickTracking(False, False)
try:
Expand Down
2 changes: 1 addition & 1 deletion backend/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_app_logger(name):
logger = logging.getLogger(name)

# Set log level based on the environment
log_level = logging.DEBUG if os.getenv("APP_ENV") == "development" else logging.INFO
log_level = logging.DEBUG if os.getenv("APP_ENV") == "dev" else logging.INFO

logger.setLevel(log_level)

Expand Down
8 changes: 7 additions & 1 deletion k8s/backend-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ kind: ConfigMap
metadata:
name: backend-config
data:
APP_ENV: "prod"
APP_ENV: "prod"
APP_HOST: "docshow.ai"
EMAIL_VERIFICATION_EXPIRE_MINUTES: "15"
PASSWORD_RESET_EXPIRE_MINUTES: "15"
SPACES_BUCKET_NAME: "docshowai"
SPACES_ENDPOINT_URL: "https://docshowai.fra1.digitaloceanspaces.com"
SPACES_REGION_NAME: "fra1"
15 changes: 15 additions & 0 deletions k8s/backend-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,18 @@ spec:
secretKeyRef:
name: jwt-secret
key: JWT_SECRET_KEY
- name: SENDGRID_API_KEY
valueFrom:
secretKeyRef:
name: sendgrid-api-key
key: SENDGRID_API_KEY
- name: SPACES_ACCESS_KEY
valueFrom:
secretKeyRef:
name: spaces-access-key
key: SPACES_ACCESS_KEY
- name: SPACES_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: spaces-secret-access-key
key: SPACES_SECRET_ACCESS_KEY

0 comments on commit 5cb277c

Please sign in to comment.