feat(static): improve static files handling and permissions in Docker
- Add script to set correct permissions on static files after collectstatic - Introduce collectstatic command in entrypoint with permission fixing - Add WhiteNoise middleware for efficient static file serving without DB access - Configure WhiteNoise static files storage backend in settings - Set STATIC_ROOT path properly for Docker container environment - Add fallback static files serving in Django urls for production without nginx - Enhance inventory_detail.html scripts to log errors if JS files or components fail to load - Add whitenoise package to requirements for static file serving support
This commit is contained in:
@@ -138,6 +138,12 @@ run_migrations() {
|
||||
echo "Collecting static files..."
|
||||
python manage.py collectstatic --noinput
|
||||
|
||||
# Устанавливаем права ПОСЛЕ collectstatic
|
||||
echo "Setting permissions on static files..."
|
||||
STATIC_ROOT="/app/myproject/staticfiles"
|
||||
find "$STATIC_ROOT" -type d -exec chmod 755 {} \; 2>/dev/null || true
|
||||
find "$STATIC_ROOT" -type f -exec chmod 644 {} \; 2>/dev/null || true
|
||||
|
||||
echo "Ensuring public tenant exists..."
|
||||
python /app/docker/create_public_tenant.py
|
||||
}
|
||||
@@ -225,6 +231,17 @@ case "$1" in
|
||||
run_migrations
|
||||
create_superuser
|
||||
;;
|
||||
collectstatic)
|
||||
wait_for_postgres
|
||||
setup_directories
|
||||
echo "Collecting static files..."
|
||||
python manage.py collectstatic --noinput
|
||||
echo "Setting permissions on static files..."
|
||||
STATIC_ROOT="/app/myproject/staticfiles"
|
||||
find "$STATIC_ROOT" -type d -exec chmod 755 {} \; 2>/dev/null || true
|
||||
find "$STATIC_ROOT" -type f -exec chmod 644 {} \; 2>/dev/null || true
|
||||
echo "Static files collected and permissions set."
|
||||
;;
|
||||
shell)
|
||||
exec python manage.py shell
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user