Browse Source

add Docker stuff

Jan Behrens 4 years ago
parent
commit
0cd4c67418
5 changed files with 110 additions and 0 deletions
  1. 37 0
      Dockerfile
  2. 23 0
      README.md
  3. 21 0
      config/apache-config.conf
  4. 22 0
      config/docker-entrypoint.sh
  5. 7 0
      docker-compose.yml

+ 37 - 0
Dockerfile

@@ -0,0 +1,37 @@
+FROM ubuntu:bionic
+
+RUN apt-get update && \
+    apt-get -y upgrade && \
+    DEBIAN_FRONTEND=noninteractive apt-get -y install \
+        apache2 php7.2 libapache2-mod-php7.2 libcap2-bin curl
+
+RUN a2enmod php7.2
+
+#RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.0/apache2/php.ini
+#RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.0/apache2/php.ini
+
+ENV APACHE_RUN_USER 1000190000
+ENV APACHE_RUN_GROUP 7100
+ENV APACHE_LOG_DIR /var/log/apache2
+ENV APACHE_LOCK_DIR /var/lock/apache2
+ENV APACHE_PID_FILE /var/run/apache2.pid
+
+RUN mkdir -p /var/log/apache2 && chown -R ${APACHE_RUN_USER} /var/log/apache2 && \
+    mkdir -p /var/lock/apache2 && chown -R ${APACHE_RUN_USER} /var/lock/apache2 && \
+    mkdir -p /var/run/apache2 && chown -R ${APACHE_RUN_USER} /var/run/apache2 && \
+    setcap 'cap_net_bind_service=+ep' /usr/sbin/apache2
+
+ADD config/apache-config.conf /etc/apache2/sites-enabled/000-default.conf
+ADD config/docker-entrypoint.sh /docker-entrypoint.sh
+RUN chmod +x /docker-entrypoint.sh
+
+RUN rm -rf /var/www/html/*
+ADD . /var/www/html
+RUN chown -R ${APACHE_RUN_USER} /var/www/html
+
+USER ${APACHE_RUN_USER}
+
+EXPOSE 80
+
+WORKDIR /var/www/html
+ENTRYPOINT /docker-entrypoint.sh

+ 23 - 0
README.md

@@ -0,0 +1,23 @@
+SDS status monitor
+==================
+
+* Runs on Apache + PHP
+* Website served by Apache process
+* Data is polled in background at regular intervals
+* Needs write access to www directory for caching
+
+Docker
+------
+
+Setup builds on Ubuntu 18.04 (bionic) and starts server + polling process.
+
+Build & run locally:
+```
+docker build -t sts-status-monitor .
+docker run -p 8001:80 --name sts-status sts-status-monitor
+docker rm -f sts-status    # terminates container
+```
+
+Runtime arguments:
+* `POLL_INTERVAL` - polling interval for background process (default: 0 seconds = disabled)
+* `POLL_SCRIPTS` - list of PHP scripts to run in parallel for polling (default: none)

+ 21 - 0
config/apache-config.conf

@@ -0,0 +1,21 @@
+<VirtualHost *:80>
+
+  #ServerAdmin example@kit.edu
+  #ServerName example.kit.edu
+
+  DocumentRoot /var/www/html
+
+  <Directory /var/www/html/>
+      Options -Indexes +FollowSymLinks +MultiViews
+      DirectoryIndex index.php
+      AllowOverride All
+      Order deny,allow
+      Allow from all
+  </Directory>
+
+  ErrorLog /dev/stderr
+  #TransferLog /dev/stdout
+
+  CustomLog ${APACHE_LOG_DIR}/access.log combined
+
+</VirtualHost>

+ 22 - 0
config/docker-entrypoint.sh

@@ -0,0 +1,22 @@
+#!/bin/bash
+
+#/usr/bin/id
+
+POLL_SCRIPTS=${POLL_SCRIPTS:-""}
+POLL_INTERVAL=${POLL_INTERVAL:-0}
+
+if [ ${POLL_INTERVAL} -gt 0 ]; then
+    for SCRIPT_NAME in ${POLL_SCRIPTS}; do
+        (
+            while true; do
+                [ -f ${SCRIPT_NAME} ] && \
+                    echo "Polling data: $(date) [${SCRIPT_NAME}]" && \
+                    php ${SCRIPT_NAME}
+                sleep ${POLL_INTERVAL}
+            done
+        ) &
+    done
+fi
+
+echo "Starting server process"
+/usr/sbin/apache2ctl -D FOREGROUND $@

+ 7 - 0
docker-compose.yml

@@ -0,0 +1,7 @@
+version: '3'
+services:
+  web:
+    build: .
+    ports:
+     - "8001:8001"
+    volumes: