diff --git a/.travis.yml b/.travis.yml index 40e90eb..4732fba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,8 @@ python: install: - pip install -r requirements.txt -script: py.test -vv test/ +script: + # prepare qemu + - docker run --rm --privileged multiarch/qemu-user-static:register --reset + # run docker build & tests + - py.test -vv test/ diff --git a/Dockerfile.template b/Dockerfile.template new file mode 100644 index 0000000..6d387c5 --- /dev/null +++ b/Dockerfile.template @@ -0,0 +1,78 @@ +FROM {{ pihole.base }} + +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/{{ 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/{{ 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' +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 && \ + sed -i '/^;pid/ s|^;||' $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 && \ + 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 '{{ 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 +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/DockerfileGeneration.py b/DockerfileGeneration.py new file mode 100644 index 0000000..40070de --- /dev/null +++ b/DockerfileGeneration.py @@ -0,0 +1,73 @@ +from jinja2 import Environment, FileSystemLoader +import os + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + +base_vars = { + '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': [ + { + 'base': 'debian:jessie', + 'arch': 'amd64' + }, + { + 'base': 'multiarch/debian-debootstrap:armhf-jessie-slim', + 'arch': 'armhf' + }, + { + 'base': 'multiarch/debian-debootstrap:arm64-jessie-slim', + 'arch': 'aarch64' + } + ], + 'alpine': [ + { + 'base': 'alpine:edge', + 'arch': 'amd64' + }, + { + 'base': 'multiarch/alpine:armhf-edge', + 'arch': 'armhf' + }, + { + 'base': 'multiarch/alpine:aarch64-edge', + 'arch': 'aarch64' + } + ] +} + +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') + + dockerfile = 'Dockerfile_{}_{}'.format(os, image['arch']) + with open(dockerfile, 'w') as f: + f.write(template.render(pihole=merged_data)) + + +if __name__ == '__main__': + generate_dockerfiles() diff --git a/Dockerfile_alpine_aarch64 b/Dockerfile_alpine_aarch64 new file mode 100644 index 0000000..fec9dbb --- /dev/null +++ b/Dockerfile_alpine_aarch64 @@ -0,0 +1,64 @@ +FROM multiarch/alpine:aarch64-edge + +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} + +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/v1.20.0.0/s6-overlay-aarch64.tar.gz + +RUN apk upgrade --update && \ + apk add bind-tools wget curl bash libcap && \ + curl -L -s $S6OVERLAY_RELEASE \ + | tar xvzf - -C / && \ + docker-install.sh && \ + rm -rf /var/cache/apk/* + +ENTRYPOINT [ "/init" ] + +ADD s6/alpine-root / +COPY s6/service /usr/local/bin/service + +# 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 && \ + sed -i '/^;pid/ s|^;||' $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 && \ + setcap CAP_NET_BIND_SERVICE=+eip `which dnsmasq` && \ + cp -f /usr/bin/list.sh /opt/pihole/list.sh && \ + echo 'Done!' + +# 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 ./start.sh / +COPY ./bash_functions.sh / + +# IPv6 disable flag for networks/devices that do not support it +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"] \ No newline at end of file diff --git a/alpine.docker b/Dockerfile_alpine_amd64 similarity index 87% rename from alpine.docker rename to Dockerfile_alpine_amd64 index 6ea64d9..4608962 100644 --- a/alpine.docker +++ b/Dockerfile_alpine_amd64 @@ -1,13 +1,17 @@ FROM alpine:edge -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} 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/v1.19.1.1/s6-overlay-amd64.tar.gz +ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.20.0.0/s6-overlay-amd64.tar.gz RUN apk upgrade --update && \ apk add bind-tools wget curl bash libcap && \ @@ -57,4 +61,4 @@ ENV S6_LOGGING 0 ENV S6_KEEP_ENV 1 ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2 -SHELL ["/bin/bash", "-c"] +SHELL ["/bin/bash", "-c"] \ No newline at end of file diff --git a/Dockerfile_alpine_armhf b/Dockerfile_alpine_armhf new file mode 100644 index 0000000..340d65e --- /dev/null +++ b/Dockerfile_alpine_armhf @@ -0,0 +1,64 @@ +FROM multiarch/alpine:armhf-edge + +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} + +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/v1.20.0.0/s6-overlay-armhf.tar.gz + +RUN apk upgrade --update && \ + apk add bind-tools wget curl bash libcap && \ + curl -L -s $S6OVERLAY_RELEASE \ + | tar xvzf - -C / && \ + docker-install.sh && \ + rm -rf /var/cache/apk/* + +ENTRYPOINT [ "/init" ] + +ADD s6/alpine-root / +COPY s6/service /usr/local/bin/service + +# 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 && \ + sed -i '/^;pid/ s|^;||' $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 && \ + setcap CAP_NET_BIND_SERVICE=+eip `which dnsmasq` && \ + cp -f /usr/bin/list.sh /opt/pihole/list.sh && \ + echo 'Done!' + +# 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 ./start.sh / +COPY ./bash_functions.sh / + +# IPv6 disable flag for networks/devices that do not support it +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"] \ No newline at end of file diff --git a/Dockerfile_debian_aarch64 b/Dockerfile_debian_aarch64 new file mode 100644 index 0000000..33caa7d --- /dev/null +++ b/Dockerfile_debian_aarch64 @@ -0,0 +1,46 @@ +FROM multiarch/debian-debootstrap:arm64-jessie-slim + +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} + +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/v1.20.0.0/s6-overlay-aarch64.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"] \ No newline at end of file diff --git a/debian.docker b/Dockerfile_debian_amd64 similarity index 79% rename from debian.docker rename to Dockerfile_debian_amd64 index fe9c060..3600d64 100644 --- a/debian.docker +++ b/Dockerfile_debian_amd64 @@ -1,13 +1,17 @@ FROM debian:jessie -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} 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/v1.19.1.1/s6-overlay-amd64.tar.gz +ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.20.0.0/s6-overlay-amd64.tar.gz RUN apt-get update && \ apt-get install -y wget curl net-tools cron && \ @@ -21,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' @@ -38,4 +43,4 @@ ENV S6_LOGGING 0 ENV S6_KEEP_ENV 1 ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2 -SHELL ["/bin/bash", "-c"] +SHELL ["/bin/bash", "-c"] \ No newline at end of file diff --git a/debian-armhf.docker b/Dockerfile_debian_armhf similarity index 76% rename from debian-armhf.docker rename to Dockerfile_debian_armhf index 5ce57ca..e19eecb 100644 --- a/debian-armhf.docker +++ b/Dockerfile_debian_armhf @@ -1,21 +1,22 @@ -FROM jsurf/rpi-raspbian -MAINTAINER adam@diginc.us +FROM multiarch/debian-debootstrap:armhf-jessie-slim -RUN [ "cross-build-start" ] +LABEL image="diginc/pi-hole:debian_armhf" +LABEL maintainer="adam@diginc.us" +LABEL url="https://www.github.com/diginc/docker-pi-hole" -ENV IMAGE debian +ENV TAG debian +ENV ARCH armhf 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/v1.19.1.1/s6-overlay-armhf.tar.gz +ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.20.0.0/s6-overlay-armhf.tar.gz RUN apt-get update && \ apt-get install -y wget curl net-tools cron && \ curl -L -s $S6OVERLAY_RELEASE \ | tar xvzf - -C / && \ - ln /lib/ld-linux-armhf.so.3 /lib/ld-linux.so.3 && \ docker-install.sh && \ rm -rf /var/cache/apt/archives /var/lib/apt/lists/* @@ -24,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' @@ -41,6 +43,4 @@ ENV S6_LOGGING 0 ENV S6_KEEP_ENV 1 ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2 -SHELL ["/bin/bash", "-c"] - -RUN [ "cross-build-end" ] +SHELL ["/bin/bash", "-c"] \ No newline at end of file diff --git a/bash_functions.sh b/bash_functions.sh index 674dac9..6ecd419 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 @@ -188,11 +188,12 @@ setup_web_password() { fi { set +x; } 2>/dev/null } + 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 +202,7 @@ setup_ipv4_ipv6() { } test_configs() { - case $IMAGE in + case $TAG in "debian") test_configs_debian ;; "alpine") test_configs_alpine ;; esac @@ -241,8 +242,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 e3211ab..2323ec4 100755 --- a/install.sh +++ b/install.sh @@ -2,7 +2,7 @@ mkdir -p /etc/pihole/ export CORE_TAG='v3.1.4' export WEB_TAG='v3.1' -export FTL_TAG='v2.10' +export FTL_TAG='v2.11.1' # Make pihole scripts fail searching for `systemctl`, # which fails pretty miserably in docker compared to `service` @@ -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,8 +74,11 @@ 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 + sed -i "s/\$_SERVER\['SERVER_NAME'\]/\$_SERVER\['HTTP_HOST'\]/" /var/www/html/pihole/index.php fi diff --git a/requirements.txt b/requirements.txt index 00e7363..04a28a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ pytest pytest-cov pytest-xdist testinfra==1.5.1 +jinja2 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" diff --git a/test/conftest.py b/test/conftest.py index d12507b..b2f336b 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,7 +1,7 @@ import pytest import testinfra -WEB_SERVER = { 'alpine': 'nginx', 'debian': 'lighttpd' } +WEB_SERVER = { 'alpine_amd64': 'nginx', 'debian_amd64': 'lighttpd' } check_output = testinfra.get_backend( "local://" @@ -9,7 +9,7 @@ check_output = testinfra.get_backend( def DockerGeneric(request, args, image, cmd): assert 'docker' in check_output('id'), "Are you in the docker group?" - if 'diginc/pi-hole' in image: + if 'pi-hole' in image: args += " --dns 127.0.0.1 -v /dev/null:/etc/.pihole/adlists.default -e PYTEST=\"True\"" docker_run = "docker run -d {} {} {}".format(args, image, cmd) print docker_run @@ -56,17 +56,25 @@ def DockerPersist(request, persist_args, persist_image, persist_cmd, Dig): def args(request): return '-e ServerIP="127.0.0.1" -e ServerIPv6="::1"' -@pytest.fixture(params=['alpine', 'debian']) -def tag(request): +@pytest.fixture(params=['amd64', 'armhf', 'aarch64']) +def arch(request): return request.param +@pytest.fixture(params=['debian', 'alpine']) +def os(request): + return request.param + +@pytest.fixture() +def tag(request, os, arch): + return '{}_{}'.format(os, arch) + @pytest.fixture def webserver(request, tag): return WEB_SERVER[tag] @pytest.fixture() def image(request, tag): - return 'diginc/pi-hole:{}'.format(tag) + return 'pi-hole:{}'.format(tag) @pytest.fixture() def cmd(request): @@ -76,7 +84,7 @@ def cmd(request): def persist_args(request): return '-e ServerIP="127.0.0.1" -e ServerIPv6="::1"' -@pytest.fixture(scope='module', params=['alpine', 'debian']) +@pytest.fixture(scope='module', params=['alpine_amd64', 'debian_amd64']) def persist_tag(request): return request.param @@ -86,7 +94,7 @@ def persist_webserver(request, persist_tag): @pytest.fixture(scope='module') def persist_image(request, persist_tag): - return 'diginc/pi-hole:{}'.format(persist_tag) + return 'pi-hole:{}'.format(persist_tag) @pytest.fixture(scope='module') def persist_cmd(request): diff --git a/test/test_000_build_containers.py b/test/test_000_build_containers.py index 1940e8f..64611d6 100644 --- a/test/test_000_build_containers.py +++ b/test/test_000_build_containers.py @@ -1,19 +1,23 @@ ''' This file starts with 000 to make it run first ''' import pytest import testinfra +import DockerfileGeneration run_local = testinfra.get_backend( "local://" ).get_module("Command").run -@pytest.mark.parametrize("upstream,image,tag", [ - ( 'alpine:edge', 'alpine.docker', 'diginc/pi-hole:alpine' ), - ( 'debian:jessie', 'debian.docker', 'diginc/pi-hole:debian' ), - #( 'jsurf/rpi-raspbian', 'debian-armhf.docker', 'diginc/pi-hole:arm' ), -]) -def test_build_pihole_image(upstream, image, tag): - run_local('docker pull {}'.format(upstream)) - build_cmd = run_local('docker build -f {} -t {} .'.format(image, tag)) + +def test_generate_dockerfiles(): + DockerfileGeneration.generate_dockerfiles() + +@pytest.mark.parametrize('arch', [ 'amd64', 'armhf', 'aarch64' ]) +@pytest.mark.parametrize('os', [ 'debian', 'alpine' ]) +def test_build_pihole_image(os, arch): + ''' Build the entire matrix of OS+Architecture ''' + dockerfile = 'Dockerfile_{}_{}'.format(os, arch) + image_tag = '{}:{}_{}'.format('pi-hole', os, arch) + build_cmd = run_local('docker build --pull -f {} -t {} .'.format(dockerfile, image_tag)) if build_cmd.rc != 0: print build_cmd.stdout print build_cmd.stderr diff --git a/test/test_bash_functions.py b/test/test_bash_functions.py index 552067b..344beb1 100644 --- a/test/test_bash_functions.py +++ b/test/test_bash_functions.py @@ -9,7 +9,7 @@ DEFAULTARGS = '-e ServerIP="127.0.0.1" ' (DEFAULTARGS + '-e "IPv6=False"', False, 'IPv4'), (DEFAULTARGS + '-e "IPv6=foobar"', False, 'IPv4'), ]) -def test_IPv6_not_True_removes_ipv6(Docker, tag, args, expected_ipv6, expected_stdout): +def test_IPv6_not_True_removes_ipv6(Docker, os, args, expected_ipv6, expected_stdout): ''' When a user overrides IPv6=True they only get IPv4 listening webservers ''' IPV6_LINE = { 'alpine': 'listen [::]:80 default_server', 'debian': 'use-ipv6.pl' } @@ -18,8 +18,8 @@ def test_IPv6_not_True_removes_ipv6(Docker, tag, args, expected_ipv6, expected_s function = Docker.run('. /bash_functions.sh ; setup_ipv4_ipv6') assert "Using {}".format(expected_stdout) in function.stdout - config = Docker.run('cat {}'.format( WEB_CONFIG[tag])).stdout - assert (IPV6_LINE[tag] in config) == expected_ipv6 + config = Docker.run('cat {}'.format( WEB_CONFIG[os])).stdout + assert (IPV6_LINE[os] in config) == expected_ipv6 @pytest.mark.parametrize('args, expected_stdout, dns1, dns2', [ ('-e ServerIP="1.2.3.4"', 'default DNS', '8.8.8.8', '8.8.4.4' ), @@ -54,11 +54,11 @@ expected_debian_lines = [ '"ServerIP" => "127.0.0.1"', '"PHP_ERROR_LOG" => "/var/log/lighttpd/error.log"' ] -@pytest.mark.parametrize('tag,expected_lines,repeat_function', [ +@pytest.mark.parametrize('os,expected_lines,repeat_function', [ ('debian', expected_debian_lines, 1), ('debian', expected_debian_lines, 2) ]) -def test_debian_setup_php_env(Docker, tag, expected_lines, repeat_function): +def test_debian_setup_php_env(Docker, os, expected_lines, repeat_function): ''' confirm all expected output is there and nothing else ''' stdout = '' for i in range(repeat_function):