Merge pull request #183 from learnhouse/feat/python-new-dev

New server start method & add local dev setup
This commit is contained in:
Badr B 2024-03-31 15:54:42 +02:00 committed by GitHub
commit 33ac0d0c21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 27 additions and 6 deletions

View file

@ -25,4 +25,4 @@ RUN poetry install --no-interaction --no-ansi
COPY ./ /usr/learnhouse
#
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "80" , "--reload" ]
CMD ["python" , "app.py"]

View file

@ -1,3 +1,4 @@
import uvicorn
from fastapi import FastAPI, Request
from config.config import LearnHouseConfig, get_learnhouse_config
from src.core.events.events import shutdown_app, startup_app
@ -60,6 +61,15 @@ app.mount("/content", StaticFiles(directory="content"), name="content")
app.include_router(v1_router)
if __name__ == "__main__":
uvicorn.run(
"app:app",
host="0.0.0.0",
port=learnhouse_config.hosting_config.port,
reload=learnhouse_config.general_config.development_mode,
)
# General Routes
@app.get("/")
async def root():

View file

@ -1,8 +1,8 @@
import os
import yaml
from typing import Literal, Optional
from pydantic import BaseModel
import os
from dotenv import load_dotenv
import yaml
class SentryConfig(BaseModel):
@ -42,6 +42,7 @@ class ContentDeliveryConfig(BaseModel):
class HostingConfig(BaseModel):
domain: str
ssl: bool
port: int
use_default_org: bool
allowed_origins: list
allowed_regexp: str
@ -118,6 +119,7 @@ def get_learnhouse_config() -> LearnHouseConfig:
env_domain = os.environ.get("LEARNHOUSE_DOMAIN")
os.environ.get("LEARNHOUSE_PORT")
env_ssl = os.environ.get("LEARNHOUSE_SSL")
env_port = os.environ.get("LEARNHOUSE_PORT")
env_use_default_org = os.environ.get("LEARNHOUSE_USE_DEFAULT_ORG")
env_allowed_origins = os.environ.get("LEARNHOUSE_ALLOWED_ORIGINS")
env_cookie_domain = os.environ.get("LEARNHOUSE_COOKIE_DOMAIN")
@ -141,6 +143,7 @@ def get_learnhouse_config() -> LearnHouseConfig:
domain = env_domain or yaml_config.get("hosting_config", {}).get("domain")
ssl = env_ssl or yaml_config.get("hosting_config", {}).get("ssl")
port = env_port or yaml_config.get("hosting_config", {}).get("port")
use_default_org = env_use_default_org or yaml_config.get("hosting_config", {}).get(
"use_default_org"
)
@ -190,7 +193,6 @@ def get_learnhouse_config() -> LearnHouseConfig:
"database_config", {}
).get("sql_connection_string")
# AI Config
env_openai_api_key = os.environ.get("LEARNHOUSE_OPENAI_API_KEY")
env_is_ai_enabled = os.environ.get("LEARNHOUSE_IS_AI_ENABLED")
@ -248,6 +250,7 @@ def get_learnhouse_config() -> LearnHouseConfig:
hosting_config = HostingConfig(
domain=domain,
ssl=bool(ssl),
port=int(port),
use_default_org=bool(use_default_org),
allowed_origins=list(allowed_origins),
allowed_regexp=allowed_regexp,

View file

@ -2,6 +2,8 @@ site_name: LearnHouse
site_description: LearnHouse is an open-source platform tailored for learning experiences.
contact_email: hi@learnhouse.app
# This config is optimized for local development. You can change the values according to your needs.
general:
development_mode: true
install_mode: true
@ -12,6 +14,7 @@ security:
hosting_config:
domain: learnhouse.app
ssl: true
port: 1338
allowed_origins:
- http://localhost:3000
- http://localhost:3001
@ -29,7 +32,7 @@ mailing_config:
system_email_adress: ""
database_config:
sql_connection_string: postgresql://learnhouse:learnhouse@db:5432/learnhouse
sql_connection_string: postgresql://learnhouse:learnhouse@localhost:5432/learnhouse
redis_config:
redis_connection_string: redis://redis:6379/learnhouse
redis_connection_string: redis://localhost:6379/learnhouse

View file

@ -5,6 +5,7 @@ lint.ignore = ["E501", "E712"]
authors = ["Badr B. (swve)"]
description = "Learnhouse Backend"
name = "learnhouse-api"
package-mode = false
readme = "README.md"
version = "0.1.0"

View file

@ -8,6 +8,10 @@ services:
- .:/usr/learnhouse
environment:
- LEARNHOUSE_COOKIE_DOMAIN=.localhost
# This overrides the default config.yaml (optimized for docker container based development)
- LEARNHOUSE_SQL_CONNECTION_STRING=postgresql://learnhouse:learnhouse@db:5432/learnhouse
- LEARNHOUSE_REDIS_CONNECTION_STRING=redis://redis:6379/learnhouse
- LEARNHOUSE_PORT=80
depends_on:
db:
condition: service_healthy