From 5404d6124f99417095c5a3314b6ff13e0a3f2d76 Mon Sep 17 00:00:00 2001 From: diginc Date: Tue, 17 Jan 2017 22:49:42 -0600 Subject: [PATCH] re-do a few things to fix up test/handle updated code --- alpine.docker | 1 + alpine/nginx.conf | 3 ++- bash_functions.sh | 20 +++++++------------- debian-armhf.docker | 1 + debian.docker | 1 + install.sh | 2 ++ requirements.txt | 6 +++--- start.sh | 15 ++++++++++----- test/test_bash_functions.py | 9 +++++---- 9 files changed, 32 insertions(+), 26 deletions(-) diff --git a/alpine.docker b/alpine.docker index 5137774..dd5caf0 100644 --- a/alpine.docker +++ b/alpine.docker @@ -58,5 +58,6 @@ ENV IPv6 True EXPOSE 53 53/udp EXPOSE 80 +SHELL ["/bin/bash", "-c"] ENTRYPOINT ["/tini", "--"] CMD [ "/start.sh" ] diff --git a/alpine/nginx.conf b/alpine/nginx.conf index 3f90e29..6479488 100644 --- a/alpine/nginx.conf +++ b/alpine/nginx.conf @@ -27,9 +27,10 @@ http { add_header X-Pi-hole "The Pi-hole Web interface is working!"; location ~ .php$ { fastcgi_pass 127.0.0.1:9000; + fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } diff --git a/bash_functions.sh b/bash_functions.sh index 420613a..80c7f97 100644 --- a/bash_functions.sh +++ b/bash_functions.sh @@ -1,4 +1,4 @@ -setupVars="${setupVars:-/etc/pihole/setupVars.conf}" +. /opt/pihole/webpage.sh validate_env() { if [ -z "$ServerIP" ] ; then @@ -7,14 +7,8 @@ validate_env() { fi; } -setup_saved_variables() { - # /tmp/piholeIP is the current override of auto-lookup in gravity.sh - echo "$ServerIP" > /etc/pihole/piholeIP; - echo "IPV4_ADDRESS=$ServerIP" > "${setupVars}"; - echo "IPV6_ADDRESS=$ServerIPv6" >> "${setupVars}"; -} - setup_dnsmasq_dns() { + . /opt/pihole/webpage.sh local DNS1="${1:-8.8.8.8}" local DNS2="${2:-8.8.4.4}" local dnsType='default' @@ -22,10 +16,10 @@ setup_dnsmasq_dns() { dnsType='custom' fi; - set -x echo "Using $dnsType DNS servers: $DNS1 & $DNS2" - sed -i 's/ProcessDnsmasqSettings/ProcessDNSSettings/g' /opt/pihole/webpage.sh - sudo pihole -a setdns "$DNS1" "$DNS2" + [ -n "$DNS1" ] && change_setting "PIHOLE_DNS_1" "${DNS1}" + [ -n "$DNS2" ] && change_setting "PIHOLE_DNS_2" "${DNS2}" + ProcessDNSSettings } setup_dnsmasq_hostnames() { @@ -155,9 +149,9 @@ test_framework_stubbing() { if [ -n "$PYTEST" ] ; then sed -i 's/^gravity_spinup$/#gravity_spinup # DISABLED FOR PYTEST/g' "$(which gravity.sh)"; fi; } -main() { +docker_main() { echo -n '::: Starting up DNS and Webserver ...' - pihole restartdns # Just get DNS up. The webserver is down!!! + service dnsmasq restart # Just get DNS up. The webserver is down!!! IMAGE="$1" case $IMAGE in # Setup webserver diff --git a/debian-armhf.docker b/debian-armhf.docker index 0181d4b..e02ccbf 100644 --- a/debian-armhf.docker +++ b/debian-armhf.docker @@ -35,6 +35,7 @@ ENV IPv6 True EXPOSE 53 53/udp EXPOSE 80 +SHELL ["/bin/bash", "-c"] ENTRYPOINT ["/tini", "--"] CMD [ "/start.sh" ] diff --git a/debian.docker b/debian.docker index 7b39d69..8b46d34 100644 --- a/debian.docker +++ b/debian.docker @@ -33,5 +33,6 @@ ENV IPv6 True EXPOSE 53 53/udp EXPOSE 80 +SHELL ["/bin/bash", "-c"] ENTRYPOINT ["/tini", "--"] CMD [ "/start.sh" ] diff --git a/install.sh b/install.sh index 3c3f703..b89fd0c 100755 --- a/install.sh +++ b/install.sh @@ -49,7 +49,9 @@ export IPV6_ADDRESS=0:0:0:0:0:0 export PIHOLE_DNS_1=8.8.8.8 export PIHOLE_DNS_2=8.8.4.4 export QUERY_LOGGING=true + installPihole | tee "${tmpLog}" +sed -i 's/readonly //g' /opt/pihole/webpage.sh mv "${tmpLog}" "${instalLogLoc}" diff --git a/requirements.txt b/requirements.txt index b455a17..00e7363 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ docker-compose -pytest==2.9.2 -pytest-cov==2.3.0 -pytest-xdist==1.14 +pytest +pytest-cov +pytest-xdist testinfra==1.5.1 diff --git a/start.sh b/start.sh index 8f06422..c2af174 100755 --- a/start.sh +++ b/start.sh @@ -1,5 +1,4 @@ -#!/bin/bash -e -. /bash_functions.sh +#!/bin/bash -ex # Dockerfile variables export IMAGE export ServerIP @@ -9,16 +8,22 @@ export PHP_ENV_CONFIG export PHP_ERROR_LOG export HOSTNAME export WEBLOGDIR +export DNS1 +export DNS2 export IPv6 +#export setupVars="${setupVars:-/etc/pihole/setupVars.conf}" +. /bash_functions.sh +echo " ::: Starting docker specific setup for docker diginc/pi-hole" validate_env -setup_saved_variables -setup_php_env +change_setting "IPV4_ADDRESS" "$ServerIP" +change_setting "IPV6_ADDRESS" "$ServerIPv6" setup_dnsmasq_dns "$DNS1" "$DNS2" +setup_php_env setup_dnsmasq_hostnames "$ServerIP" "$ServerIPv6" "$HOSTNAME" setup_ipv4_ipv6 test_configs test_framework_stubbing -main "$IMAGE" +docker_main "$IMAGE" diff --git a/test/test_bash_functions.py b/test/test_bash_functions.py index 07c98ac..59e5176 100644 --- a/test/test_bash_functions.py +++ b/test/test_bash_functions.py @@ -14,9 +14,10 @@ def cmd(request): ]) def test_IPv6_not_True_removes_ipv6(Docker, tag, args, expected_ipv6, expected_stdout): ''' When a user overrides IPv6=True they only get IPv4 listening webservers ''' - IPV6_LINE = { 'alpine': 'listen \[::\]:80', 'debian': 'use-ipv6.pl' } - WEB_CONFIG = { 'alpine': '/etc/nginx/nginx.conf', 'debian': '/etc/lighttpd/lighttpd.conf' } - + IPV6_LINE = { 'alpine': 'listen \[::\]:80', + 'debian': 'use-ipv6.pl' } + WEB_CONFIG = { 'alpine': '/etc/nginx/nginx.conf', + 'debian': '/etc/lighttpd/lighttpd.conf' } function = Docker.run('. /bash_functions.sh ; setup_ipv4_ipv6') assert "Using {}".format(expected_stdout) in function.stdout @@ -38,7 +39,7 @@ def test_DNS_Envs_override_defaults(Docker, args, expected_stdout, dns1, dns2): expected_servers = 'server={}\nserver={}\n'.format(dns1, dns2) assert expected_servers == docker_dns_servers -expected_debian_lines = [ +expected_debian_lines = [ '"VIRTUAL_HOST" => "192.168.100.2"', '"ServerIP" => "192.168.100.2"', '"PHP_ERROR_LOG" => "/var/log/lighttpd/error.log"'