Merge lp:~gesha/linaro-license-protection/add-multiple-sites-support into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Merged
Approved by: James Tunnicliffe
Approved revision: 97
Merged at revision: 96
Proposed branch: lp:~gesha/linaro-license-protection/add-multiple-sites-support
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 288 lines (+228/-0)
9 files modified
README (+16/-0)
license_protected_downloads/wsgi_releases.py (+42/-0)
license_protected_downloads/wsgi_snapshots.py (+42/-0)
middleware.py (+19/-0)
releases_urls.py (+36/-0)
settings.py (+6/-0)
settings_releases.py (+16/-0)
settings_snapshots.py (+15/-0)
snapshots_urls.py (+36/-0)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/add-multiple-sites-support
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Review via email: mp+118339@code.launchpad.net

This proposal supersedes a proposal from 2012-08-01.

Description of the change

This branch adds support of multi-sites per single Django application. It is now configured to serve releases.linaro.org and snapshots.linaro.org. Both sites use the same database for licenses. License acceptance is site-dependent: for example if you have accepted the license on snapshots you will need to accept the same license on releases if asked.
SITE_ID is not used since we separate DBs for each sites.

To post a comment you must log in.
Revision history for this message
James Tunnicliffe (dooferlad) wrote : Posted in a previous version of this proposal

Looks fine.

Since we have multiple settings and wsgi files it would be possible to use a separate database for each site and remove the site_id requirement. The databases build themselves up as they go, so unless the OpenID code stores data in them, we can just delete the existing database at a later date and start fresh.

Currently the set up uses sqlite3, which is fine for development but not for deployment, but I assume you and the sys-admins know that and will use a more traditional database when live!

review: Approve
Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Cool. If you change the databases so the sqlite3 stores are different files (licenses-release.db and licenses-snapshopt.db sort of thing) then this is good to land. Approving on condition of that change.

review: Approve
98. By Georgy Redkozubov

Added deployment steps to README.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2012-07-27 14:36:55 +0000
3+++ README 2012-08-06 12:52:18 +0000
4@@ -41,6 +41,22 @@
5 python 2.7, testrepository (>=0.0.6), python-html2text,
6 python-subunit, python-beautifulsoup, python-mock
7
8+Deployment steps
9+................
10+
11+- Checkout trunk branch into /srv/releases.linaro.org/linaro-license-protection
12+- Create directory for database: /srv/releases.linaro.org/db
13+- Create database, from /srv/releases.linaro.org/linaro-license-protection run
14+ python ./manage.py syncdb --noinput
15+- Create symlink for the application in /srv/snapshots.linaro.org:
16+ ln -s /srv/releases.linaro.org/linaro-license-protection \
17+ /srv/snapshots.linaro.org/linaro-license-protection
18+- Create directory for database: /srv/snapshots.linaro.org/db
19+- Create database, from /srv/snapshots.linaro.org/linaro-license-protection run
20+ python ./manage.py syncdb --noinput
21+- Put apache2 configs from branch lp:~linaro-infrastructure/linaro-license-protection/apache-configs
22+ in /etc/apache2/sites-available
23+- Enable sites: a2ensite releases.linaro.org snapshots.linaro.org
24
25 Technical details
26 -----------------
27
28=== added file 'license_protected_downloads/wsgi_releases.py'
29--- license_protected_downloads/wsgi_releases.py 1970-01-01 00:00:00 +0000
30+++ license_protected_downloads/wsgi_releases.py 2012-08-06 12:52:18 +0000
31@@ -0,0 +1,42 @@
32+"""
33+WSGI config for license_protected_downloads project.
34+
35+This module contains the WSGI application used by Django's development server
36+and any production WSGI deployments. It should expose a module-level variable
37+named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
38+this application via the ``WSGI_APPLICATION`` setting.
39+
40+Usually you will have the standard Django WSGI application here, but it also
41+might make sense to replace the whole Django WSGI application with a custom one
42+that later delegates to the Django one. For example, you could introduce WSGI
43+middleware here, or combine a Django application with an application of another
44+framework.
45+
46+"""
47+import os
48+import sys
49+sys.path.append("/usr/lib/python2.7/dist-packages")
50+sys.path.append("/usr/lib/pymodules/python2.7")
51+sys.path.append("/usr/lib/python2.7")
52+
53+# NOTE: Set actual path to directory containing linaro-license-protection app
54+sys.path.append("/srv/releases.linaro.org")
55+sys.path.append("/srv/releases.linaro.org/linaro-license-protection")
56+
57+os.environ.setdefault(
58+ "DJANGO_SETTINGS_MODULE",
59+ "linaro-license-protection.settings_releases"
60+)
61+
62+# This application object is used by any WSGI server configured to use this
63+# file. This includes Django's development server, if the WSGI_APPLICATION
64+# setting points here.
65+#from django.core.wsgi import get_wsgi_application
66+#application = get_wsgi_application()
67+
68+import django.core.handlers.wsgi
69+application = django.core.handlers.wsgi.WSGIHandler()
70+
71+# Apply WSGI middleware here.
72+# from helloworld.wsgi import HelloWorldApplication
73+# application = HelloWorldApplication(application)
74
75=== added file 'license_protected_downloads/wsgi_snapshots.py'
76--- license_protected_downloads/wsgi_snapshots.py 1970-01-01 00:00:00 +0000
77+++ license_protected_downloads/wsgi_snapshots.py 2012-08-06 12:52:18 +0000
78@@ -0,0 +1,42 @@
79+"""
80+WSGI config for license_protected_downloads project.
81+
82+This module contains the WSGI application used by Django's development server
83+and any production WSGI deployments. It should expose a module-level variable
84+named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
85+this application via the ``WSGI_APPLICATION`` setting.
86+
87+Usually you will have the standard Django WSGI application here, but it also
88+might make sense to replace the whole Django WSGI application with a custom one
89+that later delegates to the Django one. For example, you could introduce WSGI
90+middleware here, or combine a Django application with an application of another
91+framework.
92+
93+"""
94+import os
95+import sys
96+sys.path.append("/usr/lib/python2.7/dist-packages")
97+sys.path.append("/usr/lib/pymodules/python2.7")
98+sys.path.append("/usr/lib/python2.7")
99+
100+# NOTE: Set actual path to directory containing linaro-license-protection app
101+sys.path.append("/srv/snapshots.linaro.org")
102+sys.path.append("/srv/snapshots.linaro.org/linaro-license-protection")
103+
104+os.environ.setdefault(
105+ "DJANGO_SETTINGS_MODULE",
106+ "linaro-license-protection.settings_snapshots"
107+)
108+
109+# This application object is used by any WSGI server configured to use this
110+# file. This includes Django's development server, if the WSGI_APPLICATION
111+# setting points here.
112+#from django.core.wsgi import get_wsgi_application
113+#application = get_wsgi_application()
114+
115+import django.core.handlers.wsgi
116+application = django.core.handlers.wsgi.WSGIHandler()
117+
118+# Apply WSGI middleware here.
119+# from helloworld.wsgi import HelloWorldApplication
120+# application = HelloWorldApplication(application)
121
122=== added file 'middleware.py'
123--- middleware.py 1970-01-01 00:00:00 +0000
124+++ middleware.py 2012-08-06 12:52:18 +0000
125@@ -0,0 +1,19 @@
126+from django.conf import settings
127+from django.utils.cache import patch_vary_headers
128+
129+
130+class MultiHostMiddleware:
131+
132+ def process_request(self, request):
133+ try:
134+ host = request.META["HTTP_HOST"]
135+ if host[-3:] == ":80":
136+ host = host[:-3] # ignore default port number, if present
137+ request.urlconf = settings.HOST_MIDDLEWARE_URLCONF_MAP[host]
138+ except KeyError:
139+ pass # use default urlconf (settings.ROOT_URLCONF)
140+
141+ def process_response(self, request, response):
142+ if getattr(request, "urlconf", None):
143+ patch_vary_headers(response, ('Host',))
144+ return response
145
146=== added file 'releases_urls.py'
147--- releases_urls.py 1970-01-01 00:00:00 +0000
148+++ releases_urls.py 2012-08-06 12:52:18 +0000
149@@ -0,0 +1,36 @@
150+from django.conf.urls.defaults import patterns, include, url
151+
152+# Uncomment the next two lines to enable the admin:
153+from django.contrib import admin
154+admin.autodiscover()
155+
156+
157+urlpatterns = patterns('',
158+ # Uncomment the admin/doc line below to enable admin documentation:
159+ url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
160+
161+ # Uncomment the next line to enable the admin:
162+ url(r'^admin/', include(admin.site.urls)),
163+
164+ url(r'^openid/', include('django_openid_auth.urls')),
165+ url(r'^logout/$', 'django.contrib.auth.views.logout'),
166+
167+ # The license page...
168+ url(r'^license$',
169+ 'license_protected_downloads.views.show_license',
170+ name='show_license'),
171+
172+ # Exceptions redirected to root...
173+ url(r'^license',
174+ 'license_protected_downloads.views.redirect_to_root',
175+ name='redirect_to_root'),
176+
177+ # Accept the license
178+ url(r'^accept-license',
179+ 'license_protected_downloads.views.accept_license',
180+ name='accept_license'),
181+
182+ # Catch-all. We always return a file (or try to) if it exists.
183+ # This handler does that.
184+ url(r'(?P<path>.*)', 'license_protected_downloads.views.file_server'),
185+)
186
187=== modified file 'settings.py'
188--- settings.py 2012-07-11 13:08:55 +0000
189+++ settings.py 2012-08-06 12:52:18 +0000
190@@ -86,6 +86,7 @@
191 )
192
193 MIDDLEWARE_CLASSES = (
194+ 'middleware.MultiHostMiddleware',
195 'django.middleware.common.CommonMiddleware',
196 'django.contrib.sessions.middleware.SessionMiddleware',
197 'django.middleware.csrf.CsrfViewMiddleware',
198@@ -154,3 +155,8 @@
199 'django.contrib.messages.context_processors.messages',
200 'django.contrib.auth.context_processors.auth',
201 )
202+
203+HOST_MIDDLEWARE_URLCONF_MAP = {
204+ "releases.linaro.org": ROOT_DIR + ".releases_urls",
205+ "snapshots.linaro.org": ROOT_DIR + ".snapshots_urls",
206+}
207
208=== added file 'settings_releases.py'
209--- settings_releases.py 1970-01-01 00:00:00 +0000
210+++ settings_releases.py 2012-08-06 12:52:18 +0000
211@@ -0,0 +1,16 @@
212+from settings import *
213+
214+
215+DATABASES = {
216+ 'default': {
217+ 'ENGINE': 'django.db.backends.sqlite3',
218+ 'NAME': '/srv/releases.linaro.org/db/licenses.db',
219+ 'USER': '',
220+ 'PASSWORD': '',
221+ 'HOST': '',
222+ 'PORT': '',
223+ }
224+}
225+
226+TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates_releases" ),)
227+SERVED_PATHS = ['/srv/releases.linaro.org/www']
228
229=== added file 'settings_snapshots.py'
230--- settings_snapshots.py 1970-01-01 00:00:00 +0000
231+++ settings_snapshots.py 2012-08-06 12:52:18 +0000
232@@ -0,0 +1,15 @@
233+from settings import *
234+
235+DATABASES = {
236+ 'default': {
237+ 'ENGINE': 'django.db.backends.sqlite3',
238+ 'NAME': '/srv/snapshots.linaro.org/db/licenses.db',
239+ 'USER': '',
240+ 'PASSWORD': '',
241+ 'HOST': '',
242+ 'PORT': '',
243+ }
244+}
245+
246+TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates_snapshots" ),)
247+SERVED_PATHS = ['/srv/snapshots.linaro.org/www']
248
249=== added file 'snapshots_urls.py'
250--- snapshots_urls.py 1970-01-01 00:00:00 +0000
251+++ snapshots_urls.py 2012-08-06 12:52:18 +0000
252@@ -0,0 +1,36 @@
253+from django.conf.urls.defaults import patterns, include, url
254+
255+# Uncomment the next two lines to enable the admin:
256+from django.contrib import admin
257+admin.autodiscover()
258+
259+
260+urlpatterns = patterns('',
261+ # Uncomment the admin/doc line below to enable admin documentation:
262+ url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
263+
264+ # Uncomment the next line to enable the admin:
265+ url(r'^admin/', include(admin.site.urls)),
266+
267+ url(r'^openid/', include('django_openid_auth.urls')),
268+ url(r'^logout/$', 'django.contrib.auth.views.logout'),
269+
270+ # The license page...
271+ url(r'^license$',
272+ 'license_protected_downloads.views.show_license',
273+ name='show_license'),
274+
275+ # Exceptions redirected to root...
276+ url(r'^license',
277+ 'license_protected_downloads.views.redirect_to_root',
278+ name='redirect_to_root'),
279+
280+ # Accept the license
281+ url(r'^accept-license',
282+ 'license_protected_downloads.views.accept_license',
283+ name='accept_license'),
284+
285+ # Catch-all. We always return a file (or try to) if it exists.
286+ # This handler does that.
287+ url(r'(?P<path>.*)', 'license_protected_downloads.views.file_server'),
288+)

Subscribers

People subscribed via source and target branches