Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Switch local API dev server to use gunicorn instead of django runserver (#2936)

Ashir Amin6408b4234241
diff --git a/api/Dockerfile b/api/Dockerfile
index 680069141..a073e0357 100644
--- a/api/Dockerfile
+++ b/api/Dockerfile
@@ -101,7 +101,6 @@ COPY --chown=opener . /api/
# Collect static assets, these are used by the next stage, `nginx`
RUN env \
SETUP_ES="False" \
- STATIC_ROOT="/static" \
DJANGO_SECRET_KEY="any string" \
python manage.py collectstatic
diff --git a/api/conf/settings/static.py b/api/conf/settings/static.py
index 3c2756322..a04fe9550 100644
--- a/api/conf/settings/static.py
+++ b/api/conf/settings/static.py
@@ -5,6 +5,6 @@ from decouple import config
# https://docs.djangoproject.com/en/4.2/howto/static-files/
# Where to collect static files in production/development deployments
-STATIC_ROOT = config("STATIC_ROOT", default="/var/api_static_content/static")
+STATIC_ROOT = config("STATIC_ROOT", default="/static")
STATIC_URL = "static/"
diff --git a/api/conf/urls/__init__.py b/api/conf/urls/__init__.py
index 76e5d5d2b..432bc5aa8 100644
--- a/api/conf/urls/__init__.py
+++ b/api/conf/urls/__init__.py
@@ -4,7 +4,8 @@ URL configuration for the Openverse API.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/http/urls/
"""
-
+from django.conf import settings
+from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from django.views.generic import RedirectView
@@ -35,3 +36,6 @@ urlpatterns = [
path("healthcheck/", HealthCheck.as_view(), name="health"),
path("v1/", include(versioned_paths)),
]
+
+if settings.ENVIRONMENT == "local":
+ urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
diff --git a/api/env.docker b/api/env.docker
index fce8ad7f4..c13c36a04 100644
--- a/api/env.docker
+++ b/api/env.docker
@@ -5,7 +5,7 @@ DJANGO_SECRET_KEY="ny#b__$$f6ry4wy8oxre97&-68u_0lk3gw(z=d40_dxey3zw0v1"
DJANGO_DEBUG_ENABLED=True
BASE_URL=http://localhost:50280/
-ENVIRONMENT=development
+ENVIRONMENT=local
ALLOWED_HOSTS=api.openverse.engineering,api-dev.openverse.engineering,host.docker.internal
REDIS_HOST=cache
diff --git a/docker-compose.yml b/docker-compose.yml
index 709d78a42..1c226b6cf 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -234,12 +234,9 @@ services:
env_file:
- api/env.docker
- api/.env
- environment:
- STATIC_ROOT: ${STATIC_ROOT:-}
- MEDIA_ROOT: ${MEDIA_ROOT:-}
stdin_open: true
tty: true
- command: python manage.py runserver 0.0.0.0:8000
+ command: gunicorn --reload -w 1
ingestion_server:
profiles: