Skip to content

Commit

Permalink
Merge a816dde into 97a86b5
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Paz committed Jul 10, 2018
2 parents 97a86b5 + a816dde commit a090818
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 30 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ whitenoise = "*"
[dev-packages]
"flake8" = "*"
coverage = "*"
ipython = "*"

[requires]
python_version = "3.6"
129 changes: 122 additions & 7 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ You can set environment variables in your OS, write on ```.env``` file or pass v
| CSRF_COOKIE_DOMAIN | ```string``` | ```None``` | The domain to be used when setting the CSRF cookie.
| CSRF_COOKIE_SECURE | ```boolean``` | ```False``` | Whether to use a secure cookie for the CSRF cookie.
| BOTHUB_WEBAPP_BASE_URL | ```string``` | ```http://localhost:8080/``` | The bothub-webapp production application URL. Used to refer and redirect user correctly.
| BOTHUB_NLP_BASE_URL | ```string``` | ```http://localhost:8001/``` | The bothub-blp production application URL. Used to proxy requests.
| BOTHUB_NLP_BASE_URL | ```string``` | ```http://localhost:2657/``` | The bothub-blp production application URL. Used to proxy requests.


### Docker Environment Variables
Expand Down
45 changes: 30 additions & 15 deletions bothub/health/checks.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import logging

from rest_framework import status


logger = logging.getLogger('bothub.health.checks')

CHECK_ACCESSIBLE_API_URL = '/api/repositories/'


def check_database_connection(**kwargs):
from django.db import connections
from django.db.utils import OperationalError
db_conn = connections['default']
if not db_conn:
return False
try:
db_conn.cursor()
return True
except OperationalError as e:
if len(connections.all()) is 0:
return False
logger.info('found {} database connection'.format(len(connections.all())))
for i, conn in enumerate(connections.all(), 1):
db_conn = connections['default']
try:
db_conn.cursor()
logger.info('#{} db connection OKAY'.format(i))
except OperationalError as e:
logger.warning('#{} db connection ERROR'.format(i))
return False
return True


def check_accessible_api(request, **kwargs):
import requests
HTTP_HOST = request.META.get('HTTP_HOST')
repositories_url = 'http://{}/api/repositories/'.format(HTTP_HOST)
request = requests.get(repositories_url)
try:
request.raise_for_status()
from django.test import Client
logger.info('making request to {}'.format(CHECK_ACCESSIBLE_API_URL))
client = Client()
response = client.get(CHECK_ACCESSIBLE_API_URL)
logger.info('{} status code: {}'.format(
CHECK_ACCESSIBLE_API_URL,
response.status_code))
if response.status_code is status.HTTP_200_OK:
return True
except requests.HTTPError as e:
return False
return False
21 changes: 20 additions & 1 deletion bothub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import dj_database_url

from decouple import config
from django.utils.log import DEFAULT_LOGGING


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand Down Expand Up @@ -191,7 +192,7 @@

BOTHUB_NLP_BASE_URL = config(
'BOTHUB_NLP_BASE_URL',
default='http://localhost:8001/')
default='http://localhost:2657/')


# CSRF
Expand All @@ -204,3 +205,21 @@
'CSRF_COOKIE_SECURE',
default=False,
cast=bool)


# Logging

LOGGING = DEFAULT_LOGGING
LOGGING['formatters']['bothub.health'] = {
'format': '[bothub.health] {message}',
'style': '{',
}
LOGGING['handlers']['bothub.health'] = {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'bothub.health',
}
LOGGING['loggers']['bothub.health.checks'] = {
'handlers': ['bothub.health'],
'level': 'DEBUG',
}
8 changes: 4 additions & 4 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ services:
ports:
- 80:80
environment:
- SECRET_KEY
- SECRET_KEY=SK
- DEBUG
- ALLOWED_HOSTS
- DEFAULT_DATABASE
- LANGUAGE_CODE
- TIME_ZONE
- EMAIL_HOST
- EMAIL_HOST=
- EMAIL_PORT
- DEFAULT_FROM_EMAIL
- SERVER_EMAIL
Expand All @@ -26,8 +26,8 @@ services:
- ADMINS
- CSRF_COOKIE_DOMAIN
- CSRF_COOKIE_SECURE
- BOTHUB_WEBAPP_BASE_URL
- BOTHUB_WEBAPP_BASE_URL=http://localhost/
- BOTHUB_NLP_BASE_URL
- WEBAPP_REPO=https://github.com/Ilhasoft/bothub-webapp
- WEBAPP_BRANCH=master
- API_BASE_URL
- API_BASE_URL=/api
5 changes: 3 additions & 2 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ cd $WORKDIR
python manage.py migrate
python manage.py collectstatic --noinput

gunicorn -e DJANGO_SETTINGS_MODULE=bothub.settings -b unix:/tmp/bothub.sock -D bothub.wsgi
gunicorn -e DJANGO_SETTINGS_MODULE=bothub.settings -b unix:/tmp/bothub.sock -D bothub.wsgi --log-file /var/log/gunicorn.log --log-level debug --capture-output

mkdir -p /run/nginx/
nginx -g "daemon off;"
nginx
tail -f /var/log/nginx/* /var/log/gunicorn.log

0 comments on commit a090818

Please sign in to comment.