From c1fb17a6457f4e0a721a6f8bdbd924990d0268c7 Mon Sep 17 00:00:00 2001 From: Martin Buchleitner Date: Wed, 8 May 2019 08:12:58 +0200 Subject: [PATCH] initial commit on configdir as volume Signed-off-by: Martin Buchleitner --- Dockerfile.template | 2 ++ Dockerfile_aarch64 | 2 ++ Dockerfile_amd64 | 2 ++ Dockerfile_armel | 2 ++ Dockerfile_armhf | 2 ++ bash_functions.sh | 4 ++-- install.sh | 6 +++--- start.sh | 17 +++++++---------- 8 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Dockerfile.template b/Dockerfile.template index 59ac7aa..70c62c2 100644 --- a/Dockerfile.template +++ b/Dockerfile.template @@ -1,5 +1,6 @@ FROM {{ pihole.base }} +ENV CONFIG_DIR /etc/pihole ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/{{ pihole.s6_version }}/s6-overlay-{{ pihole.s6arch }}.tar.gz COPY install.sh /usr/local/bin/install.sh COPY VERSION /etc/docker-pi-hole-version @@ -44,5 +45,6 @@ LABEL maintainer="{{ pihole.maintainer }}" LABEL url="https://www.github.com/pi-hole/docker-pi-hole" HEALTHCHECK CMD dig @127.0.0.1 pi.hole || exit 1 +VOLUME $CONFIG_DIR SHELL ["/bin/bash", "-c"] diff --git a/Dockerfile_aarch64 b/Dockerfile_aarch64 index 72a28b6..cf57676 100644 --- a/Dockerfile_aarch64 +++ b/Dockerfile_aarch64 @@ -1,5 +1,6 @@ FROM multiarch/debian-debootstrap:arm64-stretch-slim +ENV CONFIG_DIR /etc/pihole ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.7.0/s6-overlay-aarch64.tar.gz COPY install.sh /usr/local/bin/install.sh COPY VERSION /etc/docker-pi-hole-version @@ -44,5 +45,6 @@ LABEL maintainer="adam@diginc.us" LABEL url="https://www.github.com/pi-hole/docker-pi-hole" HEALTHCHECK CMD dig @127.0.0.1 pi.hole || exit 1 +VOLUME $CONFIG_DIR SHELL ["/bin/bash", "-c"] \ No newline at end of file diff --git a/Dockerfile_amd64 b/Dockerfile_amd64 index c9affac..fbc228c 100644 --- a/Dockerfile_amd64 +++ b/Dockerfile_amd64 @@ -1,5 +1,6 @@ FROM pihole/debian-base:latest +ENV CONFIG_DIR /etc/pihole ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.7.0/s6-overlay-amd64.tar.gz COPY install.sh /usr/local/bin/install.sh COPY VERSION /etc/docker-pi-hole-version @@ -44,5 +45,6 @@ LABEL maintainer="adam@diginc.us" LABEL url="https://www.github.com/pi-hole/docker-pi-hole" HEALTHCHECK CMD dig @127.0.0.1 pi.hole || exit 1 +VOLUME $CONFIG_DIR SHELL ["/bin/bash", "-c"] \ No newline at end of file diff --git a/Dockerfile_armel b/Dockerfile_armel index fbac05b..87901cb 100644 --- a/Dockerfile_armel +++ b/Dockerfile_armel @@ -1,5 +1,6 @@ FROM multiarch/debian-debootstrap:armel-stretch-slim +ENV CONFIG_DIR /etc/pihole ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.7.0/s6-overlay-arm.tar.gz COPY install.sh /usr/local/bin/install.sh COPY VERSION /etc/docker-pi-hole-version @@ -44,5 +45,6 @@ LABEL maintainer="adam@diginc.us" LABEL url="https://www.github.com/pi-hole/docker-pi-hole" HEALTHCHECK CMD dig @127.0.0.1 pi.hole || exit 1 +VOLUME $CONFIG_DIR SHELL ["/bin/bash", "-c"] \ No newline at end of file diff --git a/Dockerfile_armhf b/Dockerfile_armhf index c0dcc42..b639fff 100644 --- a/Dockerfile_armhf +++ b/Dockerfile_armhf @@ -1,5 +1,6 @@ FROM multiarch/debian-debootstrap:armhf-stretch-slim +ENV CONFIG_DIR /etc/pihole ENV S6OVERLAY_RELEASE https://github.com/just-containers/s6-overlay/releases/download/v1.21.7.0/s6-overlay-armhf.tar.gz COPY install.sh /usr/local/bin/install.sh COPY VERSION /etc/docker-pi-hole-version @@ -44,5 +45,6 @@ LABEL maintainer="adam@diginc.us" LABEL url="https://www.github.com/pi-hole/docker-pi-hole" HEALTHCHECK CMD dig @127.0.0.1 pi.hole || exit 1 +VOLUME $CONFIG_DIR SHELL ["/bin/bash", "-c"] \ No newline at end of file diff --git a/bash_functions.sh b/bash_functions.sh index ee806ad..fe3cfef 100644 --- a/bash_functions.sh +++ b/bash_functions.sh @@ -54,7 +54,7 @@ prepare_configs() { touch /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port /var/log/pihole.log chown pihole:pihole /var/run/pihole /var/log/pihole test -f /var/run/pihole/FTL.sock && rm /var/run/pihole/FTL.sock - chown pihole:pihole /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port /etc/pihole /etc/pihole/dhcp.leases /var/log/pihole.log + chown pihole:pihole /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port $CONFIG_DIR $CONFIG_DIR/dhcp.leases /var/log/pihole.log chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port /var/log/pihole.log set -e # Update version numbers @@ -117,7 +117,7 @@ setup_dnsmasq_dns() { fi; # TODO With the addition of this to /start.sh this needs a refactor - if [ ! -f /.piholeFirstBoot ] ; then + if [ ! -f $CONFIG_DIR/.piholeFirstBoot ] ; then local setupDNS1="$(grep 'PIHOLE_DNS_1' ${setupVars})" local setupDNS2="$(grep 'PIHOLE_DNS_2' ${setupVars})" setupDNS1="${setupDNS1/PIHOLE_DNS_1=/}" diff --git a/install.sh b/install.sh index 7456b91..c9c1f29 100755 --- a/install.sh +++ b/install.sh @@ -1,6 +1,6 @@ #!/bin/bash -ex -mkdir -p /etc/pihole/ +mkdir -p $CONFIG_DIR/ mkdir -p /var/run/pihole # Production tags with valid web footers export CORE_VERSION="$(cat /etc/docker-pi-hole-version)" @@ -84,12 +84,12 @@ else fi sed -i 's/readonly //g' /opt/pihole/webpage.sh -sed -i '/^WEBPASSWORD/d' /etc/pihole/setupVars.conf +sed -i '/^WEBPASSWORD/d' $CONFIG_DIR/setupVars.conf # Replace the call to `updatePiholeFunc` in arg parse with new `unsupportedFunc` sed -i $'s/helpFunc() {/unsupportedFunc() {\\\n echo "Function not supported in Docker images"\\\n exit 0\\\n}\\\n\\\nhelpFunc() {/g' /usr/local/bin/pihole sed -i $'s/)\s*updatePiholeFunc/) unsupportedFunc/g' /usr/local/bin/pihole -touch /.piholeFirstBoot +touch $CONFIG_DIR/.piholeFirstBoot echo 'Docker install successful' diff --git a/start.sh b/start.sh index 4ee2c4b..ffac641 100755 --- a/start.sh +++ b/start.sh @@ -15,7 +15,7 @@ export DNSMASQ_LISTENING_BEHAVIOUR="$DNSMASQ_LISTENING" export IPv6 export WEB_PORT -export adlistFile='/etc/pihole/adlists.list' +export adlistFile='$CONFIG_DIR/adlists.list' # The below functions are all contained in bash_functions.sh . /bash_functions.sh @@ -27,16 +27,12 @@ echo " ::: Starting docker specific checks & setup for docker pihole/pihole" docker_checks -# TODO: -#if [ ! -f /.piholeFirstBoot ] ; then -# echo " ::: Not first container startup so not running docker's setup, re-create container to run setup again" -#else -# regular_setup_functions -#fi - fix_capabilities -generate_password validate_env || exit 1 + +if [ -f $CONFIG_DIR/.piholeFirstBoot ] || [ -z "$(ls -A $CONFIG_DIR)" ] ; then + +generate_password prepare_configs change_setting "IPV4_ADDRESS" "$ServerIP" change_setting "IPV6_ADDRESS" "$ServerIPv6" @@ -48,8 +44,9 @@ setup_dnsmasq_hostnames "$ServerIP" "$ServerIPv6" "$HOSTNAME" setup_ipv4_ipv6 setup_lighttpd_bind "$ServerIP" setup_blocklists +fi test_configs -[ -f /.piholeFirstBoot ] && rm /.piholeFirstBoot +[ -f $CONFIG_DIR/.piholeFirstBoot ] && rm $CONFIG_DIR/.piholeFirstBoot echo " ::: Docker start setup complete"