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 / scripted-deploy / docker @ 1581:ae8043b014c7
| 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 | 1581:ae8043b014c7 | Chris | COPY extra/soundsoftware/scripted-deploy/config/index.cgi /var/hg/ |
| 71 | COPY extra/soundsoftware/scripted-deploy/config/hgweb.config /var/hg/ |
||
| 72 | 1576:d1de6986e429 | Chris | 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 | 1581:ae8043b014c7 | Chris | RUN cp extra/soundsoftware/scripted-deploy/config/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 | 1581:ae8043b014c7 | Chris | RUN rm postgres-dumpall |
| 101 | 1570:ae2f71010562 | Chris | |
| 102 | |||
| 103 | # Install Perl auth module for Hg access |
||
| 104 | |||
| 105 | RUN mkdir -p /usr/local/lib/site_perl/Apache/Authn/ |
||
| 106 | RUN cp extra/soundsoftware/SoundSoftware.pm /usr/local/lib/site_perl/Apache/Authn/ |
||
| 107 | |||
| 108 | |||
| 109 | 1571:4c2b25b7e85f | Chris | # Set up Apache config (todo: insert variables) |
| 110 | 1570:ae2f71010562 | Chris | |
| 111 | 1571:4c2b25b7e85f | Chris | RUN rm -f /etc/apache2/sites-enabled/000-default.conf |
| 112 | |||
| 113 | 1581:ae8043b014c7 | Chris | RUN cp extra/soundsoftware/scripted-deploy/config/passenger.conf /etc/apache2/mods-available/ |
| 114 | RUN cp extra/soundsoftware/scripted-deploy/config/passenger.load /etc/apache2/mods-available/ |
||
| 115 | RUN cp extra/soundsoftware/scripted-deploy/config/perl.conf /etc/apache2/mods-available/ |
||
| 116 | 1571:4c2b25b7e85f | Chris | |
| 117 | RUN ln -s ../mods-available/passenger.conf /etc/apache2/mods-enabled/ |
||
| 118 | RUN ln -s ../mods-available/passenger.load /etc/apache2/mods-enabled/ |
||
| 119 | RUN ln -s ../mods-available/perl.conf /etc/apache2/mods-enabled/ |
||
| 120 | RUN ln -s ../mods-available/expires.load /etc/apache2/mods-enabled/ |
||
| 121 | RUN ln -s ../mods-available/rewrite.load /etc/apache2/mods-enabled/ |
||
| 122 | 1578:06ca2df3d7ca | Chris | RUN ln -s ../mods-available/cgi.load /etc/apache2/mods-enabled/ |
| 123 | 1571:4c2b25b7e85f | Chris | |
| 124 | 1581:ae8043b014c7 | Chris | RUN cp extra/soundsoftware/scripted-deploy/config/code.conf.interpolated /etc/apache2/sites-available/code.conf |
| 125 | 1570:ae2f71010562 | Chris | RUN ln -s ../sites-available/code.conf /etc/apache2/sites-enabled/10-code.conf |
| 126 | 1571:4c2b25b7e85f | Chris | |
| 127 | 1572:2b1b8ebb7d98 | Chris | RUN apache2ctl configtest |
| 128 | 1571:4c2b25b7e85f | Chris | |
| 129 | |||
| 130 | 1572:2b1b8ebb7d98 | Chris | # Start Postgres and foregrounded Apache |
| 131 | |||
| 132 | RUN echo "#!/bin/bash" > container-run.sh |
||
| 133 | RUN echo "/etc/init.d/postgresql start" >> container-run.sh |
||
| 134 | RUN echo "apache2ctl -D FOREGROUND" >> container-run.sh |
||
| 135 | RUN chmod +x container-run.sh |
||
| 136 | |||
| 137 | 1571:4c2b25b7e85f | Chris | EXPOSE 80 |
| 138 | 1572:2b1b8ebb7d98 | Chris | CMD ./container-run.sh |
| 139 | 1571:4c2b25b7e85f | Chris | |
| 140 | 1569:26a4f99ec679 | Chris | #!/bin/bash |
| 141 | |||
| 142 | 1574:7b23adecd963 | Chris | dbpwd="$1" |
| 143 | if [ -z "$dbpwd" ]; then |
||
| 144 | echo "Usage: $0 <database-password>" 1>&2 |
||
| 145 | exit 2 |
||
| 146 | fi |
||
| 147 | |||
| 148 | 1569:26a4f99ec679 | Chris | set -eu |
| 149 | |||
| 150 | 1581:ae8043b014c7 | Chris | deploydir=./extra/soundsoftware/scripted-deploy |
| 151 | if [ ! -d "$deploydir" ]; then |
||
| 152 | 1569:26a4f99ec679 | Chris | echo "Run this script from the root of a working copy of soundsoftware-site" |
| 153 | exit 2 |
||
| 154 | fi |
||
| 155 | |||
| 156 | 1581:ae8043b014c7 | Chris | managerdir="$deploydir/docker" |
| 157 | if [ ! -d "$managerdir" ]; then |
||
| 158 | echo "ERROR: Required directory $managerdir not found" |
||
| 159 | exit 2 |
||
| 160 | fi |
||
| 161 | |||
| 162 | configdir="$deploydir/config" |
||
| 163 | if [ ! -d "$configdir" ]; then |
||
| 164 | echo "ERROR: Required directory $configdir not found" |
||
| 165 | exit 2 |
||
| 166 | fi |
||
| 167 | |||
| 168 | if [ ! -f "postgres-dumpall" ]; then |
||
| 169 | echo "ERROR: I expect to find a Postgres SQL multi-db dump file in ./postgres-dumpall" |
||
| 170 | exit 2 |
||
| 171 | fi |
||
| 172 | |||
| 173 | 1574:7b23adecd963 | Chris | for f in database.yml code.conf ; do |
| 174 | 1581:ae8043b014c7 | Chris | cat "$configdir/$f" | |
| 175 | 1574:7b23adecd963 | Chris | sed 's/INSERT_POSTGRES_PASSWORD_HERE/'"$dbpwd"'/g' > \ |
| 176 | 1581:ae8043b014c7 | Chris | "$configdir/$f.interpolated" |
| 177 | 1574:7b23adecd963 | Chris | done |
| 178 | |||
| 179 | 1569:26a4f99ec679 | Chris | dockertag="cannam/soundsoftware-site" |
| 180 | |||
| 181 | 1581:ae8043b014c7 | Chris | sudo docker build -t "$dockertag" -f "$managerdir/Dockerfile" . |
| 182 | 1571:4c2b25b7e85f | Chris | sudo docker run -p 8080:80 -d "$dockertag" |