Skip to content

Commit

Permalink
chore: Configure for static files
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmolto committed Oct 26, 2023
1 parent e40c58b commit f255ad3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ RUN python -m venv /py && \
adduser \
--disabled-password \
--no-create-home \
django-user
django-user && \
mkdir -p /vol/web/media && \
mkdir -p /vol/web/static && \
chown -R django-user:django-user /vol && \
chmod -R 755 /vol

ENV PATH="/py/bin:$PATH"

Expand Down
6 changes: 5 additions & 1 deletion app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = 'static/'
STATIC_URL = '/static/static/'
MEDIA_URL = '/static/media/'

MEDIA_ROOT = '/vol/web/media'
STATIC_ROOT = '/vol/web/static'

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
Expand Down
8 changes: 8 additions & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@
"""
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('events.urls')),
]

if settings.DEBUG:
urlpatterns += static(
settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT,
)
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- "8000:8000"
volumes:
- ./app:/app
- dev-static-data:/vol/web
command: >
sh -c "python manage.py wait_for_db &&
python manage.py migrate &&
Expand All @@ -32,4 +33,5 @@ services:
- POSTGRES_PASSWORD=changeme

volumes:
dev-db-data:
dev-db-data:
dev-static-data:

0 comments on commit f255ad3

Please sign in to comment.