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 / extra / soundsoftware / dockertest @ 1578:06ca2df3d7ca

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