From d2f7043f2b8b47058c5cd268f3dc00c9f2afae70 Mon Sep 17 00:00:00 2001 From: diginc Date: Thu, 7 Jul 2016 23:34:41 -0500 Subject: [PATCH] Various changed to docker to make CORS happy and customizable --- .gitignore | 2 +- AdminLTE | 2 +- alpine.docker | 14 ++++++++++++-- alpine/start.sh | 18 ++++++++++++++---- debian.docker | 6 ++++++ debian/start.sh | 24 +++++++++++++----------- docker_dev.sh | 1 + 7 files changed, 48 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index f7a5585..116c249 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -*.swp +*.sw* # WIP/test stuff doco.yml diff --git a/AdminLTE b/AdminLTE index 62e898e..d1ef51a 160000 --- a/AdminLTE +++ b/AdminLTE @@ -1 +1 @@ -Subproject commit 62e898e82c601e7f58ded01bd031e444843dd125 +Subproject commit d1ef51a3589a2b3b7dfa1017f2c2c6b9d97a3788 diff --git a/alpine.docker b/alpine.docker index fb3a43b..6a2fb17 100644 --- a/alpine.docker +++ b/alpine.docker @@ -26,18 +26,25 @@ COPY ./AdminLTE /var/www/html/admin COPY ./AdminLTE_version.txt /etc/ COPY ./pi-hole_version.txt /etc/ -# Things installer did +# Things installer did and fix alpine+nginx differences +ENV WEBLOGDIR /var/log/nginx +ENV PHP_CONFIG '/etc/php5/php-fpm.conf' RUN mkdir -p /etc/pihole/ && \ mkdir -p /var/www/html/pihole && \ mkdir -p /var/www/html/admin/ && \ chown nginx:nginx /var/www/html && \ + touch ${WEBLOGDIR}/access.log ${WEBLOGDIR}/error.log && \ + chown -R nginx:nginx ${WEBLOGDIR} && \ + sed -i 's|^user\s*=.*$|user = nginx|' $PHP_CONFIG && \ chmod 775 /var/www/html && \ touch /var/log/pihole.log && \ chmod 644 /var/log/pihole.log && \ chown dnsmasq:root /var/log/pihole.log && \ sed -i "s/@INT@/eth0/" /etc/dnsmasq.d/01-pihole.conf && \ sed -i 's|"cd /etc/.pihole/ && git describe --tags --abbrev=0"|"cat /etc/pi-hole_version.txt"|g' /var/www/html/admin/footer.php && \ - sed -i 's|"cd /var/www/html/admin/ && git describe --tags --abbrev=0"|"cat /etc/AdminLTE_version.txt"|g' /var/www/html/admin/footer.php + sed -i 's|"cd /var/www/html/admin/ && git describe --tags --abbrev=0"|"cat /etc/AdminLTE_version.txt"|g' /var/www/html/admin/footer.php && \ + sed -i 's|www-data|nginx|g' /etc/sudoers.d/pihole && \ + /bin/true # placeholder # This chould be eliminated if all (upstream) files were +x in git RUN chmod +x /usr/local/bin/*.sh @@ -45,6 +52,9 @@ RUN chmod +x /usr/local/bin/*.sh # Fix dnsmasq in docker RUN grep -q '^user=root' || echo 'user=root' >> /etc/dnsmasq.conf +# php config start passes special ENVs into +ENV PHP_ENV_CONFIG '/etc/php5/fpm.d/envs.conf' +ENV PHP_ERROR_LOG '/var/log/nginx/error.log' COPY ./alpine/start.sh / EXPOSE 53 53/udp diff --git a/alpine/start.sh b/alpine/start.sh index 135c797..08a8bc3 100755 --- a/alpine/start.sh +++ b/alpine/start.sh @@ -1,12 +1,22 @@ #!/bin/sh -if [ -n "$ServerIP" ] ; then - # /tmp/piholeIP is the current override of auto-lookup in gravity.sh - echo "$ServerIP" > /etc/pihole/piholeIP; -else +if [ -z "$ServerIP" ] ; then echo "ERROR: To function correctly you must pass an environment variables of 'ServerIP' into the docker container with the IP of your docker host from which you are passing web (80) and dns (53) ports from" exit 1 fi; +# /tmp/piholeIP is the current override of auto-lookup in gravity.sh +echo "$ServerIP" > /etc/pihole/piholeIP; +echo "[www]" > $PHP_ENV_CONFIG; +echo "env[PHP_ERROR_LOG] = ${PHP_ERROR_LOG}" >> $PHP_ENV_CONFIG; +echo "env[ServerIP] = ${ServerIP}" >> $PHP_ENV_CONFIG; + +if [ -n "$VIRTUAL_HOST" ] ; then + echo "env[VIRTUAL_HOST] = ${VIRTUAL_HOST}" >> $PHP_ENV_CONFIG; +fi; + +echo "Added ENV to php:" +cat $PHP_ENV_CONFIG + dnsType='default' DNS1=${DNS1:-'8.8.8.8'} DNS2=${DNS2:-'8.8.4.4'} diff --git a/debian.docker b/debian.docker index d250bd1..e96c2ad 100644 --- a/debian.docker +++ b/debian.docker @@ -32,10 +32,13 @@ COPY ./AdminLTE /var/www/html/admin COPY ./AdminLTE_version.txt /etc/ COPY ./pi-hole_version.txt /etc/ +ENV WEBLOGDIR /var/log/lighttpd RUN mkdir -p /etc/pihole/ && \ mkdir -p /var/www/html/pihole && \ mkdir -p /var/www/html/admin/ && \ chown www-data:www-data /var/www/html && \ + touch ${WEBLOGDIR}/access.log ${WEBLOGDIR}/error.log && \ + chown -R www-data.www-data ${WEBLOGDIR} && \ chmod 775 /var/www/html && \ lighty-enable-mod fastcgi fastcgi-php || true && \ touch /var/log/pihole.log && \ @@ -51,6 +54,9 @@ RUN chmod +x /usr/local/bin/*.sh # Fix dnsmasq in docker RUN grep -q '^user=root' || echo 'user=root' >> /etc/dnsmasq.conf +# php config start passes special ENVs into +ENV PHP_ENV_CONFIG '/etc/lighttpd/conf-enabled/15-fastcgi-php.conf' +ENV PHP_ERROR_LOG '/var/log/lighttpd/error.log' COPY ./debian/start.sh / EXPOSE 53 53/udp diff --git a/debian/start.sh b/debian/start.sh index 72cc0a2..8db6a7a 100755 --- a/debian/start.sh +++ b/debian/start.sh @@ -1,12 +1,21 @@ #!/bin/sh -if [ -n "$ServerIP" ] ; then - # /tmp/piholeIP is the current override of auto-lookup in gravity.sh - echo "$ServerIP" > /etc/pihole/piholeIP; -else +if [ -z "$ServerIP" ] ; then echo "ERROR: It is required you pass an environment variables of 'ServerIP' with the IP of your docker host which you are passing 80/53 from" exit 1 fi; +# /tmp/piholeIP is the current override of auto-lookup in gravity.sh +echo "$ServerIP" > /etc/pihole/piholeIP; +sed -i "/bin-environment/ a\\\t\t\t\"ServerIP\" => \"${ServerIP}\"," $PHP_ENV_CONFIG +sed -i "/bin-environment/ a\\\t\t\t\"PHP_ERROR_LOG\" => \"${PHP_ERROR_LOG}\"," $PHP_ENV_CONFIG + +if [ -n "$VIRTUAL_HOST" ] ; then + sed -i "/bin-environment/ a\\\t\t\t\"VIRTUAL_HOST\" => \"${VIRTUAL_HOST}\"," $PHP_ENV_CONFIG +fi; + +echo "Added ENV to php:" +grep -E '(VIRTUAL_HOST|ServerIP)' $PHP_ENV_CONFIG + dnsType='default' DNS1=${DNS1:-'8.8.8.8'} DNS2=${DNS2:-'8.8.4.4'} @@ -14,13 +23,6 @@ if [ "$DNS1" != '8.8.8.8' ] || [ "$DNS2" != '8.8.4.4' ] ; then dnsType='custom' fi; -if [ -n "$VIRTUAL_HOST" ] ; then - PHP_CONFIG='/etc/lighttpd/conf-enabled/15-fastcgi-php.conf' - sed -i "/bin-environment/ a\\\t\t\t\"VIRTUAL_HOST\" => \"${VIRTUAL_HOST}\"," $PHP_CONFIG - echo "Added ENV to php:" - grep 'VIRTUAL_HOST' $PHP_CONFIG -fi; - echo "Using $dnsType DNS servers: $DNS1 & $DNS2" sed -i "s/@DNS1@/$DNS1/" /etc/dnsmasq.d/01-pihole.conf && \ sed -i "s/@DNS2@/$DNS2/" /etc/dnsmasq.d/01-pihole.conf && \ diff --git a/docker_dev.sh b/docker_dev.sh index 8e2ec8c..23a4997 100755 --- a/docker_dev.sh +++ b/docker_dev.sh @@ -14,3 +14,4 @@ docker run -it --rm --cap-add=NET_ADMIN \ -e VIRTUAL_HOST='pihole.diginc.lan:5080' \ $@ \ diginc/pi-hole:${image:-alpine} +