To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / deploy @ 1601:07deb8466f65

1 1595:98384d0defa0 Chris
2
Deploying the SoundSoftware site
3 1601:07deb8466f65 Chris
================================
4 1595:98384d0defa0 Chris
5 1601:07deb8466f65 Chris
These scripts can be used for test or staging deployments reproducing
6
much of the configuration of the live site. Currently it's assumed
7
that you are providing a database dump to load -- there is no
8
provisioning step to initialise a new database.
9
10
11
You will need
12
-------------
13
14
Required:
15
16
 * A database dump to load. This should be left in a file called
17
   postgres-dumpall in the soundsoftware-site root
18
19
 * The database password and /sys API key for the target site. (The
20
   API key can be changed in the admin UI - "grep API config/*.in" to
21
   see the files you'll need to update if you change it)
22
23
 * The (copyrighted) web font files used in our deployment. Leave
24
   these in /public/themes/soundsoftware/stylesheets/fonts/
25
26
Optional (or required for proper deployments):
27
28
 * HTTPS key/cert files
29
30
31
Three ways to deploy
32
--------------------
33
34
 1. Using Vagrant to set up a development VM: Run ./vagrant/start.sh
35
36
 2. Using Docker to set up a development container: Run ./docker/start.sh
37
38
 3. On a "real" VM or server:
39
40
    * Ensure the soundsoftware-site repo is checked out at /code-to-deploy
41
    * Run /code-to-deploy/deploy/any/run-provisioning.sh as root
42
43
    But be very careful with this! You could screw up a dev box -- or
44
    an existing live server! -- if you accidentally provision the site
45
    directly onto it when you should have used Vagrant or a container.
46 1597:eeacb8332051 Chris
47
48
After deployment
49
----------------
50
51
There is a smoke test script at test/smoketest.sh which checks that
52
the home page, a project page, a repo page etc can be retrieved. Some
53
of the pages it tries to retrieve are dependent on their generating
54
cron scripts having run at least once since the server was set up.
55
56 1593:83412a0a2389 Chris
#!/bin/bash
57
58
# To be sourced into a container-specific start.sh file, not run
59
# standalone
60
61
usage() {
62
    echo "Usage: $0 <database-password> <api-key> <api-httpauth-password>" 1>&2
63
    exit 2
64
}
65
66
dbpass="$1"
67
if [ -z "$dbpass" ]; then
68
    usage
69
fi
70
71
apikey="$2"
72
if [ -z "$apikey" ]; then
73
    usage
74
fi
75
76
apipass="$3"
77
if [ -z "$apipass" ]; then
78
    usage
79
fi
80
81
set -eu -o pipefail
82
83
rootdir="$mydir/../.."
84
85
deploydir="$rootdir"/deploy
86
if [ ! -d "$deploydir" ]; then
87
    echo "ERROR: Unexpected repository layout - expected directory at $deploydir"
88
    exit 2
89
fi
90
91
managerdir="$deploydir/vagrant"
92
if [ ! -d "$managerdir" ]; then
93
    echo "ERROR: Required directory $managerdir not found"
94
    exit 2
95
fi
96
97
configdir="$deploydir/config"
98
if [ ! -d "$configdir" ]; then
99
    echo "ERROR: Required directory $configdir not found"
100
    exit 2
101
fi
102
103
if [ ! -f "$rootdir/postgres-dumpall" ]; then
104
    echo "ERROR: I expect to find a Postgres SQL multi-db dump file in $rootdir/postgres-dumpall"
105
    exit 2
106
fi
107
108
fontdir="$rootdir"/public/themes/soundsoftware/stylesheets/fonts
109
if [ ! -f "$fontdir/24BC0E_0_0.woff" ]; then
110
    echo "ERROR: I expect to find necessary webfonts in $fontdir"
111
    exit 2
112
fi
113
114
apischeme=http
115
apihost=localhost
116
117
#apischeme=https
118
#apihost=code.soundsoftware.ac.uk
119
120
for f in "$configdir"/*.in "$rootdir"/extra/soundsoftware/extract-docs.sh ; do
121
    out="$configdir"/$(basename "$f" .in).gen
122
    cat "$f" | sed \
123
                   -e 's/INSERT_DATABASE_PASSWORD_HERE/'"$dbpass"'/g' \
124
                   -e 's/INSERT_API_KEY_HERE/'"$apikey"'/g' \
125
                   -e 's/INSERT_API_SCHEME_HERE/'"$apischeme"'/g' \
126
                   -e 's/INSERT_API_HOST_HERE/'"$apihost"'/g' \
127
                   -e 's/INSERT_API_USER_HERE/user/g' \
128
                   -e 's/INSERT_API_PASSWORD_HERE/'"$apipass"'/g' \
129
                   > "$out"
130
done
131 1601:07deb8466f65 Chris
#!/bin/bash
132
133
mydir=$(dirname "$0")
134
135
if [ "$mydir" != "/code-to-deploy/deploy/any" ]; then
136
    echo "ERROR: Expected repository to be at /code-to-deploy prior to provisioning"
137
    exit 2
138
fi
139
140
. "$mydir"/../prepare.sh
141
142
for f in "$mydir"/../provision.d/[0-9]*.sh ; do
143
    case "$f" in
144
        *~) ;;
145
        *) echo "Running provisioning script: $f"
146
           /bin/bash "$f";;
147
    esac
148
done
149
150
echo "All provisioning scripts complete"
151
152
# Apache config with SSL and admin auth stubbed in. You must provide
153
# the key/cert and auth files.
154
155
# Note this has been updated for Apache 2.4, which introduced a number
156
# of (welcome) changes to access control directives.
157
158
PerlLoadModule Apache::Authn::SoundSoftware
159
160
<VirtualHost *:80>
161
        ServerName code.soundsoftware.ac.uk
162
        ServerAdmin chris.cannam@soundsoftware.ac.uk
163
164
        DocumentRoot /var/www/code/public
165
        PassengerRestartDir restart_files
166
        PassengerHighPerformance on
167
        PassengerMaxRequests 50000
168
        PassengerStatThrottleRate 5
169
	PassengerFriendlyErrorPages off
170
        RailsSpawnMethod smart
171
        ExpiresDefault "access plus 1 minute"
172
173
        # Redirect all activity to secure site
174
        Redirect seeother / "https://code.soundsoftware.ac.uk/"
175
176
        <DirectoryMatch "^/.*/\.svn/">
177
                Require all denied
178
        </DirectoryMatch>
179
180
        <DirectoryMatch "^/.*/\.hg/">
181
                Require all denied
182
        </DirectoryMatch>
183
184
        <DirectoryMatch "^/.*/\.git/">
185
                Require all denied
186
        </DirectoryMatch>
187
188
        <Directory /var/www/code/public>
189
                Options -MultiViews
190
	</Directory>
191
192
	ErrorLog /var/log/apache2/code-error.log
193
	CustomLog /var/log/apache2/code-access.log vhost_combined
194
195
        LogLevel warn
196
        ServerSignature Off
197
</VirtualHost>
198
199
<VirtualHost *:80>
200
        ServerName code.soundsoftware.ac.uk
201
        ServerAdmin chris.cannam@soundsoftware.ac.uk
202
203
        DocumentRoot /var/www/code/public
204
        PassengerRestartDir restart_files
205
        PassengerHighPerformance on
206
        PassengerMaxRequests 50000
207
        PassengerStatThrottleRate 5
208
	PassengerStartTimeout 60
209
	PassengerFriendlyErrorPages off
210
        RailsSpawnMethod smart
211
        ExpiresDefault "access plus 1 minute"
212
213
        <Location /sys>
214
		AuthType Basic
215
		AuthUserFile "/etc/apache2/auth/user.htpasswd"
216
		AuthName "code.soundsoftware.ac.uk"
217
		Require user user
218
	</Location>
219
220
	<Location /admin>
221
		AuthType Digest
222
		AuthUserFile "/etc/apache2/auth/admin.htdigest"
223
		AuthName "code.soundsoftware.ac.uk admin interface"
224
		Require user admin
225
	</Location>
226
227
        <DirectoryMatch "^/.*/\.svn/">
228
                Require all denied
229
        </DirectoryMatch>
230
231
        <DirectoryMatch "^/.*/\.hg/">
232
                Require all denied
233
        </DirectoryMatch>
234
235
        <DirectoryMatch "^/.*/\.git/">
236
                Require all denied
237
        </DirectoryMatch>
238
239
        <Directory /var/www/code/public>
240
                Options -MultiViews
241
	</Directory>
242
243
        <Directory /var/www/code/public/themes/soundsoftware/stylesheets/fonts>
244
		# Avoid other sites embedding our fonts
245
		RewriteEngine on
246
		RewriteCond %{HTTP_REFERER} !^$
247
		RewriteCond %{HTTP_REFERER} !^http(s)?://code.soundsoftware.ac.uk/.*$ [NC]
248
		RewriteRule \.(ttf|woff|eot|otf|svg|zip|gz|html|txt)$ - [F]
249
	</Directory>
250
251
	ScriptAlias /hg "/var/hg/index.cgi"
252
253
	<Location /hg>
254
               	AuthName "Mercurial"
255
                AuthType Basic
256
                Require valid-user
257
		PerlAccessHandler Apache::Authn::SoundSoftware::access_handler
258
      		PerlAuthenHandler Apache::Authn::SoundSoftware::authen_handler
259
		PerlSetVar HTTPS "on"
260
		SoundSoftwareDSN "dbi:Pg:database=code;host=localhost"
261
    		SoundSoftwareDbUser "code"
262
     		SoundSoftwareDbPass "INSERT_DATABASE_PASSWORD_HERE"
263
		SoundSoftwareRepoPrefix "/var/hg/"
264
                SoundSoftwareSslRequired "on"
265
		Options +ExecCGI
266
		AddHandler cgi-script .cgi
267
		ExpiresDefault now
268
        </Location>
269
270
	Alias /git "/var/files/git-mirror"
271
272
	<Directory "/var/files/git-mirror">
273
		Options -Indexes +FollowSymLinks
274
                Require all granted
275
	</Directory>
276
	<Directory ~ "/var/files/git-mirror/.*\.workdir">
277
                Require all denied
278
	</Directory>
279
	<Directory ~ "/var/files/git-mirror/__.*">
280
                Require all denied
281
	</Directory>
282
283
	ErrorLog /var/log/apache2/code-error.log
284
	CustomLog /var/log/apache2/code-access.log vhost_combined
285
286
        LogLevel warn
287
        ServerSignature Off
288
289
</VirtualHost>
290
291 1570:ae2f71010562 Chris
292
# A test Apache config. Lacks SSL, lacks a desirable extra layer of
293
# authentication for admin interface paths. Do not deploy this.
294
295 1593:83412a0a2389 Chris
# Note this has been updated for Apache 2.4, which introduced a number
296
# of (welcome) changes to access control directives.
297
298 1570:ae2f71010562 Chris
PerlLoadModule Apache::Authn::SoundSoftware
299
300
<VirtualHost *:80>
301
        ServerName code.soundsoftware.ac.uk
302
        ServerAdmin chris.cannam@soundsoftware.ac.uk
303
304
        DocumentRoot /var/www/code/public
305
        PassengerRestartDir restart_files
306
        PassengerHighPerformance on
307
        PassengerMaxRequests 50000
308
        PassengerStatThrottleRate 5
309
	PassengerStartTimeout 60
310 1571:4c2b25b7e85f Chris
	PassengerFriendlyErrorPages on
311 1570:ae2f71010562 Chris
        RailsSpawnMethod smart
312
        ExpiresDefault "access plus 1 minute"
313
314 1590:c18460da6620 Chris
#        <Location /sys>
315
#		AuthType Basic
316
#		AuthUserFile "/etc/apache2/auth/user.htpasswd"
317
#		AuthName "code.soundsoftware.ac.uk"
318
#		Require user user
319
#	</Location>
320
321
#	<Location /admin>
322
#		AuthType Digest
323
#		AuthUserFile "/etc/apache2/auth/admin.htdigest"
324
#		AuthName "code.soundsoftware.ac.uk admin interface"
325
#		Require user admin
326
#	</Location>
327
328 1570:ae2f71010562 Chris
        <DirectoryMatch "^/.*/\.svn/">
329 1593:83412a0a2389 Chris
                Require all denied
330 1570:ae2f71010562 Chris
        </DirectoryMatch>
331
332
        <DirectoryMatch "^/.*/\.hg/">
333 1593:83412a0a2389 Chris
                Require all denied
334 1570:ae2f71010562 Chris
        </DirectoryMatch>
335
336
        <DirectoryMatch "^/.*/\.git/">
337 1593:83412a0a2389 Chris
                Require all denied
338 1570:ae2f71010562 Chris
        </DirectoryMatch>
339
340
        <Directory /var/www/code/public>
341
                Options -MultiViews
342
	</Directory>
343
344
        <Directory /var/www/code/public/themes/soundsoftware/stylesheets/fonts>
345
		# Avoid other sites embedding our fonts
346
		RewriteEngine on
347
		RewriteCond %{HTTP_REFERER} !^$
348
		RewriteCond %{HTTP_REFERER} !^http(s)?://code.soundsoftware.ac.uk/.*$ [NC]
349
		RewriteRule \.(ttf|woff|eot|otf|svg|zip|gz|html|txt)$ - [F]
350
	</Directory>
351
352
	ScriptAlias /hg "/var/hg/index.cgi"
353
354
	<Location /hg>
355
               	AuthName "Mercurial"
356
                AuthType Basic
357
                Require valid-user
358
		PerlAccessHandler Apache::Authn::SoundSoftware::access_handler
359
      		PerlAuthenHandler Apache::Authn::SoundSoftware::authen_handler
360 1601:07deb8466f65 Chris
		PerlSetVar HTTPS "off"
361 1570:ae2f71010562 Chris
		SoundSoftwareDSN "dbi:Pg:database=code;host=localhost"
362
    		SoundSoftwareDbUser "code"
363 1593:83412a0a2389 Chris
     		SoundSoftwareDbPass "INSERT_DATABASE_PASSWORD_HERE"
364 1570:ae2f71010562 Chris
		SoundSoftwareRepoPrefix "/var/hg/"
365 1576:d1de6986e429 Chris
                #!!! "on" in production please!:
366
                SoundSoftwareSslRequired "off"
367 1570:ae2f71010562 Chris
		Options +ExecCGI
368
		AddHandler cgi-script .cgi
369
		ExpiresDefault now
370
        </Location>
371
372
	Alias /git "/var/files/git-mirror"
373
374
	<Directory "/var/files/git-mirror">
375
		Options -Indexes +FollowSymLinks
376 1593:83412a0a2389 Chris
                Require all granted
377 1570:ae2f71010562 Chris
	</Directory>
378
	<Directory ~ "/var/files/git-mirror/.*\.workdir">
379 1593:83412a0a2389 Chris
                Require all denied
380 1570:ae2f71010562 Chris
	</Directory>
381
	<Directory ~ "/var/files/git-mirror/__.*">
382 1593:83412a0a2389 Chris
                Require all denied
383 1570:ae2f71010562 Chris
	</Directory>
384
385
	ErrorLog /var/log/apache2/code-error.log
386
	CustomLog /var/log/apache2/code-access.log vhost_combined
387
388
        LogLevel warn
389
        ServerSignature Off
390
391
</VirtualHost>
392
393 1586:d0d59d12db94 Chris
#!/bin/sh
394 1590:c18460da6620 Chris
395 1586:d0d59d12db94 Chris
outfile="/var/files/backups/postgres-dumpall-`date +%Y%m%d%H%M`"
396 1590:c18460da6620 Chris
397 1586:d0d59d12db94 Chris
oldmask=`umask`
398
umask 0277
399 1590:c18460da6620 Chris
400 1586:d0d59d12db94 Chris
su postgres -c /usr/bin/pg_dumpall > "$outfile" && bzip2 "$outfile"
401 1590:c18460da6620 Chris
402 1586:d0d59d12db94 Chris
umask "$oldmask"
403
#!/bin/bash
404 1590:c18460da6620 Chris
405 1586:d0d59d12db94 Chris
cd /tmp
406 1590:c18460da6620 Chris
407 1586:d0d59d12db94 Chris
/var/www/code/docgen/extract-docs.sh
408 1590:c18460da6620 Chris
409 1586:d0d59d12db94 Chris
#!/bin/bash
410 1590:c18460da6620 Chris
411 1586:d0d59d12db94 Chris
sudo -u code sh -c "cd /var/www/code ; ./script/rails runner -e production extra/soundsoftware/get-statistics.rb >> log/statistics.log"
412 1590:c18460da6620 Chris
413 1586:d0d59d12db94 Chris
#!/bin/bash
414 1590:c18460da6620 Chris
415 1586:d0d59d12db94 Chris
tail -2 /var/log/external-repos.log
416
#!/bin/bash
417
418 1590:c18460da6620 Chris
## No longer used - this site is now static
419
420
# /usr/bin/wget -O - -q -t 1 http://www.soundsoftware.ac.uk/cron.php
421
422 1586:d0d59d12db94 Chris
#!/bin/bash
423 1590:c18460da6620 Chris
424 1586:d0d59d12db94 Chris
sudo -u code sh -c "cd /var/www/code ; ./script/rails runner \"Repository.fetch_changesets\" -e production 2>&1 | grep -v 'Not trusting' | grep -v 'svn:' | grep -v 'working copy' | grep -v 'deprecated' | grep -v 'version_requirements'"
425
exit 0
426 1590:c18460da6620 Chris
427 1586:d0d59d12db94 Chris
#!/bin/bash
428 1590:c18460da6620 Chris
429 1586:d0d59d12db94 Chris
sudo -H -u www-data /var/www/code/reposman/run-external.sh
430 1590:c18460da6620 Chris
431 1586:d0d59d12db94 Chris
#!/bin/sh
432 1590:c18460da6620 Chris
433 1586:d0d59d12db94 Chris
rm -f /var/www/code/tmp/cache/*/*/views*explore*
434
#!/bin/bash
435 1590:c18460da6620 Chris
436 1586:d0d59d12db94 Chris
logfile="/var/www/code/log/export-git.log"
437 1590:c18460da6620 Chris
438 1586:d0d59d12db94 Chris
sudo -u code sh -c "cd /tmp ; /var/www/code/extra/soundsoftware/export-git.sh production /var/hg /var/files/git-mirror >> $logfile 2>&1"
439 1590:c18460da6620 Chris
440 1586:d0d59d12db94 Chris
#!/bin/bash
441 1590:c18460da6620 Chris
442 1586:d0d59d12db94 Chris
sudo -u www-data /var/www/code/reposman/run-reposman.sh
443
444
#!/bin/sh
445 1596:45b0571b684d Chris
cd /
446 1586:d0d59d12db94 Chris
for location in var/www etc/apache2 etc/cron.*; do
447
	target="/var/files/backups/`echo $location | sed 's,/,_,g'`-`date +%Y%m%d%H%M`"
448
	oldmask=`umask`
449
	umask 0277
450
	tar cjf "$target".tar.bz2 "$location"
451
	umask "$oldmask"
452
done
453
454 1570:ae2f71010562 Chris
production:
455
  adapter: postgresql
456
  database: code
457
  host: localhost
458
  username: code
459 1593:83412a0a2389 Chris
  password: "INSERT_DATABASE_PASSWORD_HERE"
460 1570:ae2f71010562 Chris
461 1576:d1de6986e429 Chris
[paths]
462
/ = /var/hg/*
463
464
[web]
465
allow_archive = gz, zip, bz2
466
allow_push = *
467
#!/usr/bin/env python
468
#
469
# An example CGI script to export multiple hgweb repos, edit as necessary
470
471
# adjust python path if not a system-wide install:
472
#import sys
473
#sys.path.insert(0, "/path/to/python/lib")
474
475
# enable importing on demand to reduce startup time
476
from mercurial import demandimport; demandimport.enable()
477
478
# Uncomment to send python tracebacks to the browser if an error occurs:
479
import cgitb
480
cgitb.enable()
481
482
# If you'd like to serve pages with UTF-8 instead of your default
483
# locale charset, you can do so by uncommenting the following lines.
484
# Note that this will cause your .hgrc files to be interpreted in
485
# UTF-8 and all your repo files to be displayed using UTF-8.
486
#
487
import os
488
os.environ["HGENCODING"] = "UTF-8"
489
490
from mercurial.hgweb.hgwebdir_mod import hgwebdir
491
import mercurial.hgweb.wsgicgi as wsgicgi
492
493
# The config file looks like this.  You can have paths to individual
494
# repos, collections of repos in a directory tree, or both.
495
#
496
# [paths]
497
# virtual/path1 = /real/path1
498
# virtual/path2 = /real/path2
499
# virtual/root = /real/root/*
500
# / = /real/root2/*
501
# virtual/root2 = /real/root2/**
502
#
503
# [collections]
504
# /prefix/to/strip/off = /root/of/tree/full/of/repos
505
#
506
# paths example:
507
#
508
# * First two lines mount one repository into one virtual path, like
509
# '/real/path1' into 'virtual/path1'.
510
#
511
# * The third entry mounts every mercurial repository found in '/real/root'
512
# in 'virtual/root'. This format is preferred over the [collections] one,
513
# since using absolute paths as configuration keys is not supported on every
514
# platform (especially on Windows).
515
#
516
# * The fourth entry is a special case mounting all repositories in
517
# /'real/root2' in the root of the virtual directory.
518
#
519
# * The fifth entry recursively finds all repositories under the real root,
520
# and mounts them using their relative path (to given real root) under the
521
# virtual root.
522
#
523
# collections example: say directory tree /foo contains repos /foo/bar,
524
# /foo/quux/baz.  Give this config section:
525
#   [collections]
526
#   /foo = /foo
527
# Then repos will list as bar and quux/baz.
528
#
529
# Alternatively you can pass a list of ('virtual/path', '/real/path') tuples
530
# or use a dictionary with entries like 'virtual/path': '/real/path'
531
532
application = hgwebdir('hgweb.config')
533
wsgicgi.launch(application)
534 1586:d0d59d12db94 Chris
# see "man logrotate" for details
535
# rotate log files weekly
536
weekly
537
538 1590:c18460da6620 Chris
# use the syslog group by default, since this is the owning group
539
# of /var/log/syslog.
540
su root syslog
541
542 1586:d0d59d12db94 Chris
# keep 4 weeks worth of backlogs
543
rotate 4
544
545
# create new (empty) log files after rotating old ones
546
create
547
548
# uncomment this if you want your log files compressed
549
#compress
550
551
# packages drop log rotation information into this directory
552
include /etc/logrotate.d
553
554
# no packages own wtmp, or btmp -- we'll rotate them here
555
/var/log/wtmp {
556
    missingok
557
    monthly
558
    create 0664 root utmp
559
    rotate 1
560
}
561
562
/var/log/btmp {
563
    missingok
564
    monthly
565
    create 0660 root utmp
566
    rotate 1
567
}
568
569
# system-specific logs may be configured here
570
/var/www/code/log/*.log {
571
	weekly
572
	missingok
573
	rotate 52
574
	compress
575
	delaycompress
576
	create 640 code code
577
	sharedscripts
578
	postrotate
579
		touch /var/www/code/restart_files/restart.txt
580
	endscript
581
}
582
583
/var/log/reposman.log {
584
        weekly
585
        missingok
586
        rotate 52
587
        compress
588
        delaycompress
589
        create 640 www-data code
590
        sharedscripts
591
}
592
593
/var/log/external-repos.log {
594
        weekly
595
        missingok
596
        rotate 52
597
        compress
598
        delaycompress
599
        create 640 www-data code
600
        sharedscripts
601
}
602
603 1571:4c2b25b7e85f Chris
PassengerMaxPoolSize 60
604
605
LoadModule passenger_module /var/lib/gems/2.3.0/gems/passenger-4.0.60/buildout/apache2/mod_passenger.so
606
PassengerRoot /var/lib/gems/2.3.0/gems/passenger-4.0.60
607
PassengerDefaultRuby /usr/bin/ruby2.3
608
# Apache::DBI is supposed to be a transparent replacement for Perl DBI with
609
# better performance when multiple connections are made with common DSN, user
610
# and password
611
PerlModule Apache::DBI
612 1590:c18460da6620 Chris
#!/bin/bash
613
logfile=/var/log/external-repos.log
614
(
615
flock -s 200
616
echo >> $logfile
617
date >> $logfile
618
/var/www/code/reposman/convert-external-repos.rb \
619
	-s /var/hg \
620 1593:83412a0a2389 Chris
	-r INSERT_API_SCHEME_HERE://INSERT_API_HOST_HERE/ \
621 1590:c18460da6620 Chris
	-k INSERT_API_KEY_HERE \
622
	-v \
623 1593:83412a0a2389 Chris
	--http-user=INSERT_API_USER_HERE \
624
	--http-pass=INSERT_API_PASSWORD_HERE \
625 1590:c18460da6620 Chris
        -c "/var/www/code/reposman/update-external-repo.sh" \
626
	>> $logfile 2>&1
627
date >> $logfile
628
echo Done >> $logfile
629
)200>>$logfile
630
#!/bin/bash
631
logfile=/var/log/reposman.log
632
(
633
flock -s 200
634
echo >> $logfile
635
/var/www/code/reposman/reposman-soundsoftware.rb \
636
	-s /var/hg \
637 1593:83412a0a2389 Chris
	-r INSERT_API_SCHEME_HERE://INSERT_API_HOST_HERE/ \
638 1590:c18460da6620 Chris
	-k INSERT_API_KEY_HERE \
639 1593:83412a0a2389 Chris
	--http-user=INSERT_API_USER_HERE \
640
	--http-pass=INSERT_API_PASSWORD_HERE \
641 1590:c18460da6620 Chris
	-o www-data \
642
	-g code \
643
	-c "/var/www/code/reposman/run-hginit.sh" \
644
	--scm=Mercurial \
645
	>> $logfile 2>&1
646
)200>>$logfile
647 1587:d8949733849d Chris
648
FROM ubuntu:16.04
649
MAINTAINER Chris Cannam <cannam@all-day-breakfast.com>
650
651
COPY . /var/www/code
652
653
WORKDIR /var/www/code
654
655
INSERT_PROVISIONING_HERE
656
657
# Start Postgres and foregrounded Apache
658
659
RUN echo "#!/bin/bash"                      > container-run.sh
660
RUN echo "/etc/init.d/postgresql start"    >> container-run.sh
661
RUN echo "apache2ctl -D FOREGROUND"        >> container-run.sh
662
RUN chmod +x container-run.sh
663
664
EXPOSE 80
665
CMD ./container-run.sh
666
667
668
# For documentation and experimental purposes only. As a
669
# reconstruction of the machine image that runs this application,
670
# there are lots of things missing here; but as a good Docker
671
# configuration, it fails by mixing together rather a lot of concerns.
672
673
FROM ubuntu:16.04
674
MAINTAINER Chris Cannam <cannam@all-day-breakfast.com>
675
676
RUN apt-get update && \
677
    apt-get install -y \
678
    apache2 \
679
    apache2-dev \
680
    apt-utils \
681
    build-essential \
682
    cron \
683
    curl \
684
    doxygen \
685
    exim4 \
686
    git \
687
    graphviz \
688
    imagemagick \
689
    libapache-dbi-perl \
690
    libapache2-mod-perl2 \
691
    libapr1-dev \
692
    libaprutil1-dev \
693
    libauthen-simple-ldap-perl \
694
    libcurl4-openssl-dev \
695
    libdbd-pg-perl \
696
    libpq-dev \
697
    libmagickwand-dev \
698
    libio-socket-ssl-perl \
699
    logrotate \
700
    mercurial \
701
    postgresql \
702
    rsync \
703
    ruby \
704
    ruby-dev \
705
    sudo
706
707
# Also used on the live site, for javadoc extraction, but this is
708
# would be by far the biggest package here: let's omit it while we're
709
# not making use of it
710
#   openjdk-9-jdk-headless
711
712
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
713
714
715
# Passenger gets installed through gem, not apt
716
717
RUN gem install passenger -v 4.0.60 --no-rdoc --no-ri
718
RUN passenger-install-apache2-module --languages=ruby
719
720
721
# Copy across webapp, set up ownership
722
723
COPY . /var/www/code
724
725
RUN groupadd code
726
RUN useradd -g code -G www-data code
727
RUN chown -R code.www-data /var/www/code
728
RUN find /var/www/code -type d -exec chmod g+s \{\} \;
729
730
731
# Initialise /var/hg (in reality this would be mounted from somewhere)
732
733
RUN mkdir -p /var/hg
734
RUN chown code.www-data /var/hg
735
RUN chmod g+s /var/hg
736
COPY extra/soundsoftware/scripted-deploy/config/index.cgi /var/hg/
737
COPY extra/soundsoftware/scripted-deploy/config/hgweb.config /var/hg/
738
RUN chmod +x /var/hg/index.cgi
739
740
741
# We're based in the code webapp directory from here on
742
743
WORKDIR /var/www/code
744
745
746
# Set up database config etc
747
748
RUN cp extra/soundsoftware/scripted-deploy/config/database.yml.interpolated config/database.yml
749
750
751
# Install Rails and dependencies (database.yml must be populated before this)
752
753
RUN gem install bundler
754
RUN bundle install
755
756
757
# Initialise Redmine token (bundler must be installed before this)
758
759
RUN bundle exec rake generate_secret_token
760
761
762
# Import Postgres database from postgres-dumpall file
763
764
RUN chown postgres postgres-dumpall
765
RUN /etc/init.d/postgresql start && sudo -u postgres psql -f postgres-dumpall postgres
766
RUN rm postgres-dumpall
767
768
769
# Install Perl auth module for Hg access
770
771
RUN mkdir -p /usr/local/lib/site_perl/Apache/Authn/
772
RUN cp extra/soundsoftware/SoundSoftware.pm /usr/local/lib/site_perl/Apache/Authn/
773
774
775
# Set up Apache config (todo: insert variables)
776
777
RUN rm -f /etc/apache2/sites-enabled/000-default.conf
778
779
RUN cp extra/soundsoftware/scripted-deploy/config/passenger.conf /etc/apache2/mods-available/
780
RUN cp extra/soundsoftware/scripted-deploy/config/passenger.load /etc/apache2/mods-available/
781
RUN cp extra/soundsoftware/scripted-deploy/config/perl.conf      /etc/apache2/mods-available/
782
783
RUN ln -s ../mods-available/passenger.conf  /etc/apache2/mods-enabled/
784
RUN ln -s ../mods-available/passenger.load  /etc/apache2/mods-enabled/
785
RUN ln -s ../mods-available/perl.conf       /etc/apache2/mods-enabled/
786
RUN ln -s ../mods-available/expires.load    /etc/apache2/mods-enabled/
787
RUN ln -s ../mods-available/rewrite.load    /etc/apache2/mods-enabled/
788
RUN ln -s ../mods-available/cgi.load        /etc/apache2/mods-enabled/
789
790
RUN cp extra/soundsoftware/scripted-deploy/config/code.conf.interpolated /etc/apache2/sites-available/code.conf
791
RUN ln -s ../sites-available/code.conf /etc/apache2/sites-enabled/10-code.conf
792
793
RUN apache2ctl configtest
794
795
796
# Start Postgres and foregrounded Apache
797
798
RUN echo "#!/bin/bash"                      > container-run.sh
799
RUN echo "/etc/init.d/postgresql start"    >> container-run.sh
800
RUN echo "apache2ctl -D FOREGROUND"        >> container-run.sh
801
RUN chmod +x container-run.sh
802
803
EXPOSE 80
804
CMD ./container-run.sh
805
806 1569:26a4f99ec679 Chris
#!/bin/bash
807
808 1586:d0d59d12db94 Chris
mydir=$(dirname "$0")
809 1593:83412a0a2389 Chris
. "$mydir"/../any/prepare.sh
810 1574:7b23adecd963 Chris
811 1587:d8949733849d Chris
provisioning_commands=$(
812 1590:c18460da6620 Chris
    for x in "$deploydir"/provision.d/[0-9]*.sh; do
813 1587:d8949733849d Chris
        echo "RUN /bin/bash /var/www/code/deploy/provision.d/$(basename $x)"
814
    done | sed 's/$/\\n/' | fmt -2000 | sed 's/ RUN/RUN/g' )
815
816
( echo
817
  echo "### DO NOT EDIT THIS FILE - it is generated from Dockerfile.in"
818
  echo
819
) > "$managerdir/Dockerfile"
820
821
cat "$managerdir/Dockerfile.in" |
822
    sed 's,INSERT_PROVISIONING_HERE,'"$provisioning_commands"',' >> \
823 1593:83412a0a2389 Chris
        "$managerdir/Dockerfile.gen"
824 1587:d8949733849d Chris
825 1586:d0d59d12db94 Chris
cd "$rootdir"
826
827 1569:26a4f99ec679 Chris
dockertag="cannam/soundsoftware-site"
828
829 1593:83412a0a2389 Chris
sudo docker build -t "$dockertag" -f "deploy/docker/Dockerfile.gen" .
830 1571:4c2b25b7e85f Chris
sudo docker run -p 8080:80 -d "$dockertag"
831 1569:26a4f99ec679 Chris
832 1577:e38eee2e1d47 Chris
#!/bin/bash
833
834
set -e
835
836 1589:94669513c53c Chris
# Install necessary system packages. This assumes we are deploying on
837
# Ubuntu 16.04.
838
839
# We aim to make all of these provisioning scripts non-destructive if
840
# run more than once. In this case, running the script again will
841
# install any outstanding updates.
842
843 1587:d8949733849d Chris
apt-get update && \
844
    apt-get dist-upgrade -y && \
845
    apt-get install -y \
846
            ack-grep \
847
            apache2 \
848
            apache2-dev \
849
            apt-utils \
850
            build-essential \
851
            cron \
852 1582:f26dc3004b3f Chris
            curl \
853
            doxygen \
854 1587:d8949733849d Chris
            exim4 \
855 1582:f26dc3004b3f Chris
            git \
856 1587:d8949733849d Chris
            graphviz \
857
            imagemagick \
858
            libapache-dbi-perl \
859
            libapache2-mod-perl2 \
860
            libapr1-dev \
861
            libaprutil1-dev \
862
            libauthen-simple-ldap-perl \
863
            libcurl4-openssl-dev \
864
            libdbd-pg-perl \
865
            libpq-dev \
866
            libmagickwand-dev \
867
            libio-socket-ssl-perl \
868
            logrotate \
869 1582:f26dc3004b3f Chris
            mercurial \
870 1600:ed9c467ef922 Chris
            mercurial-git \
871 1589:94669513c53c Chris
            openjdk-9-jdk-headless \
872 1582:f26dc3004b3f Chris
            postgresql \
873 1587:d8949733849d Chris
            rsync \
874
            ruby \
875
            ruby-dev \
876
            sudo
877 1582:f26dc3004b3f Chris
878 1587:d8949733849d Chris
locale-gen en_US.UTF-8
879 1582:f26dc3004b3f Chris
880
881 1577:e38eee2e1d47 Chris
#!/bin/bash
882
883
set -e
884
885 1589:94669513c53c Chris
# Phusion Passenger as application server.
886
# This gets installed through gem, not apt, and we ask for a specific
887
# version (the last in the 4.0.x line).
888 1577:e38eee2e1d47 Chris
889
if [ ! -f /var/lib/gems/2.3.0/gems/passenger-4.0.60/buildout/apache2/mod_passenger.so ]; then
890
    gem install passenger -v 4.0.60 --no-rdoc --no-ri
891
    passenger-install-apache2-module --languages=ruby
892
fi
893
894
#!/bin/bash
895
896
set -e
897
898 1590:c18460da6620 Chris
# The webapp directory is owned and run by the code user, in group
899
# www-data. The repos and other things served directly are the other
900
# way around -- owned by the www-data user, in group code.
901 1589:94669513c53c Chris
902 1590:c18460da6620 Chris
for user in code docgen ; do
903
    if ! grep -q "^$user:" /etc/passwd ; then
904
        groupadd "$user"
905
        useradd -g "$user" -G www-data "$user"
906
    fi
907
done
908 1577:e38eee2e1d47 Chris
909
#!/bin/bash
910
911
set -e
912
913 1589:94669513c53c Chris
# We might be running in one of two ways:
914
#
915
# 1. The code directory is already at /var/www/code, either because a
916
# previous provisioning step has imported it there or because this
917
# script has been run before -- in this situation all we do is
918
# re-check the ownership and permissions. OR
919
#
920
# 2. The code directory has not yet been copied to /var/www/code, in
921
# which case we expect to find it at /code-to-deploy, e.g. as a
922
# Vagrant shared folder, and we copy it over from there. (We don't
923
# deploy directly from shared folders as we might not be able to
924
# manipulate ownership and permissions properly there.)
925
926 1577:e38eee2e1d47 Chris
if [ ! -d /var/www/code ]; then
927 1587:d8949733849d Chris
    if [ ! -d /code-to-deploy ]; then
928 1589:94669513c53c Chris
        echo "ERROR: Expected to find code tree at /var/www/code or /code-to-deploy: is the deployment script being invoked correctly?"
929 1587:d8949733849d Chris
        exit 2
930
    fi
931
    cp -a /code-to-deploy /var/www/code
932 1577:e38eee2e1d47 Chris
fi
933
934 1587:d8949733849d Chris
chown -R code.www-data /var/www/code
935
find /var/www/code -type d -exec chmod g+s \{\} \;
936
937
938 1577:e38eee2e1d47 Chris
#!/bin/bash
939
940
set -e
941
942 1589:94669513c53c Chris
# In a real deployment, /var/hg is probably mounted from somewhere
943
# else. But in an empty deployment we need to create it, and in both
944
# cases we set up the config files with their current versions here.
945
946 1577:e38eee2e1d47 Chris
if [ ! -f /var/hg/index.cgi ]; then
947
    mkdir -p /var/hg
948
fi
949 1589:94669513c53c Chris
950
cp /var/www/code/deploy/config/index.cgi /var/hg/
951
cp /var/www/code/deploy/config/hgweb.config /var/hg/
952
953
chmod +x /var/hg/index.cgi
954
955 1590:c18460da6620 Chris
chown -R www-data.code /var/hg
956 1589:94669513c53c Chris
find /var/hg -type d -exec chmod g+s \{\} \;
957
958 1577:e38eee2e1d47 Chris
#!/bin/bash
959
960
set -e
961
962 1589:94669513c53c Chris
# Copy across the database config file (the source file has presumably
963
# been generated from a skeleton, earlier in provisioning)
964
965 1593:83412a0a2389 Chris
infile=/var/www/code/deploy/config/database.yml.gen
966 1589:94669513c53c Chris
outfile=/var/www/code/config/database.yml
967 1587:d8949733849d Chris
968 1589:94669513c53c Chris
if [ ! -f "$outfile" ]; then
969
    if [ ! -f "$infile" ]; then
970
        echo "ERROR: Database config file $infile not found - has the database secret been interpolated from $infile.in correctly?"
971
        exit 2
972
    fi
973
    cp "$infile" "$outfile"
974 1577:e38eee2e1d47 Chris
fi
975
976
#!/bin/bash
977
978
set -e
979
980 1589:94669513c53c Chris
# Install Ruby gems for the web app.
981
982
# We aim to make all of these provisioning scripts non-destructive if
983
# run more than once. In this case, running the script again will
984
# install any outstanding updates.
985
986 1577:e38eee2e1d47 Chris
cd /var/www/code
987
gem install bundler
988
bundle install
989
990
#!/bin/bash
991
992
set -e
993
994 1589:94669513c53c Chris
# Create a session token if it hasn't already been created.
995
996 1577:e38eee2e1d47 Chris
cd /var/www/code
997
998 1589:94669513c53c Chris
if [ ! -f config/initializers/secret_token.rb ]; then
999
    bundle exec rake generate_secret_token
1000
fi
1001
1002
1003 1577:e38eee2e1d47 Chris
#!/bin/bash
1004
1005
set -e
1006
1007 1589:94669513c53c Chris
# Start the database and if a dump file is found, load it. The dump
1008
# file is then deleted so that the db won't be overwritten on
1009
# subsequent runs. (The original repo contains no dump file, so it
1010
# should exist only if you have provided some data to load.)
1011
1012 1577:e38eee2e1d47 Chris
/etc/init.d/postgresql start
1013
1014
cd /var/www/code
1015
1016
if [ -f postgres-dumpall ]; then
1017
    chmod ugo+r postgres-dumpall
1018
    sudo -u postgres psql -f postgres-dumpall postgres
1019 1589:94669513c53c Chris
    rm postgres-dumpall
1020 1577:e38eee2e1d47 Chris
fi
1021
1022
#!/bin/bash
1023
1024
set -e
1025
1026 1589:94669513c53c Chris
# Install the Apache mod_perl module used for hg repo access control
1027
1028 1577:e38eee2e1d47 Chris
if [ ! -f /usr/local/lib/site_perl/Apache/Authn/SoundSoftware.pm ]; then
1029
    mkdir -p /usr/local/lib/site_perl/Apache/Authn/
1030 1589:94669513c53c Chris
    cp /var/www/code/extra/soundsoftware/SoundSoftware.pm \
1031
       /usr/local/lib/site_perl/Apache/Authn/
1032 1577:e38eee2e1d47 Chris
fi
1033
1034
#!/bin/bash
1035
1036
set -e
1037
1038 1589:94669513c53c Chris
# Install Apache config files and module loaders
1039
1040 1577:e38eee2e1d47 Chris
cd /var/www/code
1041
1042 1593:83412a0a2389 Chris
codeconffile=/var/www/code/deploy/config/code.conf.gen
1043 1587:d8949733849d Chris
1044
if [ ! -f "$codeconffile" ]; then
1045 1593:83412a0a2389 Chris
    echo "ERROR: Apache config file $codeconffile not found - has the database secret been interpolated from its input file correctly?"
1046 1587:d8949733849d Chris
    exit 2
1047
fi
1048
1049 1577:e38eee2e1d47 Chris
if [ ! -f /etc/apache2/sites-enabled/10-code.conf ]; then
1050
1051
    rm -f /etc/apache2/sites-enabled/000-default.conf
1052
1053 1587:d8949733849d Chris
    cp deploy/config/passenger.conf /etc/apache2/mods-available/
1054
    cp deploy/config/passenger.load /etc/apache2/mods-available/
1055
    cp deploy/config/perl.conf      /etc/apache2/mods-available/
1056 1577:e38eee2e1d47 Chris
1057
    ln -s ../mods-available/passenger.conf  /etc/apache2/mods-enabled/
1058
    ln -s ../mods-available/passenger.load  /etc/apache2/mods-enabled/
1059
    ln -s ../mods-available/perl.conf       /etc/apache2/mods-enabled/
1060
    ln -s ../mods-available/expires.load    /etc/apache2/mods-enabled/
1061
    ln -s ../mods-available/rewrite.load    /etc/apache2/mods-enabled/
1062 1578:06ca2df3d7ca Chris
    ln -s ../mods-available/cgi.load        /etc/apache2/mods-enabled/
1063 1577:e38eee2e1d47 Chris
1064 1587:d8949733849d Chris
    cp "$codeconffile" /etc/apache2/sites-available/code.conf
1065 1577:e38eee2e1d47 Chris
    ln -s ../sites-available/code.conf /etc/apache2/sites-enabled/10-code.conf
1066
1067
    apache2ctl configtest
1068
1069
fi
1070
1071 1588:9149f2098413 Chris
#!/bin/bash
1072
1073
set -e
1074
1075 1589:94669513c53c Chris
# In case we are running without a properly mounted /var/hg directory,
1076
# check for the existence of one repo and, if absent, attempt to clone
1077
# it so that we have something we can serve for test purposes.
1078
1079 1588:9149f2098413 Chris
if [ ! -d /var/hg/vamp-plugin-sdk ]; then
1080
    echo "Cloning vamp-plugin-sdk repo for testing..."
1081
    cd /var/hg
1082
    hg clone https://code.soundsoftware.ac.uk/hg/vamp-plugin-sdk
1083 1590:c18460da6620 Chris
    chown -R www-data.code vamp-plugin-sdk
1084 1588:9149f2098413 Chris
fi
1085 1598:073a75bf07fb Chris
#!/bin/bash
1086
1087
set -e
1088
1089
# Initialise directories used as targets for cron activity (if they
1090
# don't already exist)
1091
1092
# Reminder: the webapp directory is owned and run by the code user, in
1093
# group www-data. The repos and other things served directly are
1094
# usually the other way around -- owned by the www-data user, in group
1095
# code. I don't recall whether there is a good reason for this.
1096
1097
for dir in \
1098
    /var/files/backups \
1099
    /var/doc \
1100
    /var/files/git-mirror ; do
1101
    if [ ! -d "$dir" ]; then
1102
        mkdir -p "$dir"
1103
        chown -R code.www-data "$dir"
1104
        chmod g+s "$dir"
1105
    fi
1106
done
1107
1108
for dir in \
1109
    /var/mirror ; do
1110
    if [ ! -d "$dir" ]; then
1111
        mkdir -p "$dir"
1112
        chown -R www-data.code "$dir"
1113
        chmod g+s "$dir"
1114
    fi
1115
done
1116 1590:c18460da6620 Chris
#!/bin/bash
1117
1118
set -e
1119
1120 1596:45b0571b684d Chris
# Copy docgen scripts, including the generated scripts with
1121
# interpolated API key etc, to the directory they will be run from.
1122
1123
# These are run from cron jobs to do the (currently daily) update of
1124
# extracted documentation from Doxygen, Javadoc, and MATLAB, and to
1125
# enable displaying them with the redmine_embedded plugin. (The API
1126
# key is needed to automatically switch on the embedded module for a
1127
# project the first time its docs are extracted.)
1128 1590:c18460da6620 Chris
1129
cd /var/www/code
1130
1131
mkdir -p docgen
1132
1133
for file in \
1134
    doxysafe.pl \
1135
    extract-doxygen.sh \
1136
    extract-javadoc.sh \
1137
    extract-matlabdocs.sh \
1138
    matlab-docs.conf \
1139
    matlab-docs-credit.html \
1140
    matlab-docs.pl ; do
1141
    if [ ! -f docgen/"$file" ]; then
1142
        cp extra/soundsoftware/"$file" docgen/
1143
    fi
1144
done
1145
1146 1593:83412a0a2389 Chris
for file in \
1147
    extract-docs.sh ; do
1148
    if [ ! -f docgen/"$file" ]; then
1149
        cp deploy/config/"$file".gen docgen/"$file"
1150
    fi
1151
done
1152
1153 1590:c18460da6620 Chris
chown code.www-data docgen/*
1154
chmod +x docgen/*.sh
1155
1156
#!/bin/bash
1157
1158
set -e
1159
1160 1596:45b0571b684d Chris
# Copy reposman (repository manager) scripts, including the generated
1161
# scripts with interpolated API key etc, to the directory they will be
1162
# run from.
1163
1164
# There are two sets of scripts here:
1165
#
1166
# 1. The reposman script that plods through all the projects that have
1167
# repositories defined, creates those repositories on disc, and
1168
# registers their locations with the projects. This happens often,
1169
# currently every minute.
1170
#
1171
# 2. The external repo management script that plods through all the
1172
# projects that have external repositories defined, clones or updates
1173
# those external repos to their local locations, and if necessary
1174
# registers them with the projects. This happens less often, currently
1175
# every hour.
1176 1590:c18460da6620 Chris
1177
cd /var/www/code
1178
1179
mkdir -p reposman
1180
1181
for file in \
1182
    convert-external-repos.rb \
1183
    reposman-soundsoftware.rb \
1184
    run-hginit.sh \
1185
    update-external-repo.sh ; do
1186
    if [ ! -f reposman/"$file" ]; then
1187
        cp extra/soundsoftware/"$file" reposman/
1188
    fi
1189
done
1190
1191
for file in \
1192
    run-external.sh \
1193
    run-reposman.sh ; do
1194
    if [ ! -f reposman/"$file" ]; then
1195 1593:83412a0a2389 Chris
        cp deploy/config/"$file".gen reposman/"$file"
1196 1590:c18460da6620 Chris
    fi
1197
done
1198
1199
chown code.www-data reposman/*
1200
chmod +x reposman/*.sh
1201
chmod +x reposman/*.rb
1202
1203
touch /var/log/reposman.log
1204
touch /var/log/external-repos.log
1205
chown www-data.code /var/log/reposman.log
1206
chown www-data.code /var/log/external-repos.log
1207
1208
#!/bin/bash
1209
1210
set -e
1211
1212
# Copy cron scripts to the appropriate destinations
1213
1214
cd /var/www/code
1215
1216
if [ ! -d /etc/cron.minutely ]; then
1217
    mkdir -p /etc/cron.minutely
1218
    echo '*  *    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.minutely )' >> /etc/crontab
1219
fi
1220
1221
for t in minutely hourly daily monthly; do
1222
    for s in deploy/config/cron.$t/[0-9]* ; do
1223
        name=$(basename $s)
1224
        dest="/etc/cron.$t/$name"
1225
        if [ ! -f "$dest" ]; then
1226
            cp "$s" "$dest"
1227
            chmod +x "$dest"
1228
        fi
1229
    done
1230
done
1231
1232
1233
1234
#!/bin/bash
1235
1236
cd /var/www/code
1237
cp deploy/config/logrotate.conf /etc/logrotate.conf
1238 1601:07deb8466f65 Chris
#!/bin/bash
1239
1240
set -e
1241
1242
# Print reminders of the things that we haven't covered in the deploy
1243
# scripts
1244
1245
cat <<EOF
1246
1247
*** APACHE SSL CONFIGURATION
1248
1249
    The provisioning scripts set up a simple HTTP site only. Refer to
1250
    deploy/config/code-ssl.conf.in for an example HTTPS configuration
1251
    (you will of course need to provide the key/cert files).
1252
1253
*** EMAIL
1254
1255
    Outgoing email is required for notifications, but has not been
1256
    configured as part of this provisioning setup.
1257
1258
*** STATIC FRONT PAGE
1259
1260
    We have set up only the code/repository site -- if you want a
1261
    separate front page, remember to configure that!
1262
1263
EOF
1264 1581:ae8043b014c7 Chris
#!/bin/bash
1265
1266
set -e
1267
1268 1601:07deb8466f65 Chris
# Last action: check & start the webserver
1269
1270
apache2ctl configtest
1271 1589:94669513c53c Chris
1272 1581:ae8043b014c7 Chris
apache2ctl restart
1273
1274 1596:45b0571b684d Chris
#!/bin/bash
1275
1276
# The big problem with this test script is that it needs the cron
1277
# scripts that generate some of this stuff to have been run at least
1278
# once
1279
1280
usage() {
1281
    echo 1>&2
1282
    echo "Usage: $0 <uri-base>" 1>&2
1283
    echo 1>&2
1284
    echo "  e.g. $0 https://code.soundsoftware.ac.uk" 1>&2
1285
    echo "    or $0 http://localhost:8080" 1>&2
1286
    echo 1>&2
1287
    exit 2
1288
}
1289
1290
uribase="$1"
1291
if [ -z "$uribase" ]; then
1292
    usage
1293
fi
1294
1295
set -eu
1296
1297 1597:eeacb8332051 Chris
# A project known to exist, be public, and have a repository
1298
project_with_repo=vamp-plugin-sdk
1299
1300
# A project known to exist, be public, and have embedded documentation
1301
project_with_docs=vamp-plugin-sdk
1302
1303
# A project known to exist, be public, and have a bibliography
1304
project_with_biblio=sonic-visualiser
1305 1596:45b0571b684d Chris
1306
tried=0
1307
succeeded=0
1308
1309
mydir=$(dirname "$0")
1310
1311
try() {
1312
    mkdir -p "$mydir/output"
1313
    origin=$(pwd)
1314
    cd "$mydir/output"
1315
    path="$1"
1316
    description="$2"
1317
    url="$uribase$path"
1318
    echo
1319
    echo "Trying \"$description\" [$url]..."
1320
    echo
1321
    if wget "$url" ; then
1322
        echo "+++ Succeeded"
1323
        succeeded=$(($succeeded + 1))
1324
    else
1325
        echo "--- FAILED"
1326
    fi
1327 1597:eeacb8332051 Chris
    tried=$(($tried + 1))
1328
    cd "$origin"
1329 1596:45b0571b684d Chris
}
1330
1331
try "/" "Front page"
1332 1597:eeacb8332051 Chris
try "/projects/$project_with_repo" "Project page"
1333
try "/projects/$project_with_biblio" "Project page with bibliography"
1334
try "/projects/$project_with_repo/repository" "Repository page"
1335
try "/hg/$project_with_repo" "Mercurial repo"
1336
try "/projects/$project_with_docs/embedded" "Project documentation page (from docgen cron script)"
1337
try "/git/$project_with_repo/info/refs" "Git repo mirror"
1338 1596:45b0571b684d Chris
1339
echo
1340
echo "Passed $succeeded of $tried"
1341
echo
1342
1343 1577:e38eee2e1d47 Chris
# -*- mode: ruby -*-
1344
# vi: set ft=ruby :
1345
1346
Vagrant.configure("2") do |config|
1347 1583:0dcd4f8c2b8a Chris
  config.vm.box = "ubuntu/xenial64"
1348 1577:e38eee2e1d47 Chris
  config.vm.network "forwarded_port", guest: 80, host: 8080
1349 1587:d8949733849d Chris
  config.vm.synced_folder "../..", "/code-to-deploy"
1350 1577:e38eee2e1d47 Chris
  config.vm.provision :shell, path: "vagrant-provision.sh"
1351
end
1352 1581:ae8043b014c7 Chris
#!/bin/bash
1353
1354 1586:d0d59d12db94 Chris
mydir=$(dirname "$0")
1355 1593:83412a0a2389 Chris
. "$mydir"/../any/prepare.sh
1356 1581:ae8043b014c7 Chris
1357
cd "$managerdir"
1358
vagrant up
1359
1360 1577:e38eee2e1d47 Chris
#!/bin/bash
1361
1362
set -e
1363
1364 1590:c18460da6620 Chris
for f in /code-to-deploy/deploy/provision.d/[0-9]*.sh ; do
1365 1577:e38eee2e1d47 Chris
    case "$f" in
1366
        *~) ;;
1367 1593:83412a0a2389 Chris
        *) echo "Running provisioning script: $f"
1368 1577:e38eee2e1d47 Chris
           /bin/bash "$f";;
1369
    esac
1370
done
1371
1372 1593:83412a0a2389 Chris
echo "All provisioning scripts complete"