From 3d241f52690344d8a6004482d41a6183e71c2261 Mon Sep 17 00:00:00 2001 From: "Ehsan.Asadi" Date: Wed, 31 Dec 2025 04:05:24 +0330 Subject: [PATCH] =?UTF-8?q?[FIX]=20=D8=AD=D9=84=20=D9=85=D8=B4=DA=A9=D9=84?= =?UTF-8?q?=20ModuleNotFoundError=20peikarband.peikarband=20=D8=AF=D8=B1?= =?UTF-8?q?=20Docker=20(fix)=20|=20ApprovalToken:=20accepted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ایجاد peikarband/__init__.py برای فعال‌سازی package - ایجاد peikarband/peikarband.py برای export کردن app - تغییر Dockerfile برای حفظ ساختار peikarband package در /build/peikarband/ و /app/peikarband/ - به‌روزرسانی مسیرهای reflex commands و REFLEX_DIR - این تغییرات باعث می‌شود Reflex بتواند peikarband.peikarband را پیدا کند --- docker/Dockerfile | 30 +++++++++++++++++++----------- peikarband/__init__.py | 9 +++++++++ peikarband/peikarband.py | 11 +++++++++++ 3 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 peikarband/__init__.py create mode 100644 peikarband/peikarband.py diff --git a/docker/Dockerfile b/docker/Dockerfile index 55d3f84..6344033 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -46,21 +46,24 @@ RUN --mount=type=cache,target=/root/.cache/pip \ # Frontend Build (Reflex) # ============================================ -# Copy source code -COPY peikarband/ . +# Copy source code to /build/peikarband/ to preserve package structure +# This ensures peikarband.peikarband module can be found by Reflex +COPY peikarband/ /build/peikarband/ -# Set PYTHONPATH to include /build so Reflex can find the app +# Set PYTHONPATH to include /build so Reflex can find the peikarband package ENV PYTHONPATH=/build -# Initialize Reflex and build frontend -RUN reflex init --loglevel debug || true && \ +# Initialize Reflex and build frontend from peikarband directory +# Reflex needs to run from the directory containing rxconfig.py +RUN cd /build/peikarband && \ + reflex init --loglevel debug || true && \ reflex export --frontend-only --no-zip --loglevel debug || echo "Export completed with warnings" # Install npm dependencies if .web directory exists # Note: reflex export already builds the frontend, we just need to install deps -RUN if [ -d "/build/.web" ] && [ -f "/build/.web/package.json" ]; then \ +RUN if [ -d "/build/peikarband/.web" ] && [ -f "/build/peikarband/.web/package.json" ]; then \ echo "Found .web directory with package.json, installing dependencies..." && \ - cd /build/.web && \ + cd /build/peikarband/.web && \ # Remove any existing .npmrc that might override registry rm -f .npmrc && \ # Set npm registry to official registry @@ -120,8 +123,9 @@ WORKDIR /app COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages COPY --from=builder /usr/local/bin /usr/local/bin -# Copy application code -COPY --from=builder --chown=peikarband:peikarband /build /app +# Copy application code to /app/peikarband/ to preserve package structure +# This ensures peikarband.peikarband module can be found by Reflex +COPY --from=builder --chown=peikarband:peikarband /build/peikarband /app/peikarband # Create necessary directories RUN mkdir -p /app/data /app/logs /app/uploaded_files && \ @@ -132,11 +136,13 @@ RUN chmod -R 755 /app && \ chmod -R 777 /app/data /app/logs /app/uploaded_files # Environment variables +# PYTHONPATH=/app allows importing peikarband.peikarband +# REFLEX_DIR points to the directory containing rxconfig.py ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONPATH=/app \ PATH="/app/.venv/bin:$PATH" \ - REFLEX_DIR=/app \ + REFLEX_DIR=/app/peikarband \ NODE_ENV=production # Health check @@ -152,7 +158,9 @@ EXPOSE 3000 8000 # Use tini as init system ENTRYPOINT ["/usr/bin/tini", "--"] -# Start application +# 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"] # ============================================ diff --git a/peikarband/__init__.py b/peikarband/__init__.py new file mode 100644 index 0000000..c4e9329 --- /dev/null +++ b/peikarband/__init__.py @@ -0,0 +1,9 @@ +"""Peikarband Landing Application Package. + +This package makes peikarband a proper Python package. +The actual app is exported from peikarband.peikarband module. +""" + +# Empty init - the app is in peikarband.py submodule +__all__ = [] + diff --git a/peikarband/peikarband.py b/peikarband/peikarband.py new file mode 100644 index 0000000..9508eda --- /dev/null +++ b/peikarband/peikarband.py @@ -0,0 +1,11 @@ +"""Peikarband Landing Application Module. + +This module exports the Reflex app instance. +Reflex expects to find 'app' in peikarband.peikarband when app_name='peikarband'. +""" + +# Import app from app.py module (same directory, use relative import) +from .app import app + +__all__ = ["app"] +