Skip to content

Commit

Permalink
Switch local API dev server to use gunicorn instead of django runserv…
Browse files Browse the repository at this point in the history
…er (#2936)

* Added gunicorn

* added value for STATIC_ROOT for local dev setup
  • Loading branch information
ashiramin authored Sep 6, 2023
1 parent 3969e17 commit 6408b42
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion api/conf/settings/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
# 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/"
6 changes: 5 additions & 1 deletion api/conf/urls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
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
Expand Down Expand Up @@ -35,3 +36,6 @@
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)
2 changes: 1 addition & 1 deletion api/env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6408b42

Please sign in to comment.