Merge lp:~mwhudson/lava-deployment-tool/use-buildout into lp:~linaro-validation/lava-deployment-tool/trunk

Proposed by Michael Hudson-Doyle
Status: Merged
Merged at revision: 185
Proposed branch: lp:~mwhudson/lava-deployment-tool/use-buildout
Merge into: lp:~linaro-validation/lava-deployment-tool/trunk
Diff against target: 1356 lines (+462/-514)
3 files modified
README (+242/-122)
_compare_manifests.py (+0/-47)
lava-deployment-tool (+220/-345)
To merge this branch: bzr merge lp:~mwhudson/lava-deployment-tool/use-buildout
Reviewer Review Type Date Requested Status
Linaro Validation Team Pending
Review via email: mp+109769@code.launchpad.net

Description of the change

Hi,

This branch changes everything to use buildout for deployment rather than pip. It is intimately related to https://code.launchpad.net/~mwhudson/lava-server/use-buildout/+merge/109768. I'm sure the diff is going to be hard to read, so maybe just try it out? You'll need to run ./lava-deployment-tool setup again, but that shouldn't change anything that will break your old instances.

I've htmlified the new README and put it online at http://people.linaro.org/~mwh/ldt.html.

Cheers,
mwh

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

There are some conflicts in the tree

766 +<<<<<<< TREE
767 if [ \! -e /etc/apache2/mods-available/uwsgi.load ]; then
768 logger "Building uWSGI apache module..."
769 # NOTE: we may not have this file cached as we used bundle to get it
770 @@ -691,6 +617,8 @@
771 INSTANCE_WSGI
772 fi
773
774 +=======
775 +>>>>>>> MERGE-SOURCE

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Zygmunt Krynicki <email address hidden> writes:

> There are some conflicts in the tree

Thanks, fixed.

Cheers,
mwh

222. By Michael Hudson-Doyle

merge trunk

223. By Michael Hudson-Doyle

stoopid

224. By Michael Hudson-Doyle

run setup with -e ffs

225. By Michael Hudson-Doyle

chown -R

226. By Michael Hudson-Doyle

possible conversion code

227. By Michael Hudson-Doyle

more conversion

228. By Michael Hudson-Doyle

no plan survives contact etc

229. By Michael Hudson-Doyle

yet more details

230. By Michael Hudson-Doyle

ffs

231. By Michael Hudson-Doyle

mutilate the uwsgi.ini file too, and it works!

232. By Michael Hudson-Doyle

document upgrading from old world

233. By Michael Hudson-Doyle

start to use a pure manifest branch

234. By Michael Hudson-Doyle

point template_dirs and staticfiles_dirs at symlink to current lava-server code that the buildout now creates

235. By Michael Hudson-Doyle

rename variables to make sense now

236. By Michael Hudson-Doyle

update docs (so much simpler for the local development case!)

237. By Michael Hudson-Doyle

lets make everyone run setup again

238. By Michael Hudson-Doyle

do not download pre-seeded deps if they are already present!

239. By Michael Hudson-Doyle

do not depend on the version of distribute that virtualenv installs by default
also, check sha256s of downloaded files

240. By Michael Hudson-Doyle

no point having a PIP_PROXY_OPTION if we do not let pip touch the network

241. By Michael Hudson-Doyle

work with older virtualenvs

242. By Michael Hudson-Doyle

load configuration before determining $LAVA_REVNO (as that may depend on the branch the instance uses)

243. By Michael Hudson-Doyle

document lava-develop-branch/lava-undevelop-branch a bit

244. By Michael Hudson-Doyle

small tweak

245. By Michael Hudson-Doyle

i renamed the helper scripts

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2012-03-23 01:30:07 +0000
3+++ README 2012-06-18 06:02:17 +0000
4@@ -5,42 +5,46 @@
5 The tool is suitable for both personal and more "production" installations that
6 are expected to perform adequately with more concurrent users. This tool is
7 not, however, designed for multi-machine installation, including cloud
8-deployment. For that it is likely we will turn to Juju
9-(https://juju.ubuntu.com/)
10+deployment. For that it is likely we will turn to Juju_.
11+
12+.. _Juju: https://juju.ubuntu.com/
13+
14+.. contents::
15
16 Quickstart
17 ^^^^^^^^^^
18+
19 For the impatient, or those just looking for a cheat sheet but know what they
20-are doing otherwise, here are the basic set of commands to get an instance
21-up and running based on the requirements-mini file provided as an example,
22-which only installs lava-server.
23+are doing otherwise, here are the basic set of commands to get an instance::
24
25 $ ./lava-deployment-tool setup
26- $ ./lava-deployment-tool bundle requirements/requirements-mini.txt
27- $ ./lava-deployment-tool install testinstance lava.pybundle
28- $ sudo start lava-instance LAVA_INSTANCE=testinstance
29+ $ ./lava-deployment-tool install testinstance
30 $ ./lava-deployment-tool manage testinstance createsuperuser
31-
32-Assuming everything went well, you should be able to point a web browser
33-at the system you did this, see the lava-server default page and sign-in.
34-
35+ $ ./lava-deployment-tool manage testinstance runserver
36+
37+Assuming everything went well, you should be able to point a web
38+browser at http://127.0.0.1:8000/, see the lava-server default page
39+and sign-in.
40
41 Software Requirements
42 ^^^^^^^^^^^^^^^^^^^^^
43
44-This tool should work on Ubuntu versions starting with 10.10 release
45-(Maverick). If you'd like to help us with other distributions feel free to
46-contact us at validation (at) linaro (dot) org.
47+We currently recommmend using Ubuntu 12.04. This tool should work on
48+Ubuntu versions 11.10 (Oneiric) and newer.
49+
50+If you'd like to help us with other distributions feel free to contact
51+us at linaro-validation (at) lists (dot) linaro (dot) org.
52
53 Hardware Requirements
54 ^^^^^^^^^^^^^^^^^^^^^
55
56-A small LAVA instance can be deployed on any modest hardware. We recommend at
57-least one 1GB of RAM for runtime activity (this is shared, on a single host,
58-among the database server, the application server and the web server). For
59-storage please reserve about 20GB for application data, especially if you wish
60-to mirror current public LAVA instance used by Linaro. LAVA uses append-only
61-models so the storage requirements will grow at about several GB a year.
62+A small LAVA instance can be deployed on any modest hardware. We
63+recommend at least one 1GB of RAM for runtime activity (this is
64+shared, on a single host, among the database server, the application
65+server and the web server). For storage please reserve about 20GB for
66+application data, especially if you wish to mirror current public LAVA
67+instance used by Linaro. LAVA uses append-only models so the storage
68+requirements will grow at about several GB a year.
69
70 Before installing
71 ^^^^^^^^^^^^^^^^^
72@@ -53,45 +57,62 @@
73 development headers and a working compiler to build some of the native (C)
74 extensions for python.
75
76-This step is largely automated. To perform it run this command:
77-
78-$ ./lava-deployment-tool setup
79-
80-This step also prepares file-system places for LAVA. In particular it creates
81-/srv/lava/ where all LAVA instances are later stored.
82-
83-Creating LAVA instance
84-^^^^^^^^^^^^^^^^^^^^^^
85-
86-You can create multiple LAVA instances on a single machine. Being able to do
87-so is very valuable for testing and developing LAVA itself. Before installing
88-you must first create a bundle of sources you wish to install. This simply
89-downloads all the things you intend to install into a single, local archive
90-so that installation or updating is not impacted by any problems getting the
91-sources later. This also enables offline installs, or installs behind a
92-restrictive firewall by allowing you to download the bundle in advance.
93-To create the bundle, run:
94-
95-$ ./lava-deployment-tool bundle URL_to_requirements [bundle_file_name]
96-If you do not specify the bundle_file_name, it will use the name 'lava.pybundle'
97-
98-To create a new instance run this command:
99-
100-$ ./lava-deployment-tool install NAME BUNDLE
101-
102-This will create a fresh instance called NAME, the instance will be composed of
103-the software specified in the requirements file that was used to build the
104-bundle and associated dependencies.
105-
106-To create an administrator user for this instance:
107-
108-$ ./lava-deployment-tool manage NAME createsuperuser
109+This step is largely automated. To perform it run this command::
110+
111+ $ ./lava-deployment-tool setup
112+
113+This step also prepares file-system places for LAVA. In particular it
114+creates ``/srv/lava/`` where all LAVA instances are later stored.
115+
116+Creating an instance of LAVA
117+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
118+
119+An instance of LAVA is a self-contained installation of LAVA. This
120+means the code that makes up LAVA, configuration data, a Postgres
121+database, and the log files and test result bundles produced by
122+running tests.
123+
124+You can create multiple LAVA instances on a single machine, which is
125+very valuable for testing and developing LAVA itself.
126+
127+The code part of an instance is described by a `buildout`_
128+configuration file, which lives in a branch of the `lava-manifest`_
129+project on Launchpad. By default, lava-deployment-tool creates an
130+instance that uses the buildout.cfg file from the most recent revision
131+of the lp:lava-manifest branch.
132+
133+To create an instance, run::
134+
135+ $ ./lava-deployment-tool install NAME
136+
137+This will ask you a few questions and then create a fresh instance
138+called NAME.
139+
140+You can override details about how to construct the instance:
141+
142+ 1. To override the branch to deploy from, set LAVA_MANIFEST_BRANCH in
143+ the environment.
144+
145+ 2. To override the name of the buildout config file, set
146+ LAVA_BUILDOUT_CFG.
147+
148+ 3. To deploy a specific revision of LAVA_MANIFEST_BRANCH, add the
149+ revision number to the command line::
150+
151+ $ ./lava-deployment-tool install NAME <revno>
152+
153+See `different kinds of deployment`_ below for more about customizing
154+instances.
155+
156+To create an administrator user for a newly-created instance::
157+
158+ $ ./lava-deployment-tool manage NAME createsuperuser
159
160 This user can access the administration panel, edit permissions to other users
161 and add bundle streams, devices, etc...
162
163-The script produces verbose output, at the end it should say that everything
164-went fine.
165+.. _buildout: http://www.buildout.org/
166+.. _lava-manifest: https://launchpad.net/lava-manifest
167
168 Backing Up LAVA instance
169 ^^^^^^^^^^^^^^^^^^^^^^^^
170@@ -99,13 +120,14 @@
171 LAVA instances store persistent data in two locations:
172
173 * On the filesystem, in the directory
174- /srv/lava/$LAVA_INSTANCE/var/lib/lava-server/media
175- * In a PostgreSQL database in the default cluster named $LAVA_INSTANCE
176+ ``/srv/lava/$LAVA_INSTANCE/var/lib/lava-server/media``
177+ * In a PostgreSQL database in the default cluster named
178+ ``lava-$LAVA_INSTANCE``
179
180 Backing up those two items is sufficient to preserve the entire system
181-state. You can do this by running:
182+state. You can do this by running::
183
184-$ lava-deployment-tool backup $LAVA_INSTANCE
185+ $ lava-deployment-tool backup $LAVA_INSTANCE
186
187 which will create a backup with an ID based on the current date and
188 time in a directory named
189@@ -115,9 +137,9 @@
190
191 Generally before backing up you should make sure that LAVA instance is
192 turned off. This depends on how your instance is started. If you were
193-using upstart the following shell command should turn LAVA off:
194+using upstart the following shell command should turn LAVA off::
195
196-$ sudo service lava stop
197+ $ sudo stop lava
198
199 If you take a backup while running, you will need to do some manual
200 cleanup when you restore from it.
201@@ -125,18 +147,18 @@
202 Restoring from backup
203 ^^^^^^^^^^^^^^^^^^^^^
204
205-Running the command
206+Running the command ::
207
208-$ lava-deployment-tool restore $LAVA_INSTANCE $SNAPSHOT_ID
209+ $ lava-deployment-tool restore $LAVA_INSTANCE $SNAPSHOT_ID
210
211 will restore the given snapshot of the named instance. This will
212 first erase the database and media files of the named instance, so be
213 careful what you type!
214
215 You can restore an instance from a backup taken from a distinct
216-instance with a command like:
217+instance with a command like::
218
219-$ lava-deployment-tool restore $TARGET_INSTANCE $SOURCE_INSTANCE/$SNAPSHOT_ID
220+ $ lava-deployment-tool restore $TARGET_INSTANCE $SOURCE_INSTANCE/$SNAPSHOT_ID
221
222 Currently to restore from a backup taken on a different machine, you
223 have to put it under /srv/lava/backups, then run an appropriate
224@@ -148,57 +170,77 @@
225 Updating LAVA instance
226 ^^^^^^^^^^^^^^^^^^^^^^
227
228-LAVA is released periodically. Currently this is once a month but the release
229-cycle becomes more and more fluid and eventually we'd like to release multiple
230-tiny changes every day.
231-
232-Once you installed some LAVA components you can upgrade your installation to a
233-more recent release using this deployment tool. There are some important
234-upgrade considerations:
235-
236-1) Upgrades may alter the database or persistent media files. It is wise to
237-perform a full system backup before each upgrade. While we don't anticipate
238-catastrophic failures it's better to be safe than sorry. Refer to the previous
239-chapter for details.
240-
241-2) Some database schema changes take a lot of time to finish. We try to
242-minimize such changes but as you can install any third-party LAVA extensions we
243-cannot predict the overall downtime in such case. For official Linaro releases
244-please refer to our monthly release notes that are available at
245-http://lava.readthedocs.org/
246-
247-3) Upgrades may introduce additional dependencies, which will be installed
248-automatically. Periodically we make use of additional third party open source
249-libraries. Those libraries will be installed for a single LAVA instance
250-_only_. Your system libraries are not affected by this step.
251-
252-4) Upgrades require network access. If you are behind a firewall or a
253-corporate http proxy you may experience failures. Please note that the
254-upgrade process does not install components without first downloading all of
255-the required pieces so in case of a network failure your current installation
256-should not be affected. While typically only HTTP and HTTPS protocols are
257-being used at times you may see attempts to connect to native protocols used
258-by git, bazaar or mercurial.
259-
260-5) Upgrading process rebuilds the collection of static assets served by
261-Apache. During that moment you may encounter a very brief failure to resolve
262-some of the static assets (typically images, cascading style sheets and
263-javascript libraries)
264-
265-Prior to upgrading and instance, you will need to build a new bundle based
266-on your new requirements file:
267-
268-$ ./lava-deployment-tool bundle URL-to-requirements [bundle_file_name]
269-
270-To upgrade an existing instance run the following command:
271-
272-$ ./lava-deployment-tool upgrade NAME BUNDLE
273-
274-Again the NAME and URL-to-requirements have the same meaning as in the
275-install command mentioned in preceding chapter.
276+In some sense, each revision of $LAVA_MANIFEST_BRANCH is a release and
277+can be updated to (from time to time a revision of lp:lava-manifest will
278+receive additional testing and be tagged as a release). You can use
279+lava-deployment-tool to update to a revision of the LAVA_MANIFEST_BRANCH
280+that was used for that instance::
281+
282+ $ ./lava-deployment-tool upgrade <revno>
283+
284+There are some points to consider:
285+
286+1) Upgrades may alter the database or persistent media files. It is
287+ wise to perform a full system backup before each upgrade. While we
288+ don't anticipate catastrophic failures it's better to be safe than
289+ sorry. Refer to the previous chapter for details.
290+
291+2) Upgrades may introduce additional dependencies, which will be
292+ installed automatically. Periodically we make use of additional
293+ third party open source libraries. Those libraries will be
294+ installed for a single LAVA instance _only_. Your system libraries
295+ are not affected by this step.
296+
297+3) Upgrades require network access. If you are behind a firewall or a
298+ corporate http proxy you may experience failures. Please note that the
299+ upgrade process does not install components without first downloading all of
300+ the required pieces so in case of a network failure your current installation
301+ should not be affected. While typically only HTTP and HTTPS protocols are
302+ being used at times you may see attempts to connect to native protocols used
303+ by git, bazaar or mercurial.
304+
305+4) The upgrade works by first installing the new code independently
306+ from the currently running code, updates a symlink to make the new
307+ code current, runs any database migrations that are needed and
308+ restarts the services. This means that many, but not all, kinds of
309+ error during upgrade will not result in disruption to the running
310+ service.
311+
312+5) Upgrading process rebuilds the collection of static assets served
313+ by Apache. During that moment you may encounter a very brief
314+ failure to resolve some of the static assets (typically images,
315+ cascading style sheets and javascript libraries)
316+
317+Upgrading from a pip-based instance to a buildout based instance
318+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
319+
320+In June 2012, we switched from a pip-based installation method to
321+using buildout. lava-deployment-tool can convert a pip-based
322+installation to a buildout-based one, but without care this can result
323+in changes to the set of packages/LAVA extensions installed.
324+
325+If you have no special requirements as to the extensions that should
326+be installed you can just run "lava-deployment-tool upgrade
327+$instance", and say y when prompted.
328+
329+If you have custom requirements, you should:
330+
331+ 1. create a test instance
332+
333+ 2. in this test instance, create custom buildout config file (see
334+ `Limited Deployments`_ below) that installs the components you
335+ want
336+
337+ 3. put this config file into the root of your existing instance as a
338+ filed called, say, custom.cfg
339+
340+ 4. run LAVA_BUILDOUT_CFG=../../custom.cfg upgrade $instance
341+
342+Testing this process several times before running it on your
343+production instance is advisable!
344
345 Installing multiple LAVA instances on single IP machine
346-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
347+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
348
349 After installing and starting a LAVA instance using the instructions above,
350 you can use "toggle" sub command to change how you access the instance.
351@@ -210,21 +252,22 @@
352 called "test1" and "test2", you can use the "location" toggle to set it
353 so that you can access them on your local machine using:
354 http://localhost/test1
355-http://localhost/test2
356+http://localhost/test2 ::
357
358-$ lava-deployment-tool toggle $LAVA_INSTANCE location
359+ $ lava-deployment-tool toggle $LAVA_INSTANCE location
360
361 Then you can access the LAVA instance via:
362 http://IP/$LAVA_INSTANCE
363
364-You also can turn it back with the command below:
365+You also can turn it back with the command below::
366
367-$ lava-deployment-tool toggle $LAVA_INSTANCE vhost
368+ $ lava-deployment-tool toggle $LAVA_INSTANCE vhost
369
370 Then you can access the LAVA instance via:
371 http://virtual-host/
372
373-There is also a command to toggle all LAVA instances one time:
374+There is also a command to toggle all LAVA instances one time::
375+
376 lava-deployment-tool toggle_all location
377
378 Anatomy of a LAVA instance
379@@ -232,11 +275,11 @@
380
381 An instance is composed of several parts:
382
383- - A new system user account called $LAVA_INSTANCE
384+ - A new system user account called lava-$LAVA_INSTANCE
385 - A directory tree similar to standard unix filesystem rooted
386 in $LAVA_PREFIX/$LAVA_INSTANCE/
387 - A postgres user and database in the default cluster, both named
388- $LAVA_INSTANCE
389+ lava-$LAVA_INSTANCE
390
391 A note on Postgres versions
392 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
393@@ -247,6 +290,83 @@
394 moving between versions is not technically difficult but not currently
395 supported.
396
397+Different kinds of deployment
398+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
399+
400+Production-like
401+---------------
402+
403+For our production deployment, we use the buildout-production.cfg
404+buildout file which completely locks down the version of everything
405+that's being deployed. If you want to run the same kind of deployment
406+as we do, set LAVA_BUILDOUT_CFG to ``buildout-production.cfg`` when
407+creating the instance::
408+
409+ $ LAVA_BUILDOUT_CFG=buildout-production.cfg lava-deployment-tool install production
410+
411+To update the version of some component that is deployed we release
412+that component, update the buildout-production.cfg file in
413+lp:lava-manigest to refer to the new version and deploy the new
414+revision.
415+
416+Local Development
417+-----------------
418+
419+If you want an instance to use a custom branch of a component, you can
420+drop the branch or a symlink to the branch in
421+``/srv/lava/instances/$instances/code/current/local`` and re-run
422+buildout. For example::
423+
424+ $ bzr branch lp:lava-scheduler ~/src/my-scheduler-branch
425+ $ cd /srv/lava/instances/$instance/code/current
426+ $ ln -s ~/src/my-scheduler-branch local/ # The name of the symlink doesn't matter;
427+ # buildout looks at the setup.py
428+ $ ./bin/buildout
429+
430+Non-production instances contain some scripts that can help create and
431+remove symlinks::
432+
433+ $ bzr branch lp:lava-scheduler ~/src/my-scheduler-branch
434+ $ . /srv/lava/instances/testinstance/bin/activate
435+ $ lava-develop-local ~/src/my-scheduler-branch
436+ Determining egg name... lava-scheduler
437+ + ln -sfT ~/src/my-scheduler-branch /srv/lava/instances/testinstance/code/current/local/lava-scheduler
438+ ...
439+ ... hack ...
440+ $ lava-undevelop-local ~/src/my-scheduler-branch
441+ removed /srv/lava/instances/testinstance/code/current/local/lava-scheduler
442+
443+Limited Deployments
444+-------------------
445+
446+For a limited deployment, for example if you do not want to run the
447+scheduler, you can set ``LAVA_BUILDOUT_CFG`` to point to a buildout
448+config file you create. Currently you can only do this after an
449+instance is created (unfortunately). So create an instance::
450+
451+ $ lava-deployment-tool install limited
452+
453+Create the custom buildout.cfg::
454+
455+ $ cat > /srv/lava/instances/limited/code/custom.cfg <<EOF
456+ [buildout]
457+ extends = buildout.cfg
458+
459+ [server]
460+ eggs -= lava-scheduler
461+ EOF
462+
463+And set it to be used in ``instance.conf``::
464+
465+ $ vim /srv/lava/instances/limited/code/custom.cfg
466+ $ grep LAVA_BUILDOUT_CFG /srv/lava/instances/limited/code/custom.cfg
467+ LAVA_BUILDOUT_CFG='../custom.cfg'
468+
469+Finally, 'upgrade' the instance to get it to use the new config file::
470+
471+ $ ./lava-deployment-tool upgrade limited
472+
473+
474 Contact and bug reports
475 ^^^^^^^^^^^^^^^^^^^^^^^
476
477
478=== removed file '_compare_manifests.py'
479--- _compare_manifests.py 2012-05-25 04:30:58 +0000
480+++ _compare_manifests.py 1970-01-01 00:00:00 +0000
481@@ -1,47 +0,0 @@
482-#!/usr/bin/python
483-
484-import sys
485-
486-def load(fname):
487- d = {}
488- for line in open(fname):
489- line = line.strip()
490- if line.startswith('-e'):
491- # This bit is a total hack.
492- _, stuff = line.split('#egg=')
493- package, version, _ = stuff.split('-', 2)
494- package = package.replace('_', '-')
495- else:
496- package, version = line.split('==')
497- d[package] = version
498- return d
499-
500-cur = load(sys.argv[1])
501-new = load(sys.argv[2])
502-if 'pip' in new:
503- del new['pip']
504-
505-not_present = set(cur) - set(new)
506-new_packaged = set(new) - set(cur)
507-changed = {}
508-for package in set(cur) & set(new):
509- if cur[package] != new[package]:
510- changed[package] = (cur[package], new[package])
511-
512-if not_present:
513- print "Already installed, but not in bundle:"
514- w1 = max(len(p) for p in not_present)
515- for k in sorted(not_present):
516- print " %-*s %s" % (w1, k, cur[k])
517-if changed:
518- print "To be upgraded:"
519- w1 = max(len(p) for p in changed)
520- w2 = max(len(t[0]) for t in changed.itervalues())
521- w3 = max(len(t[1]) for t in changed.itervalues())
522- for k in sorted(changed):
523- print " %-*s %-*s -> %-*s" % (w1, k, w2, changed[k][0], w3, changed[k][1])
524-if new_packaged:
525- print "To be installed:"
526- w1 = max(len(p) for p in new_packaged)
527- for k in sorted(new_packaged):
528- print " %-*s %s" % (w1, k, new[k])
529
530=== modified file 'lava-deployment-tool'
531--- lava-deployment-tool 2012-06-11 10:02:34 +0000
532+++ lava-deployment-tool 2012-06-18 06:02:17 +0000
533@@ -1,5 +1,5 @@
534 #!/bin/bash
535-LAVA_DEPLOYMENT_TOOL_VERSION="0.4"
536+LAVA_DEPLOYMENT_TOOL_VERSION="0.5"
537
538 # Global Configuration
539
540@@ -9,10 +9,14 @@
541 # All LAVA instances are created relative to this path
542 LAVA_PREFIX=$LAVA_ROOT/instances
543
544-# Pip download cache
545-export PIP_DOWNLOAD_CACHE=$LAVA_ROOT/.downloads
546+# Deploy revisions of this branch
547+LAVA_MANIFEST_BRANCH="${LAVA_MANIFEST_BRANCH-lp:lava-manifest}"
548+# Use this buildout config file from $LAVA_MANIFEST_BRANCH
549+LAVA_BUILDOUT_CFG="${LAVA_BUILDOUT_CFG-buildout.cfg}"
550
551-test -n "$http_proxy" && PIP_PROXY_OPTION="--proxy=$http_proxy"
552+# Where to cache the eggs and downloads for buildbot
553+LAVA_EGG_CACHE=$LAVA_ROOT/.cache/eggs
554+LAVA_DOWNLOAD_CACHE=$LAVA_ROOT/.cache/download-cache
555
556 # All LAVA uses this python version
557 LAVA_PYTHON=python2.6
558@@ -21,13 +25,13 @@
559 LAVA_UWSGI=1.0.3
560
561 # Current version of setup required by lava (global state)
562-export LAVA_SETUP_REQUIRED_VERSION=20
563+export LAVA_SETUP_REQUIRED_VERSION=22
564
565 # Check if this installation is supported
566 export LAVA_SUPPORTED=0
567
568 # Installation and configuration steps (all the wizard_xxx install_xxx functions)
569-LAVA_INSTALL_STEPS="user fs venv database broker web_hosting app config_app"
570+LAVA_INSTALL_STEPS="user fs buildout database broker web_hosting app config_app"
571
572
573 os_check() {
574@@ -44,7 +48,7 @@
575 oneiric|precise)
576 export LAVA_PYTHON=python2.7
577 export LAVA_SUPPORTED=1
578- LAVA_PKG_LIST="whiptail python-virtualenv python-pip git build-essential $LAVA_PYTHON-dev libxml2-dev apache2 apache2-dev postgresql rabbitmq-server mercurial conmux linaro-image-tools unzip"
579+ LAVA_PKG_LIST="whiptail python-virtualenv python-pip git build-essential $LAVA_PYTHON-dev libxml2-dev apache2 apache2-dev postgresql rabbitmq-server mercurial conmux linaro-image-tools unzip bzr"
580 ;;
581 esac
582 ;;
583@@ -89,6 +93,9 @@
584 LAVA_PREFIX='$LAVA_PREFIX'
585 # Instance name
586 LAVA_INSTANCE='$LAVA_INSTANCE'
587+# The lava-server branch used by upgrade
588+LAVA_MANIFEST_BRANCH='$LAVA_MANIFEST_BRANCH'
589+LAVA_BUILDOUT_CFG='$LAVA_BUILDOUT_CFG'
590 # System configuration (Unix-level)
591 LAVA_SYS_USER='$LAVA_SYS_USER'
592 # Apache configuration
593@@ -112,31 +119,10 @@
594
595 _save_config() {
596 mkdir -p $LAVA_PREFIX/$LAVA_INSTANCE/
597- cat >$LAVA_PREFIX/$LAVA_INSTANCE/instance.conf <<INSTANCE_CONF
598-# Installation prefix
599-LAVA_PREFIX='$LAVA_PREFIX'
600-# Instance name
601-LAVA_INSTANCE='$LAVA_INSTANCE'
602-# System configuration (Unix-level)
603-LAVA_SYS_USER='$LAVA_SYS_USER'
604-# Apache configuration
605-LAVA_APACHE_VHOST='$LAVA_APACHE_VHOST'
606-LAVA_DEV_MODE='$LAVA_DEV_MODE'
607-# PostgreSQL configuration
608-LAVA_DB_NAME='$LAVA_DB_NAME'
609-LAVA_DB_USER='$LAVA_DB_USER'
610-LAVA_DB_PASSWORD='$LAVA_DB_PASSWORD'
611-# RabbitMQ configuration
612-LAVA_RABBIT_VHOST='$LAVA_RABBIT_VHOST'
613-LAVA_RABBIT_USER='$LAVA_RABBIT_USER'
614-LAVA_RABBIT_PASSWORD='$LAVA_RABBIT_PASSWORD'
615-# Scheduler configuration
616-LAVA_SCHEDULER_ENABLED='$LAVA_SCHEDULER_ENABLED'
617-INSTANCE_CONF
618+ _show_config >$LAVA_PREFIX/$LAVA_INSTANCE/instance.conf
619 }
620
621
622-
623 _configure() {
624 set +x
625 export LAVA_INSTANCE="$1"
626@@ -193,7 +179,7 @@
627 _install() {
628 for install_step in $LAVA_INSTALL_STEPS; do
629 echo "Running installation step $install_step"
630- install_$install_step || die "Failed at $install_step"
631+ install_$install_step
632 done
633 echo "All installation is done"
634 }
635@@ -204,11 +190,6 @@
636 }
637
638
639-pkglist_user() {
640- true
641-}
642-
643-
644 wizard_user() {
645 export LAVA_SYS_USER_DESC="User for LAVA instance $LAVA_INSTANCE"
646
647@@ -257,11 +238,6 @@
648 }
649
650
651-pkglist_fs() {
652- true
653-}
654-
655-
656 wizard_fs() {
657 echo
658 echo "Filesystem configuration"
659@@ -316,11 +292,13 @@
660 mkdir -p $LAVA_PREFIX/$LAVA_INSTANCE/var/log
661 # Sockets and other runtime stuff
662 mkdir -p $LAVA_PREFIX/$LAVA_INSTANCE/run
663- # Source code (used when tracking trunk)
664- mkdir -p $LAVA_PREFIX/$LAVA_INSTANCE/src
665 # Temporary files
666 mkdir -p $LAVA_PREFIX/$LAVA_INSTANCE/tmp
667
668+ # For buildout
669+ bzr init-repo $LAVA_PREFIX/$LAVA_INSTANCE/code
670+ ln -s $LAVA_PREFIX/$LAVA_INSTANCE/code/current/bin $LAVA_PREFIX/$LAVA_INSTANCE
671+
672 # Allow apache (running as www-data) to read our public web files
673 sudo chgrp -R www-data $LAVA_PREFIX/$LAVA_INSTANCE/var/www/lava-server/
674 sudo chmod -R g+rXs $LAVA_PREFIX/$LAVA_INSTANCE/var/www/lava-server/
675@@ -350,58 +328,29 @@
676 }
677
678
679-defaults_venv() {
680- true
681-}
682-
683-pkglist_venv() {
684- echo "https://github.com/zyga/pip/tarball/develop"
685-}
686-
687-
688-wizard_venv() {
689- echo
690- echo "Python virtual environment configuration"
691- echo "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
692- echo
693- echo "We will use python virtualenv to isolate LAVA code from your system"
694- echo
695- echo "Python version: $LAVA_PYTHON"
696- echo
697- echo "You can interact with this source code (installation) as if it"
698- echo "was globally by invoking the following line:"
699- echo
700- echo "$ . $LAVA_PREFIX/$LAVA_INSTANCE/bin/activate"
701- echo
702- echo "(Note that the intent is to source (read) the file, not execute it)"
703- echo "When you are done just type:"
704- echo
705- echo "$ deactivate"
706- echo
707- echo "While inside your virtualenv you can invoke additional commands,"
708- echo "most notably, lava-server manage ..."
709- echo
710- echo "(this is just a notification, it is not configurable)"
711- echo
712- echo "next - continue"
713-
714- read -p "Please decide what to do: " RESPONSE
715-
716- case "$RESPONSE" in
717- next)
718- return 0 # loop complete
719- esac
720- return 1 # another loop please
721-}
722-
723-
724-install_venv() {
725- logger "Creating virtualenv using $LAVA_PYTHON for LAVA instance $LAVA_INSTANCE"
726-
727- # Create virtualenv
728- virtualenv --no-site-packages --distribute $LAVA_PREFIX/$LAVA_INSTANCE -p $LAVA_PYTHON
729-}
730-
731+defaults_buildout () {
732+ true
733+}
734+
735+wizard_buildout () {
736+ true
737+}
738+
739+install_buildout () {
740+ set -xe
741+ local venv="$LAVA_PREFIX/$LAVA_INSTANCE/var/lib/bootstrap-venv"
742+ if [ $(virtualenv --version) '<' '1.7' ]; then
743+ virtualenv --no-site-packages "${venv}"
744+ else
745+ virtualenv "${venv}"
746+ fi
747+ "${venv}/bin/pip" install \
748+ $LAVA_DOWNLOAD_CACHE/dist/distribute-0.6.24.tar.gz \
749+ $LAVA_DOWNLOAD_CACHE/dist/zc.buildout-1.5.2.tar.gz \
750+ $LAVA_DOWNLOAD_CACHE/dist/uwsgi-$LAVA_UWSGI.tar.gz \
751+ $LAVA_DOWNLOAD_CACHE/dist/bzr-2.5.1.tar.gz
752+ set +xe
753+}
754
755 defaults_database() {
756 export LAVA_DB_NAME="lava-$LAVA_INSTANCE"
757@@ -410,11 +359,6 @@
758 }
759
760
761-pkglist_database() {
762- echo psycopg2
763-}
764-
765-
766 wizard_database() {
767 echo
768 echo "PostgreSQL configuration"
769@@ -491,11 +435,6 @@
770 }
771
772
773-pkglist_broker() {
774- true
775-}
776-
777-
778 wizard_broker() {
779 echo
780 echo "RabbitMQ configuration"
781@@ -539,15 +478,6 @@
782 export LAVA_DEV_MODE=no
783 }
784
785-
786-pkglist_web_hosting() {
787- echo "http://projects.unbit.it/downloads/old/uwsgi-$LAVA_UWSGI.tar.gz"
788- echo "django-seatbelt"
789- echo "django-debian"
790- echo "django-celery"
791-}
792-
793-
794 wizard_web_hosting() {
795 echo
796 echo "Apache and uWSGI configuration"
797@@ -615,82 +545,6 @@
798 install_web_hosting() {
799 logger "Installing uWSGI and other hosting parts for LAVA instance $LAVA_INSTANCE"
800
801- if [ \! -e /etc/apache2/mods-available/uwsgi.load ]; then
802- logger "Building uWSGI apache module..."
803- # NOTE: we may not have this file cached as we used bundle to get it
804- if [ ! -e $PIP_DOWNLOAD_CACHE/http%3A%2F%2Fprojects.unbit.it%2Fdownloads%2Fold%2Fuwsgi-$LAVA_UWSGI.tar.gz ]; then
805- pip install $PIP_PROXY_OPTION --no-install http://projects.unbit.it/downloads/old/uwsgi-$LAVA_UWSGI.tar.gz || die "Failed to download uWSGI"
806- fi
807- ( cd $LAVA_PREFIX/$LAVA_INSTANCE/tmp && tar zxf $PIP_DOWNLOAD_CACHE/http%3A%2F%2Fprojects.unbit.it%2Fdownloads%2Fold%2Fuwsgi-$LAVA_UWSGI.tar.gz )
808- ( cd $LAVA_PREFIX/$LAVA_INSTANCE/tmp/uwsgi-$LAVA_UWSGI/apache2 && sudo apxs2 -c -i -a mod_uwsgi.c )
809- fi
810-
811- if [ "$LAVA_DEV_MODE" = "yes" ]; then
812- cat >$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/lava-server.wsgi <<INSTANCE_WSGI
813-# This file was automatically generated by lava-deployment-tool.sh
814-import os
815-
816-# Force django to use the specified settings module.
817-os.environ['DJANGO_SETTINGS_MODULE'] = 'lava_server.settings.debian'
818-# And force django-debian to look at our instance-specific configuration directory
819-os.environ['DJANGO_DEBIAN_SETTINGS_TEMPLATE'] = '$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/{filename}.conf'
820-
821-# Setup django WSGI handler
822-import django.core.handlers.wsgi
823-
824-application = django.core.handlers.wsgi.WSGIHandler()
825-INSTANCE_WSGI
826- else
827- cat >$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/lava-server.wsgi <<INSTANCE_WSGI
828-# This file was automatically generated by lava-deployment-tool.sh
829-import os
830-import sys
831-from django_seatbelt import seatbelt
832-
833-# We need those to get stuff like threading that seems not to be supported when
834-# running virtualenv. Despite virtualenv setting up symlinks for some of the
835-# .so files this one does not seem to work. More insight on if this is really
836-# the case welcome.
837-core_python_paths = [
838- "/usr/lib/$LAVA_PYTHON",
839- "/usr/lib/$LAVA_PYTHON/lib-dynload"]
840-
841-# Construct new path starting with core python, followed by the rest
842-sys.path = core_python_paths + [path for path in sys.path if path not in core_python_paths]
843-
844-# Filter path, allow only core python paths and prefix paths (no local/user/junk)
845-def allow_core_python(path):
846- return path in core_python_paths
847-
848-# In virtualenv sys.prefix points to the root of the virtualenv, outside it
849-# points to the prefix of the system python installation (typically /usr)
850-def allow_sys_prefix(path):
851- return path.startswith(sys.prefix)
852-
853-# seatbelt.solder filters sys.path according to the callbacks specified below.
854-seatbelt.solder(allow_callbacks=[allow_sys_prefix, allow_core_python])
855-
856-# Print summary (for debugging)
857-# print "sys.prefix:", sys.prefix
858-# print "sys.path:"
859-# for path in sys.path:
860-# print " - %s" % path
861-
862-# Force django to use the specified settings module.
863-os.environ['DJANGO_SETTINGS_MODULE'] = 'lava_server.settings.debian'
864-# And force django-debian to look at our instance-specific configuration directory
865-os.environ['DJANGO_DEBIAN_SETTINGS_TEMPLATE'] = '$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/{filename}.conf'
866-
867-# Setup django WSGI handler
868-import django.core.handlers.wsgi
869-
870-# NOTE: Here one might also use applications = {'/': application} to define
871-# namespace mapping. I'm not sure if this is used by uWSGI or by any handler
872-# but I found that in the docs to uWSGI.
873-application = django.core.handlers.wsgi.WSGIHandler()
874-INSTANCE_WSGI
875- fi
876-
877 # Create apache2 site
878 cat >$LAVA_PREFIX/$LAVA_INSTANCE/etc/apache2/sites-available/lava-server.conf <<INSTANCE_SITE
879 <VirtualHost *:80>
880@@ -742,10 +596,10 @@
881 # Create uWSGI configuration file
882 cat >$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/uwsgi.ini <<UWSGI_INI
883 [uwsgi]
884-home = $LAVA_PREFIX/$LAVA_INSTANCE
885+home = $LAVA_PREFIX/$LAVA_INSTANCE/var/lib/bootstrap-venv
886 socket = $LAVA_PREFIX/$LAVA_INSTANCE/run/uwsgi.sock
887 chmod-socket = 660
888-wsgi-file = $LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/lava-server.wsgi
889+wsgi-file = $LAVA_PREFIX/$LAVA_INSTANCE/bin/lava-server.wsgi
890 master = true
891 workers = 8
892 logto = $LAVA_PREFIX/$LAVA_INSTANCE/var/log/lava-uwsgi.log
893@@ -767,11 +621,6 @@
894 }
895
896
897-pkglist_app() {
898- cat $LAVA_REQUIREMENT
899-}
900-
901-
902 wizard_app() {
903 echo
904 echo "LAVA application configuration"
905@@ -782,86 +631,66 @@
906
907
908 install_app() {
909- echo "Installing/upgrading application code from $LAVA_BUNDLE file"
910-
911- # Clean all builds to allow package upgrading
912- rm -rf $LAVA_PREFIX/$LAVA_INSTANCE/build/*
913- . $LAVA_PREFIX/$LAVA_INSTANCE/bin/activate
914- set -x
915- pip install --upgrade $PIP_PROXY_OPTION "$LAVA_BUNDLE" || die "Failed to install application bundle"
916- set +x
917- deactivate
918+ echo "Installing/upgrading application code from a revision of $LAVA_MANIFEST_BRANCH"
919+
920+ if [ ! -e $LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/settings.conf ]; then
921+ echo "Generating $LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/settings.conf for PRODUCTION"
922+ cat >$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/settings.conf <<SETTINGS_CONF
923+{
924+ "DEBUG": false,
925+ "TEMPLATE_DIRS": [
926+ "$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/templates",
927+ "$LAVA_PREFIX/$LAVA_INSTANCE/code/current/server_code/templates/"
928+ ],
929+ "STATICFILES_DIRS": [
930+ ["lava-server", "$LAVA_PREFIX/$LAVA_INSTANCE/code/current/server_code/htdocs/"]
931+ ],
932+ "MEDIA_ROOT": "$LAVA_PREFIX/$LAVA_INSTANCE/var/lib/lava-server/media",
933+ "STATIC_ROOT": "$LAVA_PREFIX/$LAVA_INSTANCE/var/www/lava-server/static",
934+ "MEDIA_URL": "/media/",
935+ "STATIC_URL": "/static/",
936+ "MOUNT_POINT": "/",
937+ "LOGIN_URL": "/accounts/login/",
938+ "LOGIN_REDIRECT_URL": "/",
939+ "BROKER_USER": "$LAVA_RABBIT_USER",
940+ "BROKER_VHOST": "$LAVA_RABBIT_VHOST",
941+ "BROKER_PASSWORD": "$LAVA_RABBIT_PASSWORD",
942+ "DATAREPORT_DIRS": [
943+ "$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/reports"
944+ ],
945+ "DATAVIEW_DIRS": [
946+ "$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/views"
947+ ]
948+}
949+SETTINGS_CONF
950+ fi
951+
952+ local venv="$LAVA_PREFIX/$LAVA_INSTANCE/var/lib/bootstrap-venv"
953+ local code="$LAVA_PREFIX/$LAVA_INSTANCE/code/r$LAVA_REVNO"
954+
955+ set -ex
956+ if [ ! -e ${code} ]; then
957+ bzr branch -r $LAVA_REVNO $LAVA_MANIFEST_BRANCH $code
958+ mkdir ${code}/bin
959+ ln -s ${venv}/bin/{uwsgi,buildout} ${code}/bin/
960+ ln -s $LAVA_DOWNLOAD_CACHE ${code}/download-cache
961+ ln -s $LAVA_EGG_CACHE ${code}/eggs
962+ fi
963+ # If LAVA_BUILDOUT_CFG does not specify a file in the branch,
964+ # symlink it in here before running buildout (as buildout works
965+ # relative to the config file).
966+ local cfg="$(basename "${LAVA_BUILDOUT_CFG}")"
967+ if [ "${cfg}" != "${LAVA_BUILDOUT_CFG}" ]; then
968+ ln -sfT "${LAVA_BUILDOUT_CFG}" "${cfg}"
969+ fi
970+ pushd $code
971+ ${venv}/bin/buildout -c "${cfg}"
972+ popd
973+ set +ex
974
975 gen_lava_dispatcher_config
976
977- if [ ! -e $LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/settings.conf ]; then
978- if [ -e $LAVA_PREFIX/$LAVA_INSTANCE/src/lava-server ]; then
979- # We're in editable server mode, let's use alternate paths for tempates and static files
980- echo "Generating $LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/settings.conf for DEVELOPMENT"
981- echo "This means that lava-server (which has to be special) is installed in editable mode"
982- echo "Some of the paths will refer to $LAVA_PREFIX/$LAVA_INSTANCE/src/lava-server."
983- echo "Even if you later on upgrade to non-editable lava-server those paths"
984- echo "will remain to be in use untill you wipe your old config and upgrade again"
985- cat >$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/settings.conf <<SETTINGS_CONF
986-{
987- "DEBUG": false,
988- "TEMPLATE_DIRS": [
989- "$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/templates",
990- "$LAVA_PREFIX/$LAVA_INSTANCE/src/lava-server/lava_server/templates/"
991- ],
992- "STATICFILES_DIRS": [
993- ["lava-server", "$LAVA_PREFIX/$LAVA_INSTANCE/src/lava-server/lava_server/htdocs/"]
994- ],
995- "MEDIA_ROOT": "$LAVA_PREFIX/$LAVA_INSTANCE/var/lib/lava-server/media",
996- "STATIC_ROOT": "$LAVA_PREFIX/$LAVA_INSTANCE/var/www/lava-server/static",
997- "MEDIA_URL": "/media/",
998- "STATIC_URL": "/static/",
999- "MOUNT_POINT": "/",
1000- "LOGIN_URL": "/accounts/login/",
1001- "LOGIN_REDIRECT_URL": "/",
1002- "BROKER_USER": "$LAVA_RABBIT_USER",
1003- "BROKER_VHOST": "$LAVA_RABBIT_VHOST",
1004- "BROKER_PASSWORD": "$LAVA_RABBIT_PASSWORD",
1005- "DATAREPORT_DIRS": [
1006- "$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/reports"
1007- ],
1008- "DATAVIEW_DIRS": [
1009- "$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/views"
1010- ]
1011-}
1012-SETTINGS_CONF
1013- else
1014- echo "Generating $LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/settings.conf for PRODUCTION"
1015- cat >$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/settings.conf <<SETTINGS_CONF
1016-{
1017- "DEBUG": false,
1018- "TEMPLATE_DIRS": [
1019- "$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/templates",
1020- "$LAVA_PREFIX/$LAVA_INSTANCE/lib/$LAVA_PYTHON/site-packages/lava_server/templates/"
1021- ],
1022- "STATICFILES_DIRS": [
1023- ["lava-server", "$LAVA_PREFIX/$LAVA_INSTANCE/lib/$LAVA_PYTHON/site-packages/lava_server/htdocs/"]
1024- ],
1025- "MEDIA_ROOT": "$LAVA_PREFIX/$LAVA_INSTANCE/var/lib/lava-server/media",
1026- "STATIC_ROOT": "$LAVA_PREFIX/$LAVA_INSTANCE/var/www/lava-server/static",
1027- "MEDIA_URL": "/media/",
1028- "STATIC_URL": "/static/",
1029- "MOUNT_POINT": "/",
1030- "LOGIN_URL": "/accounts/login/",
1031- "LOGIN_REDIRECT_URL": "/",
1032- "BROKER_USER": "$LAVA_RABBIT_USER",
1033- "BROKER_VHOST": "$LAVA_RABBIT_VHOST",
1034- "BROKER_PASSWORD": "$LAVA_RABBIT_PASSWORD",
1035- "DATAREPORT_DIRS": [
1036- "$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/reports"
1037- ],
1038- "DATAVIEW_DIRS": [
1039- "$LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/views"
1040- ]
1041-}
1042-SETTINGS_CONF
1043- fi
1044-fi
1045+ ln -sfT $code $LAVA_PREFIX/$LAVA_INSTANCE/code/current
1046 }
1047
1048
1049@@ -870,22 +699,17 @@
1050 }
1051
1052
1053-pkglist_config_app() {
1054- true
1055-}
1056-
1057-
1058 wizard_config_app() {
1059 local _question="Do you want to enable the scheduler in this instance?"
1060 whiptail --title "Enable the scheduler?" --yesno "$_question" 10 40 && LAVA_SCHEDULER_ENABLED=yes || LAVA_SCHEDULER_ENABLED=no
1061
1062 local _question="Do you want to config the lava-dispatcher?"
1063 whiptail --title "Configurate the lava-dispatcher?" --yesno "$_question" 10 40 && LAVA_DISPATCHER_CONFIG=yes || LAVA_DISPATCHER_CONFIG=no
1064-
1065+
1066 if [ $LAVA_DISPATCHER_CONFIG = yes ]; then
1067 config_lava_dispatcher
1068 fi
1069-
1070+
1071 return 0
1072 }
1073
1074@@ -998,8 +822,6 @@
1075 set -x
1076 rm -rf $LAVA_PREFIX/$LAVA_INSTANCE/var/www/lava-server/static
1077 lava-server manage \
1078- --instance-template=$LAVA_ROOT/instances/{instance}/etc/lava-server/{{filename}}.conf \
1079- --instance=$LAVA_INSTANCE \
1080 build_static --noinput --link || die "Failed to update the cache of static content"
1081 set +x
1082
1083@@ -1011,16 +833,12 @@
1084 echo "Synchronizing database..."
1085 set -x
1086 lava-server manage \
1087- --instance-template=$LAVA_ROOT/instances/{instance}/etc/lava-server/{{filename}}.conf \
1088- --instance=$LAVA_INSTANCE \
1089 syncdb --noinput || die "Failed to synchronize database (run non-migration db updates)"
1090 set +x
1091
1092 echo "Running migrations..."
1093 set -x
1094 lava-server manage \
1095- --instance-template=$LAVA_ROOT/instances/{instance}/etc/lava-server/{{filename}}.conf \
1096- --instance=$LAVA_INSTANCE \
1097 migrate --noinput || die "Failed to run database migrations"
1098 set +x
1099
1100@@ -1045,6 +863,16 @@
1101 fi
1102 }
1103
1104+ensure_downloaded_check_sha256 () {
1105+ local url="$1"
1106+ local sha256="$2"
1107+ local filename="$(basename "$url")"
1108+ if [ ! -f "$filename" ]; then
1109+ wget "$url"
1110+ fi
1111+ echo "$sha256 $filename" | sha256sum -c || die "checksum mismatch on $filename"
1112+}
1113+
1114 cmd_setup() {
1115 SETUP_VER=0
1116 if [ -e $LAVA_PREFIX/.setup ]; then
1117@@ -1060,15 +888,17 @@
1118 echo "System preparation steps:"
1119 echo " 1) Installing $LAVA_PKG_LIST"
1120 echo " 2) Setting up $LAVA_PREFIX owned by you"
1121- echo " 3) Setting up $PIP_DOWNLOAD_CACHE for downloads"
1122+ echo " 3) Setting up the egg and download cache for buildbot"
1123 echo " 4) Setting up upstart jobs (incuding removal of stale jobs)"
1124 echo
1125 read -p "Type YES to continue: " RESPONSE
1126 test "$RESPONSE" = 'YES' || return
1127
1128+ set -xe
1129+
1130 echo "Updating apt cache..."
1131 sudo apt-get update
1132-
1133+
1134 echo "Add Linaro tools ppa"
1135 sudo apt-get install --yes python-software-properties
1136 sudo add-apt-repository --yes ppa:linaro-maintainers/tools
1137@@ -1086,12 +916,29 @@
1138 echo "Creating LAVA filesystem in $LAVA_PREFIX"
1139 sudo mkdir -p $LAVA_PREFIX
1140 echo "Making $(whoami) the owner of that location"
1141- sudo chown $(whoami):$(id -gn) $LAVA_PREFIX
1142-
1143- echo "Creating PIP download cache in $PIP_DOWNLOAD_CACHE and making it writable"
1144- sudo mkdir -p $PIP_DOWNLOAD_CACHE
1145- sudo chown $(whoami):$(id -gn) $PIP_DOWNLOAD_CACHE
1146-
1147+ sudo chown $(whoami):$(id -gn) $LAVA_PREFIX
1148+
1149+ echo "Creating buildout caches"
1150+ sudo mkdir -p $LAVA_EGG_CACHE
1151+ sudo chown $(whoami):$(id -gn) $LAVA_EGG_CACHE
1152+ sudo mkdir -p $LAVA_DOWNLOAD_CACHE/dist
1153+ sudo chown -R $(whoami):$(id -gn) $LAVA_DOWNLOAD_CACHE
1154+ pushd $LAVA_DOWNLOAD_CACHE/dist
1155+ ensure_downloaded_check_sha256 \
1156+ http://pypi.python.org/packages/source/d/distribute/distribute-0.6.24.tar.gz \
1157+ c61fde9f388c9600eb8ee54bd7168039c5fb74fa334138bc49cdf6a6c1341627
1158+ ensure_downloaded_check_sha256 \
1159+ https://launchpad.net/bzr/2.5/2.5.1/+download/bzr-2.5.1.tar.gz \
1160+ 967346fa6cc52971a8dfd5171ec22e1928cf455fb4317013b05b0915ff927982
1161+ ensure_downloaded_check_sha256 \
1162+ http://projects.unbit.it/downloads/old/uwsgi-$LAVA_UWSGI.tar.gz \
1163+ 81dc137bc8b7b3962e527cafb1a719342c34eb07d568dc61c7766f9a9bcdee62
1164+ ensure_downloaded_check_sha256 \
1165+ http://pypi.python.org/packages/source/z/zc.buildout/zc.buildout-1.5.2.tar.gz \
1166+ 0ac5a325d3ffbc5a988fb3ba87f4159d4769cc73e3331cb5234edc8839b6506b
1167+ popd
1168+
1169+ set +x
1170 echo "Creating upstart script for: lava"
1171 sudo sh -c "cat >/etc/init/lava.conf" <<LAVA_CONF
1172 author "Zygmunt Krynicki"
1173@@ -1434,6 +1281,21 @@
1174 end script
1175 LAVA_CONF
1176
1177+ if [ \! -e /etc/apache2/mods-available/uwsgi.load ]; then
1178+ echo "Building uWSGI apache module..."
1179+ _tmpdir="$(mktemp -d)"
1180+
1181+ trap "rm -rf \"${_tmpdir}\"" EXIT
1182+ set -x
1183+ pushd $_tmpdir
1184+ tar -xzf $LAVA_DOWNLOAD_CACHE/dist/uwsgi-$LAVA_UWSGI.tar.gz --strip-components=1
1185+ cd apache2
1186+ apxs2 -c mod_uwsgi.c
1187+ sudo apxs2 -i -a mod_uwsgi.c
1188+ popd
1189+ set +x
1190+ fi
1191+
1192 # Store setup version
1193 echo $LAVA_SETUP_REQUIRED_VERSION > $LAVA_PREFIX/.setup
1194 echo "Setup complete, you can now install LAVA"
1195@@ -1459,7 +1321,7 @@
1196
1197 cmd_install() {
1198 export LAVA_INSTANCE=$1
1199- export LAVA_BUNDLE=$2
1200+ export LAVA_REVNO=$2
1201
1202 check_min_version
1203 _banner
1204@@ -1469,9 +1331,10 @@
1205 return
1206 fi
1207
1208- if [ -z "$LAVA_BUNDLE" ]; then
1209- echo "You need to pass the name of the bundle to use as second argument"
1210- return
1211+ if [ -z "$LAVA_REVNO" ]; then
1212+ echo -n "Determining revno to deploy... "
1213+ LAVA_REVNO="$(bzr revno $LAVA_MANIFEST_BRANCH)"
1214+ echo $LAVA_REVNO
1215 fi
1216
1217 # Sanity checking, ensure that instance does not exist yet
1218@@ -1489,7 +1352,7 @@
1219
1220 cmd_upgrade() {
1221 export LAVA_INSTANCE=$1
1222- export LAVA_BUNDLE=$2
1223+ export LAVA_REVNO=$2
1224
1225 check_min_version
1226 _banner
1227@@ -1499,9 +1362,12 @@
1228 return
1229 fi
1230
1231- if [ -z "$LAVA_BUNDLE" ]; then
1232- echo "You need to pass the name of the bundle to use as second argument"
1233- return
1234+ _load_configuration "$LAVA_INSTANCE"
1235+
1236+ if [ -z "$LAVA_REVNO" ]; then
1237+ echo -n "Determining revno to deploy... "
1238+ LAVA_REVNO="$(bzr revno $LAVA_MANIFEST_BRANCH)"
1239+ echo $LAVA_REVNO
1240 fi
1241
1242 # Sanity checking, ensure that instance exist
1243@@ -1510,9 +1376,58 @@
1244 return
1245 fi
1246
1247- _load_configuration "$LAVA_INSTANCE"
1248- install_app || die "Failed to upgrade application code"
1249- install_config_app || die "Failed to run post-upgrade configuration"
1250+ _maybe_pre_convert_to_buildout
1251+ install_app
1252+ _maybe_post_convert_to_buildout
1253+ install_config_app
1254+}
1255+
1256+
1257+_maybe_pre_convert_to_buildout () {
1258+ if [ -e $LAVA_PREFIX/$LAVA_INSTANCE/code ]; then
1259+ return
1260+ fi
1261+ if [ ! -e $LAVA_PREFIX/$LAVA_INSTANCE/lib ]; then
1262+ echo "Instance appears to be neither pip based or buildout based."
1263+ echo "Cowardly refusing to proceed."
1264+ exit 1;
1265+ fi
1266+
1267+ echo "$LAVA_INSTANCE appears to be a pip based instance"
1268+ echo "This script can attempt to convert it, but this may "
1269+ echo "lose any custom packages you have installed unless you "
1270+ echo "already have a plan to cope with that."
1271+ echo
1272+ read -p "Proceed? (y/n) " RESPONSE
1273+
1274+ if [ "$RESPONSE" != 'y' ]; then
1275+ exit 1;
1276+ fi
1277+
1278+ set -xe
1279+ _save_config
1280+ install_buildout
1281+ bzr init-repo $LAVA_PREFIX/$LAVA_INSTANCE/code
1282+ set +xe
1283+}
1284+
1285+
1286+_maybe_post_convert_to_buildout () {
1287+ local instpath=$LAVA_PREFIX/$LAVA_INSTANCE
1288+ set -xe
1289+ if [ ! -e $instpath/lib ]; then
1290+ return
1291+ fi
1292+ $instpath/bin/pip freeze > $instpath/last-pip-installed-versions.txt
1293+ rm -rf $instpath/{bin,lib,src,build,local}
1294+ rm $instpath/etc/lava-server/lava-server.wsgi
1295+ ln -s $instpath/code/current/bin $instpath
1296+ sed -i -e 's%lib/python2\../site-packages/lava_server%code/current/server_code%' \
1297+ $instpath/etc/lava-server/settings.conf
1298+ sed -i -e "s%home = $instpath%&/var/lib/bootstrap-venv%" \
1299+ -e "s%$instpath/etc/lava-server/lava-server\.wsgi%$instpath/bin/lava-server.wsgi%" \
1300+ $instpath/etc/lava-server/uwsgi.ini
1301+ set +xe
1302 }
1303
1304
1305@@ -1788,51 +1703,11 @@
1306
1307 set -x
1308 lava-server manage \
1309- --instance-template=$LAVA_ROOT/instances/{instance}/etc/lava-server/{{filename}}.conf \
1310- --instance=$LAVA_INSTANCE \
1311 "$@"
1312 set +x
1313 }
1314
1315
1316-cmd_bundle() {
1317- LAVA_REQUIREMENT=${1:-requirements/requirements.txt}
1318- LAVA_BUNDLE=${2:-lava.pybundle}
1319- local step
1320- for step in $LAVA_INSTALL_STEPS; do
1321- defaults_$step
1322- done
1323- LAVA_FULL_REQUIREMENT=$(mktemp)
1324- for step in $LAVA_INSTALL_STEPS; do
1325- pkglist_$step >> "$LAVA_FULL_REQUIREMENT"
1326- done
1327- set -x
1328- pip bundle "$LAVA_BUNDLE" $PIP_PROXY_OPTION --timeout=30 --use-mirrors --requirement="$LAVA_FULL_REQUIREMENT" || die "Failed to create bundle"
1329- set +x
1330- rm -f "$LAVA_FULL_REQUIREMENT"
1331-}
1332-
1333-cmd_preview () {
1334- export LAVA_INSTANCE=$1
1335- export LAVA_BUNDLE=$2
1336-
1337- check_min_version
1338-
1339- local compare_manifests="$(dirname $(readlink -f "$0"))/_compare_manifests.py"
1340-
1341- _bundle="$(readlink -f $LAVA_BUNDLE)"
1342- _tmpdir="$(mktemp -d)"
1343-
1344- trap "rm -rf \"${_tmpdir}\"" EXIT
1345-
1346- cd "${_tmpdir}"
1347-
1348- unzip -qc "${_bundle}" pip-manifest.txt | grep -v '^#' | tr '[A-Z]' '[a-z]' | sort > bundle-versions.txt
1349- $LAVA_PREFIX/$LAVA_INSTANCE/bin/pip freeze | tr '[A-Z]' '[a-z]' | sort > installed-versions.txt
1350-
1351- "${compare_manifests}" installed-versions.txt bundle-versions.txt
1352-}
1353-
1354 is_vhost(){
1355 export LAVA_INSTANCE=$1
1356 vhost_conf="/etc/apache2/sites-enabled/$LAVA_INSTANCE.conf"

Subscribers

People subscribed via source and target branches