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 @ 1572:2b1b8ebb7d98

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