To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / extra / soundsoftware / dockertest @ 1574:7b23adecd963
| 1 | 1570:ae2f71010562 | Chris | |
|---|---|---|---|
| 2 | # For documentation and experimental purposes only. As a |
||
| 3 | # reconstruction of the machine image that runs this application, |
||
| 4 | 1573:8edb54e29f00 | Chris | # 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 | 1570:ae2f71010562 | Chris | |
| 7 | 1569:26a4f99ec679 | Chris | FROM ubuntu:16.04 |
| 8 | MAINTAINER Chris Cannam <cannam@all-day-breakfast.com> |
||
| 9 | 1570:ae2f71010562 | Chris | |
| 10 | 1569:26a4f99ec679 | Chris | RUN apt-get update && \ |
| 11 | apt-get install -y \ |
||
| 12 | 1570:ae2f71010562 | Chris | apache2 \ |
| 13 | apache2-dev \ |
||
| 14 | apt-utils \ |
||
| 15 | 1569:26a4f99ec679 | Chris | build-essential \ |
| 16 | 1570:ae2f71010562 | Chris | 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 | 1572:2b1b8ebb7d98 | Chris | sudo |
| 40 | |||
| 41 | 1573:8edb54e29f00 | Chris | # 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 | 1572:2b1b8ebb7d98 | Chris | RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
| 47 | 1570:ae2f71010562 | Chris | |
| 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 | 1569:26a4f99ec679 | Chris | RUN groupadd code |
| 60 | RUN useradd -g code -G www-data code |
||
| 61 | RUN chown -R code.www-data /var/www/code |
||
| 62 | 1570:ae2f71010562 | Chris | RUN find /var/www/code -type d -exec chmod g+s \{\} \;
|
| 63 | |||
| 64 | |||
| 65 | # We're based in the code webapp directory from here on |
||
| 66 | |||
| 67 | 1569:26a4f99ec679 | Chris | WORKDIR /var/www/code |
| 68 | 1570:ae2f71010562 | Chris | |
| 69 | |||
| 70 | 1574:7b23adecd963 | Chris | # Set up database config etc |
| 71 | 1570:ae2f71010562 | Chris | |
| 72 | 1574:7b23adecd963 | Chris | RUN cp extra/soundsoftware/dockertest/database.yml.interpolated config/database.yml |
| 73 | 1570:ae2f71010562 | Chris | |
| 74 | |||
| 75 | 1573:8edb54e29f00 | Chris | # Install Rails and dependencies (database.yml must be populated before this) |
| 76 | 1570:ae2f71010562 | Chris | |
| 77 | 1569:26a4f99ec679 | Chris | RUN gem install bundler |
| 78 | RUN bundle install |
||
| 79 | 1570:ae2f71010562 | Chris | |
| 80 | |||
| 81 | 1573:8edb54e29f00 | Chris | # Initialise Redmine token (bundler must be installed before this) |
| 82 | |||
| 83 | RUN bundle exec rake generate_secret_token |
||
| 84 | |||
| 85 | |||
| 86 | 1570:ae2f71010562 | Chris | # Import Postgres database from postgres-dumpall file |
| 87 | |||
| 88 | 1569:26a4f99ec679 | Chris | RUN chown postgres postgres-dumpall |
| 89 | 1571:4c2b25b7e85f | Chris | RUN /etc/init.d/postgresql start && sudo -u postgres psql -f postgres-dumpall postgres |
| 90 | 1570:ae2f71010562 | Chris | |
| 91 | |||
| 92 | # Install Perl auth module for Hg access |
||
| 93 | |||
| 94 | RUN mkdir -p /usr/local/lib/site_perl/Apache/Authn/ |
||
| 95 | RUN cp extra/soundsoftware/SoundSoftware.pm /usr/local/lib/site_perl/Apache/Authn/ |
||
| 96 | |||
| 97 | |||
| 98 | 1571:4c2b25b7e85f | Chris | # Set up Apache config (todo: insert variables) |
| 99 | 1570:ae2f71010562 | Chris | |
| 100 | 1571:4c2b25b7e85f | Chris | RUN rm -f /etc/apache2/sites-enabled/000-default.conf |
| 101 | |||
| 102 | RUN cp extra/soundsoftware/dockertest/passenger.conf /etc/apache2/mods-available/ |
||
| 103 | RUN cp extra/soundsoftware/dockertest/passenger.load /etc/apache2/mods-available/ |
||
| 104 | RUN cp extra/soundsoftware/dockertest/perl.conf /etc/apache2/mods-available/ |
||
| 105 | |||
| 106 | RUN ln -s ../mods-available/passenger.conf /etc/apache2/mods-enabled/ |
||
| 107 | RUN ln -s ../mods-available/passenger.load /etc/apache2/mods-enabled/ |
||
| 108 | RUN ln -s ../mods-available/perl.conf /etc/apache2/mods-enabled/ |
||
| 109 | RUN ln -s ../mods-available/expires.load /etc/apache2/mods-enabled/ |
||
| 110 | RUN ln -s ../mods-available/rewrite.load /etc/apache2/mods-enabled/ |
||
| 111 | |||
| 112 | 1574:7b23adecd963 | Chris | RUN cp extra/soundsoftware/dockertest/code.conf.interpolated /etc/apache2/sites-available/code.conf |
| 113 | 1570:ae2f71010562 | Chris | RUN ln -s ../sites-available/code.conf /etc/apache2/sites-enabled/10-code.conf |
| 114 | 1571:4c2b25b7e85f | Chris | |
| 115 | 1572:2b1b8ebb7d98 | Chris | RUN apache2ctl configtest |
| 116 | 1571:4c2b25b7e85f | Chris | |
| 117 | |||
| 118 | 1572:2b1b8ebb7d98 | Chris | # Start Postgres and foregrounded Apache |
| 119 | |||
| 120 | RUN echo "#!/bin/bash" > container-run.sh |
||
| 121 | RUN echo "/etc/init.d/postgresql start" >> container-run.sh |
||
| 122 | RUN echo "apache2ctl -D FOREGROUND" >> container-run.sh |
||
| 123 | RUN chmod +x container-run.sh |
||
| 124 | |||
| 125 | 1571:4c2b25b7e85f | Chris | EXPOSE 80 |
| 126 | 1572:2b1b8ebb7d98 | Chris | CMD ./container-run.sh |
| 127 | 1571:4c2b25b7e85f | Chris | |
| 128 | 1570:ae2f71010562 | Chris | |
| 129 | # A test Apache config. Lacks SSL, lacks a desirable extra layer of |
||
| 130 | # authentication for admin interface paths. Do not deploy this. |
||
| 131 | |||
| 132 | PerlLoadModule Apache::Authn::SoundSoftware |
||
| 133 | |||
| 134 | <VirtualHost *:80> |
||
| 135 | ServerName code.soundsoftware.ac.uk |
||
| 136 | ServerAdmin chris.cannam@soundsoftware.ac.uk |
||
| 137 | |||
| 138 | DocumentRoot /var/www/code/public |
||
| 139 | PassengerRestartDir restart_files |
||
| 140 | PassengerHighPerformance on |
||
| 141 | PassengerMaxRequests 50000 |
||
| 142 | PassengerStatThrottleRate 5 |
||
| 143 | PassengerStartTimeout 60 |
||
| 144 | 1571:4c2b25b7e85f | Chris | PassengerFriendlyErrorPages on |
| 145 | 1570:ae2f71010562 | Chris | RailsSpawnMethod smart |
| 146 | ExpiresDefault "access plus 1 minute" |
||
| 147 | |||
| 148 | <DirectoryMatch "^/.*/\.svn/"> |
||
| 149 | Order allow,deny |
||
| 150 | Deny from all |
||
| 151 | Satisfy All |
||
| 152 | </DirectoryMatch> |
||
| 153 | |||
| 154 | <DirectoryMatch "^/.*/\.hg/"> |
||
| 155 | Order allow,deny |
||
| 156 | Deny from all |
||
| 157 | Satisfy All |
||
| 158 | </DirectoryMatch> |
||
| 159 | |||
| 160 | <DirectoryMatch "^/.*/\.git/"> |
||
| 161 | Order allow,deny |
||
| 162 | Deny from all |
||
| 163 | Satisfy All |
||
| 164 | </DirectoryMatch> |
||
| 165 | |||
| 166 | <Directory /var/www/code/public> |
||
| 167 | Options -MultiViews |
||
| 168 | </Directory> |
||
| 169 | |||
| 170 | <Directory /var/www/code/public/themes/soundsoftware/stylesheets/fonts> |
||
| 171 | # Avoid other sites embedding our fonts |
||
| 172 | RewriteEngine on |
||
| 173 | RewriteCond %{HTTP_REFERER} !^$
|
||
| 174 | RewriteCond %{HTTP_REFERER} !^http(s)?://code.soundsoftware.ac.uk/.*$ [NC]
|
||
| 175 | RewriteRule \.(ttf|woff|eot|otf|svg|zip|gz|html|txt)$ - [F] |
||
| 176 | </Directory> |
||
| 177 | |||
| 178 | ScriptAlias /hg "/var/hg/index.cgi" |
||
| 179 | |||
| 180 | <Location /hg> |
||
| 181 | AuthName "Mercurial" |
||
| 182 | AuthType Basic |
||
| 183 | Require valid-user |
||
| 184 | PerlAccessHandler Apache::Authn::SoundSoftware::access_handler |
||
| 185 | PerlAuthenHandler Apache::Authn::SoundSoftware::authen_handler |
||
| 186 | PerlSetVar HTTPS "on" |
||
| 187 | SoundSoftwareDSN "dbi:Pg:database=code;host=localhost" |
||
| 188 | SoundSoftwareDbUser "code" |
||
| 189 | SoundSoftwareDbPass "INSERT_POSTGRES_PASSWORD_HERE" |
||
| 190 | SoundSoftwareRepoPrefix "/var/hg/" |
||
| 191 | SoundSoftwareSslRequired "on" |
||
| 192 | Options +ExecCGI |
||
| 193 | AddHandler cgi-script .cgi |
||
| 194 | ExpiresDefault now |
||
| 195 | </Location> |
||
| 196 | |||
| 197 | Alias /git "/var/files/git-mirror" |
||
| 198 | |||
| 199 | <Directory "/var/files/git-mirror"> |
||
| 200 | Options -Indexes +FollowSymLinks |
||
| 201 | Order allow,deny |
||
| 202 | Allow from all |
||
| 203 | </Directory> |
||
| 204 | <Directory ~ "/var/files/git-mirror/.*\.workdir"> |
||
| 205 | Order allow,deny |
||
| 206 | Deny from all |
||
| 207 | </Directory> |
||
| 208 | <Directory ~ "/var/files/git-mirror/__.*"> |
||
| 209 | Order allow,deny |
||
| 210 | Deny from all |
||
| 211 | </Directory> |
||
| 212 | |||
| 213 | ErrorLog /var/log/apache2/code-error.log |
||
| 214 | CustomLog /var/log/apache2/code-access.log vhost_combined |
||
| 215 | |||
| 216 | LogLevel warn |
||
| 217 | ServerSignature Off |
||
| 218 | |||
| 219 | </VirtualHost> |
||
| 220 | |||
| 221 | production: |
||
| 222 | adapter: postgresql |
||
| 223 | database: code |
||
| 224 | host: localhost |
||
| 225 | username: code |
||
| 226 | password: "INSERT_POSTGRES_PASSWORD_HERE" |
||
| 227 | |||
| 228 | 1571:4c2b25b7e85f | Chris | PassengerMaxPoolSize 60 |
| 229 | |||
| 230 | LoadModule passenger_module /var/lib/gems/2.3.0/gems/passenger-4.0.60/buildout/apache2/mod_passenger.so |
||
| 231 | PassengerRoot /var/lib/gems/2.3.0/gems/passenger-4.0.60 |
||
| 232 | PassengerDefaultRuby /usr/bin/ruby2.3 |
||
| 233 | # Apache::DBI is supposed to be a transparent replacement for Perl DBI with |
||
| 234 | # better performance when multiple connections are made with common DSN, user |
||
| 235 | # and password |
||
| 236 | PerlModule Apache::DBI |
||
| 237 | 1569:26a4f99ec679 | Chris | #!/bin/bash |
| 238 | |||
| 239 | 1574:7b23adecd963 | Chris | dbpwd="$1" |
| 240 | if [ -z "$dbpwd" ]; then |
||
| 241 | echo "Usage: $0 <database-password>" 1>&2 |
||
| 242 | exit 2 |
||
| 243 | fi |
||
| 244 | |||
| 245 | 1569:26a4f99ec679 | Chris | set -eu |
| 246 | |||
| 247 | dockerdir=./extra/soundsoftware/dockertest |
||
| 248 | if [ ! -d "$dockerdir" ]; then |
||
| 249 | echo "Run this script from the root of a working copy of soundsoftware-site" |
||
| 250 | exit 2 |
||
| 251 | fi |
||
| 252 | |||
| 253 | 1574:7b23adecd963 | Chris | for f in database.yml code.conf ; do |
| 254 | cat "$dockerdir/$f" | |
||
| 255 | sed 's/INSERT_POSTGRES_PASSWORD_HERE/'"$dbpwd"'/g' > \ |
||
| 256 | "$dockerdir/$f.interpolated" |
||
| 257 | done |
||
| 258 | |||
| 259 | 1569:26a4f99ec679 | Chris | dockertag="cannam/soundsoftware-site" |
| 260 | |||
| 261 | sudo docker build -t "$dockertag" -f "$dockerdir/Dockerfile" . |
||
| 262 | 1571:4c2b25b7e85f | Chris | sudo docker run -p 8080:80 -d "$dockertag" |