To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / deploy / docker @ 1587:d8949733849d
| 1 | 1587:d8949733849d | Chris | |
|---|---|---|---|
| 2 | FROM ubuntu:16.04 |
||
| 3 | MAINTAINER Chris Cannam <cannam@all-day-breakfast.com> |
||
| 4 | |||
| 5 | COPY . /var/www/code |
||
| 6 | |||
| 7 | WORKDIR /var/www/code |
||
| 8 | |||
| 9 | INSERT_PROVISIONING_HERE |
||
| 10 | |||
| 11 | # Start Postgres and foregrounded Apache |
||
| 12 | |||
| 13 | RUN echo "#!/bin/bash" > container-run.sh |
||
| 14 | RUN echo "/etc/init.d/postgresql start" >> container-run.sh |
||
| 15 | RUN echo "apache2ctl -D FOREGROUND" >> container-run.sh |
||
| 16 | RUN chmod +x container-run.sh |
||
| 17 | |||
| 18 | EXPOSE 80 |
||
| 19 | CMD ./container-run.sh |
||
| 20 | |||
| 21 | |||
| 22 | # For documentation and experimental purposes only. As a |
||
| 23 | # reconstruction of the machine image that runs this application, |
||
| 24 | # there are lots of things missing here; but as a good Docker |
||
| 25 | # configuration, it fails by mixing together rather a lot of concerns. |
||
| 26 | |||
| 27 | FROM ubuntu:16.04 |
||
| 28 | MAINTAINER Chris Cannam <cannam@all-day-breakfast.com> |
||
| 29 | |||
| 30 | RUN apt-get update && \ |
||
| 31 | apt-get install -y \ |
||
| 32 | apache2 \ |
||
| 33 | apache2-dev \ |
||
| 34 | apt-utils \ |
||
| 35 | build-essential \ |
||
| 36 | cron \ |
||
| 37 | curl \ |
||
| 38 | doxygen \ |
||
| 39 | exim4 \ |
||
| 40 | git \ |
||
| 41 | graphviz \ |
||
| 42 | imagemagick \ |
||
| 43 | libapache-dbi-perl \ |
||
| 44 | libapache2-mod-perl2 \ |
||
| 45 | libapr1-dev \ |
||
| 46 | libaprutil1-dev \ |
||
| 47 | libauthen-simple-ldap-perl \ |
||
| 48 | libcurl4-openssl-dev \ |
||
| 49 | libdbd-pg-perl \ |
||
| 50 | libpq-dev \ |
||
| 51 | libmagickwand-dev \ |
||
| 52 | libio-socket-ssl-perl \ |
||
| 53 | logrotate \ |
||
| 54 | mercurial \ |
||
| 55 | postgresql \ |
||
| 56 | rsync \ |
||
| 57 | ruby \ |
||
| 58 | ruby-dev \ |
||
| 59 | sudo |
||
| 60 | |||
| 61 | # Also used on the live site, for javadoc extraction, but this is |
||
| 62 | # would be by far the biggest package here: let's omit it while we're |
||
| 63 | # not making use of it |
||
| 64 | # openjdk-9-jdk-headless |
||
| 65 | |||
| 66 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
||
| 67 | |||
| 68 | |||
| 69 | # Passenger gets installed through gem, not apt |
||
| 70 | |||
| 71 | RUN gem install passenger -v 4.0.60 --no-rdoc --no-ri |
||
| 72 | RUN passenger-install-apache2-module --languages=ruby |
||
| 73 | |||
| 74 | |||
| 75 | # Copy across webapp, set up ownership |
||
| 76 | |||
| 77 | COPY . /var/www/code |
||
| 78 | |||
| 79 | RUN groupadd code |
||
| 80 | RUN useradd -g code -G www-data code |
||
| 81 | RUN chown -R code.www-data /var/www/code |
||
| 82 | RUN find /var/www/code -type d -exec chmod g+s \{\} \;
|
||
| 83 | |||
| 84 | |||
| 85 | # Initialise /var/hg (in reality this would be mounted from somewhere) |
||
| 86 | |||
| 87 | RUN mkdir -p /var/hg |
||
| 88 | RUN chown code.www-data /var/hg |
||
| 89 | RUN chmod g+s /var/hg |
||
| 90 | COPY extra/soundsoftware/scripted-deploy/config/index.cgi /var/hg/ |
||
| 91 | COPY extra/soundsoftware/scripted-deploy/config/hgweb.config /var/hg/ |
||
| 92 | RUN chmod +x /var/hg/index.cgi |
||
| 93 | |||
| 94 | |||
| 95 | # We're based in the code webapp directory from here on |
||
| 96 | |||
| 97 | WORKDIR /var/www/code |
||
| 98 | |||
| 99 | |||
| 100 | # Set up database config etc |
||
| 101 | |||
| 102 | RUN cp extra/soundsoftware/scripted-deploy/config/database.yml.interpolated config/database.yml |
||
| 103 | |||
| 104 | |||
| 105 | # Install Rails and dependencies (database.yml must be populated before this) |
||
| 106 | |||
| 107 | RUN gem install bundler |
||
| 108 | RUN bundle install |
||
| 109 | |||
| 110 | |||
| 111 | # Initialise Redmine token (bundler must be installed before this) |
||
| 112 | |||
| 113 | RUN bundle exec rake generate_secret_token |
||
| 114 | |||
| 115 | |||
| 116 | # Import Postgres database from postgres-dumpall file |
||
| 117 | |||
| 118 | RUN chown postgres postgres-dumpall |
||
| 119 | RUN /etc/init.d/postgresql start && sudo -u postgres psql -f postgres-dumpall postgres |
||
| 120 | RUN rm postgres-dumpall |
||
| 121 | |||
| 122 | |||
| 123 | # Install Perl auth module for Hg access |
||
| 124 | |||
| 125 | RUN mkdir -p /usr/local/lib/site_perl/Apache/Authn/ |
||
| 126 | RUN cp extra/soundsoftware/SoundSoftware.pm /usr/local/lib/site_perl/Apache/Authn/ |
||
| 127 | |||
| 128 | |||
| 129 | # Set up Apache config (todo: insert variables) |
||
| 130 | |||
| 131 | RUN rm -f /etc/apache2/sites-enabled/000-default.conf |
||
| 132 | |||
| 133 | RUN cp extra/soundsoftware/scripted-deploy/config/passenger.conf /etc/apache2/mods-available/ |
||
| 134 | RUN cp extra/soundsoftware/scripted-deploy/config/passenger.load /etc/apache2/mods-available/ |
||
| 135 | RUN cp extra/soundsoftware/scripted-deploy/config/perl.conf /etc/apache2/mods-available/ |
||
| 136 | |||
| 137 | RUN ln -s ../mods-available/passenger.conf /etc/apache2/mods-enabled/ |
||
| 138 | RUN ln -s ../mods-available/passenger.load /etc/apache2/mods-enabled/ |
||
| 139 | RUN ln -s ../mods-available/perl.conf /etc/apache2/mods-enabled/ |
||
| 140 | RUN ln -s ../mods-available/expires.load /etc/apache2/mods-enabled/ |
||
| 141 | RUN ln -s ../mods-available/rewrite.load /etc/apache2/mods-enabled/ |
||
| 142 | RUN ln -s ../mods-available/cgi.load /etc/apache2/mods-enabled/ |
||
| 143 | |||
| 144 | RUN cp extra/soundsoftware/scripted-deploy/config/code.conf.interpolated /etc/apache2/sites-available/code.conf |
||
| 145 | RUN ln -s ../sites-available/code.conf /etc/apache2/sites-enabled/10-code.conf |
||
| 146 | |||
| 147 | RUN apache2ctl configtest |
||
| 148 | |||
| 149 | |||
| 150 | # Start Postgres and foregrounded Apache |
||
| 151 | |||
| 152 | RUN echo "#!/bin/bash" > container-run.sh |
||
| 153 | RUN echo "/etc/init.d/postgresql start" >> container-run.sh |
||
| 154 | RUN echo "apache2ctl -D FOREGROUND" >> container-run.sh |
||
| 155 | RUN chmod +x container-run.sh |
||
| 156 | |||
| 157 | EXPOSE 80 |
||
| 158 | CMD ./container-run.sh |
||
| 159 | |||
| 160 | 1569:26a4f99ec679 | Chris | #!/bin/bash |
| 161 | |||
| 162 | 1586:d0d59d12db94 | Chris | mydir=$(dirname "$0") |
| 163 | |||
| 164 | 1574:7b23adecd963 | Chris | dbpwd="$1" |
| 165 | if [ -z "$dbpwd" ]; then |
||
| 166 | echo "Usage: $0 <database-password>" 1>&2 |
||
| 167 | exit 2 |
||
| 168 | fi |
||
| 169 | |||
| 170 | 1587:d8949733849d | Chris | set -eu -o pipefail |
| 171 | 1569:26a4f99ec679 | Chris | |
| 172 | 1587:d8949733849d | Chris | rootdir="$mydir/../.." |
| 173 | 1586:d0d59d12db94 | Chris | |
| 174 | 1587:d8949733849d | Chris | deploydir="$rootdir"/deploy |
| 175 | 1581:ae8043b014c7 | Chris | if [ ! -d "$deploydir" ]; then |
| 176 | 1586:d0d59d12db94 | Chris | echo "ERROR: Unexpected repository layout - expected directory at $deploydir" |
| 177 | 1569:26a4f99ec679 | Chris | exit 2 |
| 178 | fi |
||
| 179 | |||
| 180 | 1581:ae8043b014c7 | Chris | managerdir="$deploydir/docker" |
| 181 | if [ ! -d "$managerdir" ]; then |
||
| 182 | echo "ERROR: Required directory $managerdir not found" |
||
| 183 | exit 2 |
||
| 184 | fi |
||
| 185 | |||
| 186 | configdir="$deploydir/config" |
||
| 187 | if [ ! -d "$configdir" ]; then |
||
| 188 | echo "ERROR: Required directory $configdir not found" |
||
| 189 | exit 2 |
||
| 190 | fi |
||
| 191 | |||
| 192 | 1586:d0d59d12db94 | Chris | if [ ! -f "$rootdir/postgres-dumpall" ]; then |
| 193 | echo "ERROR: I expect to find a Postgres SQL multi-db dump file in $rootdir/postgres-dumpall" |
||
| 194 | exit 2 |
||
| 195 | fi |
||
| 196 | |||
| 197 | fontdir="$rootdir"/public/themes/soundsoftware/stylesheets/fonts |
||
| 198 | if [ ! -f "$fontdir/24BC0E_0_0.woff" ]; then |
||
| 199 | echo "ERROR: I expect to find necessary webfonts in $fontdir" |
||
| 200 | 1581:ae8043b014c7 | Chris | exit 2 |
| 201 | fi |
||
| 202 | |||
| 203 | 1574:7b23adecd963 | Chris | for f in database.yml code.conf ; do |
| 204 | 1587:d8949733849d | Chris | cat "$configdir/$f.in" | |
| 205 | 1574:7b23adecd963 | Chris | sed 's/INSERT_POSTGRES_PASSWORD_HERE/'"$dbpwd"'/g' > \ |
| 206 | 1587:d8949733849d | Chris | "$configdir/$f" |
| 207 | 1574:7b23adecd963 | Chris | done |
| 208 | |||
| 209 | 1587:d8949733849d | Chris | provisioning_commands=$( |
| 210 | for x in "$deploydir"/provision.d/[0-9]*; do |
||
| 211 | echo "RUN /bin/bash /var/www/code/deploy/provision.d/$(basename $x)" |
||
| 212 | done | sed 's/$/\\n/' | fmt -2000 | sed 's/ RUN/RUN/g' ) |
||
| 213 | |||
| 214 | ( echo |
||
| 215 | echo "### DO NOT EDIT THIS FILE - it is generated from Dockerfile.in" |
||
| 216 | echo |
||
| 217 | ) > "$managerdir/Dockerfile" |
||
| 218 | |||
| 219 | cat "$managerdir/Dockerfile.in" | |
||
| 220 | sed 's,INSERT_PROVISIONING_HERE,'"$provisioning_commands"',' >> \ |
||
| 221 | "$managerdir/Dockerfile" |
||
| 222 | |||
| 223 | 1586:d0d59d12db94 | Chris | cd "$rootdir" |
| 224 | |||
| 225 | 1569:26a4f99ec679 | Chris | dockertag="cannam/soundsoftware-site" |
| 226 | |||
| 227 | 1587:d8949733849d | Chris | sudo docker build -t "$dockertag" -f "deploy/docker/Dockerfile" . |
| 228 | 1571:4c2b25b7e85f | Chris | sudo docker run -p 8080:80 -d "$dockertag" |