Skip to content

Commit

Permalink
Heroku compatibility and support scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphoting committed Nov 29, 2018
1 parent b30d4a2 commit 3119214
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 2 deletions.
1 change: 1 addition & 0 deletions Procfile
@@ -0,0 +1 @@
web: gunicorn hc.wsgi --log-file -
42 changes: 42 additions & 0 deletions app.json
@@ -0,0 +1,42 @@
{
"name": "healthchecks",
"website": "https://github.com/healthchecks/healthchecks",
"keywords": ["heroku", "cron", "devops", "python", "monitoring", "cron-jobs"],
"image": "heroku/python",
"addons": [
"heroku-postgresql:hobby-dev",
"mailgun:starter",
"scheduler:standard"
],
"scripts": {
"postdeploy": "python manage.py migrate"
},
"env": {
"SITE_ROOT": {
"description": "Used to build fully qualified URLs for pings, and for use in emails and notifications. Enter your App Name defined above here.",
"value": "https://appname.herokuapp.com"
},
"PING_ROOT": {
"description": "Used to build fully qualified URLs for pings. Will fall-back to SITE_ROOT above if undefined.",
"required": false
},
"SITE_NAME": {
"description": "Used throughout the templates.",
"value": "My Monitoring Project"
},
"FROM_EMAIL": {
"description": "Email from address.",
"value": "noreply@example.com"
},
"PING_EMAIL_DOMAIN": {
"description": "Email domain used to received email pings.",
"value": "example.com"
},
"SECRET_KEY": {
"generator": "secret"
},
"ON_HEROKU": {
"value": "yes"
}
}
}
36 changes: 36 additions & 0 deletions bin/post_compile
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -eo pipefail

# The post_compile hook is run by heroku-buildpack-python

echo "-----> Custom post-compile hook"

# Work around Heroku bug whereby pylibmc isn't available during
# compile phase. See: https://github.com/heroku/heroku-buildpack-python/issues/57
export MEMCACHE_SERVERS='' MEMCACHIER_SERVERS=''

if [ -f bin/install_nodejs ]; then
echo "-----> Running install_nodejs"
chmod +x bin/install_nodejs
bin/install_nodejs

if [ -f bin/install_less ]; then
echo "-----> Running install_lessc"
chmod +x bin/install_less
bin/install_less
fi
fi

if [ -f bin/run_collectstatic ]; then
echo "-----> Running run_collectstatic"
chmod +x bin/run_collectstatic
bin/run_collectstatic
fi

if [ -f bin/run_compress ]; then
echo "-----> Running run_compress"
chmod +x bin/run_compress
bin/run_compress
fi

echo "-----> Post-compile done"
15 changes: 15 additions & 0 deletions bin/run_compress
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -eo pipefail

indent() {
RE="s/^/ /"
[ $(uname) == "Darwin" ] && sed -l "$RE" || sed -u "$RE"
}

MANAGE_FILE=$(find . -maxdepth 3 -type f -name 'manage.py' | head -1)
MANAGE_FILE=${MANAGE_FILE:2}

echo "-----> Compressing static files"
python $MANAGE_FILE compress 2>&1 | indent

echo
65 changes: 65 additions & 0 deletions hc/heroku_settings.py
@@ -0,0 +1,65 @@
import os
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SITE_ROOT = os.getenv('SITE_ROOT', "https://my-monitoring-project.com")
SITE_NAME = os.getenv('SITE_NAME', "My Monitoring Project")
DEFAULT_FROM_EMAIL = os.getenv('FROM_EMAIL', "noreply@my-monitoring-project.com")
PING_ENDPOINT = os.getenv('PING_ROOT', SITE_ROOT) + "/ping/"
PING_EMAIL_DOMAIN = os.getenv('PING_EMAIL_DOMAIN', "example.com")

import herokuify
from herokuify.common import *
from herokuify.mail.mailgun import *

DATABASES = herokuify.get_db_config()

DEBUG = False
SECRET_KEY = os.getenv('SECRET_KEY', "---")

# Allow all host headers
ALLOWED_HOSTS = ['*']

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

import sys
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt': "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
'stream': sys.stdout,
},
},
'loggers': {
'django': {
'handlers': ['console'],
'propagate': True,
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'django.request': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': False,
},
'django.security': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': False,
}
}
}
2 changes: 2 additions & 0 deletions hc/settings.py
Expand Up @@ -193,5 +193,7 @@ def envint(s, default):

if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
from .local_settings import *
elif ('ON_HEROKU' in os.environ or 'DYNO' in os.environ or 'STACK' in os.environ) and os.path.exists(os.path.join(BASE_DIR, "hc/heroku_settings.py")):
from .heroku_settings import *
else:
warnings.warn("local_settings.py not found, using defaults")
5 changes: 3 additions & 2 deletions hc/wsgi.py
Expand Up @@ -8,9 +8,10 @@
"""

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hc.settings")

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hc.settings")
from whitenoise.django import DjangoWhiteNoise

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

0 comments on commit 3119214

Please sign in to comment.