summaryrefslogtreecommitdiffstats
path: root/adei
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2018-02-20 16:16:15 +0100
committerSuren A. Chilingaryan <csa@suren.me>2018-02-20 16:16:15 +0100
commit3d19ce5671e45b8e06a91cb09065d81e22f9d6fd (patch)
treee6221f12bdc4c48f5dc919874265633e3709559c /adei
downloadadei-3d19ce5671e45b8e06a91cb09065d81e22f9d6fd.tar.gz
adei-3d19ce5671e45b8e06a91cb09065d81e22f9d6fd.tar.bz2
adei-3d19ce5671e45b8e06a91cb09065d81e22f9d6fd.tar.xz
adei-3d19ce5671e45b8e06a91cb09065d81e22f9d6fd.zip
Initial import
Diffstat (limited to 'adei')
-rw-r--r--adei/Dockerfile58
-rw-r--r--adei/Makefile47
-rw-r--r--adei/configs/apache.conf25
-rw-r--r--adei/configs/apache.passwd1
-rw-r--r--adei/configs/config.actual.php22
-rw-r--r--adei/configs/config.override.php0
-rwxr-xr-xadei/docker-entrypoint.sh6
-rwxr-xr-xadei/scripts/adei-branch.sh51
-rwxr-xr-xadei/scripts/configure.sh9
-rwxr-xr-xadei/scripts/log.sh54
-rw-r--r--adei/scripts/override.sed19
-rwxr-xr-xadei/scripts/run-apache.sh40
-rwxr-xr-xadei/scripts/run-cron.sh7
-rw-r--r--adei/supervisor/supervisord.conf14
14 files changed, 353 insertions, 0 deletions
diff --git a/adei/Dockerfile b/adei/Dockerfile
new file mode 100644
index 0000000..94f5016
--- /dev/null
+++ b/adei/Dockerfile
@@ -0,0 +1,58 @@
+FROM opensuse:42.1
+MAINTAINER Suren A. Chilingaryan <csa@suren.me>
+
+# Useful system applications
+RUN zypper -n in glibc-locale mc bzr git openssh telnet curl python-pycurl
+
+ENV LANG en_US.UTF-8
+ENV LANGUAGE en_US:en
+ENV LC_ALL en_US.UTF-8
+
+# Installation of ADEI & dependencies
+RUN zypper ar http://download.opensuse.org/repositories/home:/csa7fff:/adei/openSUSE_Leap_42.1/home:csa7fff:adei.repo && \
+ zypper ar http://download.opensuse.org/repositories/server:/php:/extensions/openSUSE_Leap_42.1/server:php:extensions.repo && \
+ zypper ar http://download.opensuse.org/repositories/devel:languages:python/openSUSE_Tumbleweed/devel:languages:python.repo && \
+ zypper --gpg-auto-import-keys ref -s && \
+ zypper -n in supervisor procmail alpine which w3m && \
+ zypper -n in perl perl-DateTime-Format-Strptime mailx && \
+ zypper -n in make java && \
+ zypper -n in adei adei-config-default adei-req-mssql adei-webroot
+
+VOLUME /var/log/apache2
+VOLUME /var/spool/mail
+
+VOLUME /adei/src
+VOLUME /adei/cfg
+VOLUME /adei/tmp
+VOLUME /adei/sys
+
+COPY supervisor/supervisord.conf /etc/supervisord.conf
+
+# Apply configuration changes
+COPY configs /opt/configs
+COPY scripts /opt/scripts
+RUN /opt/scripts/configure.sh
+
+# Replace packaged ADEI with repository version
+RUN rm -rf /srv/www/htdocs/adei && \
+ ln -s /adei/src /srv/www/htdocs/adei
+
+ENV MYSQL_SERVER adei-mysql
+ENV MYSQL_PORT 3306
+ENV MYSQL_USER adei
+ENV MYSQL_PASSWORD adei
+ENV MYSQL_DATABASE adei
+
+ENV ADEI_REVISION last:1
+ENV ADEI_PARALLEL sources
+ENV ADEI_SETUP all
+ENV ADEI_ENABLED_SETUPS autogen logs
+ENV ADEI_PORTS 80
+
+ENV APACHE_SERVERS 0
+
+COPY docker-entrypoint.sh /
+ENTRYPOINT ["/docker-entrypoint.sh"]
+
+EXPOSE 80
+CMD /usr/bin/supervisord -c /etc/supervisord.conf
diff --git a/adei/Makefile b/adei/Makefile
new file mode 100644
index 0000000..eb40411
--- /dev/null
+++ b/adei/Makefile
@@ -0,0 +1,47 @@
+all: build
+install: push
+
+.PHONY: rebuild build push start stop restart bash
+
+build: Dockerfile
+ docker build --tag chsa/adei:latest .
+
+rebuild: Dockerfile
+ docker build --no-cache --tag chsa/adei:latest .
+
+push: build
+ docker push chsa/adei:latest
+
+start: build
+ @if [ `docker ps | grep adei-mysql | wc -l` -eq 0 ]; then \
+ if [ `docker ps -a | grep adei-mysql | wc -l` -eq 0 ]; then \
+ docker run --name adei-mysql -p 53306:3306/tcp -e MYSQL_ROOT_PASSWORD="adei" -e MYSQL_DATABASE="adei" -e MYSQL_USER="adei" -e MYSQL_PASSWORD="adei" -d mysql:5.7 ;\
+ else \
+ docker start adei-mysql ;\
+ fi ;\
+ fi ;\
+ if [ `docker ps | grep chsa/adei | wc -l` -eq 0 ]; then \
+ if [ `docker ps -a | grep adei-full | wc -l` -gt 0 ]; then \
+ echo "Removing the stalled copy..." ;\
+ docker rm adei-full ;\
+ fi ;\
+ docker run -p 8000:80 --name adei-full --link adei-mysql:adei-mysql -e ADEI_PORTS=8000 -t -d chsa/adei:latest ;\
+ else \
+ echo "Already running..." ;\
+ fi
+
+stop:
+ @if [ `docker ps | grep adei-full | wc -l` -gt 0 ]; then \
+ docker stop adei-full ;\
+ docker rm adei-full ;\
+ fi
+
+stop_mysql: stop
+ docker stop adei-mysql
+
+restart:
+ make stop
+ make start
+
+bash: build
+ docker exec -it adei-full /bin/bash
diff --git a/adei/configs/apache.conf b/adei/configs/apache.conf
new file mode 100644
index 0000000..5ea312d
--- /dev/null
+++ b/adei/configs/apache.conf
@@ -0,0 +1,25 @@
+<Location /adei/admin/>
+ AuthType Basic
+ AuthName "ADEI/Admin Authentication"
+ AuthBasicProvider file
+ AuthUserFile /adei/cfg/apache.passwd
+ Require valid-user
+ Order deny,allow
+ Deny from all
+ Allow from 127.0.0.1
+ Allow from ::1
+ Satisfy Any
+</Location>
+
+<Location /adei/services/control.php>
+ AuthType Basic
+ AuthName "ADEI/Control Authentication"
+ AuthBasicProvider file
+ AuthUserFile /adei/cfg/apache.passwd
+ Require valid-user
+ Order deny,allow
+ Deny from all
+ Allow from 127.0.0.1
+ Allow from ::1
+ Satisfy Any
+</Location>
diff --git a/adei/configs/apache.passwd b/adei/configs/apache.passwd
new file mode 100644
index 0000000..1a7a4bb
--- /dev/null
+++ b/adei/configs/apache.passwd
@@ -0,0 +1 @@
+adei:$apr1$CmdT4hVc$GIf7BaO/POJn8b5GgkR6K/
diff --git a/adei/configs/config.actual.php b/adei/configs/config.actual.php
new file mode 100644
index 0000000..4c28e59
--- /dev/null
+++ b/adei/configs/config.actual.php
@@ -0,0 +1,22 @@
+<?php
+ function env($var, $default = false) {
+ $env = getenv($var);
+ if ($env === false) return $default;
+ return $env;
+ }
+
+ $ADEI_SETUP = env("ADEI_SETUP", "all");
+
+ $ADEI_RELEASE = true;
+ $LOGGER_LOG_REQUESTS = false;
+ $LOGGER_LOG_OUTPUT = false;
+ $LOGGER_STORE_OBJECTS = false;
+
+ $ADEI_DB = array (
+ "host" => env("MYSQL_SERVER", "localhost"),
+ "port" => env("MYSQL_PORT", 0),
+ "database" => env("MYSQL_DATABASE", "adei"),
+ "user" => env("MYSQL_USER", "adei"),
+ "password" => env("MYSQL_PASSWORD", "adei")
+ );
+?> \ No newline at end of file
diff --git a/adei/configs/config.override.php b/adei/configs/config.override.php
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/adei/configs/config.override.php
diff --git a/adei/docker-entrypoint.sh b/adei/docker-entrypoint.sh
new file mode 100755
index 0000000..a82a970
--- /dev/null
+++ b/adei/docker-entrypoint.sh
@@ -0,0 +1,6 @@
+#! /bin/bash
+
+set -e
+
+echo "Running: $@"
+exec "$@"
diff --git a/adei/scripts/adei-branch.sh b/adei/scripts/adei-branch.sh
new file mode 100755
index 0000000..6fa8db2
--- /dev/null
+++ b/adei/scripts/adei-branch.sh
@@ -0,0 +1,51 @@
+#! /bin/bash
+
+function branch {
+ url="$1"
+ bzr branch "$url"
+}
+
+if [ ! -d /adei/src -o ! -d /adei/tmp -o ! -d /adei/sys -o ! -d /adei/cfg ]; then
+ echo "Incorrect volume configration, we expect /adei folder with populated docker volumes"
+ exit 1
+fi
+
+
+if [ ! -f /adei/src/VERSION ]; then
+ bzr branch -r $ADEI_REVISION --use-existing-dir http://darksoft.org/bzr/adei/trunk/ /adei/src
+ (
+ cd /adei/src
+ make
+
+ [ -d tmp ] && rm tmp
+ ln -s ../tmp tmp
+ chmod 0777 /adei/tmp
+
+ # Additional setups are clonned based on the environment for adei container creation
+ # but can be easily added in future. We cache all non-excluded setups. The .exclude
+ # file is removed afterwards from all
+
+ if [ ! -f /adei/cfg/config.actual.php ]; then
+
+ cp -a /opt/configs/config.*.php /adei/cfg/
+ fi
+
+ ln -s ../cfg/config.actual.php config.actual.php
+ ln -s ../cfg/config.override.php config.override.php
+ )
+fi
+
+(
+ cd /adei/src
+ for setup in $ADEI_ENABLED_SETUPS $ADEI_SETUP; do
+ if [[ ! -a setups/$setup ]]; then
+ if [[ ! -a /adei/cfg/$setup ]]; then
+ (
+ cd /adei/cfg/
+ branch "http://darksoft.org/bzr/adei/setups/$setup"
+ )
+ fi
+ ln -s ../../cfg/$setup setups/$setup
+ fi
+ done
+)
diff --git a/adei/scripts/configure.sh b/adei/scripts/configure.sh
new file mode 100755
index 0000000..88b48fc
--- /dev/null
+++ b/adei/scripts/configure.sh
@@ -0,0 +1,9 @@
+#! /bin/bash
+
+chmod 0777 /adei/tmp
+
+sed -i'' -re 's/^.*pam_loginuid\.so.*$//' /etc/pam.d/crond
+
+sed -i'' -re 's/APACHE_MODULES="(.*)"/APACHE_MODULES="\1 php5 rewrite proxy mod_proxy_http access_compat"/' /etc/sysconfig/apache2
+sed -i'' -rf /opt/scripts/override.sed /etc/apache2/default-server.conf
+sed -i'' -re 's/short_open_tag\s*=.*/short_open_tag = On/' /etc/php5/apache2/php.ini
diff --git a/adei/scripts/log.sh b/adei/scripts/log.sh
new file mode 100755
index 0000000..4237682
--- /dev/null
+++ b/adei/scripts/log.sh
@@ -0,0 +1,54 @@
+#! /bin/bash
+
+max_age=10
+max_mails=10
+log_lines=50
+
+cur=`date +%s`
+since=$(($cur - $max_age * 60))
+
+echo "Apache error log"
+echo "================"
+tail -n $log_lines /var/log/apache2/error_log | perl -MDateTime::Format::Strptime -F';' -ane '
+ my $parser = DateTime::Format::Strptime->new(
+ pattern => "%a %b %d %H:%M:%S.%N %Y"
+ );
+ my $formater = DateTime::Format::Strptime->new(
+ pattern => "%s"
+ );
+ if (/^\[([^]]+)\]/) {
+ $last = $formater->format_datetime($parser->parse_datetime($1));
+ } elsif ($last !~ /\d+/) {
+ $last = 0;
+ }
+ print "$last $_\n";
+' | awk "{ if (\$1 > $since) print \$0 }" | cut -d ' ' -f 2-
+echo
+echo
+
+
+mails=`mailutil check | cut -d ' ' -f 6`
+if [ "$mails" == "in" ]; then
+ mails=`mailutil check | cut -d ' ' -f 4`
+fi
+
+if [ $mails -gt 0 ]; then
+ [ $mails -gt $max_mails ] && mails=$max_mails
+
+ cur=`date -u +%s`
+ for id in `seq $mails -1 1`; do
+ mail=$(($mails - $id + 1))
+
+ lastmail=`echo "type $mail" | mailx -R "" -N`
+ dt=`echo "$lastmail" | grep "From" | head -n 1 | cut -d ' ' -f 3-`
+ last=`date -u --date "$dt" +%s`
+ since=$((($cur - $last) / 60))
+ if [ $since -le $max_age ]; then
+ echo "Cron reports on$dt"
+ echo "========================================"
+ echo "$lastmail" | sed -e '1,/^$/d' | head -n 10
+ echo
+ echo
+ fi
+ done
+fi
diff --git a/adei/scripts/override.sed b/adei/scripts/override.sed
new file mode 100644
index 0000000..7b96a5b
--- /dev/null
+++ b/adei/scripts/override.sed
@@ -0,0 +1,19 @@
+\,<Directory "/srv/www/htdocs">, {
+ :loop
+
+ \,</Directory>, {
+ b exit
+ }
+
+ s/^(\s*Options|\s*AllowOverride).*/\1 All/
+ n
+
+ b loop
+}
+\,/adei/cfg/apache.conf, {
+ $ ! d
+}
+\,/adei/cfg/apache.conf, ! {
+ $aInclude /adei/cfg/apache.conf
+}
+:exit
diff --git a/adei/scripts/run-apache.sh b/adei/scripts/run-apache.sh
new file mode 100755
index 0000000..3ad9d5f
--- /dev/null
+++ b/adei/scripts/run-apache.sh
@@ -0,0 +1,40 @@
+#! /bin/bash
+
+if [ ! -f /adei/cfg/apache.conf ]; then
+ cp -a /opt/configs/apache* /adei/cfg
+fi
+
+sed -i'' -re '/Listen/ { /(80|443)/!d }' /etc/apache2/listen.conf
+if [ -n "$ADEI_PORTS" ]; then
+ for port in $ADEI_PORTS; do
+ [ $port -eq 80 ] && continue
+ [ $port -eq 443 ] && continue
+
+ echo "Listen $port" >> /etc/apache2/listen.conf
+ done
+fi
+
+if [ -n "$APACHE_SERVERS" -a "$APACHE_SERVERS" -ne 0 ]; then
+ if [ $APACHE_SERVERS -eq 1 ]; then
+ start=1
+ limit=1
+ min_spare=1
+ max_spare=1
+ elif [ $APACHE_SERVERS -lt 10 ]; then
+ start=$(($APACHE_SERVERS / 2))
+ limit=$APACHE_SERVERS
+ min_spare=$start
+ max_spare=$limit
+ else
+ start=0
+ limit=$APACHE_SERVERS
+ min_spare=0
+ max_spare=0
+ fi
+ [ $start -eq 0 ] || sed -i'' -re "s/StartServers(.*)/StartServers $start/" /etc/apache2/server-tuning.conf
+ [ $limit -eq 0 ] || sed -i'' -re "s/MaxClients(.*)/MaxClients $limit/" /etc/apache2/server-tuning.conf
+ [ $min_spare -eq 0 ] || sed -i'' -re "s/MinSpareServers(.*)/MinSpareServers $min_spare/" /etc/apache2/server-tuning.conf
+ [ $max_spare -eq 0 ] || sed -i'' -re "s/MaxSpareServers(.*)/MaxSpareServers $max_spare/" /etc/apache2/server-tuning.conf
+fi
+
+/usr/sbin/apache2ctl start -D FOREGROUND
diff --git a/adei/scripts/run-cron.sh b/adei/scripts/run-cron.sh
new file mode 100755
index 0000000..5f4b9e2
--- /dev/null
+++ b/adei/scripts/run-cron.sh
@@ -0,0 +1,7 @@
+#! /bin/bash
+
+printenv | grep -v affinity:container | sed -r 's/^(.*)=("?)(.*)\2$/export \1="\3"/g' > /adei/env
+
+/opt/scripts/adei-branch.sh
+
+cron -n -m '/usr/bin/procmail -d root'
diff --git a/adei/supervisor/supervisord.conf b/adei/supervisor/supervisord.conf
new file mode 100644
index 0000000..53a6dcd
--- /dev/null
+++ b/adei/supervisor/supervisord.conf
@@ -0,0 +1,14 @@
+[supervisord]
+nodaemon=true
+
+[program:apache2]
+command=/opt/scripts/run-apache.sh
+autorestart=true
+startsecs=5
+exitcodes=0
+
+[program:cron]
+command=/opt/scripts/run-cron.sh
+autorestart=true
+startsecs=5
+exitcodes=0