Skip to content

Instantly share code, notes, and snippets.

@rcrowley
Created April 5, 2012 14:34
Show Gist options
  • Save rcrowley/2311507 to your computer and use it in GitHub Desktop.
Save rcrowley/2311507 to your computer and use it in GitHub Desktop.
Graphite Debian packaging
VERSION="0.9.9"
BUILD="betable1"
set -e -x
# Keep track of the original working directory.
OLDESTPWD="$PWD"
# Work in a temporary directory.
cd "$(mktemp -d)"
trap "rm -rf \"$PWD\"" EXIT INT QUIT TERM
# Clone the mainline Graphite repository from Launchpad.
bzr branch "lp:graphite"
cd "graphite"
REVNO="$(bzr revno)"
# Replace settings.py with one that delegates all settings to a
# local_settings.py that will be placed by Puppet.
cat >"webapp/graphite/settings.py" <<EOF
import os.path
import sys
sys.path.append('/etc/graphite')
from local_settings import *
WEBAPP_VERSION = '$VERSION'
DEBUG = False
JAVASCRIPT_DEBUG = False
TEMPLATE_DEBUG = DEBUG
CSS_DIR = CONTENT_DIR + 'css/'
LISTS_DIR = STORAGE_DIR + 'lists/'
INDEX_FILE = STORAGE_DIR + 'index'
WHITELIST_FILE = LISTS_DIR + 'whitelist'
sys.path.append(os.path.dirname(__file__) + '/thirdparty')
WHISPER_DIR = STORAGE_DIR + 'whisper/'
RRD_DIR = STORAGE_DIR + 'rrd/'
try:
import rrdtool
DATA_DIRS = [WHISPER_DIR, RRD_DIR]
except ImportError:
DATA_DIRS = [WHISPER_DIR]
DASHBOARD_CONF = os.path.join(CONF_DIR, 'dashboard.conf')
GRAPHTEMPLATES_CONF = os.path.join(CONF_DIR, 'graphTemplates.conf')
ADMINS = ()
MANAGERS = ADMINS
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates'),
)
APPEND_SLASH = False
if MEMCACHE_HOSTS:
CACHE_BACKEND = 'memcached://' + ';'.join(MEMCACHE_HOSTS) + ('/?timeout=%d' % DEFAULT_CACHE_DURATION)
else:
CACHE_BACKEND = "dummy:///"
TIME_ZONE = 'UTC'
LANGUAGE_CODE = 'en-US'
SITE_ID = 1
MEDIA_ROOT = ''
MEDIA_URL = ''
ADMIN_MEDIA_PREFIX = '/media/'
SECRET_KEY = ''
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.middleware.gzip.GZipMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
if USE_REMOTE_USER_AUTHENTICATION:
MIDDLEWARE_CLASSES += ('django.contrib.auth.middleware.RemoteUserMiddleware',)
ROOT_URLCONF = 'graphite.urls'
INSTALLED_APPS = (
'graphite.metrics',
'graphite.render',
'graphite.cli',
'graphite.browser',
'graphite.composer',
'graphite.account',
'graphite.dashboard',
'graphite.whitelist',
'graphite.events',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.contenttypes',
'tagging',
)
if USE_REMOTE_USER_AUTHENTICATION:
AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.RemoteUserBackend']
else:
AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend']
if USE_LDAP_AUTH:
AUTHENTICATION_BACKENDS.insert(0,'graphite.account.ldapBackend.LDAPBackend')
if ADDITIONAL_AUTHENTICATION_BACKENDS:
for backend in ADDITIONAL_AUTHENTICATION_BACKENDS:
AUTHENTICATION_BACKENDS.insert(0, backend)
EOF
#rm "webapp/graphite/settings.py"
# Remove all of the example configuration files. We have Internet for that.
find -name "*.example"
find -name "*.example" -delete
# Reorganize Whisper to fit into the combined setup.py's expectations.
rm "whisper/setup.py"
mv "whisper/whisper.py" "whisper/__init__.py"
# Place a patched setup.cfg and setup.py for the Graphite web app.
cat >"setup.cfg" <<EOF
[install]
prefix = /var/www/graphite
install-lib = %(prefix)s/webapp
EOF
cat >"setup.py" <<EOF
from collections import defaultdict
from distutils.core import setup
from glob import glob
import os
webapp_content = defaultdict(list)
for root, dirs, files in os.walk('webapp/content'):
for filename in files:
filepath = os.path.join(root, filename)
webapp_content[root[15:]].append(filepath)
setup(name='graphite',
version='$VERSION-$BUILD-$REVNO',
url='https://launchpad.net/graphite',
author='Chris Davis',
author_email='[email protected]',
license='Apache Software License 2.0',
description='Enterprise scalable realtime graphing',
package_dir={'carbon': 'carbon/lib/carbon',
'graphite': 'webapp/graphite',
'twisted': 'carbon/lib/twisted',
'whisper': 'whisper'},
packages=['carbon',
'carbon.aggregator',
'graphite',
'graphite.account',
'graphite.browser',
'graphite.cli',
'graphite.composer',
'graphite.render',
'graphite.whitelist',
'graphite.metrics',
'graphite.dashboard',
'graphite.graphlot',
'graphite.events',
'graphite.version',
'graphite.thirdparty',
'graphite.thirdparty.pytz',
'twisted.plugins',
'whisper'],
package_data={'carbon': ['*.xml'],
'graphite': ['templates/*', 'render/graphTemplates.conf']},
scripts=glob('bin/*') + glob('carbon/bin/*') + glob('whisper/bin/*'),
data_files=webapp_content.items())
EOF
# FPM that bitch. The dependencies are incomplete as it still needs Django,
# django-tagging, and Twisted.
fakeroot fpm -d "python" -d "python-cairo" -d "libsqlite3-0" \
-m "Richard Crowley <[email protected]>" \
-n "graphite" \
-p "$OLDESTPWD/graphite_${VERSION}-${BUILD}-${REVNO}_all.deb" \
-s "python" -t "deb" "setup.py"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment