Merge lp:~danilo/linaro-license-protection/staging-configs into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Данило Шеган
Status: Merged
Approved by: James Tunnicliffe
Approved revision: 107
Merged at revision: 99
Proposed branch: lp:~danilo/linaro-license-protection/staging-configs
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 330 lines (+157/-131)
6 files modified
README (+8/-16)
license_protected_downloads/wsgi_releases.py (+0/-42)
license_protected_downloads/wsgi_snapshots.py (+0/-42)
scripts/update-deployment.py (+149/-0)
settings_releases.py (+0/-16)
settings_snapshots.py (+0/-15)
To merge this branch: bzr merge lp:~danilo/linaro-license-protection/staging-configs
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Review via email: mp+119304@code.launchpad.net

Description of the change

Remove configs related to our production/staging deployment
(they now live in lp:linaro-license-protection/configs) and
prepare a script to be used for updating staging instance
from a cronjob.

No tests for the update script yet, but I will be providing
them later.

I'll also modify the script later to be possible to use it
for production deployments as well.

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

Looks good to me (apart from, as you pointed out, the lack of tests).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2012-08-06 12:30:16 +0000
3+++ README 2012-08-13 11:45:25 +0000
4@@ -34,6 +34,7 @@
5 ............
6
7 libapache2-mod-xsendfile >= 0.10
8+libapache2-mod-python
9 python-django >= 1.3.1
10 python-django-openid-auth
11
12@@ -41,22 +42,13 @@
13 python 2.7, testrepository (>=0.0.6), python-html2text,
14 python-subunit, python-beautifulsoup, python-mock
15
16-Deployment steps
17-................
18-
19-- Checkout trunk branch into /srv/releases.linaro.org/linaro-license-protection
20-- Create directory for database: /srv/releases.linaro.org/db
21-- Create database, from /srv/releases.linaro.org/linaro-license-protection run
22- python ./manage.py syncdb --noinput
23-- Create symlink for the application in /srv/snapshots.linaro.org:
24- ln -s /srv/releases.linaro.org/linaro-license-protection \
25- /srv/snapshots.linaro.org/linaro-license-protection
26-- Create directory for database: /srv/snapshots.linaro.org/db
27-- Create database, from /srv/snapshots.linaro.org/linaro-license-protection run
28- python ./manage.py syncdb --noinput
29-- Put apache2 configs from branch lp:~linaro-infrastructure/linaro-license-protection/apache-configs
30- in /etc/apache2/sites-available
31-- Enable sites: a2ensite releases.linaro.org snapshots.linaro.org
32+Deployment
33+..........
34+
35+Please see
36+
37+ http://bazaar.launchpad.net/~linaro-infrastructure/linaro-license-protection/configs/view/head:/README
38+
39
40 Technical details
41 -----------------
42
43=== removed file 'license_protected_downloads/wsgi_releases.py'
44--- license_protected_downloads/wsgi_releases.py 2012-08-06 11:53:16 +0000
45+++ license_protected_downloads/wsgi_releases.py 1970-01-01 00:00:00 +0000
46@@ -1,42 +0,0 @@
47-"""
48-WSGI config for license_protected_downloads project.
49-
50-This module contains the WSGI application used by Django's development server
51-and any production WSGI deployments. It should expose a module-level variable
52-named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
53-this application via the ``WSGI_APPLICATION`` setting.
54-
55-Usually you will have the standard Django WSGI application here, but it also
56-might make sense to replace the whole Django WSGI application with a custom one
57-that later delegates to the Django one. For example, you could introduce WSGI
58-middleware here, or combine a Django application with an application of another
59-framework.
60-
61-"""
62-import os
63-import sys
64-sys.path.append("/usr/lib/python2.7/dist-packages")
65-sys.path.append("/usr/lib/pymodules/python2.7")
66-sys.path.append("/usr/lib/python2.7")
67-
68-# NOTE: Set actual path to directory containing linaro-license-protection app
69-sys.path.append("/srv/releases.linaro.org")
70-sys.path.append("/srv/releases.linaro.org/linaro-license-protection")
71-
72-os.environ.setdefault(
73- "DJANGO_SETTINGS_MODULE",
74- "linaro-license-protection.settings_releases"
75-)
76-
77-# This application object is used by any WSGI server configured to use this
78-# file. This includes Django's development server, if the WSGI_APPLICATION
79-# setting points here.
80-#from django.core.wsgi import get_wsgi_application
81-#application = get_wsgi_application()
82-
83-import django.core.handlers.wsgi
84-application = django.core.handlers.wsgi.WSGIHandler()
85-
86-# Apply WSGI middleware here.
87-# from helloworld.wsgi import HelloWorldApplication
88-# application = HelloWorldApplication(application)
89
90=== removed file 'license_protected_downloads/wsgi_snapshots.py'
91--- license_protected_downloads/wsgi_snapshots.py 2012-08-06 11:53:16 +0000
92+++ license_protected_downloads/wsgi_snapshots.py 1970-01-01 00:00:00 +0000
93@@ -1,42 +0,0 @@
94-"""
95-WSGI config for license_protected_downloads project.
96-
97-This module contains the WSGI application used by Django's development server
98-and any production WSGI deployments. It should expose a module-level variable
99-named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
100-this application via the ``WSGI_APPLICATION`` setting.
101-
102-Usually you will have the standard Django WSGI application here, but it also
103-might make sense to replace the whole Django WSGI application with a custom one
104-that later delegates to the Django one. For example, you could introduce WSGI
105-middleware here, or combine a Django application with an application of another
106-framework.
107-
108-"""
109-import os
110-import sys
111-sys.path.append("/usr/lib/python2.7/dist-packages")
112-sys.path.append("/usr/lib/pymodules/python2.7")
113-sys.path.append("/usr/lib/python2.7")
114-
115-# NOTE: Set actual path to directory containing linaro-license-protection app
116-sys.path.append("/srv/snapshots.linaro.org")
117-sys.path.append("/srv/snapshots.linaro.org/linaro-license-protection")
118-
119-os.environ.setdefault(
120- "DJANGO_SETTINGS_MODULE",
121- "linaro-license-protection.settings_snapshots"
122-)
123-
124-# This application object is used by any WSGI server configured to use this
125-# file. This includes Django's development server, if the WSGI_APPLICATION
126-# setting points here.
127-#from django.core.wsgi import get_wsgi_application
128-#application = get_wsgi_application()
129-
130-import django.core.handlers.wsgi
131-application = django.core.handlers.wsgi.WSGIHandler()
132-
133-# Apply WSGI middleware here.
134-# from helloworld.wsgi import HelloWorldApplication
135-# application = HelloWorldApplication(application)
136
137=== added file 'scripts/update-deployment.py'
138--- scripts/update-deployment.py 1970-01-01 00:00:00 +0000
139+++ scripts/update-deployment.py 2012-08-13 11:45:25 +0000
140@@ -0,0 +1,149 @@
141+#!/usr/bin/env python2.7
142+
143+"""Update a deployment of lp:linaro-license-protection.
144+
145+This script assumes that initial deployment has been done in accordance
146+with the README as found in lp:linaro-license-protection/configs.
147+
148+This means at least:
149+
150+ * /srv/shared-branches/linaro-license-protection
151+ Branch of lp:linaro-license-protection (script will do 'bzr pull' on it)
152+
153+ * /srv/shared-branches/linaro-license-protection-config
154+ Branch of lp:linaro-license-protection/configs
155+
156+ * /srv/staging.snapshots.linaro.org/linaro-license-protection
157+ Checkout of /srv/shared-branches/linaro-license-protection
158+ (script will do an equivalent of 'bzr update' on it)
159+
160+ Note that this applies to staging snapshots config. Replace paths
161+ accordingly.
162+
163+ * /srv/staging.snapshots.linaro.org/configs
164+ Checkout of /srv/shared-branches/linaro-license-protection-configs
165+
166+ * /srv/staging.snapshots.linaro.org/db exists and is writeable by
167+ both apache and the user running update-deployment.py script.
168+
169+ * /srv/staging.snapshots.linaro.org/linaro-license-protection/static
170+ is writeable by the user running update-deployment.py script.
171+
172+Supported configs so far are snapshots.linaro.org, releases.linaro.org,
173+staging.snapshots.linaro.org and staging.releases.linaro.org.
174+
175+"""
176+
177+import argparse
178+import bzrlib.branch
179+import logging
180+import os
181+import subprocess
182+
183+code_base = '/srv/shared-branches'
184+branch_name = 'linaro-license-protection'
185+configs_branch_name = 'linaro-license-protection-config'
186+snapshots_root = '/srv/snapshots.linaro.org'
187+releases_root = '/srv/releases.linaro.org'
188+staging_snapshots_root = '/srv/staging.snapshots.linaro.org'
189+staging_releases_root = '/srv/staging.releases.linaro.org'
190+
191+configs_to_use = {
192+ "settings_releases": releases_root,
193+ "settings_snapshots": snapshots_root,
194+ "settings_staging_releases": staging_releases_root,
195+ "settings_staging_snapshots": staging_snapshots_root,
196+ }
197+
198+logging_level = logging.DEBUG
199+
200+code_root = os.path.join(code_base, branch_name)
201+configs_root = os.path.join(code_base, configs_branch_name)
202+
203+
204+def refresh_branch(branch_dir):
205+ """Refreshes a branch checked-out to a branch_dir."""
206+
207+ code_branch = bzrlib.branch.Branch.open(branch_dir)
208+ parent_branch = bzrlib.branch.Branch.open(
209+ code_branch.get_parent())
210+ result = code_branch.pull(source=parent_branch)
211+ if result.old_revno != result.new_revno:
212+ logger.info("Updated %s from %d to %d.",
213+ branch_dir, result.old_revno, result.new_revno)
214+ else:
215+ logger.info("No changes to pull from %s.", code_branch.get_parent())
216+ return code_branch
217+
218+
219+def update_branch(branch_dir):
220+ """Does a checkout update."""
221+ code_branch = bzrlib.branch.Branch.open(branch_dir)
222+ code_branch.update()
223+
224+
225+def update_installation(config, installation_root):
226+ """Updates a single installation code and databases.
227+
228+ It expects code and config branches to be simple checkouts so it only
229+ does an "update" on them.
230+
231+ Afterwards, it runs "syncdb" and "collectstatic" steps.
232+ """
233+ update_branch(os.path.join(installation_root, branch_name))
234+ update_branch(os.path.join(installation_root, "configs"))
235+ os.environ["PYTHONPATH"] = (
236+ ":".join(
237+ [installation_root,
238+ os.path.join(installation_root, branch_name),
239+ os.path.join(installation_root, "configs", "django"),
240+ os.environ.get("PYTHONPATH", "")]))
241+
242+ logger.info("Updating installation in %s with config %s...",
243+ installation_root, config)
244+ os.environ["DJANGO_SETTINGS_MODULE"] = config
245+ logger.debug("DJANGO_SETTINGS_MODULE=%s",
246+ os.environ.get("DJANGO_SETTINGS_MODULE"))
247+
248+ logger.debug("Doing 'syncdb'...")
249+ logger.debug(subprocess.check_output(
250+ ["django-admin", "syncdb", "--noinput"], cwd=code_root))
251+
252+ logger.debug("Doing 'collectstatic'...")
253+ logger.debug(subprocess.check_output(
254+ ["django-admin", "collectstatic", "--noinput"],
255+ cwd=code_root))
256+
257+
258+if __name__ == '__main__':
259+ parser = argparse.ArgumentParser(
260+ description=(
261+ "Update staging deployment of lp:linaro-license-protection."))
262+ parser.add_argument(
263+ 'configs', metavar='CONFIG', nargs='+', choices=configs_to_use.keys(),
264+ help=("Django configuration module to use. One of " +
265+ ', '.join(configs_to_use.keys())))
266+ parser.add_argument("-v", "--verbose", action='count',
267+ help=("Increase the output verbosity. "
268+ "Can be used multiple times"))
269+ args = parser.parse_args()
270+
271+ if args.verbose == 0:
272+ logging_level = logging.ERROR
273+ elif args.verbose == 1:
274+ logging_level = logging.INFO
275+ elif args.verbose >= 2:
276+ logging_level = logging.DEBUG
277+
278+ logger = logging.getLogger('update-staging')
279+ logging.basicConfig(
280+ format='%(asctime)s %(levelname)s: %(message)s',
281+ level=logging_level)
282+
283+ # Refresh code in shared-branches.
284+ refresh_branch(code_root)
285+ refresh_branch(configs_root)
286+
287+ # We update installations for all the configs we've got.
288+ for config in args.configs:
289+ update_installation(config, configs_to_use[config])
290
291=== removed file 'settings_releases.py'
292--- settings_releases.py 2012-08-06 11:53:16 +0000
293+++ settings_releases.py 1970-01-01 00:00:00 +0000
294@@ -1,16 +0,0 @@
295-from settings import *
296-
297-
298-DATABASES = {
299- 'default': {
300- 'ENGINE': 'django.db.backends.sqlite3',
301- 'NAME': '/srv/releases.linaro.org/db/licenses.db',
302- 'USER': '',
303- 'PASSWORD': '',
304- 'HOST': '',
305- 'PORT': '',
306- }
307-}
308-
309-TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates_releases" ),)
310-SERVED_PATHS = ['/srv/releases.linaro.org/www']
311
312=== removed file 'settings_snapshots.py'
313--- settings_snapshots.py 2012-08-06 11:53:16 +0000
314+++ settings_snapshots.py 1970-01-01 00:00:00 +0000
315@@ -1,15 +0,0 @@
316-from settings import *
317-
318-DATABASES = {
319- 'default': {
320- 'ENGINE': 'django.db.backends.sqlite3',
321- 'NAME': '/srv/snapshots.linaro.org/db/licenses.db',
322- 'USER': '',
323- 'PASSWORD': '',
324- 'HOST': '',
325- 'PORT': '',
326- }
327-}
328-
329-TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates_snapshots" ),)
330-SERVED_PATHS = ['/srv/snapshots.linaro.org/www']

Subscribers

People subscribed via source and target branches