Permalink
Browse files

Adds support for the database relation, including:

 * Updating the settings so that during db-relation-changed the first
   database relation is used as the default django database.
 * documenting (via the Makefile) the custom steps required to ensure
   that the debversion postgresql type is available on the postgres
   service.
 * Adding a syncdb 'hook' (really a task), which can be called via juju
   run.
 * Removing south from the installed apps due to the broken migration,
   instead creating the tables in teh currently defined state (although
   south is still required on the python path due to being imported by
   the app).
  • Loading branch information...
Michael Nelson
Michael Nelson committed Jun 23, 2014
1 parent de1d11a commit c32e2b4537bde3a36cca1a8bccf097909d74843f
Showing with 61 additions and 4 deletions.
  1. +9 −0 Makefile
  2. +1 −1 django-project/clickreviewsproject/urls.py
  3. +7 −1 django-project/manage.py
  4. +1 −0 hooks/db-relation-changed
  5. +1 −0 hooks/syncdb
  6. +3 −0 metadata.yaml
  7. +13 −1 playbook.yml
  8. +26 −1 templates/settings.py.j2
View
@@ -37,8 +37,17 @@ deploy: create-tarball
@juju set ubuntu-reviews build_label=r$(REVIEWS_REVNO)
@juju deploy gunicorn
@juju deploy nrpe-external-master
+ @juju deploy postgresql
@juju add-relation ubuntu-reviews gunicorn
@juju add-relation ubuntu-reviews nrpe-external-master
+ @juju add-relation ubuntu-reviews postgresql:db
+ @juju set postgresql extra-packages=postgresql-9.1-debversion
+ @echo "Once the services are related, run 'make setup-db'"
+
+setup-db:
+ @echo "Creating custom debversion postgres type and syncing the ubuntu-reviews database."
+ @juju run --service postgresql 'psql -U postgres ubuntu-reviews -c "CREATE EXTENSION debversion;"'
+ @juju run --unit=ubuntu-reviews/0 "hooks/syncdb"
@echo See the README for explorations after deploying.
curl:
@@ -2,5 +2,5 @@
urlpatterns = patterns(
'',
- url(r'^$', include('clickreviews.api.urls'), name='api'),
+ url(r'^', include('clickreviews.api.urls'), name='api'),
)
View
@@ -3,7 +3,13 @@
import sys
if __name__ == "__main__":
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "clickreviews.settings")
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "clickreviewsproject.settings")
+ extra_paths = [
+ '/srv/click-reviews.ubuntu.com/code/current/branches/scaclient/',
+ '/srv/click-reviews.ubuntu.com/code/current/branches/piston-mini-client/',
+ '/srv/click-reviews.ubuntu.com/code/current/branches/django-piston/',
+ ]
+ sys.path.extend(extra_paths)
from django.core.management import execute_from_command_line
View
View
@@ -15,3 +15,6 @@ provides:
nrpe-external-master:
interface: nrpe-external-master
scope: container
+requires:
+ db:
+ interface: pgsql
View
@@ -3,13 +3,13 @@
vars:
- app_label: click-reviews.ubuntu.com
+ - code_archive: "{{ build_label }}/rnr-server.tgz"
roles:
- role: wsgi-app
listen_port: 8080
python_path: "{{ application_dir }}/django-project:{{ current_code_dir }}/src"
wsgi_application: clickreviewsproject.wsgi:application
- code_archive: "{{ build_label }}/rnr-server.tgz"
when: build_label != ''
- role: nrpe-external-master
@@ -25,6 +25,7 @@
- python-django=1.5.4-1ubuntu1~ctools0
- python-tz
- python-pip
+ - python-psycopg2
tags:
- install
- upgrade-charm
@@ -46,13 +47,24 @@
tags:
- install
- upgrade-charm
+ - db-relation-changed
notify:
- Restart wsgi
+
# XXX Normally our deployment build would ensure these are all available in the tarball.
- name: Install any non-distro dependencies (Don't depend on pip for a real deployment!)
pip: name={{ item.key }} version={{ item.value }}
with_dict:
south: 0.7.6
+ django-openid-auth: 0.2
tags:
- install
- upgrade-charm
+
+ - name: sync the database
+ django_manage: >
+ command="syncdb --noinput"
+ app_path="{{ application_dir }}/django-project"
+ pythonpath="{{ code_dir }}/current/src"
+ tags:
+ - syncdb
View
@@ -1,6 +1,31 @@
DEBUG = True
TEMPLATE_DEBUG = DEBUG
SECRET_KEY = '{{ django_secret_key }}'
+
+{% if 'db' in relations %}
+DATABASES = {
+ {% for dbrelation in relations['db'] %}
+ {% if loop.first %}
+ {% set services=relations['db'][dbrelation] %}
+ {% for service in services %}
+ {% if service.startswith('postgres') %}
+ {% set dbdetails = services[service] %}
+ {% if 'database' in dbdetails %}
+ 'default': {
+ 'ENGINE': 'django.db.backends.postgresql_psycopg2',
+ 'NAME': '{{ dbdetails["database"] }}',
+ 'HOST': '{{ dbdetails["host"] }}',
+ 'USER': '{{ dbdetails["user"] }}',
+ 'PASSWORD': '{{ dbdetails["password"] }}',
+ }
+ {% endif %}
+ {% endif %}
+ {% endfor %}
+ {% endif %}
+ {% endfor %}
+}
+{% endif %}
+
TIME_ZONE = 'UTC'
ROOT_URLCONF = 'clickreviewsproject.urls'
WSGI_APPLICATION = 'clickreviewsproject.wsgi.application'
@@ -12,8 +37,8 @@ INSTALLED_APPS = (
'django_openid_auth',
'django.contrib.messages',
'django.contrib.staticfiles',
+ 'reviewsapp',
'clickreviews',
- 'south',
)
AUTHENTICATION_BACKENDS = (
'django_openid_auth.auth.OpenIDBackend',

0 comments on commit c32e2b4

Please sign in to comment.