[FIX] حل مشکل ModuleNotFoundError peikarband.peikarband در Docker (fix) | ApprovalToken: accepted
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
- ایجاد peikarband/__init__.py برای فعالسازی package - ایجاد peikarband/peikarband.py برای export کردن app - تغییر Dockerfile برای حفظ ساختار peikarband package در /build/peikarband/ و /app/peikarband/ - بهروزرسانی مسیرهای reflex commands و REFLEX_DIR - این تغییرات باعث میشود Reflex بتواند peikarband.peikarband را پیدا کند
This commit is contained in:
@@ -46,21 +46,24 @@ RUN --mount=type=cache,target=/root/.cache/pip \
|
|||||||
# Frontend Build (Reflex)
|
# Frontend Build (Reflex)
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code to /build/peikarband/ to preserve package structure
|
||||||
COPY peikarband/ .
|
# 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
|
ENV PYTHONPATH=/build
|
||||||
|
|
||||||
# Initialize Reflex and build frontend
|
# Initialize Reflex and build frontend from peikarband directory
|
||||||
RUN reflex init --loglevel debug || true && \
|
# 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"
|
reflex export --frontend-only --no-zip --loglevel debug || echo "Export completed with warnings"
|
||||||
|
|
||||||
# Install npm dependencies if .web directory exists
|
# Install npm dependencies if .web directory exists
|
||||||
# Note: reflex export already builds the frontend, we just need to install deps
|
# 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..." && \
|
echo "Found .web directory with package.json, installing dependencies..." && \
|
||||||
cd /build/.web && \
|
cd /build/peikarband/.web && \
|
||||||
# Remove any existing .npmrc that might override registry
|
# Remove any existing .npmrc that might override registry
|
||||||
rm -f .npmrc && \
|
rm -f .npmrc && \
|
||||||
# Set npm registry to official registry
|
# 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/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
|
||||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||||
|
|
||||||
# Copy application code
|
# Copy application code to /app/peikarband/ to preserve package structure
|
||||||
COPY --from=builder --chown=peikarband:peikarband /build /app
|
# This ensures peikarband.peikarband module can be found by Reflex
|
||||||
|
COPY --from=builder --chown=peikarband:peikarband /build/peikarband /app/peikarband
|
||||||
|
|
||||||
# Create necessary directories
|
# Create necessary directories
|
||||||
RUN mkdir -p /app/data /app/logs /app/uploaded_files && \
|
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
|
chmod -R 777 /app/data /app/logs /app/uploaded_files
|
||||||
|
|
||||||
# Environment variables
|
# Environment variables
|
||||||
|
# PYTHONPATH=/app allows importing peikarband.peikarband
|
||||||
|
# REFLEX_DIR points to the directory containing rxconfig.py
|
||||||
ENV PYTHONUNBUFFERED=1 \
|
ENV PYTHONUNBUFFERED=1 \
|
||||||
PYTHONDONTWRITEBYTECODE=1 \
|
PYTHONDONTWRITEBYTECODE=1 \
|
||||||
PYTHONPATH=/app \
|
PYTHONPATH=/app \
|
||||||
PATH="/app/.venv/bin:$PATH" \
|
PATH="/app/.venv/bin:$PATH" \
|
||||||
REFLEX_DIR=/app \
|
REFLEX_DIR=/app/peikarband \
|
||||||
NODE_ENV=production
|
NODE_ENV=production
|
||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
@@ -152,7 +158,9 @@ EXPOSE 3000 8000
|
|||||||
# Use tini as init system
|
# Use tini as init system
|
||||||
ENTRYPOINT ["/usr/bin/tini", "--"]
|
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"]
|
CMD ["reflex", "run", "--env", "prod", "--loglevel", "info"]
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|||||||
9
peikarband/__init__.py
Normal file
9
peikarband/__init__.py
Normal file
@@ -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__ = []
|
||||||
|
|
||||||
11
peikarband/peikarband.py
Normal file
11
peikarband/peikarband.py
Normal file
@@ -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"]
|
||||||
|
|
||||||
Reference in New Issue
Block a user