From 40a92ccafdc71219e1f59b165b8e8aca4a85343f Mon Sep 17 00:00:00 2001 From: Christopher Gondek Date: Wed, 15 Oct 2025 11:02:39 +0200 Subject: [PATCH] chore: add app.py for azure deploy --- .env.example | 9 +++++---- app.py | 23 +++++++++++++++++++++++ env_prod.env | 3 +-- src/settings.py | 7 ++++++- 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 app.py diff --git a/.env.example b/.env.example index 4ff550d..4cc3816 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ # Preprocessor Configuration -# Path to the preprocessor configuration YAML file -PP_CONFIG_PATH="/path/to/your/pp-config.yaml" +# Path to the preprocessor configuration YAML file (relative to project root) +PP_CONFIG_PATH="src/pp-config.yaml" # API Keys # API key for the preprocessor service @@ -10,8 +10,9 @@ PP_API_KEY="your-preprocessor-api-key-here" DB_ENDPOINT_API_KEY="your-database-endpoint-api-key-here" # Database Configuration -# Path to the SQLite database file -DB_URL="/path/to/your/database.db" +# Note: DB_PATH is automatically set based on DATA_DIR environment variable +# Local: defaults to data/database.sqlite +# Azure: set DATA_DIR=/home/_data in Azure App Settings # Power BI Configuration # Power BI dataset identifier diff --git a/app.py b/app.py new file mode 100644 index 0000000..da23242 --- /dev/null +++ b/app.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +""" +Azure entry point for PowerOn Preprocessing App. +This file redirects to the actual application in the src directory. +""" + +import os +import sys + +# Add current directory to Python path +sys.path.insert(0, os.path.dirname(__file__)) + +# Ensure DATA_DIR exists (Azure persistent storage at /home/_data) +data_dir = os.environ.get("DATA_DIR", "/home/_data") +os.makedirs(data_dir, exist_ok=True) +print(f"Data directory ready: {data_dir}") + +# Import the actual application +from src.main import app + +# For Azure App Service with uvicorn, expose the app at module level +# This allows uvicorn to find it as 'app:app' +application = app diff --git a/env_prod.env b/env_prod.env index 658a4d4..d201db4 100644 --- a/env_prod.env +++ b/env_prod.env @@ -1,7 +1,6 @@ -PP_CONFIG_PATH="/Users/christopher/Documents/Repos/vo-customer-preprocessor/src/pp-config.yaml" +PP_CONFIG_PATH="src/pp-config.yaml" PP_API_KEY="kj823u90209mj020394jp2msakhfkjashjkf" DB_ENDPOINT_API_KEY="ouho02j0rj2oijroi3rj2oijro23jr0990" -DB_URL="/Users/christopher/Documents/Repos/vo-customer-preprocessor/data/data_althaus.db" POWERBI_DATASET_ID="0e72b1f1-3d32-4caa-bc1a-e523b6232343" POWERBI_CLIENT_ID="9f6fa2cf-3fe1-4ed5-a430-bb7e408c0d87" POWERBI_CLIENT_SECRET="Vdy8Q~Bm2_5ooy-pgYtEgvA9-LjRN2HiXFw6Ody0" diff --git a/src/settings.py b/src/settings.py index 4778f55..2f492ff 100644 --- a/src/settings.py +++ b/src/settings.py @@ -1,5 +1,6 @@ """General application settings.""" +import os from pydantic import Field from pydantic_settings import BaseSettings, SettingsConfigDict @@ -21,8 +22,12 @@ class Settings(BaseSettings): # SQLite database file path. # For in memory, use ":memory:" (not persistent). + # Uses DATA_DIR environment variable for Azure persistent storage DB_PATH: str = Field( - "data/database.sqlite", description="Path to the SQLite database." + default_factory=lambda: os.path.join( + os.environ.get("DATA_DIR", "data"), "database.sqlite" + ), + description="Path to the SQLite database.", ) # --- API Keys ---