diff --git a/docker/Dockerfile b/docker/Dockerfile index f642be5..44f629f 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -166,10 +166,11 @@ EXPOSE 3000 8000 # Use tini as init system ENTRYPOINT ["/usr/bin/tini", "--"] -# Start application from peikarband directory (contains rxconfig.py) -# Reflex needs to run from the directory containing rxconfig.py -WORKDIR /app/peikarband -CMD ["reflex", "run", "--env", "prod", "--loglevel", "info"] +# Start application +# We run from /app directory so Python can find peikarband package +# Reflex will find rxconfig.py in /app/peikarband/ automatically +WORKDIR /app +CMD ["reflex", "run", "--env", "prod", "--loglevel", "info", "--frontend-port", "3000", "--backend-port", "8000"] # ============================================ # Build Information diff --git a/peikarband/peikarband/__init__.py b/peikarband/peikarband/__init__.py index 07a7652..d878839 100644 --- a/peikarband/peikarband/__init__.py +++ b/peikarband/peikarband/__init__.py @@ -4,10 +4,30 @@ Reflex expects to find 'app' in peikarband.peikarband when app_name='peikarband' This submodule provides that structure. """ -# Import app from peikarband.app -# This works when PYTHONPATH includes the parent directory of peikarband package -# For example: PYTHONPATH=/build allows importing peikarband.app -from peikarband.app import app +# Import app from parent package's app.py +# We use importlib to directly load app.py, which works regardless of working directory +# This is necessary because when Reflex runs from /app/peikarband, Python cannot +# find the peikarband package using normal imports +import importlib.util +import os +import sys + +# Get the parent directory (peikarband/) and load app.py directly +_parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +_app_file = os.path.join(_parent_dir, 'app.py') + +# Load app.py as a module +_spec = importlib.util.spec_from_file_location("peikarband.app", _app_file) +_app_module = importlib.util.module_from_spec(_spec) + +# Register the module in sys.modules so it can be imported elsewhere +sys.modules["peikarband.app"] = _app_module +_spec.loader.exec_module(_app_module) + +# Get the app from the loaded module +app = _app_module.app + +__all__ = ["app"] __all__ = ["app"]