Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion layer.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,76 @@
includes: ['layer:basic', 'interface:pgsql', 'interface:http']
includes:
- 'layer:basic'
- 'layer:apt'
- 'interface:pgsql'
- 'interface:http'
defines:
install-path:
type: string
default: '/srv/django'
description: 'install path for django site'
settings-import:
type: string
default: '.settings'
description: 'python import path for the settings module'
pip-requirements:
type: string
description: 'path relative to `install-path` for a pip requirements.txt file'
wsgi:
type: string
default: '.wsgi:application'
description: 'Python import path relative to install-path for wsgi'
source:
type: object
params:
url:
type: string
description: 'vcs source (lp, github, etc) for Django site'
python:
type: string
default: '/usr/bin/python'
pip:
default: '/usr/bin/pip'
type: string
description: 'full path to pip binary for installation'
static-path:
default: 'static'
type: string
description: 'relative path from install-path for static content'
media-path:
default: 'static'
type: string
description: 'relative path from install-path for media content'
options:
basic:
packages:
- 'build-essential'
- 'binutils-doc'
- 'autoconf'
- 'authbind'
- 'bison'
- 'libjpeg-dev'
- 'libfreetype6-dev'
- 'zlib1g-dev'
- 'libzmq3-dev'
- 'libgdbm-dev'
- 'libncurses5-dev'
- 'automake'
- 'libtool'
- 'libffi-dev'
- 'curl'
- 'git'
- 'gettext'
- 'flex'
- 'postgresql-client'
- 'postgresql-client-common'
- 'python3'
- 'python3-pip'
- 'python-dev'
- 'python3-dev'
- 'python-pip'
- 'libxml2-dev'
- 'virtualenvwrapper'
- 'libxslt-dev'
- 'git-core',
- 'python-git'
- 'libpq-dev'
43 changes: 3 additions & 40 deletions lib/charms/django.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
import yaml
import subprocess
from warnings import warn
from charms.layer.django import *

from charmhelpers.core.unitdata import kv
from charmhelpers.core.hookenv import status_set

def config():
db = kv()
with open('django.yaml') as f:
django_cfg = yaml.safe_load(f.read())

for k, v in django_cfg.items():
db.set(k, v)

return db


def manage(cmd):
dcfg = config()
if not isinstance(cmd, list):
cmd = cmd.split(' ')

exe = [python(), 'manage.py']
extra = []
if dcfg.get('config-import'):
extra.append('--settings=%s' % dcfg.get('config-import'))

status_set('maintenance', ' '.join(['manage.py'] + cmd))
call(exe + cmd + extra)

def call(cmd):
dcfg = config()
subprocess.check_call(cmd, cwd=dcfg.get('source-path'))


def pip():
return config().get('pip', '/usr/bin/pip')


def python():
return config().get('python', '/usr/bin/python')
warn('this module is being deprecated, use charms.layer.django instead')
47 changes: 47 additions & 0 deletions lib/charms/layer/django.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import yaml
import subprocess

from charmhelpers.core.unitdata import kv
from charmhelpers.core.hookenv import status_set
from charms import layer

def config():
db = kv()

if os.path.exists('django.yaml'):
with open('django.yaml') as f:
django_cfg = yaml.safe_load(f.read())
else:
django_cfg = layer.options('django')

for k, v in django_cfg.items():
db.set(k, v)

return db


def manage(cmd):
dcfg = config()
if not isinstance(cmd, list):
cmd = cmd.split(' ')

exe = [python(), 'manage.py']
extra = []
if dcfg.get('config-import'):
extra.append('--settings=%s' % dcfg.get('config-import'))

status_set('maintenance', ' '.join(['manage.py'] + cmd))
call(exe + cmd + extra)

def call(cmd):
dcfg = config()
subprocess.check_call(cmd, cwd=dcfg.get('source-path'))


def pip():
return config().get('pip', '/usr/bin/pip')


def python():
return config().get('python', '/usr/bin/python')
30 changes: 13 additions & 17 deletions reactive/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
service_start,
)

from charmhelpers.fetch import (
apt_install,
install_remote,
)
from charmhelpers.fetch import install_remote

from charms import apt
from charms.layer import django

from charms import django
from charms.reactive import (
hook,
when,
Expand All @@ -32,29 +31,23 @@
)


@hook('install')
@when_not('django.installed')
def install():
adduser('django')
dcfg = django.config()
status_set('maintenance', 'installing system deps')
apt_install(['build-essential', 'binutils-doc', 'autoconf', 'authbind',
'bison', 'libjpeg-dev', 'libfreetype6-dev', 'zlib1g-dev',
'libzmq3-dev', 'libgdbm-dev', 'libncurses5-dev', 'automake',
'libtool', 'libffi-dev', 'curl', 'git', 'gettext', 'flex',
'postgresql-client', 'postgresql-client-common', 'python3',
'python3-pip', 'python-dev', 'python3-dev', 'python-pip',
'libxml2-dev', 'virtualenvwrapper', 'libxslt-dev', 'git-core',
'python-git', 'libpq-dev'] + dcfg.get('apt-packages', []))
status_set('maintenance', 'installing deps')
apt.queue_install(dcfg.get('apt-packages', []))

subprocess.check_call([django.pip(), 'install', 'circus', 'gunicorn', ])
source_install(dcfg)
open_port(config('django-port'))
set_state('django.installed')
start()

@when('django.ready')
@when('website.available')
def send_port(http):
http.configure(80)
http.configure(config('django-port'))


@when('django.source.available')
Expand Down Expand Up @@ -122,14 +115,14 @@ def start():
service_start('circus')

set_state('circus.running')
remove_state('django.restart')


@when('django.ready')
@when('django.restart')
def restart():
remove_state('circus.running')
start()
remove_state('django.restart')


def source_install(dcfg):
Expand All @@ -138,6 +131,9 @@ def source_install(dcfg):
if not os.path.exists(dcfg.get('install-path')):
os.makedirs(dcfg.get('install-path'))

if 'url' not in source:
return

source_path = install_remote(source['url'],
dest=dcfg.get('install-path'))

Expand Down