[FIX] Fix Reflex build errors and improve Docker permissions
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

- Add state_auto_setters=True to rxconfig.py (fixes Reflex 0.8.9+ deprecation)
- Fix node_modules/.bin permissions in Dockerfile (both files and symlinks)
- Add permission validation in entrypoint.sh
- Fix healthcheck endpoint from /_health to /ping on port 8000
- Add diagnostic commands to Dockerfile for debugging
- Improve permission handling in builder and runtime stages

Fixes permission denied error for react-router during production build
This commit is contained in:
Ehsan.Asadi
2025-12-31 10:02:01 +03:30
parent 99778c07be
commit 846c41111f
3 changed files with 38 additions and 14 deletions

View File

@@ -64,13 +64,12 @@ ENV PYTHONPATH=/build:/build/peikarband
# 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"
# Ensure executable permissions for node_modules/.bin files in builder stage
# This ensures they are preserved when copying to runtime stage
RUN if [ -d /build/peikarband/.web/node_modules/.bin ]; then \
find /build/peikarband/.web/node_modules/.bin -type f -exec chmod +x {} \; && \
echo "✅ Set executable permissions for .bin files in builder"; \
reflex export --frontend-only --no-zip --loglevel debug && \
echo "Frontend export completed" && \
if [ -d .web/node_modules/.bin ]; then \
find .web/node_modules/.bin -type f -exec chmod +x {} \; && \
find .web/node_modules/.bin -type l -exec chmod +x {} \; && \
echo "✅ Set executable permissions for all .bin files (files and symlinks)"; \
fi
# Note: reflex export already builds and installs everything needed
@@ -119,8 +118,7 @@ COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code to /app/peikarband/ to create peikarband.peikarband structure
# With app_name="peikarband", Reflex expects to find peikarband.peikarband module
# Use --chmod to preserve executable permissions for node_modules/.bin
COPY --from=builder --chown=peikarband:peikarband --chmod=755 /build/peikarband /app/peikarband
COPY --from=builder --chown=peikarband:peikarband /build/peikarband /app/peikarband
# Copy entrypoint script
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
@@ -130,10 +128,12 @@ RUN chmod +x /usr/local/bin/entrypoint.sh
RUN mkdir -p /app/data /app/logs /app/uploaded_files
# Set proper permissions for application files
# Explicitly set executable permissions for node_modules/.bin files
# Explicitly set executable permissions for node_modules/.bin files (both files and symlinks)
RUN if [ -d /app/peikarband/.web/node_modules/.bin ]; then \
chmod +x /app/peikarband/.web/node_modules/.bin/* && \
echo "✅ Set executable permissions for .bin files"; \
find /app/peikarband/.web/node_modules/.bin -type f -exec chmod +x {} \; && \
find /app/peikarband/.web/node_modules/.bin -type l -exec chmod +x {} \; && \
ls -la /app/peikarband/.web/node_modules/.bin/ | head -20 && \
echo "✅ Verified executable permissions for .bin files"; \
fi && \
chmod -R 777 /app/data /app/logs /app/uploaded_files
@@ -150,9 +150,20 @@ ENV PYTHONUNBUFFERED=1 \
REFLEX_DIR=/app/peikarband \
NODE_ENV=production
# Health check
# Diagnostic information (before switching to non-root user)
RUN echo "=== Diagnostic Info ===" && \
if [ -f /app/peikarband/.web/node_modules/.bin/react-router ]; then \
ls -la /app/peikarband/.web/node_modules/.bin/react-router && \
file /app/peikarband/.web/node_modules/.bin/react-router || true; \
fi && \
if [ -f /app/peikarband/.web/node_modules/@react-router/dev/bin.js ]; then \
head -5 /app/peikarband/.web/node_modules/@react-router/dev/bin.js || true; \
fi && \
echo "======================="
# Health check (using backend health endpoint on port 8000)
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:${PORT:-3000}/_health || exit 1
CMD curl -f http://localhost:8000/ping || exit 1
# Switch to non-root user
USER peikarband

View File

@@ -1,6 +1,18 @@
#!/bin/bash
set -e
# Validate node_modules permissions before starting
if [ -d /app/peikarband/.web/node_modules/.bin ]; then
echo "Checking node_modules/.bin permissions..."
if [ ! -x /app/peikarband/.web/node_modules/.bin/react-router ]; then
echo "WARNING: react-router is not executable, attempting to fix..."
chmod +x /app/peikarband/.web/node_modules/.bin/* 2>/dev/null || true
echo "Permission fix attempted (may fail if running as non-root)"
else
echo "✅ react-router is executable"
fi
fi
# Change to the directory containing rxconfig.py
cd /app/peikarband

View File

@@ -18,6 +18,7 @@ config = rx.Config(
frontend_port=FRONTEND_PORT,
backend_port=BACKEND_PORT,
db_url=DB_URL,
state_auto_setters=True, # Temporary fix for 0.8.9+ deprecation warning
disable_plugins=["reflex.plugins.sitemap.SitemapPlugin"],
stylesheets=[
"https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap",