Skip to content

Commit

Permalink
feat(healthcheck): Added healthcheck app as required for deployments;…
Browse files Browse the repository at this point in the history
… added django-dbmi-client
  • Loading branch information
b32147 committed Aug 5, 2021
1 parent 17f9dc9 commit 5e0daf4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,20 @@ services:
DBMI_CREATE_SSL: ${DBMI_CREATE_SSL}
DBMI_HEALTHCHECK: ${DBMI_HEALTHCHECK}
DBMI_APP_STATIC_ROOT: ${DBMI_APP_STATIC_ROOT}
DJANGO_SUPERUSER_USERNAME: ${DJANGO_SUPERUSER_USERNAME}
DJANGO_SUPERUSER_EMAIL: ${DJANGO_SUPERUSER_EMAIL}
DJANGO_SUPERUSER_PASSWORD: ${DJANGO_SUPERUSER_PASSWORD}
GUNICORN_CMD_ARGS: "--log-level info --reload --access-logfile /var/log/gunicorn.log"
volumes:
- ./starter:/app
- ./docker-entrypoint-init.d/45-django-admin.sh:/docker-entrypoint-init.d/45-django-admin.sh
ports:
- "8020:80"
healthcheck:
test: curl -s http://localhost/healthcheck || exit 1
interval: 30s
timeout: 5s
retries: 15
depends_on:
db:
condition: service_healthy
Expand Down
4 changes: 4 additions & 0 deletions docker-entrypoint-init.d/45-django-admin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e

# Create an admin user (uses DJANGO_SUPERUSER_* environment variables)
python ${DBMI_APP_ROOT}/manage.py createsuperuser --no-input
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
asgiref==3.4.1
Django==3.2.5
django-dbmi-client==0.4.5
django-health-check==3.16.4
djangorestframework==3.12.4
mysqlclient==2.0.3
Expand Down
26 changes: 14 additions & 12 deletions starter/starter/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import os
from pathlib import Path
from dbmi_client import environment

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -21,12 +21,12 @@
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['SECRET_KEY']
SECRET_KEY = environment.get_str('SECRET_KEY', required=True)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = environment.get_bool('DEBUG', default=False)

ALLOWED_HOSTS = os.environ['ALLOWED_HOSTS'].split(",")
ALLOWED_HOSTS = environment.get_list('ALLOWED_HOSTS', required=True)


# Application definition
Expand All @@ -38,6 +38,8 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'health_check',
'health_check.db',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -76,12 +78,12 @@

DATABASES = {
"default": {
"ENGINE": os.environ["DB_ENGINE"],
"NAME": os.environ["DB_DATABASE"],
"USER": os.environ["DB_USER"],
"PASSWORD": os.environ["DB_PASSWORD"],
"HOST": os.environ["DB_HOST"],
"PORT": os.environ["DB_PORT"],
"ENGINE": environment.get_str("DB_ENGINE", required=True),
"NAME": environment.get_str("DB_DATABASE", required=True),
"USER": environment.get_str("DB_USER", required=True),
"PASSWORD": environment.get_str("DB_PASSWORD", required=True),
"HOST": environment.get_str("DB_HOST", required=True),
"PORT": environment.get_str("DB_PORT", required=True),
}
}

Expand Down Expand Up @@ -122,8 +124,8 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = os.environ.get('DBMI_APP_STATIC_URL_PATH') + '/'
STATIC_ROOT = os.environ.get('DBMI_APP_STATIC_ROOT')
STATIC_URL = environment.get_str('DBMI_APP_STATIC_URL_PATH', default="/static") + "/"
STATIC_ROOT = environment.get_str('DBMI_APP_STATIC_ROOT', default="/var/static")

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
Expand Down
3 changes: 3 additions & 0 deletions starter/starter/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"""
from django.contrib import admin
from django.urls import path, re_path, include
from django.views.debug import default_urlconf

urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'^healthcheck/?', include('health_check.urls')),
re_path(r'^$', default_urlconf),
]

0 comments on commit 5e0daf4

Please # to comment.