diff --git a/alpine.docker b/alpine.docker index 6d55c89..fb70104 100644 --- a/alpine.docker +++ b/alpine.docker @@ -18,11 +18,8 @@ RUN apk upgrade --update && \ ENTRYPOINT [ "/init" ] -ADD alpine/root / -COPY ./alpine/service /usr/local/bin/service - -# Customized from submodules -COPY ./alpine/nginx.conf /etc/nginx/nginx.conf +ADD s6/alpine-root / +COPY s6/service /usr/local/bin/service # Things installer did and fix alpine+nginx differences ENV WEBLOGDIR /var/log/nginx @@ -52,7 +49,7 @@ 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 +# IPv6 disable flag for networks/devices that do not support it ENV IPv6 True EXPOSE 53 53/udp @@ -60,7 +57,5 @@ EXPOSE 80 ENV S6_LOGGING 0 ENV S6_KEEP_ENV 1 -#ENV S6_LOGGING_SCRIPT "n20 s1000000 T" SHELL ["/bin/bash", "-c"] -#CMD [ "/start.sh" ] diff --git a/bash_functions.sh b/bash_functions.sh index bdc42cb..52e5bd1 100644 --- a/bash_functions.sh +++ b/bash_functions.sh @@ -182,16 +182,3 @@ test_configs_alpine() { test_framework_stubbing() { if [ -n "$PYTEST" ] ; then sed -i 's/^gravity_spinup$/#gravity_spinup # DISABLED FOR PYTEST/g' "$(which gravity.sh)"; fi; } - -docker_main() { - IMAGE="$1" - case $IMAGE in # Setup webserver - "debian") - echo -n '::: Starting up DNS and Webserver ...' - service dnsmasq restart - service lighttpd start - gravity.sh - tail -F "${WEBLOGDIR}"/*.log /var/log/pihole.log - ;; - esac -} diff --git a/debian.docker b/debian.docker index 8b46d34..cd60282 100644 --- a/debian.docker +++ b/debian.docker @@ -4,22 +4,23 @@ MAINTAINER adam@diginc.us ENV IMAGE debian ENV PATH /opt/pihole:${PATH} -COPY install.sh /install.sh +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.18.1.5/s6-overlay-amd64.tar.gz -ENV TINI_VERSION v0.13.0 -ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini -ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini.asc /tini.asc - -RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 0527A9B7 && \ - gpg --verify /tini.asc && \ - chmod +x /tini && \ - apt-get -q update && \ - apt-get install -y wget net-tools && \ - /install.sh && \ +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' @@ -33,6 +34,7 @@ ENV IPv6 True EXPOSE 53 53/udp EXPOSE 80 +ENV S6_LOGGING 0 +ENV S6_KEEP_ENV 1 + SHELL ["/bin/bash", "-c"] -ENTRYPOINT ["/tini", "--"] -CMD [ "/start.sh" ] diff --git a/alpine/root/etc/cont-init.d/20-start.sh b/s6/alpine-root/etc/cont-init.d/20-start.sh similarity index 100% rename from alpine/root/etc/cont-init.d/20-start.sh rename to s6/alpine-root/etc/cont-init.d/20-start.sh diff --git a/alpine/root/etc/fix-attrs.d/01-resolver-resolv b/s6/alpine-root/etc/fix-attrs.d/01-resolver-resolv similarity index 100% rename from alpine/root/etc/fix-attrs.d/01-resolver-resolv rename to s6/alpine-root/etc/fix-attrs.d/01-resolver-resolv diff --git a/alpine/nginx.conf b/s6/alpine-root/etc/nginx/nginx.conf similarity index 100% rename from alpine/nginx.conf rename to s6/alpine-root/etc/nginx/nginx.conf diff --git a/alpine/root/etc/services.d/cron/run b/s6/alpine-root/etc/services.d/cron/run similarity index 100% rename from alpine/root/etc/services.d/cron/run rename to s6/alpine-root/etc/services.d/cron/run diff --git a/alpine/root/etc/services.d/dnsmasq/finish b/s6/alpine-root/etc/services.d/dnsmasq/finish similarity index 100% rename from alpine/root/etc/services.d/dnsmasq/finish rename to s6/alpine-root/etc/services.d/dnsmasq/finish diff --git a/alpine/root/etc/services.d/dnsmasq/run b/s6/alpine-root/etc/services.d/dnsmasq/run similarity index 100% rename from alpine/root/etc/services.d/dnsmasq/run rename to s6/alpine-root/etc/services.d/dnsmasq/run diff --git a/alpine/root/etc/services.d/nginx/run b/s6/alpine-root/etc/services.d/nginx/run similarity index 100% rename from alpine/root/etc/services.d/nginx/run rename to s6/alpine-root/etc/services.d/nginx/run diff --git a/alpine/root/etc/services.d/php-fpm/run b/s6/alpine-root/etc/services.d/php-fpm/run similarity index 100% rename from alpine/root/etc/services.d/php-fpm/run rename to s6/alpine-root/etc/services.d/php-fpm/run diff --git a/alpine/root/usr/bin/host-ip b/s6/alpine-root/usr/bin/host-ip similarity index 100% rename from alpine/root/usr/bin/host-ip rename to s6/alpine-root/usr/bin/host-ip diff --git a/alpine/root/usr/bin/set-contenv b/s6/alpine-root/usr/bin/set-contenv similarity index 100% rename from alpine/root/usr/bin/set-contenv rename to s6/alpine-root/usr/bin/set-contenv diff --git a/s6/debian-root/etc/cont-init.d/20-start.sh b/s6/debian-root/etc/cont-init.d/20-start.sh new file mode 100644 index 0000000..4b09fe9 --- /dev/null +++ b/s6/debian-root/etc/cont-init.d/20-start.sh @@ -0,0 +1,4 @@ +#!/usr/bin/with-contenv bash + +/start.sh +gravity.sh diff --git a/s6/debian-root/etc/fix-attrs.d/01-resolver-resolv b/s6/debian-root/etc/fix-attrs.d/01-resolver-resolv new file mode 100644 index 0000000..84e9986 --- /dev/null +++ b/s6/debian-root/etc/fix-attrs.d/01-resolver-resolv @@ -0,0 +1 @@ +/etc/resolv.conf false doesntexist,0:1000 0664 0664 \ No newline at end of file diff --git a/s6/debian-root/etc/services.d/cron/run b/s6/debian-root/etc/services.d/cron/run new file mode 100644 index 0000000..b2ad9b7 --- /dev/null +++ b/s6/debian-root/etc/services.d/cron/run @@ -0,0 +1,7 @@ +#!/usr/bin/with-contenv bash +s6-echo "Starting crond" + +exec -c +fdmove -c 2 1 + +/usr/sbin/cron -f diff --git a/s6/debian-root/etc/services.d/dnsmasq/finish b/s6/debian-root/etc/services.d/dnsmasq/finish new file mode 100644 index 0000000..77aec95 --- /dev/null +++ b/s6/debian-root/etc/services.d/dnsmasq/finish @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv bash + +kill -9 $(pgrep dnsmasq) diff --git a/s6/debian-root/etc/services.d/dnsmasq/run b/s6/debian-root/etc/services.d/dnsmasq/run new file mode 100644 index 0000000..7a19a39 --- /dev/null +++ b/s6/debian-root/etc/services.d/dnsmasq/run @@ -0,0 +1,5 @@ +#!/usr/bin/with-contenv bash + +s6-echo "Starting dnsmasq" + +s6-setuidgid root dnsmasq -7 /etc/dnsmasq.d --no-daemon diff --git a/s6/debian-root/etc/services.d/lighttpd/run b/s6/debian-root/etc/services.d/lighttpd/run new file mode 100644 index 0000000..20a1809 --- /dev/null +++ b/s6/debian-root/etc/services.d/lighttpd/run @@ -0,0 +1,5 @@ +#!/usr/bin/with-contenv bash + +s6-echo "Starting lighttpd" + +lighttpd -D -f /etc/lighttpd/lighttpd.conf diff --git a/s6/debian-root/usr/bin/host-ip b/s6/debian-root/usr/bin/host-ip new file mode 100755 index 0000000..ff2f67b --- /dev/null +++ b/s6/debian-root/usr/bin/host-ip @@ -0,0 +1,10 @@ +#!/usr/bin/with-contenv sh + +# +# This script will determine the network IP of the container. +# +# Return format should be a single IP address. +# + +# Default to using the value of the $HOSTNAME ENV variable. +getent hosts ${1:-$HOSTNAME} | awk '{print $1}' diff --git a/s6/debian-root/usr/bin/set-contenv b/s6/debian-root/usr/bin/set-contenv new file mode 100755 index 0000000..7cb86c9 --- /dev/null +++ b/s6/debian-root/usr/bin/set-contenv @@ -0,0 +1,12 @@ +#!/usr/bin/execlineb -S0 + +if { s6-test $# -eq 2 } + +backtick -in FILENAME { + pipeline { s6-echo "${1}" } + tr "a-z" "A-Z" +} +import -u FILENAME + +redirfd -w 1 /var/run/s6/container_environment/${FILENAME} +s6-echo -n -- ${2} diff --git a/alpine/service b/s6/service similarity index 78% rename from alpine/service rename to s6/service index 4360442..10ab8df 100755 --- a/alpine/service +++ b/s6/service @@ -27,9 +27,4 @@ if [[ ! -d "/var/run/s6/services/$service" ]] ; then exit fi; -if [[ "$service" == 'lighttpd' ]] ; then - echo -e "Lighttpd replaced by nginx in diginc/pi-hole:alpine\nrunning service nginx $command instead"; - service='nginx' -fi; - ${command} "${service}" diff --git a/start.sh b/start.sh index 0ecc7f8..c4ae3da 100755 --- a/start.sh +++ b/start.sh @@ -28,4 +28,4 @@ setup_ipv4_ipv6 test_configs test_framework_stubbing -docker_main "$IMAGE" +# s6's init takes care of running services now, no more main start services function diff --git a/test/conftest.py b/test/conftest.py index 70b299f..ea0cf02 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -10,8 +10,8 @@ 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: - #args += " -v /dev/null:/etc/pihole/adlists.default -e PYTEST=\"True\"" - args += " -e PYTEST=\"True\"" + args += " -v /dev/null:/etc/pihole/adlists.default -e PYTEST=\"True\"" + #args += " -e PYTEST=\"True\"" docker_run = "docker run -d {} {} {}".format(args, image, cmd) docker_id = check_output(docker_run) diff --git a/test/test_pihole_scripts.py b/test/test_pihole_scripts.py index 3b03e66..53be8ae 100644 --- a/test/test_pihole_scripts.py +++ b/test/test_pihole_scripts.py @@ -5,10 +5,6 @@ def start_cmd(): ''' broken by default, required override ''' return None -START_DNS_STDOUT = { - 'alpine': '', - 'debian': 'Restarting DNS forwarder and DHCP server: dnsmasq.\n' -} @pytest.fixture def RunningPiHole(DockerPersist, Slow, persist_webserver, persist_tag, start_cmd): ''' Override the RunningPiHole to run and check for success of a @@ -46,5 +42,5 @@ def test_pihole_start_cmd(RunningPiHole, Dig, persist_tag, start_cmd, hostname, lookup = RunningPiHole.dig.run(dig_cmd).stdout.rstrip('\n') assert lookup == expected_ip - stdout = "::: Blocking has been {}d!\n{}".format(start_cmd, START_DNS_STDOUT[persist_tag]) + stdout = "::: Blocking has been {}d!\n".format(start_cmd) assert RunningPiHole.cmd.stdout == stdout