Files
peikarband/docker/entrypoint.sh
Ehsan.Asadi a1f53c59c7
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
fix: Run container as root to fix react-router permission denied
- Change Dockerfile to run as root instead of peikarband user
- Update Helm values.yaml to use root user (runAsUser: 0, runAsNonRoot: false)
- Improve entrypoint.sh permission handling with reusable function
- Add reflex init before run if packages not installed
- Fix node_modules/.bin permissions for symlinks and targets

This resolves the 'react-router: Permission denied' error by running
containers with root privileges. TODO: Switch back to non-root user
after permission issues are fully resolved.
2025-12-31 12:30:41 +03:30

72 lines
2.9 KiB
Bash

#!/bin/bash
set -e
# Function to fix node_modules permissions
fix_node_modules_permissions() {
if [ -d /app/peikarband/.web/node_modules/.bin ]; then
echo "Checking node_modules/.bin permissions..."
REACT_ROUTER_BIN="/app/peikarband/.web/node_modules/.bin/react-router"
# Check if react-router exists
if [ -e "$REACT_ROUTER_BIN" ]; then
# If it's a symlink, check and fix the target
if [ -L "$REACT_ROUTER_BIN" ]; then
TARGET=$(readlink -f "$REACT_ROUTER_BIN")
echo "react-router is a symlink pointing to: $TARGET"
if [ -f "$TARGET" ] && [ ! -x "$TARGET" ]; then
echo "WARNING: Target file is not executable, attempting to fix..."
chmod +x "$TARGET" 2>/dev/null || true
fi
fi
# Fix permissions for react-router itself (file or symlink)
if [ ! -x "$REACT_ROUTER_BIN" ]; then
echo "WARNING: react-router is not executable, attempting to fix..."
chmod +x "$REACT_ROUTER_BIN" 2>/dev/null || true
fi
# Fix all .bin files and their symlink targets
echo "Fixing permissions for all .bin files and symlink targets..."
find /app/peikarband/.web/node_modules/.bin -type f -exec chmod +x {} \; 2>/dev/null || true
find /app/peikarband/.web/node_modules/.bin -type l | while read symlink; do
target=$(readlink -f "$symlink" 2>/dev/null || true)
if [ -n "$target" ] && [ -f "$target" ]; then
chmod +x "$target" 2>/dev/null || true
fi
chmod +x "$symlink" 2>/dev/null || true
done
# Verify react-router is executable
if [ -x "$REACT_ROUTER_BIN" ]; then
echo "✅ react-router is executable"
else
echo "⚠️ WARNING: react-router may still not be executable (running as non-root)"
fi
else
echo "⚠️ WARNING: react-router binary not found (packages may not be installed yet)"
fi
else
echo "⚠️ WARNING: .web/node_modules/.bin directory not found (packages may not be installed yet)"
fi
}
# Change to the directory containing rxconfig.py
cd /app/peikarband
# If reflex run is being executed, ensure packages are installed first
# This handles the case where .web directory doesn't exist from build time
if [ "$1" = "run" ] && [ ! -d /app/peikarband/.web/node_modules ]; then
echo "Initializing Reflex (installing packages)..."
reflex init --loglevel info || true
echo "Packages installed, fixing permissions..."
fix_node_modules_permissions
fi
# Fix permissions if node_modules already exists (from build time or init)
fix_node_modules_permissions
# Run reflex with all passed arguments
exec reflex "$@"