diff --git a/Dockerfile_alpine.template b/Dockerfile.template similarity index 66% rename from Dockerfile_alpine.template rename to Dockerfile.template index b605139..6d387c5 100644 --- a/Dockerfile_alpine.template +++ b/Dockerfile.template @@ -1,27 +1,40 @@ -FROM {{ image.base }} -LABEL maintainer="{{ image.maintainer }}" +FROM {{ pihole.base }} -ENV IMAGE {{ os }} -ENV ARCH {{ image.arch }} +LABEL image="{{ pihole.name }}:{{ pihole.os }}_{{ pihole.arch }}" +LABEL maintainer="{{ pihole.maintainer }}" +LABEL url="https://www.github.com/diginc/docker-pi-hole" + +ENV TAG {{ pihole.os }} +ENV ARCH {{ pihole.arch }} ENV PATH /opt/pihole:${PATH} COPY install.sh /usr/local/bin/docker-install.sh ENV setupVars /etc/pihole/setupVars.conf ENV PIHOLE_INSTALL /tmp/ph_install.sh -ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/{{ image.s6_version }}/s6-overlay-{{ image.arch }}.tar.gz +ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/{{ pihole.s6_version }}/s6-overlay-{{ pihole.arch }}.tar.gz +{% if pihole.os == 'alpine' %} RUN apk upgrade --update && \ apk add bind-tools wget curl bash libcap && \ +{% else %} +RUN apt-get update && \ + apt-get install -y wget curl net-tools cron && \ +{% endif %} curl -L -s $S6OVERLAY_RELEASE \ | tar xvzf - -C / && \ docker-install.sh && \ +{% if pihole.os == 'alpine' %} rm -rf /var/cache/apk/* +{% else %} + rm -rf /var/cache/apt/archives /var/lib/apt/lists/* +{% endif %} ENTRYPOINT [ "/init" ] -ADD s6/alpine-root / +ADD s6/{{ pihole.os }}-root / COPY s6/service /usr/local/bin/service +{% if pihole.os == 'alpine' %} # Things installer did and fix alpine+nginx differences ENV WEBLOGDIR /var/log/nginx ENV PHP_CONFIG '/etc/php5/php-fpm.conf' @@ -41,14 +54,18 @@ RUN mkdir -p /etc/pihole/ && \ setcap CAP_NET_BIND_SERVICE=+eip `which dnsmasq` && \ cp -f /usr/bin/list.sh /opt/pihole/list.sh && \ echo 'Done!' +{% endif %} # 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' +ENV PHP_ENV_CONFIG '{{ pihole.php_env_config }}' +ENV PHP_ERROR_LOG '{{ pihole.php_error_log }}' COPY ./start.sh / COPY ./bash_functions.sh / # IPv6 disable flag for networks/devices that do not support it +{% if pihole.os == 'debian' %} +# not fully supported in debian yet +{% endif %} ENV IPv6 True EXPOSE 53 53/udp diff --git a/DockerfileGeneration.py b/DockerfileGeneration.py index 4c7454c..40070de 100644 --- a/DockerfileGeneration.py +++ b/DockerfileGeneration.py @@ -4,52 +4,70 @@ import os THIS_DIR = os.path.dirname(os.path.abspath(__file__)) base_vars = { - 'name': 'pi-hole', + 'name': 'diginc/pi-hole', 'maintainer' : 'adam@diginc.us', 's6_version' : 'v1.20.0.0', } +os_base_vars = { + 'debian': { + 'php_env_config': '/etc/lighttpd/conf-enabled/15-fastcgi-php.conf', + 'php_error_log': '/var/log/lighttpd/error.log' + }, + 'alpine': { + 'php_env_config': '/etc/php5/fpm.d/envs.conf', + 'php_error_log': '/var/log/nginx/error.log' + } +} + images = { 'debian': [ - dict(base_vars.items() + { + { 'base': 'debian:jessie', 'arch': 'amd64' - }.items()), - dict(base_vars.items() + { + }, + { 'base': 'multiarch/debian-debootstrap:armhf-jessie-slim', 'arch': 'armhf' - }.items()), - dict(base_vars.items() + { + }, + { 'base': 'multiarch/debian-debootstrap:arm64-jessie-slim', 'arch': 'aarch64' - }.items()), + } ], 'alpine': [ - dict(base_vars.items() + { + { 'base': 'alpine:edge', 'arch': 'amd64' - }.items()), - dict(base_vars.items() + { + }, + { 'base': 'multiarch/alpine:armhf-edge', 'arch': 'armhf' - }.items()), - dict(base_vars.items() + { + }, + { 'base': 'multiarch/alpine:aarch64-edge', 'arch': 'aarch64' - }.items()) + } ] } def generate_dockerfiles(): for os, archs in images.iteritems(): for image in archs: + merged_data = dict( + { 'os': os }.items() + + base_vars.items() + + os_base_vars[os].items() + + image.items() + ) j2_env = Environment(loader=FileSystemLoader(THIS_DIR), trim_blocks=True) - template = j2_env.get_template('Dockerfile_{}.template'.format(os)) + template = j2_env.get_template('Dockerfile.template') dockerfile = 'Dockerfile_{}_{}'.format(os, image['arch']) with open(dockerfile, 'w') as f: - f.write(template.render(os=os, image=image)) + f.write(template.render(pihole=merged_data)) + if __name__ == '__main__': generate_dockerfiles() diff --git a/Dockerfile_alpine_aarch64 b/Dockerfile_alpine_aarch64 index 485c93d..fec9dbb 100644 --- a/Dockerfile_alpine_aarch64 +++ b/Dockerfile_alpine_aarch64 @@ -1,7 +1,10 @@ FROM multiarch/alpine:aarch64-edge -LABEL maintainer="adam@diginc.us" -ENV IMAGE alpine +LABEL image="diginc/pi-hole:alpine_aarch64" +LABEL maintainer="adam@diginc.us" +LABEL url="https://www.github.com/diginc/docker-pi-hole" + +ENV TAG alpine ENV ARCH aarch64 ENV PATH /opt/pihole:${PATH} diff --git a/Dockerfile_alpine_amd64 b/Dockerfile_alpine_amd64 index 30b8a77..4608962 100644 --- a/Dockerfile_alpine_amd64 +++ b/Dockerfile_alpine_amd64 @@ -1,7 +1,10 @@ FROM alpine:edge -LABEL maintainer="adam@diginc.us" -ENV IMAGE alpine +LABEL image="diginc/pi-hole:alpine_amd64" +LABEL maintainer="adam@diginc.us" +LABEL url="https://www.github.com/diginc/docker-pi-hole" + +ENV TAG alpine ENV ARCH amd64 ENV PATH /opt/pihole:${PATH} diff --git a/Dockerfile_alpine_armhf b/Dockerfile_alpine_armhf index 09753dc..340d65e 100644 --- a/Dockerfile_alpine_armhf +++ b/Dockerfile_alpine_armhf @@ -1,7 +1,10 @@ FROM multiarch/alpine:armhf-edge -LABEL maintainer="adam@diginc.us" -ENV IMAGE alpine +LABEL image="diginc/pi-hole:alpine_armhf" +LABEL maintainer="adam@diginc.us" +LABEL url="https://www.github.com/diginc/docker-pi-hole" + +ENV TAG alpine ENV ARCH armhf ENV PATH /opt/pihole:${PATH} diff --git a/Dockerfile_debian.template b/Dockerfile_debian.template deleted file mode 100644 index 1a003bc..0000000 --- a/Dockerfile_debian.template +++ /dev/null @@ -1,42 +0,0 @@ -FROM {{ image.base }} -LABEL maintainer="{{ image.maintainer }}" - -ENV IMAGE {{ os }} -ENV ARCH {{ image.arch }} -ENV PATH /opt/pihole:${PATH} - -COPY install.sh /usr/local/bin/docker-install.sh -ENV setupVars /etc/pihole/setupVars.conf -ENV PIHOLE_INSTALL /tmp/ph_install.sh -ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/{{ image.s6_version }}/s6-overlay-{{ image.arch }}.tar.gz - -RUN apt-get update && \ - apt-get install -y wget curl net-tools cron && \ - curl -L -s $S6OVERLAY_RELEASE \ - | tar xvzf - -C / && \ - docker-install.sh && \ - rm -rf /var/cache/apt/archives /var/lib/apt/lists/* - -ENTRYPOINT [ "/init" ] - -ADD s6/debian-root / -COPY s6/service /usr/local/bin/service - -# 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 ./start.sh / -COPY ./bash_functions.sh / - -# IPv6 disable flag for networks/devices that do not support it -# not fully supported in debian yet -ENV IPv6 True - -EXPOSE 53 53/udp -EXPOSE 80 - -ENV S6_LOGGING 0 -ENV S6_KEEP_ENV 1 -ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2 - -SHELL ["/bin/bash", "-c"] diff --git a/Dockerfile_debian_aarch64 b/Dockerfile_debian_aarch64 index 32b136e..33caa7d 100644 --- a/Dockerfile_debian_aarch64 +++ b/Dockerfile_debian_aarch64 @@ -1,7 +1,10 @@ FROM multiarch/debian-debootstrap:arm64-jessie-slim -LABEL maintainer="adam@diginc.us" -ENV IMAGE debian +LABEL image="diginc/pi-hole:debian_aarch64" +LABEL maintainer="adam@diginc.us" +LABEL url="https://www.github.com/diginc/docker-pi-hole" + +ENV TAG debian ENV ARCH aarch64 ENV PATH /opt/pihole:${PATH} @@ -22,6 +25,7 @@ ENTRYPOINT [ "/init" ] ADD s6/debian-root / COPY s6/service /usr/local/bin/service + # 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' diff --git a/Dockerfile_debian_amd64 b/Dockerfile_debian_amd64 index 103cc2e..3600d64 100644 --- a/Dockerfile_debian_amd64 +++ b/Dockerfile_debian_amd64 @@ -1,7 +1,10 @@ FROM debian:jessie -LABEL maintainer="adam@diginc.us" -ENV IMAGE debian +LABEL image="diginc/pi-hole:debian_amd64" +LABEL maintainer="adam@diginc.us" +LABEL url="https://www.github.com/diginc/docker-pi-hole" + +ENV TAG debian ENV ARCH amd64 ENV PATH /opt/pihole:${PATH} @@ -22,6 +25,7 @@ ENTRYPOINT [ "/init" ] ADD s6/debian-root / COPY s6/service /usr/local/bin/service + # 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' diff --git a/Dockerfile_debian_armhf b/Dockerfile_debian_armhf index 8e298af..e19eecb 100644 --- a/Dockerfile_debian_armhf +++ b/Dockerfile_debian_armhf @@ -1,7 +1,10 @@ FROM multiarch/debian-debootstrap:armhf-jessie-slim -LABEL maintainer="adam@diginc.us" -ENV IMAGE debian +LABEL image="diginc/pi-hole:debian_armhf" +LABEL maintainer="adam@diginc.us" +LABEL url="https://www.github.com/diginc/docker-pi-hole" + +ENV TAG debian ENV ARCH armhf ENV PATH /opt/pihole:${PATH} @@ -22,6 +25,7 @@ ENTRYPOINT [ "/init" ] ADD s6/debian-root / COPY s6/service /usr/local/bin/service + # 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' diff --git a/bash_functions.sh b/bash_functions.sh index 674dac9..f02b1bf 100644 --- a/bash_functions.sh +++ b/bash_functions.sh @@ -17,7 +17,7 @@ validate_env() { # Debian nc_error='Name or service not known' - if [[ "$IMAGE" == 'alpine' ]] ; then + if [[ "$TAG" == 'alpine' ]] ; then nc_error='bad address' fi; @@ -119,7 +119,7 @@ setup_dnsmasq_hostnames() { } setup_lighttpd_bind() { - if [[ "$IMAGE" == 'debian' ]] ; then + if [[ "$TAG" == 'debian' ]] ; then # if using '--net=host' only bind lighttpd on $ServerIP if grep -q "docker" /proc/net/dev ; then #docker (docker0 by default) should only be present on the host system if ! grep -q "server.bind" /etc/lighttpd/lighttpd.conf ; then # if the declaration is already there, don't add it again @@ -130,7 +130,7 @@ setup_lighttpd_bind() { } setup_php_env() { - case $IMAGE in + case $TAG in "debian") setup_php_env_debian ;; "alpine") setup_php_env_alpine ;; esac @@ -192,7 +192,7 @@ setup_ipv4_ipv6() { local ip_versions="IPv4 and IPv6" if [ "$IPv6" != "True" ] ; then ip_versions="IPv4" - case $IMAGE in + case $TAG in "debian") sed -i '/use-ipv6.pl/ d' /etc/lighttpd/lighttpd.conf ;; "alpine") sed -i '/listen \[::\]:80/ d' /etc/nginx/nginx.conf ;; esac @@ -201,7 +201,7 @@ setup_ipv4_ipv6() { } test_configs() { - case $IMAGE in + case $TAG in "debian") test_configs_debian ;; "alpine") test_configs_alpine ;; esac @@ -241,8 +241,8 @@ docker_main() { echo -n '::: Starting up DNS and Webserver ...' service dnsmasq restart # Just get DNS up. The webserver is down!!! - IMAGE="$1" - case $IMAGE in # Setup webserver + TAG="$1" + case $TAG in # Setup webserver "alpine") php-fpm5 nginx diff --git a/install.sh b/install.sh index 8b838ba..a1af9e2 100755 --- a/install.sh +++ b/install.sh @@ -13,7 +13,7 @@ mv "$(which debconf-apt-progress)" /bin/no_debconf-apt-progress # Get the install functions wget -O "$PIHOLE_INSTALL" https://raw.githubusercontent.com/pi-hole/pi-hole/${CORE_TAG}/automated%20install/basic-install.sh -if [[ "$IMAGE" == 'alpine' ]] ; then +if [[ "$TAG" == 'alpine' ]] ; then sed -i '/OS distribution not supported/ i\ echo "Hi Alpine"' "$PIHOLE_INSTALL" sed -i '/OS distribution not supported/,+1d' "$PIHOLE_INSTALL" sed -i 's#nologin pihole#nologin pihole 2>/dev/null || adduser -S -s /sbin/nologin pihole#g' "$PIHOLE_INSTALL" @@ -36,7 +36,7 @@ PH_TEST=true . "${PIHOLE_INSTALL}" # Run only what we need from installer export USER=pihole -if [[ "$IMAGE" == 'debian' ]] ; then +if [[ "$TAG" == 'debian' ]] ; then distro_check install_dependent_packages INSTALLER_DEPS[@] install_dependent_packages PIHOLE_DEPS[@] @@ -44,7 +44,7 @@ if [[ "$IMAGE" == 'debian' ]] ; then sed -i "/sleep 2/ d" /etc/init.d/dnsmasq # SLOW # IPv6 support for nc openbsd better than traditional apt-get install -y --force-yes netcat-openbsd -elif [[ "$IMAGE" == 'alpine' ]] ; then +elif [[ "$TAG" == 'alpine' ]] ; then apk add \ dnsmasq \ nginx \ @@ -74,7 +74,7 @@ tmpLog="${tmpLog}" instalLogLoc="${instalLogLoc}" installPihole | tee "${tmpLog}" sed -i 's/readonly //g' /opt/pihole/webpage.sh -if [[ "$IMAGE" == 'alpine' ]] ; then +if [[ "$TAG" == 'alpine' ]] ; then cp /etc/.pihole/advanced/pihole.cron /etc/crontabs/pihole # Fix hostname bug on block page diff --git a/start.sh b/start.sh index 2e4585a..55e3441 100755 --- a/start.sh +++ b/start.sh @@ -1,6 +1,6 @@ #!/bin/bash -e # Dockerfile variables -export IMAGE +export TAG export ServerIP export ServerIPv6 export PYTEST @@ -25,7 +25,7 @@ setup_dnsmasq "$DNS1" "$DNS2" setup_php_env setup_dnsmasq_hostnames "$ServerIP" "$ServerIPv6" "$HOSTNAME" setup_ipv4_ipv6 -setup_lighttpd_bind "$ServerIP" "$IMAGE" +setup_lighttpd_bind "$ServerIP" "$TAG" test_configs test_framework_stubbing echo "::: Docker start setup complete - beginning s6 services"