Skip to content

Commit

Permalink
Resolve PermissionError for static files in Docker (#46)
Browse files Browse the repository at this point in the history
* Resolve PermissionError for static files in Docker

* Create 0008_alter_customuser_encryption_salt.py
  • Loading branch information
KafetzisThomas authored Feb 1, 2025
1 parent 7a5aed1 commit cdcc657
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
10 changes: 8 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
services:
app:
django-web:
build: .
container_name: django-docker
volumes:
- static_volume:/app/staticfiles
env_file:
- main/.env

Expand All @@ -11,5 +13,9 @@ services:
- "8001:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- static_volume:/static:ro
depends_on:
- app
- django-web

volumes:
static_volume:
3 changes: 3 additions & 0 deletions entrypoint.prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ set -o errexit
# Collect static files
python manage.py collectstatic --noinput

# Change ownership of static files
chown -R appuser:appuser /app/staticfiles

# Apply database migrations
python manage.py migrate --noinput

Expand Down
4 changes: 4 additions & 0 deletions main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,7 @@
EMAIL_PORT = 587
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD")

INTERNAL_IPS = [
"127.0.0.1",
]
4 changes: 2 additions & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ http {

# Requests to /static/ are served directly from the /static/ directory
location /static/ {
alias /app/staticfiles/;
alias /static/;
expires 7d;
}

Expand All @@ -29,7 +29,7 @@ http {
# Handles all other requests
location / {
# Forward requests to Django application
proxy_pass http://app:8000;
proxy_pass http://django-web:8000;

# Pass important headers to Django for proper request handling
proxy_set_header Host $host; # Original host header
Expand Down
18 changes: 18 additions & 0 deletions users/migrations/0008_alter_customuser_encryption_salt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.18 on 2025-02-01 15:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0007_customuser_encryption_salt'),
]

operations = [
migrations.AlterField(
model_name='customuser',
name='encryption_salt',
field=models.CharField(blank=True, max_length=44, null=True),
),
]

0 comments on commit cdcc657

Please sign in to comment.