
Commit 8fed685f12
added a HEALTHCHECK
instruction in the Dockerfile. The healthcheck script calls http://localhost:8000/api/v3/status/, which fails if localhost is not in ALLOWED_HOSTS.
With this change, the healthcheck script is now a Django management
command. It reads Django's ALLOWED_HOSTS setting, grabs the first
element, and uses it in the "Host:" HTTP header when making a HTTP
request.
cc: #1051
20 lines
556 B
Python
20 lines
556 B
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
from urllib.request import Request, urlopen
|
|
|
|
from django.conf import settings
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, **options: Any) -> str:
|
|
host = settings.ALLOWED_HOSTS[0]
|
|
if host == "*":
|
|
host = "localhost"
|
|
|
|
req = Request("http://localhost:8000/api/v3/status/", headers={"Host": host})
|
|
with urlopen(req) as response:
|
|
assert response.status == 200
|
|
|
|
return "Status OK"
|