Skip to content

Commit

Permalink
Adding docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
mettke committed Apr 7, 2019
1 parent 772fc84 commit 7cc45d9
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 7 deletions.
38 changes: 38 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM alpine:3.8
LABEL maintainer="Marc Mettke <marc@itmettke.de>"

ENV SYSTEM https://github.com/operasoftware/ssh-key-authority.git
ADD entrypoint.sh /entrypoint.sh
ADD healthcheck.sh /healthcheck.sh
ADD cron /var/spool/cron/crontabs/root

RUN mkdir -p /var/log/keys/ /run/php/ /ska/ && \
adduser --system --disabled-password keys-sync && \
apk add openssh \
php \
php-fpm \
php7-json \
php7-ldap \
php7-mbstring \
php7-mysqli \
php7-pcntl \
php7-posix \
php7-ssh2 \
rsync \
ssmtp \
sudo && \
sed -i -e '/listen =/ s/= .*/= 0.0.0.0:9000/' /etc/php7/php-fpm.d/www.conf && \
sed -i -e '/;pid =/ s/.*/pid = \/var\/run\/php-fpm.pid/' /etc/php7/php-fpm.conf && \
echo "" >> /etc/php7/php-fpm.conf && \
chmod +x /entrypoint.sh /healthcheck.sh
RUN apk add git && \
git clone ${SYSTEM} /ska && \
apk del git && \
chown -R keys-sync:nogroup /ska/config

EXPOSE 9000
VOLUME /ska/config
VOLUME /public_html

ENTRYPOINT "/entrypoint.sh"
HEALTHCHECK CMD /healcheck.sh
2 changes: 2 additions & 0 deletions docker/cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0 1 * * * /ska/scripts/ldap_update.php
*/1 * * * * /bin/ash -c "PID=$(cat /var/run/keys-sync.pid) && [ -n ${PID} -a -d /proc/${PID} ] || /ska/scripts/syncd.php --user keys-sync"
35 changes: 35 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env ash
if [ `whoami` == 'keys-sync' ]; then
if [ ! -r /ska/config/config.ini ]; then
echo "config.ini not found or incorrect permissions."
echo "Permissions must be $(id -u keys-sync):$(id -g keys-sync) with at least 400"
exit 1
fi
if [ ! -r /ska/config/keys-sync ]; then
echo "private key not found or incorrect permissions."
echo "Permissions must be $(id -u keys-sync):$(id -g keys-sync) with 400"
exit 1
fi
if [ ! -r /ska/config/keys-sync.pub ]; then
echo "public key not found or incorrect permissions."
echo "Permissions must be $(id -u keys-sync):$(id -g keys-sync) with at least 400"
exit 1
fi
if ! grep "^timeout_util = BusyBox$" /ska/config/config.ini > /dev/null; then
echo "timeout_util must be set to BusyBox."
echo "Change it to: timeout_util = BusyBox"
exit 1
fi
elif [ $(id -u) = 0 ]; then
if ! sudo -u keys-sync /entrypoint.sh; then
exit 1
fi
rsync -a --delete /ska/public_html/ /public_html/
/usr/sbin/crond
echo "Waiting for database..."
sleep 5
/ska/scripts/syncd.php --user keys-sync
/usr/sbin/php-fpm7 -F
else
echo "Must be executed with root"
fi
7 changes: 7 additions & 0 deletions docker/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ash
for PID_FILE in /var/run/crond.pid /var/run/keys-sync.pid /var/run/php-fpm.pid; do
PID=$(cat ${PID_FILE})
if ! [ -n "${PID}" -a -d "/proc/${PID}" ]; then
exit 1
fi
done
3 changes: 2 additions & 1 deletion examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
db/
db/
public_html/
9 changes: 4 additions & 5 deletions examples/httpd-ldap/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@ services:
- net

ska-php:
image: alpine:3.8
command: /bin/ash -c "mkdir -p /var/log/keys /run/php/ && (id -u keys-sync 2> /dev/null || adduser --system --disabled-password keys-sync) && chown keys-sync:nogroup /ska/config/keys-sync && apk add php php-fpm ssmtp openssh php7-json php7-ldap php7-mbstring php7-mysqli php7-ssh2 php7-posix php7-pcntl && sed -i -e '/listen =/ s/= .*/= 0.0.0.0:9000/' /etc/php7/php-fpm.d/www.conf && crond && /ska/scripts/syncd.php --user keys-sync && php-fpm7 -F"
build:
context: ../../docker
restart: always
depends_on:
- ska-db
- mail
volumes:
- ../../:/ska/:ro
- ../shared/config-ldap/:/ska/config/:rw
- ../shared/ssmtp.conf:/etc/ssmtp/ssmtp.conf:ro
- ../shared/cron/:/var/spool/cron/crontabs/:rw
- ./public_html:/public_html:rw
networks:
- net

Expand All @@ -62,7 +61,7 @@ services:
depends_on:
- ska-php
volumes:
- ../../:/ska/:ro
- ./public_html:/ska/public_html:ro
- ./httpd.conf:/usr/local/apache2/conf/httpd.conf:ro
networks:
- net
Expand Down
1 change: 0 additions & 1 deletion examples/shared/cron/root

This file was deleted.

0 comments on commit 7cc45d9

Please sign in to comment.