changeset 1589:94669513c53c dockerise

Docs etc
author Chris Cannam
date Thu, 17 Aug 2017 13:56:15 +0100
parents 9149f2098413
children c18460da6620
files deploy/provision.d/000-system-packages.sh deploy/provision.d/010-passenger.sh deploy/provision.d/020-users.sh deploy/provision.d/030-webapp-dir.sh deploy/provision.d/040-hg-dir.sh deploy/provision.d/050-webapp-db.sh deploy/provision.d/060-bundler.sh deploy/provision.d/070-secret-token.sh deploy/provision.d/080-database-load.sh deploy/provision.d/090-perl-auth-module.sh deploy/provision.d/100-apache-config.sh deploy/provision.d/110-hg-testdir.sh deploy/provision.d/200-apache-start.sh
diffstat 13 files changed, 82 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/deploy/provision.d/000-system-packages.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/000-system-packages.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,6 +2,13 @@
 
 set -e
 
+# Install necessary system packages. This assumes we are deploying on
+# Ubuntu 16.04.
+
+# We aim to make all of these provisioning scripts non-destructive if
+# run more than once. In this case, running the script again will
+# install any outstanding updates.
+
 apt-get update && \
     apt-get dist-upgrade -y && \
     apt-get install -y \
@@ -29,6 +36,7 @@
             libio-socket-ssl-perl \
             logrotate \
             mercurial \
+            openjdk-9-jdk-headless \
             postgresql \
             rsync \
             ruby \
--- a/deploy/provision.d/010-passenger.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/010-passenger.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,7 +2,9 @@
 
 set -e
 
-# Passenger gets installed through gem, not apt
+# Phusion Passenger as application server.
+# This gets installed through gem, not apt, and we ask for a specific
+# version (the last in the 4.0.x line).
 
 if [ ! -f /var/lib/gems/2.3.0/gems/passenger-4.0.60/buildout/apache2/mod_passenger.so ]; then
     gem install passenger -v 4.0.60 --no-rdoc --no-ri
--- a/deploy/provision.d/020-users.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/020-users.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,6 +2,9 @@
 
 set -e
 
+# The "code" user (in group www-data) owns the site and repo
+# directories.
+
 if ! grep -q '^code:' /etc/passwd ; then
     groupadd code
     useradd -g code -G www-data code
--- a/deploy/provision.d/030-webapp-dir.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/030-webapp-dir.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,9 +2,22 @@
 
 set -e
 
+# We might be running in one of two ways:
+#
+# 1. The code directory is already at /var/www/code, either because a
+# previous provisioning step has imported it there or because this
+# script has been run before -- in this situation all we do is
+# re-check the ownership and permissions. OR
+#
+# 2. The code directory has not yet been copied to /var/www/code, in
+# which case we expect to find it at /code-to-deploy, e.g. as a
+# Vagrant shared folder, and we copy it over from there. (We don't
+# deploy directly from shared folders as we might not be able to
+# manipulate ownership and permissions properly there.)
+
 if [ ! -d /var/www/code ]; then
     if [ ! -d /code-to-deploy ]; then
-        echo "ERROR: Expected to find code tree at /code-to-deploy: is the deployment script being invoked correctly?"
+        echo "ERROR: Expected to find code tree at /var/www/code or /code-to-deploy: is the deployment script being invoked correctly?"
         exit 2
     fi
     cp -a /code-to-deploy /var/www/code
--- a/deploy/provision.d/040-hg-dir.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/040-hg-dir.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,11 +2,19 @@
 
 set -e
 
+# In a real deployment, /var/hg is probably mounted from somewhere
+# else. But in an empty deployment we need to create it, and in both
+# cases we set up the config files with their current versions here.
+
 if [ ! -f /var/hg/index.cgi ]; then
     mkdir -p /var/hg
-    chown code.www-data /var/hg
-    chmod g+s /var/hg
-    cp /var/www/code/deploy/config/index.cgi /var/hg/
-    cp /var/www/code/deploy/config/hgweb.config /var/hg/
-    chmod +x /var/hg/index.cgi
 fi
+
+cp /var/www/code/deploy/config/index.cgi /var/hg/
+cp /var/www/code/deploy/config/hgweb.config /var/hg/
+
+chmod +x /var/hg/index.cgi
+
+chown -R code.www-data /var/hg
+find /var/hg -type d -exec chmod g+s \{\} \;
+
--- a/deploy/provision.d/050-webapp-db.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/050-webapp-db.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,14 +2,17 @@
 
 set -e
 
+# Copy across the database config file (the source file has presumably
+# been generated from a skeleton, earlier in provisioning)
+
 infile=/var/www/code/deploy/config/database.yml
+outfile=/var/www/code/config/database.yml
 
-if [ ! -f "$infile" ]; then
-    echo "ERROR: Database config file $infile not found - has the database secret been interpolated from $infile.in correctly?"
-    exit 2
+if [ ! -f "$outfile" ]; then
+    if [ ! -f "$infile" ]; then
+        echo "ERROR: Database config file $infile not found - has the database secret been interpolated from $infile.in correctly?"
+        exit 2
+    fi
+    cp "$infile" "$outfile"
 fi
 
-if [ ! -f /var/www/code/config/database.yml ]; then
-    cp "$infile" /var/www/code/config/database.yml
-fi
-
--- a/deploy/provision.d/060-bundler.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/060-bundler.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,6 +2,12 @@
 
 set -e
 
+# Install Ruby gems for the web app.
+
+# We aim to make all of these provisioning scripts non-destructive if
+# run more than once. In this case, running the script again will
+# install any outstanding updates.
+
 cd /var/www/code
 gem install bundler
 bundle install
--- a/deploy/provision.d/070-secret-token.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/070-secret-token.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,6 +2,12 @@
 
 set -e
 
+# Create a session token if it hasn't already been created.
+
 cd /var/www/code
-bundle exec rake generate_secret_token
 
+if [ ! -f config/initializers/secret_token.rb ]; then
+    bundle exec rake generate_secret_token
+fi
+
+
--- a/deploy/provision.d/080-database-load.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/080-database-load.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,6 +2,11 @@
 
 set -e
 
+# Start the database and if a dump file is found, load it. The dump
+# file is then deleted so that the db won't be overwritten on
+# subsequent runs. (The original repo contains no dump file, so it
+# should exist only if you have provided some data to load.)
+
 /etc/init.d/postgresql start
 
 cd /var/www/code
@@ -9,8 +14,6 @@
 if [ -f postgres-dumpall ]; then
     chmod ugo+r postgres-dumpall
     sudo -u postgres psql -f postgres-dumpall postgres
-    rm postgres-dumpall # This was just a copy of the shared folder file anyway
+    rm postgres-dumpall
 fi
 
-
-
--- a/deploy/provision.d/090-perl-auth-module.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/090-perl-auth-module.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,8 +2,11 @@
 
 set -e
 
+# Install the Apache mod_perl module used for hg repo access control
+
 if [ ! -f /usr/local/lib/site_perl/Apache/Authn/SoundSoftware.pm ]; then
     mkdir -p /usr/local/lib/site_perl/Apache/Authn/
-    cp /var/www/code/extra/soundsoftware/SoundSoftware.pm /usr/local/lib/site_perl/Apache/Authn/
+    cp /var/www/code/extra/soundsoftware/SoundSoftware.pm \
+       /usr/local/lib/site_perl/Apache/Authn/
 fi
 
--- a/deploy/provision.d/100-apache-config.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/100-apache-config.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,6 +2,8 @@
 
 set -e
 
+# Install Apache config files and module loaders
+
 cd /var/www/code
 
 codeconffile=/var/www/code/deploy/config/code.conf
--- a/deploy/provision.d/110-hg-testdir.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/110-hg-testdir.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,8 +2,11 @@
 
 set -e
 
+# In case we are running without a properly mounted /var/hg directory,
+# check for the existence of one repo and, if absent, attempt to clone
+# it so that we have something we can serve for test purposes.
+
 if [ ! -d /var/hg/vamp-plugin-sdk ]; then
-    # This project can be used for testing
     echo "Cloning vamp-plugin-sdk repo for testing..."
     cd /var/hg
     hg clone https://code.soundsoftware.ac.uk/hg/vamp-plugin-sdk
--- a/deploy/provision.d/200-apache-start.sh	Thu Aug 17 12:06:04 2017 +0100
+++ b/deploy/provision.d/200-apache-start.sh	Thu Aug 17 13:56:15 2017 +0100
@@ -2,5 +2,7 @@
 
 set -e
 
+# Last action: start the webserver
+
 apache2ctl restart