Browse Source

Heroku compatibility.

pull/114/head
Ronald Ip 8 years ago
parent
commit
ec1f4966b5
No known key found for this signature in database GPG Key ID: B74B616707867821
9 changed files with 184 additions and 7 deletions
  1. +1
    -0
      Procfile
  2. +34
    -0
      app.json
  3. +36
    -0
      bin/post_compile
  4. +15
    -0
      bin/run_compress
  5. +57
    -0
      hc/heroku_settings.py
  6. +2
    -0
      hc/settings.py
  7. +3
    -2
      hc/wsgi.py
  8. +9
    -0
      requirements.in
  9. +27
    -5
      requirements.txt

+ 1
- 0
Procfile View File

@ -0,0 +1 @@
web: gunicorn hc.wsgi --log-file -

+ 34
- 0
app.json View File

@ -0,0 +1,34 @@
{
"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/"
},
"SITE_NAME": {
"description": "Used throughout the templates.",
"value": "My Monitoring Project"
},
"FROM_EMAIL": {
"description": "Email from address.",
"value": "[email protected]"
},
"SECRET_KEY": {
"generator": "secret"
},
"ON_HEROKU": {
"value": "yes"
}
}
}

+ 36
- 0
bin/post_compile View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -eo pipefail
# The post_compile hook is run by heroku-buildpack-python
echo "-----> I'm 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
- 0
bin/run_compress View File

@ -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

+ 57
- 0
hc/heroku_settings.py View File

@ -0,0 +1,57 @@
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', "[email protected]")
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':'DEBUG',
},
'MYAPP': {
'handlers': ['console'],
'level': 'DEBUG',
},
}
}

+ 2
- 0
hc/settings.py View File

@ -153,5 +153,7 @@ PUSHBULLET_CLIENT_SECRET = None
if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")): if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
from .local_settings import * from .local_settings import *
elif ('ON_HEROKU' in os.environ == 'yes' or 'STACK' in os.environ) and os.path.exists(os.path.join(BASE_DIR, "hc/heroku_settings.py")):
from .heroku_settings import *
else: else:
warnings.warn("local_settings.py not found, using defaults") warnings.warn("local_settings.py not found, using defaults")

+ 3
- 2
hc/wsgi.py View File

@ -8,9 +8,10 @@ https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
""" """
import os import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hc.settings")
from django.core.wsgi import get_wsgi_application 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 = get_wsgi_application()
application = DjangoWhiteNoise(application)

+ 9
- 0
requirements.in View File

@ -0,0 +1,9 @@
croniter
Django
django_compressor
psycopg2
pytz
requests
gunicorn
whitenoise
django-herokuify

+ 27
- 5
requirements.txt View File

@ -1,6 +1,28 @@
croniter
Django==1.10.5
django_compressor==2.1
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements.txt requirements.in
#
boto==2.46.1 # via django-herokuify
croniter==0.3.15
dj-database-url==0.4.2 # via django-heroku-postgresify, django-herokuify
django-appconf==1.0.2 # via django-compressor
django-compressor==2.1.1
django-heroku-memcacheify==1.0.0 # via django-herokuify
django-heroku-postgresify==0.4 # via django-herokuify
django-herokuify==1.0rc3
django-pylibmc-sasl==0.2.4 # via django-herokuify
django-pylibmc==0.6.1 # via django-heroku-memcacheify
django-storages==1.5.2 # via django-herokuify
Django==1.10.5 # via django-heroku-postgresify, django-pylibmc-sasl
gunicorn==19.6.0
psycopg2==2.6.2 psycopg2==2.6.2
pytz==2016.7
requests==2.9.1
pylibmc==1.5.1 # via django-herokuify, django-pylibmc, django-pylibmc-sasl
python-dateutil==2.6.0 # via croniter
pytz==2016.10
rcssmin==1.0.6 # via django-compressor
requests==2.13.0
rjsmin==1.0.12 # via django-compressor
six==1.10.0 # via python-dateutil
whitenoise==3.3.0

Loading…
Cancel
Save