[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)
|
||||
# ============================================
|
||||
|
||||
# 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"]
|
||||
|
||||
# ============================================
|
||||
|
||||
Reference in New Issue
Block a user