Revision 1581:ae8043b014c7 extra/soundsoftware/scripted-deploy

View differences:

extra/soundsoftware/scripted-deploy/config/code.conf
1

  
2
# A test Apache config. Lacks SSL, lacks a desirable extra layer of
3
# authentication for admin interface paths. Do not deploy this.
4

  
5
PerlLoadModule Apache::Authn::SoundSoftware
6

  
7
<VirtualHost *:80>
8
        ServerName code.soundsoftware.ac.uk
9
        ServerAdmin chris.cannam@soundsoftware.ac.uk
10

  
11
        DocumentRoot /var/www/code/public
12
        PassengerRestartDir restart_files
13
        PassengerHighPerformance on
14
        PassengerMaxRequests 50000
15
        PassengerStatThrottleRate 5
16
	PassengerStartTimeout 60
17
	PassengerFriendlyErrorPages on
18
        RailsSpawnMethod smart
19
        ExpiresDefault "access plus 1 minute"
20

  
21
        <DirectoryMatch "^/.*/\.svn/">
22
                Order allow,deny
23
                Deny from all
24
                Satisfy All
25
        </DirectoryMatch>
26

  
27
        <DirectoryMatch "^/.*/\.hg/">
28
                Order allow,deny
29
                Deny from all
30
                Satisfy All
31
        </DirectoryMatch>
32

  
33
        <DirectoryMatch "^/.*/\.git/">
34
                Order allow,deny
35
                Deny from all
36
                Satisfy All
37
        </DirectoryMatch>
38

  
39
        <Directory /var/www/code/public>
40
                Options -MultiViews
41
	</Directory>
42

  
43
        <Directory /var/www/code/public/themes/soundsoftware/stylesheets/fonts>
44
		# Avoid other sites embedding our fonts
45
		RewriteEngine on
46
		RewriteCond %{HTTP_REFERER} !^$
47
		RewriteCond %{HTTP_REFERER} !^http(s)?://code.soundsoftware.ac.uk/.*$ [NC]
48
		RewriteRule \.(ttf|woff|eot|otf|svg|zip|gz|html|txt)$ - [F]
49
	</Directory>
50

  
51
	ScriptAlias /hg "/var/hg/index.cgi"
52

  
53
	<Location /hg>
54
               	AuthName "Mercurial"
55
                AuthType Basic
56
                Require valid-user
57
		PerlAccessHandler Apache::Authn::SoundSoftware::access_handler
58
      		PerlAuthenHandler Apache::Authn::SoundSoftware::authen_handler
59
		PerlSetVar HTTPS "on"
60
		SoundSoftwareDSN "dbi:Pg:database=code;host=localhost"
61
    		SoundSoftwareDbUser "code"
62
     		SoundSoftwareDbPass "INSERT_POSTGRES_PASSWORD_HERE"
63
		SoundSoftwareRepoPrefix "/var/hg/"
64
                #!!! "on" in production please!:
65
                SoundSoftwareSslRequired "off"
66
		Options +ExecCGI
67
		AddHandler cgi-script .cgi
68
		ExpiresDefault now
69
        </Location>
70

  
71
	Alias /git "/var/files/git-mirror"	
72

  
73
	<Directory "/var/files/git-mirror">
74
		Options -Indexes +FollowSymLinks
75
                Order allow,deny
76
                Allow from all
77
	</Directory>
78
	<Directory ~ "/var/files/git-mirror/.*\.workdir">
79
		Order allow,deny
80
		Deny from all
81
	</Directory>
82
	<Directory ~ "/var/files/git-mirror/__.*">
83
                Order allow,deny
84
                Deny from all
85
	</Directory>
86

  
87
	ErrorLog /var/log/apache2/code-error.log
88
	CustomLog /var/log/apache2/code-access.log vhost_combined
89

  
90
        LogLevel warn
91
        ServerSignature Off
92
        
93
</VirtualHost>
94

  
extra/soundsoftware/scripted-deploy/config/database.yml
1
production:
2
  adapter: postgresql
3
  database: code
4
  host: localhost
5
  username: code
6
  password: "INSERT_POSTGRES_PASSWORD_HERE"
7

  
extra/soundsoftware/scripted-deploy/config/hgweb.config
1
[paths]
2
/ = /var/hg/*
3

  
4
[web]
5
allow_archive = gz, zip, bz2
6
allow_push = *
extra/soundsoftware/scripted-deploy/config/index.cgi
1
#!/usr/bin/env python
2
#
3
# An example CGI script to export multiple hgweb repos, edit as necessary
4

  
5
# adjust python path if not a system-wide install:
6
#import sys
7
#sys.path.insert(0, "/path/to/python/lib")
8

  
9
# enable importing on demand to reduce startup time
10
from mercurial import demandimport; demandimport.enable()
11

  
12
# Uncomment to send python tracebacks to the browser if an error occurs:
13
import cgitb
14
cgitb.enable()
15

  
16
# If you'd like to serve pages with UTF-8 instead of your default
17
# locale charset, you can do so by uncommenting the following lines.
18
# Note that this will cause your .hgrc files to be interpreted in
19
# UTF-8 and all your repo files to be displayed using UTF-8.
20
#
21
import os
22
os.environ["HGENCODING"] = "UTF-8"
23

  
24
from mercurial.hgweb.hgwebdir_mod import hgwebdir
25
import mercurial.hgweb.wsgicgi as wsgicgi
26

  
27
# The config file looks like this.  You can have paths to individual
28
# repos, collections of repos in a directory tree, or both.
29
#
30
# [paths]
31
# virtual/path1 = /real/path1
32
# virtual/path2 = /real/path2
33
# virtual/root = /real/root/*
34
# / = /real/root2/*
35
# virtual/root2 = /real/root2/**
36
#
37
# [collections]
38
# /prefix/to/strip/off = /root/of/tree/full/of/repos
39
#
40
# paths example: 
41
#
42
# * First two lines mount one repository into one virtual path, like
43
# '/real/path1' into 'virtual/path1'.
44
#
45
# * The third entry mounts every mercurial repository found in '/real/root'
46
# in 'virtual/root'. This format is preferred over the [collections] one,
47
# since using absolute paths as configuration keys is not supported on every
48
# platform (especially on Windows).
49
#
50
# * The fourth entry is a special case mounting all repositories in
51
# /'real/root2' in the root of the virtual directory.
52
#
53
# * The fifth entry recursively finds all repositories under the real root,
54
# and mounts them using their relative path (to given real root) under the
55
# virtual root.
56
#
57
# collections example: say directory tree /foo contains repos /foo/bar,
58
# /foo/quux/baz.  Give this config section:
59
#   [collections]
60
#   /foo = /foo
61
# Then repos will list as bar and quux/baz.
62
#
63
# Alternatively you can pass a list of ('virtual/path', '/real/path') tuples
64
# or use a dictionary with entries like 'virtual/path': '/real/path'
65

  
66
application = hgwebdir('hgweb.config')
67
wsgicgi.launch(application)
extra/soundsoftware/scripted-deploy/config/passenger.conf
1
PassengerMaxPoolSize 60
2

  
extra/soundsoftware/scripted-deploy/config/passenger.load
1
LoadModule passenger_module /var/lib/gems/2.3.0/gems/passenger-4.0.60/buildout/apache2/mod_passenger.so
2
PassengerRoot /var/lib/gems/2.3.0/gems/passenger-4.0.60
3
PassengerDefaultRuby /usr/bin/ruby2.3
extra/soundsoftware/scripted-deploy/config/perl.conf
1
# Apache::DBI is supposed to be a transparent replacement for Perl DBI with
2
# better performance when multiple connections are made with common DSN, user
3
# and password
4
PerlModule Apache::DBI
extra/soundsoftware/scripted-deploy/docker/Dockerfile
1

  
2
# For documentation and experimental purposes only. As a
3
# reconstruction of the machine image that runs this application,
4
# there are lots of things missing here; but as a good Docker
5
# configuration, it fails by mixing together rather a lot of concerns.
6

  
7
FROM ubuntu:16.04
8
MAINTAINER Chris Cannam <cannam@all-day-breakfast.com>
9

  
10
RUN apt-get update && \
11
    apt-get install -y \
12
    apache2 \
13
    apache2-dev \
14
    apt-utils \
15
    build-essential \
16
    cron \
17
    curl \
18
    doxygen \
19
    exim4 \
20
    git \
21
    graphviz \
22
    imagemagick \
23
    libapache-dbi-perl \
24
    libapache2-mod-perl2 \
25
    libapr1-dev \
26
    libaprutil1-dev \
27
    libauthen-simple-ldap-perl \
28
    libcurl4-openssl-dev \
29
    libdbd-pg-perl \
30
    libpq-dev \
31
    libmagickwand-dev \
32
    libio-socket-ssl-perl \
33
    logrotate \
34
    mercurial \
35
    postgresql \
36
    rsync \
37
    ruby \
38
    ruby-dev \
39
    sudo
40

  
41
# Also used on the live site, for javadoc extraction, but this is
42
# would be by far the biggest package here: let's omit it while we're
43
# not making use of it
44
#   openjdk-9-jdk-headless
45

  
46
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
47

  
48

  
49
# Passenger gets installed through gem, not apt
50

  
51
RUN gem install passenger -v 4.0.60 --no-rdoc --no-ri
52
RUN passenger-install-apache2-module --languages=ruby
53

  
54

  
55
# Copy across webapp, set up ownership
56

  
57
COPY . /var/www/code
58

  
59
RUN groupadd code
60
RUN useradd -g code -G www-data code
61
RUN chown -R code.www-data /var/www/code
62
RUN find /var/www/code -type d -exec chmod g+s \{\} \;
63

  
64

  
65
# Initialise /var/hg (in reality this would be mounted from somewhere)
66

  
67
RUN mkdir -p /var/hg
68
RUN chown code.www-data /var/hg
69
RUN chmod g+s /var/hg
70
COPY extra/soundsoftware/scripted-deploy/config/index.cgi /var/hg/
71
COPY extra/soundsoftware/scripted-deploy/config/hgweb.config /var/hg/
72
RUN chmod +x /var/hg/index.cgi
73

  
74

  
75
# We're based in the code webapp directory from here on
76

  
77
WORKDIR /var/www/code
78

  
79

  
80
# Set up database config etc
81

  
82
RUN cp extra/soundsoftware/scripted-deploy/config/database.yml.interpolated config/database.yml
83

  
84

  
85
# Install Rails and dependencies (database.yml must be populated before this)
86

  
87
RUN gem install bundler
88
RUN bundle install
89

  
90

  
91
# Initialise Redmine token (bundler must be installed before this)
92

  
93
RUN bundle exec rake generate_secret_token
94

  
95

  
96
# Import Postgres database from postgres-dumpall file
97

  
98
RUN chown postgres postgres-dumpall
99
RUN /etc/init.d/postgresql start && sudo -u postgres psql -f postgres-dumpall postgres
100
RUN rm postgres-dumpall
101

  
102

  
103
# Install Perl auth module for Hg access
104

  
105
RUN mkdir -p /usr/local/lib/site_perl/Apache/Authn/
106
RUN cp extra/soundsoftware/SoundSoftware.pm /usr/local/lib/site_perl/Apache/Authn/
107

  
108

  
109
# Set up Apache config (todo: insert variables)
110

  
111
RUN rm -f /etc/apache2/sites-enabled/000-default.conf
112

  
113
RUN cp extra/soundsoftware/scripted-deploy/config/passenger.conf /etc/apache2/mods-available/
114
RUN cp extra/soundsoftware/scripted-deploy/config/passenger.load /etc/apache2/mods-available/
115
RUN cp extra/soundsoftware/scripted-deploy/config/perl.conf      /etc/apache2/mods-available/
116

  
117
RUN ln -s ../mods-available/passenger.conf  /etc/apache2/mods-enabled/
118
RUN ln -s ../mods-available/passenger.load  /etc/apache2/mods-enabled/
119
RUN ln -s ../mods-available/perl.conf       /etc/apache2/mods-enabled/
120
RUN ln -s ../mods-available/expires.load    /etc/apache2/mods-enabled/
121
RUN ln -s ../mods-available/rewrite.load    /etc/apache2/mods-enabled/
122
RUN ln -s ../mods-available/cgi.load        /etc/apache2/mods-enabled/
123

  
124
RUN cp extra/soundsoftware/scripted-deploy/config/code.conf.interpolated /etc/apache2/sites-available/code.conf
125
RUN ln -s ../sites-available/code.conf /etc/apache2/sites-enabled/10-code.conf
126

  
127
RUN apache2ctl configtest
128

  
129

  
130
# Start Postgres and foregrounded Apache
131

  
132
RUN echo "#!/bin/bash"                      > container-run.sh
133
RUN echo "/etc/init.d/postgresql start"    >> container-run.sh
134
RUN echo "apache2ctl -D FOREGROUND"        >> container-run.sh
135
RUN chmod +x container-run.sh
136

  
137
EXPOSE 80
138
CMD ./container-run.sh
139

  
extra/soundsoftware/scripted-deploy/docker/start.sh
1
#!/bin/bash
2

  
3
dbpwd="$1"
4
if [ -z "$dbpwd" ]; then
5
    echo "Usage: $0 <database-password>" 1>&2
6
    exit 2
7
fi
8

  
9
set -eu
10

  
11
deploydir=./extra/soundsoftware/scripted-deploy
12
if [ ! -d "$deploydir" ]; then
13
    echo "Run this script from the root of a working copy of soundsoftware-site"
14
    exit 2
15
fi
16

  
17
managerdir="$deploydir/docker"
18
if [ ! -d "$managerdir" ]; then
19
    echo "ERROR: Required directory $managerdir not found"
20
    exit 2
21
fi
22

  
23
configdir="$deploydir/config"
24
if [ ! -d "$configdir" ]; then
25
    echo "ERROR: Required directory $configdir not found"
26
    exit 2
27
fi
28

  
29
if [ ! -f "postgres-dumpall" ]; then
30
    echo "ERROR: I expect to find a Postgres SQL multi-db dump file in ./postgres-dumpall"
31
    exit 2
32
fi
33

  
34
for f in database.yml code.conf ; do
35
    cat "$configdir/$f" |
36
        sed 's/INSERT_POSTGRES_PASSWORD_HERE/'"$dbpwd"'/g' > \
37
            "$configdir/$f.interpolated"
38
done
39

  
40
dockertag="cannam/soundsoftware-site"
41

  
42
sudo docker build -t "$dockertag" -f "$managerdir/Dockerfile" .
43
sudo docker run -p 8080:80 -d "$dockertag"
44

  
extra/soundsoftware/scripted-deploy/vagrant/Vagrantfile
1
# -*- mode: ruby -*-
2
# vi: set ft=ruby :
3

  
4
Vagrant.configure("2") do |config|
5
  config.vm.box = "ubuntu/xenial64"
6
  config.vm.network "forwarded_port", guest: 80, host: 8080
7
  config.vm.synced_folder "../../../..", "/vagrant-code"
8
  config.vm.provision :shell, path: "vagrant-provision.sh"
9
end
extra/soundsoftware/scripted-deploy/vagrant/provision.d/000-apt.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
apt-get update && \
6
    apt-get dist-upgrade -y && \
7
    apt-get install -y \
8
    ack-grep \
9
    apache2 \
10
    apache2-dev \
11
    apt-utils \
12
    build-essential \
13
    cron \
14
    curl \
15
    doxygen \
16
    exim4 \
17
    git \
18
    graphviz \
19
    imagemagick \
20
    libapache-dbi-perl \
21
    libapache2-mod-perl2 \
22
    libapr1-dev \
23
    libaprutil1-dev \
24
    libauthen-simple-ldap-perl \
25
    libcurl4-openssl-dev \
26
    libdbd-pg-perl \
27
    libpq-dev \
28
    libmagickwand-dev \
29
    libio-socket-ssl-perl \
30
    logrotate \
31
    mercurial \
32
    postgresql \
33
    rsync \
34
    ruby \
35
    ruby-dev \
36
    sudo
extra/soundsoftware/scripted-deploy/vagrant/provision.d/010-passenger.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
# Passenger gets installed through gem, not apt
6

  
7
if [ ! -f /var/lib/gems/2.3.0/gems/passenger-4.0.60/buildout/apache2/mod_passenger.so ]; then
8
    gem install passenger -v 4.0.60 --no-rdoc --no-ri
9
    passenger-install-apache2-module --languages=ruby
10
fi
11

  
extra/soundsoftware/scripted-deploy/vagrant/provision.d/020-users.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
if ! grep -q '^code:' /etc/passwd ; then
6
    groupadd code
7
    useradd -g code -G www-data code
8
fi
9

  
extra/soundsoftware/scripted-deploy/vagrant/provision.d/030-webapp-dir.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
if [ ! -d /var/www/code ]; then
6
    cp -a /vagrant-code /var/www/code
7
    chown -R code.www-data /var/www/code
8
    find /var/www/code -type d -exec chmod g+s \{\} \;
9
fi
10

  
extra/soundsoftware/scripted-deploy/vagrant/provision.d/040-hg-dir.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
if [ ! -f /var/hg/index.cgi ]; then
6
    mkdir -p /var/hg
7
    chown code.www-data /var/hg
8
    chmod g+s /var/hg
9
    cp /var/www/code/extra/soundsoftware/scripted-deploy/config/index.cgi /var/hg/
10
    cp /var/www/code/extra/soundsoftware/scripted-deploy/config/hgweb.config /var/hg/
11
    chmod +x /var/hg/index.cgi
12
fi
13

  
14
if [ ! -d /var/hg/vamp-plugin-sdk ]; then
15
    # This project can be used for testing
16
    cd /var/hg
17
    hg clone https://code.soundsoftware.ac.uk/hg/vamp-plugin-sdk
18
    chown -R code.www-data vamp-plugin-sdk
19
fi
extra/soundsoftware/scripted-deploy/vagrant/provision.d/050-webapp-db.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
if [ ! -f /var/www/code/config/database.yml ]; then
6
    cp /var/www/code/extra/soundsoftware/scripted-deploy/config/database.yml.interpolated \
7
       /var/www/code/config/database.yml
8
fi
9

  
extra/soundsoftware/scripted-deploy/vagrant/provision.d/060-bundler.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
cd /var/www/code
6
gem install bundler
7
bundle install
8

  
extra/soundsoftware/scripted-deploy/vagrant/provision.d/070-secret-token.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
cd /var/www/code
6
bundle exec rake generate_secret_token
7

  
extra/soundsoftware/scripted-deploy/vagrant/provision.d/080-database-load.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
/etc/init.d/postgresql start
6

  
7
cd /var/www/code
8

  
9
if [ -f postgres-dumpall ]; then
10
    chmod ugo+r postgres-dumpall
11
    sudo -u postgres psql -f postgres-dumpall postgres
12
    rm postgres-dumpall # This was just a copy of the shared folder file anyway
13
fi
14

  
15

  
16

  
extra/soundsoftware/scripted-deploy/vagrant/provision.d/090-perl-auth-module.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
if [ ! -f /usr/local/lib/site_perl/Apache/Authn/SoundSoftware.pm ]; then
6
    mkdir -p /usr/local/lib/site_perl/Apache/Authn/
7
    cp /var/www/code/extra/soundsoftware/SoundSoftware.pm /usr/local/lib/site_perl/Apache/Authn/
8
fi
9

  
extra/soundsoftware/scripted-deploy/vagrant/provision.d/100-apache-config.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
cd /var/www/code
6

  
7
if [ ! -f /etc/apache2/sites-enabled/10-code.conf ]; then
8
    
9
    rm -f /etc/apache2/sites-enabled/000-default.conf
10

  
11
    cp extra/soundsoftware/scripted-deploy/config/passenger.conf /etc/apache2/mods-available/
12
    cp extra/soundsoftware/scripted-deploy/config/passenger.load /etc/apache2/mods-available/
13
    cp extra/soundsoftware/scripted-deploy/config/perl.conf      /etc/apache2/mods-available/
14

  
15
    ln -s ../mods-available/passenger.conf  /etc/apache2/mods-enabled/
16
    ln -s ../mods-available/passenger.load  /etc/apache2/mods-enabled/
17
    ln -s ../mods-available/perl.conf       /etc/apache2/mods-enabled/
18
    ln -s ../mods-available/expires.load    /etc/apache2/mods-enabled/
19
    ln -s ../mods-available/rewrite.load    /etc/apache2/mods-enabled/
20
    ln -s ../mods-available/cgi.load        /etc/apache2/mods-enabled/
21

  
22
    cp extra/soundsoftware/scripted-deploy/config/code.conf.interpolated /etc/apache2/sites-available/code.conf
23
    ln -s ../sites-available/code.conf /etc/apache2/sites-enabled/10-code.conf
24

  
25
    apache2ctl configtest
26

  
27
fi
28

  
extra/soundsoftware/scripted-deploy/vagrant/provision.d/110-apache-start.sh
1
#!/bin/bash
2

  
3
set -e
4

  
5
apache2ctl restart
6

  
extra/soundsoftware/scripted-deploy/vagrant/start.sh
1
#!/bin/bash
2

  
3
dbpwd="$1"
4
if [ -z "$dbpwd" ]; then
5
    echo "Usage: $0 <database-password>" 1>&2
6
    exit 2
7
fi
8

  
9
set -eu
10

  
11
deploydir=./extra/soundsoftware/scripted-deploy
12
if [ ! -d "$deploydir" ]; then
13
    echo "Run this script from the root of a working copy of soundsoftware-site"
14
    exit 2
15
fi
16

  
17
managerdir="$deploydir/vagrant"
18
if [ ! -d "$managerdir" ]; then
19
    echo "ERROR: Required directory $managerdir not found"
20
    exit 2
21
fi
22

  
23
configdir="$deploydir/config"
24
if [ ! -d "$configdir" ]; then
25
    echo "ERROR: Required directory $configdir not found"
26
    exit 2
27
fi
28

  
29
if [ ! -f "postgres-dumpall" ]; then
30
    echo "ERROR: I expect to find a Postgres SQL multi-db dump file in ./postgres-dumpall"
31
    exit 2
32
fi
33

  
34
for f in database.yml code.conf ; do
35
    cat "$configdir/$f" |
36
        sed 's/INSERT_POSTGRES_PASSWORD_HERE/'"$dbpwd"'/g' > \
37
            "$configdir/$f.interpolated"
38
done
39

  
40
cd "$managerdir"
41

  
42
vagrant up
43

  
extra/soundsoftware/scripted-deploy/vagrant/vagrant-provision.sh
1
#!/bin/bash
2

  
3
#!!! still not covered:
4
# * cron jobs
5
# * https
6
# * web fonts
7

  
8
set -e
9

  
10
for f in /vagrant/provision.d/[0-9]* ; do
11
    case "$f" in
12
        *~) ;;
13
        *) echo "Running provision script: $f"
14
           /bin/bash "$f";;
15
    esac
16
done
17

  

Also available in: Unified diff