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 @ 1576:d1de6986e429
| 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 | 1576:d1de6986e429 | Chris | # 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/dockertest/index.cgi /var/hg/ |
||
| 71 | COPY extra/soundsoftware/dockertest/hgweb.config /var/hg/ |
||
| 72 | RUN chmod +x /var/hg/index.cgi |
||
| 73 | |||
| 74 | |||
| 75 | 1570:ae2f71010562 | Chris | # We're based in the code webapp directory from here on |
| 76 | |||
| 77 | 1569:26a4f99ec679 | Chris | WORKDIR /var/www/code |
| 78 | 1570:ae2f71010562 | Chris | |
| 79 | |||
| 80 | 1574:7b23adecd963 | Chris | # Set up database config etc |
| 81 | 1570:ae2f71010562 | Chris | |
| 82 | 1574:7b23adecd963 | Chris | RUN cp extra/soundsoftware/dockertest/database.yml.interpolated config/database.yml |
| 83 | 1570:ae2f71010562 | Chris | |
| 84 | |||
| 85 | 1573:8edb54e29f00 | Chris | # Install Rails and dependencies (database.yml must be populated before this) |
| 86 | 1570:ae2f71010562 | Chris | |
| 87 | 1569:26a4f99ec679 | Chris | RUN gem install bundler |
| 88 | RUN bundle install |
||
| 89 | 1570:ae2f71010562 | Chris | |
| 90 | |||
| 91 | 1573:8edb54e29f00 | Chris | # Initialise Redmine token (bundler must be installed before this) |
| 92 | |||
| 93 | RUN bundle exec rake generate_secret_token |
||
| 94 | |||
| 95 | |||
| 96 | 1570:ae2f71010562 | Chris | # Import Postgres database from postgres-dumpall file |
| 97 | |||
| 98 | 1569:26a4f99ec679 | Chris | RUN chown postgres postgres-dumpall |
| 99 | 1571:4c2b25b7e85f | Chris | RUN /etc/init.d/postgresql start && sudo -u postgres psql -f postgres-dumpall postgres |
| 100 | 1570:ae2f71010562 | Chris | |
| 101 | |||
| 102 | # Install Perl auth module for Hg access |
||
| 103 | |||
| 104 | RUN mkdir -p /usr/local/lib/site_perl/Apache/Authn/ |
||
| 105 | RUN cp extra/soundsoftware/SoundSoftware.pm /usr/local/lib/site_perl/Apache/Authn/ |
||
| 106 | |||
| 107 | |||
| 108 | 1571:4c2b25b7e85f | Chris | # Set up Apache config (todo: insert variables) |
| 109 | 1570:ae2f71010562 | Chris | |
| 110 | 1571:4c2b25b7e85f | Chris | RUN rm -f /etc/apache2/sites-enabled/000-default.conf |
| 111 | |||
| 112 | RUN cp extra/soundsoftware/dockertest/passenger.conf /etc/apache2/mods-available/ |
||
| 113 | RUN cp extra/soundsoftware/dockertest/passenger.load /etc/apache2/mods-available/ |
||
| 114 | RUN cp extra/soundsoftware/dockertest/perl.conf /etc/apache2/mods-available/ |
||
| 115 | |||
| 116 | RUN ln -s ../mods-available/passenger.conf /etc/apache2/mods-enabled/ |
||
| 117 | RUN ln -s ../mods-available/passenger.load /etc/apache2/mods-enabled/ |
||
| 118 | RUN ln -s ../mods-available/perl.conf /etc/apache2/mods-enabled/ |
||
| 119 | RUN ln -s ../mods-available/expires.load /etc/apache2/mods-enabled/ |
||
| 120 | RUN ln -s ../mods-available/rewrite.load /etc/apache2/mods-enabled/ |
||
| 121 | |||
| 122 | 1574:7b23adecd963 | Chris | RUN cp extra/soundsoftware/dockertest/code.conf.interpolated /etc/apache2/sites-available/code.conf |
| 123 | 1570:ae2f71010562 | Chris | RUN ln -s ../sites-available/code.conf /etc/apache2/sites-enabled/10-code.conf |
| 124 | 1571:4c2b25b7e85f | Chris | |
| 125 | 1572:2b1b8ebb7d98 | Chris | RUN apache2ctl configtest |
| 126 | 1571:4c2b25b7e85f | Chris | |
| 127 | |||
| 128 | 1572:2b1b8ebb7d98 | Chris | # Start Postgres and foregrounded Apache |
| 129 | |||
| 130 | RUN echo "#!/bin/bash" > container-run.sh |
||
| 131 | RUN echo "/etc/init.d/postgresql start" >> container-run.sh |
||
| 132 | RUN echo "apache2ctl -D FOREGROUND" >> container-run.sh |
||
| 133 | RUN chmod +x container-run.sh |
||
| 134 | |||
| 135 | 1571:4c2b25b7e85f | Chris | EXPOSE 80 |
| 136 | 1572:2b1b8ebb7d98 | Chris | CMD ./container-run.sh |
| 137 | 1571:4c2b25b7e85f | Chris | |
| 138 | 1570:ae2f71010562 | Chris | |
| 139 | # A test Apache config. Lacks SSL, lacks a desirable extra layer of |
||
| 140 | # authentication for admin interface paths. Do not deploy this. |
||
| 141 | |||
| 142 | PerlLoadModule Apache::Authn::SoundSoftware |
||
| 143 | |||
| 144 | <VirtualHost *:80> |
||
| 145 | ServerName code.soundsoftware.ac.uk |
||
| 146 | ServerAdmin chris.cannam@soundsoftware.ac.uk |
||
| 147 | |||
| 148 | DocumentRoot /var/www/code/public |
||
| 149 | PassengerRestartDir restart_files |
||
| 150 | PassengerHighPerformance on |
||
| 151 | PassengerMaxRequests 50000 |
||
| 152 | PassengerStatThrottleRate 5 |
||
| 153 | PassengerStartTimeout 60 |
||
| 154 | 1571:4c2b25b7e85f | Chris | PassengerFriendlyErrorPages on |
| 155 | 1570:ae2f71010562 | Chris | RailsSpawnMethod smart |
| 156 | ExpiresDefault "access plus 1 minute" |
||
| 157 | |||
| 158 | <DirectoryMatch "^/.*/\.svn/"> |
||
| 159 | Order allow,deny |
||
| 160 | Deny from all |
||
| 161 | Satisfy All |
||
| 162 | </DirectoryMatch> |
||
| 163 | |||
| 164 | <DirectoryMatch "^/.*/\.hg/"> |
||
| 165 | Order allow,deny |
||
| 166 | Deny from all |
||
| 167 | Satisfy All |
||
| 168 | </DirectoryMatch> |
||
| 169 | |||
| 170 | <DirectoryMatch "^/.*/\.git/"> |
||
| 171 | Order allow,deny |
||
| 172 | Deny from all |
||
| 173 | Satisfy All |
||
| 174 | </DirectoryMatch> |
||
| 175 | |||
| 176 | <Directory /var/www/code/public> |
||
| 177 | Options -MultiViews |
||
| 178 | </Directory> |
||
| 179 | |||
| 180 | <Directory /var/www/code/public/themes/soundsoftware/stylesheets/fonts> |
||
| 181 | # Avoid other sites embedding our fonts |
||
| 182 | RewriteEngine on |
||
| 183 | RewriteCond %{HTTP_REFERER} !^$
|
||
| 184 | RewriteCond %{HTTP_REFERER} !^http(s)?://code.soundsoftware.ac.uk/.*$ [NC]
|
||
| 185 | RewriteRule \.(ttf|woff|eot|otf|svg|zip|gz|html|txt)$ - [F] |
||
| 186 | </Directory> |
||
| 187 | |||
| 188 | ScriptAlias /hg "/var/hg/index.cgi" |
||
| 189 | |||
| 190 | <Location /hg> |
||
| 191 | AuthName "Mercurial" |
||
| 192 | AuthType Basic |
||
| 193 | Require valid-user |
||
| 194 | PerlAccessHandler Apache::Authn::SoundSoftware::access_handler |
||
| 195 | PerlAuthenHandler Apache::Authn::SoundSoftware::authen_handler |
||
| 196 | PerlSetVar HTTPS "on" |
||
| 197 | SoundSoftwareDSN "dbi:Pg:database=code;host=localhost" |
||
| 198 | SoundSoftwareDbUser "code" |
||
| 199 | SoundSoftwareDbPass "INSERT_POSTGRES_PASSWORD_HERE" |
||
| 200 | SoundSoftwareRepoPrefix "/var/hg/" |
||
| 201 | 1576:d1de6986e429 | Chris | #!!! "on" in production please!: |
| 202 | SoundSoftwareSslRequired "off" |
||
| 203 | 1570:ae2f71010562 | Chris | Options +ExecCGI |
| 204 | AddHandler cgi-script .cgi |
||
| 205 | ExpiresDefault now |
||
| 206 | </Location> |
||
| 207 | |||
| 208 | Alias /git "/var/files/git-mirror" |
||
| 209 | |||
| 210 | <Directory "/var/files/git-mirror"> |
||
| 211 | Options -Indexes +FollowSymLinks |
||
| 212 | Order allow,deny |
||
| 213 | Allow from all |
||
| 214 | </Directory> |
||
| 215 | <Directory ~ "/var/files/git-mirror/.*\.workdir"> |
||
| 216 | Order allow,deny |
||
| 217 | Deny from all |
||
| 218 | </Directory> |
||
| 219 | <Directory ~ "/var/files/git-mirror/__.*"> |
||
| 220 | Order allow,deny |
||
| 221 | Deny from all |
||
| 222 | </Directory> |
||
| 223 | |||
| 224 | ErrorLog /var/log/apache2/code-error.log |
||
| 225 | CustomLog /var/log/apache2/code-access.log vhost_combined |
||
| 226 | |||
| 227 | LogLevel warn |
||
| 228 | ServerSignature Off |
||
| 229 | |||
| 230 | </VirtualHost> |
||
| 231 | |||
| 232 | production: |
||
| 233 | adapter: postgresql |
||
| 234 | database: code |
||
| 235 | host: localhost |
||
| 236 | username: code |
||
| 237 | password: "INSERT_POSTGRES_PASSWORD_HERE" |
||
| 238 | |||
| 239 | 1576:d1de6986e429 | Chris | [paths] |
| 240 | / = /var/hg/* |
||
| 241 | |||
| 242 | [web] |
||
| 243 | allow_archive = gz, zip, bz2 |
||
| 244 | allow_push = * |
||
| 245 | #!/usr/bin/env python |
||
| 246 | # |
||
| 247 | # An example CGI script to export multiple hgweb repos, edit as necessary |
||
| 248 | |||
| 249 | # adjust python path if not a system-wide install: |
||
| 250 | #import sys |
||
| 251 | #sys.path.insert(0, "/path/to/python/lib") |
||
| 252 | |||
| 253 | # enable importing on demand to reduce startup time |
||
| 254 | from mercurial import demandimport; demandimport.enable() |
||
| 255 | |||
| 256 | # Uncomment to send python tracebacks to the browser if an error occurs: |
||
| 257 | import cgitb |
||
| 258 | cgitb.enable() |
||
| 259 | |||
| 260 | # If you'd like to serve pages with UTF-8 instead of your default |
||
| 261 | # locale charset, you can do so by uncommenting the following lines. |
||
| 262 | # Note that this will cause your .hgrc files to be interpreted in |
||
| 263 | # UTF-8 and all your repo files to be displayed using UTF-8. |
||
| 264 | # |
||
| 265 | import os |
||
| 266 | os.environ["HGENCODING"] = "UTF-8" |
||
| 267 | |||
| 268 | from mercurial.hgweb.hgwebdir_mod import hgwebdir |
||
| 269 | import mercurial.hgweb.wsgicgi as wsgicgi |
||
| 270 | |||
| 271 | # The config file looks like this. You can have paths to individual |
||
| 272 | # repos, collections of repos in a directory tree, or both. |
||
| 273 | # |
||
| 274 | # [paths] |
||
| 275 | # virtual/path1 = /real/path1 |
||
| 276 | # virtual/path2 = /real/path2 |
||
| 277 | # virtual/root = /real/root/* |
||
| 278 | # / = /real/root2/* |
||
| 279 | # virtual/root2 = /real/root2/** |
||
| 280 | # |
||
| 281 | # [collections] |
||
| 282 | # /prefix/to/strip/off = /root/of/tree/full/of/repos |
||
| 283 | # |
||
| 284 | # paths example: |
||
| 285 | # |
||
| 286 | # * First two lines mount one repository into one virtual path, like |
||
| 287 | # '/real/path1' into 'virtual/path1'. |
||
| 288 | # |
||
| 289 | # * The third entry mounts every mercurial repository found in '/real/root' |
||
| 290 | # in 'virtual/root'. This format is preferred over the [collections] one, |
||
| 291 | # since using absolute paths as configuration keys is not supported on every |
||
| 292 | # platform (especially on Windows). |
||
| 293 | # |
||
| 294 | # * The fourth entry is a special case mounting all repositories in |
||
| 295 | # /'real/root2' in the root of the virtual directory. |
||
| 296 | # |
||
| 297 | # * The fifth entry recursively finds all repositories under the real root, |
||
| 298 | # and mounts them using their relative path (to given real root) under the |
||
| 299 | # virtual root. |
||
| 300 | # |
||
| 301 | # collections example: say directory tree /foo contains repos /foo/bar, |
||
| 302 | # /foo/quux/baz. Give this config section: |
||
| 303 | # [collections] |
||
| 304 | # /foo = /foo |
||
| 305 | # Then repos will list as bar and quux/baz. |
||
| 306 | # |
||
| 307 | # Alternatively you can pass a list of ('virtual/path', '/real/path') tuples
|
||
| 308 | # or use a dictionary with entries like 'virtual/path': '/real/path' |
||
| 309 | |||
| 310 | application = hgwebdir('hgweb.config')
|
||
| 311 | wsgicgi.launch(application) |
||
| 312 | 1571:4c2b25b7e85f | Chris | PassengerMaxPoolSize 60 |
| 313 | |||
| 314 | LoadModule passenger_module /var/lib/gems/2.3.0/gems/passenger-4.0.60/buildout/apache2/mod_passenger.so |
||
| 315 | PassengerRoot /var/lib/gems/2.3.0/gems/passenger-4.0.60 |
||
| 316 | PassengerDefaultRuby /usr/bin/ruby2.3 |
||
| 317 | # Apache::DBI is supposed to be a transparent replacement for Perl DBI with |
||
| 318 | # better performance when multiple connections are made with common DSN, user |
||
| 319 | # and password |
||
| 320 | PerlModule Apache::DBI |
||
| 321 | 1569:26a4f99ec679 | Chris | #!/bin/bash |
| 322 | |||
| 323 | 1574:7b23adecd963 | Chris | dbpwd="$1" |
| 324 | if [ -z "$dbpwd" ]; then |
||
| 325 | echo "Usage: $0 <database-password>" 1>&2 |
||
| 326 | exit 2 |
||
| 327 | fi |
||
| 328 | |||
| 329 | 1569:26a4f99ec679 | Chris | set -eu |
| 330 | |||
| 331 | dockerdir=./extra/soundsoftware/dockertest |
||
| 332 | if [ ! -d "$dockerdir" ]; then |
||
| 333 | echo "Run this script from the root of a working copy of soundsoftware-site" |
||
| 334 | exit 2 |
||
| 335 | fi |
||
| 336 | |||
| 337 | 1574:7b23adecd963 | Chris | for f in database.yml code.conf ; do |
| 338 | cat "$dockerdir/$f" | |
||
| 339 | sed 's/INSERT_POSTGRES_PASSWORD_HERE/'"$dbpwd"'/g' > \ |
||
| 340 | "$dockerdir/$f.interpolated" |
||
| 341 | done |
||
| 342 | |||
| 343 | 1569:26a4f99ec679 | Chris | dockertag="cannam/soundsoftware-site" |
| 344 | |||
| 345 | sudo docker build -t "$dockertag" -f "$dockerdir/Dockerfile" . |
||
| 346 | 1571:4c2b25b7e85f | Chris | sudo docker run -p 8080:80 -d "$dockertag" |