Merge lp:~michael.nelson/open-goal-tracker/ensemble_deploy into lp:open-goal-tracker

Proposed by Michael Nelson
Status: Work in progress
Proposed branch: lp:~michael.nelson/open-goal-tracker/ensemble_deploy
Merge into: lp:open-goal-tracker
Diff against target: 245 lines (+142/-6)
11 files modified
.bzrignore (+1/-0)
fabfile.py (+7/-4)
ogt_project/apache/django.wsgi (+27/-0)
ogt_project/ensemble_deploy/ogt/hooks/db-relation-changed (+35/-0)
ogt_project/ensemble_deploy/ogt/hooks/install (+36/-0)
ogt_project/ensemble_deploy/ogt/hooks/local_settings-template.py (+14/-0)
ogt_project/ensemble_deploy/ogt/hooks/start (+2/-0)
ogt_project/ensemble_deploy/ogt/hooks/stop (+3/-0)
ogt_project/ensemble_deploy/ogt/metadata.yaml (+10/-0)
ogt_project/settings.py (+5/-0)
ogt_project/templates/base.html (+2/-2)
To merge this branch: bzr merge lp:~michael.nelson/open-goal-tracker/ensemble_deploy
Reviewer Review Type Date Requested Status
Michael Nelson Pending
Review via email: mp+69078@code.launchpad.net

Description of the change

Just a WIP. Currently it seems that we're getting both python 2.6 and 2.7 installed which is causing an issue during the install hook: http://paste.ubuntu.com/651735/. After chatting with niemeyer, solved by unsetting PYTHONPATH in the install hook, and created bug 816264.

To post a comment you must log in.
81. By Michael Nelson

Left over file that wasn't added to repo earlier.

82. By Michael Nelson

Put the stop hook in the hooks directory.

83. By Michael Nelson

Add python-virtualenv to install.

84. By Michael Nelson

Updated recipe to reset pythonpath after chatting with niemeyer.

85. By Michael Nelson

Small changes after testing the db relationship.

86. By Michael Nelson

Ensure virtualenvs_path can be set in environ.

87. By Michael Nelson

Updated to use django-socialauth (after finding django_openid_auth is incompatible with mysql :/ ).

88. By Michael Nelson

Included the extra app openid_consumer for django_socialauth.

89. By Michael Nelson

Switch back to django_openid_auth.

90. By Michael Nelson

Initial postgres integration.

91. By Michael Nelson

Small tweaks for postgres deploy.

92. By Michael Nelson

Ensure install is idempotent.

93. By Michael Nelson

Fixed db-relation-changed and added template dir to settings template.

94. By Michael Nelson

Added alias for static media (until updated to separate static service).

Unmerged revisions

94. By Michael Nelson

Added alias for static media (until updated to separate static service).

93. By Michael Nelson

Fixed db-relation-changed and added template dir to settings template.

92. By Michael Nelson

Ensure install is idempotent.

91. By Michael Nelson

Small tweaks for postgres deploy.

90. By Michael Nelson

Initial postgres integration.

89. By Michael Nelson

Switch back to django_openid_auth.

88. By Michael Nelson

Included the extra app openid_consumer for django_socialauth.

87. By Michael Nelson

Updated to use django-socialauth (after finding django_openid_auth is incompatible with mysql :/ ).

86. By Michael Nelson

Ensure virtualenvs_path can be set in environ.

85. By Michael Nelson

Small changes after testing the db relationship.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2011-06-14 17:52:29 +0000
3+++ .bzrignore 2011-09-12 20:54:36 +0000
4@@ -10,3 +10,4 @@
5 .virtualenvs
6 .downloads
7 virtualenv
8+ogt_project/local_settings.py
9
10=== modified file 'fabfile.py'
11--- fabfile.py 2011-06-23 06:30:45 +0000
12+++ fabfile.py 2011-09-12 20:54:36 +0000
13@@ -2,6 +2,7 @@
14 import shutil
15 import tempfile
16 from fabric.api import (
17+ env,
18 local,
19 settings,
20 )
21@@ -11,14 +12,16 @@
22 from zipfile import ZipFile
23
24
25-def ensure_virtualenv(virtualenvs_path='.virtualenvs',
26- virtualenv_symlink='virtualenv'):
27+env.virtualenvs_path = os.environ.get('VIRTUALENVS_PATH', '.virtualenvs')
28+
29+
30+def ensure_virtualenv(virtualenv_symlink='virtualenv'):
31 # Check the SHA1 hash of the requirements.txt and see if the
32 # corresponding virtual env already exists, if not create it.
33 with open('requirements.txt', 'r') as requirements:
34 digest = sha1(requirements.read()).hexdigest()
35
36- real_virtualenvs_path = os.path.realpath(virtualenvs_path)
37+ real_virtualenvs_path = os.path.realpath(env.virtualenvs_path)
38 venv_matching_requirements = os.path.join(real_virtualenvs_path, 'goaltracker_' + digest)
39 if not os.path.exists(venv_matching_requirements):
40 print("No virtualenv matching requirements.txt found. Creating one now.")
41@@ -134,7 +137,7 @@
42
43 def install_jquery_media():
44 jquery_zip = download_resource(
45- 'http://jqueryui.com/download/jquery-ui-1.8.10.custom.zip')
46+ 'http://jqueryui.com/download/jquery-ui-1.8.16.custom.zip')
47 # Copy the js and css.
48 copy_files_map = {
49 'js': os.path.join('media-root-dev', 'js', 'jquery'),
50
51=== added directory 'ogt_project/apache'
52=== added file 'ogt_project/apache/django.wsgi'
53--- ogt_project/apache/django.wsgi 1970-01-01 00:00:00 +0000
54+++ ogt_project/apache/django.wsgi 2011-09-12 20:54:36 +0000
55@@ -0,0 +1,27 @@
56+# XXX Move to be a template of the ensemble_deploy/ogt/hooks rather than here.
57+import os
58+import site
59+import sys
60+
61+# As per http://code.google.com/p/modwsgi/wiki/VirtualEnvironments
62+# Remember original sys.path.
63+prev_sys_path = list(sys.path)
64+
65+site.addsitedir('/opt/open-goal-tracker/current/virtualenv/lib/python2.7/site-packages')
66+
67+# Reorder sys.path so new directories at the front.
68+new_sys_path = []
69+for item in list(sys.path):
70+ if item not in prev_sys_path:
71+ new_sys_path.append(item)
72+ sys.path.remove(item)
73+sys.path[:0] = new_sys_path
74+
75+project_path = '/opt/open-goal-tracker/current'
76+if project_path not in sys.path:
77+ sys.path.append(project_path)
78+
79+os.environ['DJANGO_SETTINGS_MODULE'] = 'ogt_project.settings'
80+
81+import django.core.handlers.wsgi
82+application = django.core.handlers.wsgi.WSGIHandler()
83
84=== added directory 'ogt_project/ensemble_deploy'
85=== added directory 'ogt_project/ensemble_deploy/ogt'
86=== added directory 'ogt_project/ensemble_deploy/ogt/hooks'
87=== added file 'ogt_project/ensemble_deploy/ogt/hooks/db-relation-changed'
88--- ogt_project/ensemble_deploy/ogt/hooks/db-relation-changed 1970-01-01 00:00:00 +0000
89+++ ogt_project/ensemble_deploy/ogt/hooks/db-relation-changed 2011-09-12 20:54:36 +0000
90@@ -0,0 +1,35 @@
91+#!/bin/bash
92+set -eux # -x for verbose logging to ensemble debug-log
93+IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{print $1}'|head -n 1`
94+ensemble-log "setting ip to $IP"
95+relation-set ip=$IP
96+
97+hooksdir=$PWD
98+user=`relation-get user`
99+# All values are set together, so checking on a single value is enough
100+# If $user is not set, DB is still setting itself up, we exit awaiting next run
101+[ -z "$user" ] && exit 0
102+password=`relation-get password`
103+host=`relation-get host`
104+database=`relation-get database`
105+
106+ensemble-log "Updating local_settings.py."
107+cd /opt/open-goal-tracker/current/ogt_project
108+sed -e "s/DATABASE_USER/$user/" \
109+-e "s/DATABASE_PASSWORD/$password/" \
110+-e "s/DATABASE_HOST/$host/" \
111+-e "s/DATABASE_NAME/$database/" \
112+$hooksdir/local_settings-template.py > local_settings.py
113+chown www-data local_settings.py
114+
115+ensemble-log "Syncing and migration database (if necessary)."
116+cd ..
117+export VIRTUALENVS_PATH=/opt/open-goal-tracker/virtualenvs
118+fab manage:'syncdb --noinput'
119+fab manage:'migrate'
120+chown -R www-data .
121+
122+ensemble-log "Setting up the wsgi alias."
123+# XXX Use a separate lighttpd or similar for serving static content.
124+echo 'Alias /site_media/ /opt/open-goal-tracker/current/media-root-dev/\nWSGIScriptAlias / /opt/open-goal-tracker/current/ogt_project/apache/django.wsgi' >> /etc/apache2/httpd.conf
125+service apache2 restart
126
127=== added file 'ogt_project/ensemble_deploy/ogt/hooks/install'
128--- ogt_project/ensemble_deploy/ogt/hooks/install 1970-01-01 00:00:00 +0000
129+++ ogt_project/ensemble_deploy/ogt/hooks/install 2011-09-12 20:54:36 +0000
130@@ -0,0 +1,36 @@
131+#!/bin/bash
132+set -eux # -x for verbose logging to ensemble debug-log
133+
134+# XXX Resetting PYTHONPATH to avoid package dependency issues with python2.6
135+# (which is required by libapache2, even though unused).
136+ensemble-log "Resetting PYTHONPATH."
137+export PYTHONPATH=
138+
139+ensemble-log "Upgrading machine."
140+apt-get update
141+apt-get -y upgrade
142+
143+ensemble-log "Installing required packages via apt-get."
144+apt-get -y install apache2 libapache2-mod-wsgi bzr fabric python-virtualenv python-psycopg2
145+
146+ensemble-log "Pulling open-goal-tracker into /opt/open-goal-tracker/current"
147+rm -rf /opt/open-goal-tracker
148+mkdir -p /opt/open-goal-tracker
149+cd /opt/open-goal-tracker
150+umask 022
151+
152+# Switch to trunk/release branch.
153+bzr branch lp:~michael.nelson/open-goal-tracker/ensemble_deploy current
154+
155+ensemble-log "Creating the virtualenv in /opt/open-goal-tracker/virtualenvs"
156+mkdir virtualenvs
157+cd current
158+export VIRTUALENVS_PATH=/opt/open-goal-tracker/virtualenvs
159+fab ensure_virtualenv
160+cd ..
161+chown -R ubuntu:www-data current
162+
163+# Download any 3rd party static medial that we need.
164+fab install_local_media_libraries
165+
166+ensemble-log "Finished install."
167
168=== added file 'ogt_project/ensemble_deploy/ogt/hooks/local_settings-template.py'
169--- ogt_project/ensemble_deploy/ogt/hooks/local_settings-template.py 1970-01-01 00:00:00 +0000
170+++ ogt_project/ensemble_deploy/ogt/hooks/local_settings-template.py 2011-09-12 20:54:36 +0000
171@@ -0,0 +1,14 @@
172+DATABASES = {
173+ 'default': {
174+ 'ENGINE': 'django.db.backends.postgresql_psycopg2',
175+ 'NAME': 'DATABASE_NAME',
176+ 'PASSWORD': 'DATABASE_PASSWORD',
177+ 'USER': 'DATABASE_USER',
178+ 'HOST': 'DATABASE_HOST',
179+ }
180+ }
181+
182+TEMPLATE_DIRS = (
183+ '/opt/open-goal-tracker/current/ogt_project/templates/',
184+ )
185+
186
187=== added file 'ogt_project/ensemble_deploy/ogt/hooks/start'
188--- ogt_project/ensemble_deploy/ogt/hooks/start 1970-01-01 00:00:00 +0000
189+++ ogt_project/ensemble_deploy/ogt/hooks/start 2011-09-12 20:54:36 +0000
190@@ -0,0 +1,2 @@
191+#!/bin/bash
192+service apache2 restart
193
194=== added file 'ogt_project/ensemble_deploy/ogt/hooks/stop'
195--- ogt_project/ensemble_deploy/ogt/hooks/stop 1970-01-01 00:00:00 +0000
196+++ ogt_project/ensemble_deploy/ogt/hooks/stop 2011-09-12 20:54:36 +0000
197@@ -0,0 +1,3 @@
198+#!/bin/bash
199+ensemble-log "Stopping apache"
200+service apache2 stop
201
202=== added file 'ogt_project/ensemble_deploy/ogt/metadata.yaml'
203--- ogt_project/ensemble_deploy/ogt/metadata.yaml 1970-01-01 00:00:00 +0000
204+++ ogt_project/ensemble_deploy/ogt/metadata.yaml 2011-09-12 20:54:36 +0000
205@@ -0,0 +1,10 @@
206+ensemble: formula
207+name: ogt
208+revision: 1
209+summary: "Open Goal Tracker"
210+description: |
211+ Installs the Open Goal Tracker web service and relates it to
212+ the standard mysql formula.
213+requires:
214+ db:
215+ interface: pgsql
216
217=== modified file 'ogt_project/settings.py'
218--- ogt_project/settings.py 2011-06-23 06:30:45 +0000
219+++ ogt_project/settings.py 2011-09-12 20:54:36 +0000
220@@ -50,3 +50,8 @@
221 LOGIN_URL = '/openid/login/'
222 LOGIN_REDIRECT_URL = '/'
223 OPENID_USE_AS_ADMIN_LOGIN = True
224+
225+try:
226+ from local_settings import *
227+except ImportError:
228+ pass
229
230=== modified file 'ogt_project/templates/base.html'
231--- ogt_project/templates/base.html 2011-06-22 06:35:23 +0000
232+++ ogt_project/templates/base.html 2011-09-12 20:54:36 +0000
233@@ -6,10 +6,10 @@
234 <link rel="stylesheet" href="{{ MEDIA_URL }}css/blueprint/screen.css" type="text/css" media="screen, projection">
235 <link rel="stylesheet" href="{{ MEDIA_URL }}css/blueprint/print.css" type="text/css" media="print">
236 <!--[if lt IE 8]><link rel="stylesheet" href="{{ MEDIA_URL }}css/blueprint/ie.css" type="text/css" media="screen, projection"><![endif]-->
237- <link type="text/css" href="{{ MEDIA_URL }}css/jquery/smoothness/jquery-ui-1.8.10.custom.css" rel="Stylesheet" />
238+ <link type="text/css" href="{{ MEDIA_URL }}css/jquery/smoothness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />
239 <link rel="stylesheet" href="{{ MEDIA_URL }}css/learninggoals.css" type="text/css" media="screen, projection">
240 <script type="text/javascript" src="{{ MEDIA_URL }}js/jquery/jquery-1.4.4.min.js"></script>
241- <script type="text/javascript" src="{{ MEDIA_URL }}js/jquery/jquery-ui-1.8.10.custom.min.js"></script>
242+ <script type="text/javascript" src="{{ MEDIA_URL }}js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
243 <script type="text/javascript" src="{{ MEDIA_URL }}js/behaviour-sheet.js"></script>
244 <script type="text/javascript" src="{{ MEDIA_URL }}js/jquery.taconite.js"></script>
245 <script type="text/javascript" src="{{ MEDIA_URL }}js/jquery.form.js"></script>

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: