Merge pull request #173 from diginc/dev

Release latest version to master & mainline tags
This commit is contained in:
Adam Hill 2017-10-15 22:52:22 -05:00 committed by GitHub
commit 885ef2d836
16 changed files with 407 additions and 52 deletions

View File

@ -7,4 +7,8 @@ python:
install: install:
- pip install -r requirements.txt - 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/

78
Dockerfile.template Normal file
View File

@ -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"]

73
DockerfileGeneration.py Normal file
View File

@ -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()

64
Dockerfile_alpine_aarch64 Normal file
View File

@ -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"]

View File

@ -1,13 +1,17 @@
FROM alpine:edge FROM alpine:edge
MAINTAINER adam@diginc.us <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} ENV PATH /opt/pihole:${PATH}
COPY install.sh /usr/local/bin/docker-install.sh COPY install.sh /usr/local/bin/docker-install.sh
ENV setupVars /etc/pihole/setupVars.conf ENV setupVars /etc/pihole/setupVars.conf
ENV PIHOLE_INSTALL /tmp/ph_install.sh 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 && \ RUN apk upgrade --update && \
apk add bind-tools wget curl bash libcap && \ apk add bind-tools wget curl bash libcap && \
@ -57,4 +61,4 @@ ENV S6_LOGGING 0
ENV S6_KEEP_ENV 1 ENV S6_KEEP_ENV 1
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2 ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2
SHELL ["/bin/bash", "-c"] SHELL ["/bin/bash", "-c"]

64
Dockerfile_alpine_armhf Normal file
View File

@ -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"]

46
Dockerfile_debian_aarch64 Normal file
View File

@ -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"]

View File

@ -1,13 +1,17 @@
FROM debian:jessie FROM debian:jessie
MAINTAINER adam@diginc.us <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} ENV PATH /opt/pihole:${PATH}
COPY install.sh /usr/local/bin/docker-install.sh COPY install.sh /usr/local/bin/docker-install.sh
ENV setupVars /etc/pihole/setupVars.conf ENV setupVars /etc/pihole/setupVars.conf
ENV PIHOLE_INSTALL /tmp/ph_install.sh 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 && \ RUN apt-get update && \
apt-get install -y wget curl net-tools cron && \ apt-get install -y wget curl net-tools cron && \
@ -21,6 +25,7 @@ ENTRYPOINT [ "/init" ]
ADD s6/debian-root / ADD s6/debian-root /
COPY s6/service /usr/local/bin/service COPY s6/service /usr/local/bin/service
# php config start passes special ENVs into # php config start passes special ENVs into
ENV PHP_ENV_CONFIG '/etc/lighttpd/conf-enabled/15-fastcgi-php.conf' ENV PHP_ENV_CONFIG '/etc/lighttpd/conf-enabled/15-fastcgi-php.conf'
ENV PHP_ERROR_LOG '/var/log/lighttpd/error.log' ENV PHP_ERROR_LOG '/var/log/lighttpd/error.log'
@ -38,4 +43,4 @@ ENV S6_LOGGING 0
ENV S6_KEEP_ENV 1 ENV S6_KEEP_ENV 1
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2 ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2
SHELL ["/bin/bash", "-c"] SHELL ["/bin/bash", "-c"]

View File

@ -1,21 +1,22 @@
FROM jsurf/rpi-raspbian FROM multiarch/debian-debootstrap:armhf-jessie-slim
MAINTAINER adam@diginc.us <adam@diginc.us>
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} ENV PATH /opt/pihole:${PATH}
COPY install.sh /usr/local/bin/docker-install.sh COPY install.sh /usr/local/bin/docker-install.sh
ENV setupVars /etc/pihole/setupVars.conf ENV setupVars /etc/pihole/setupVars.conf
ENV PIHOLE_INSTALL /tmp/ph_install.sh 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 && \ RUN apt-get update && \
apt-get install -y wget curl net-tools cron && \ apt-get install -y wget curl net-tools cron && \
curl -L -s $S6OVERLAY_RELEASE \ curl -L -s $S6OVERLAY_RELEASE \
| tar xvzf - -C / && \ | tar xvzf - -C / && \
ln /lib/ld-linux-armhf.so.3 /lib/ld-linux.so.3 && \
docker-install.sh && \ docker-install.sh && \
rm -rf /var/cache/apt/archives /var/lib/apt/lists/* rm -rf /var/cache/apt/archives /var/lib/apt/lists/*
@ -24,6 +25,7 @@ ENTRYPOINT [ "/init" ]
ADD s6/debian-root / ADD s6/debian-root /
COPY s6/service /usr/local/bin/service COPY s6/service /usr/local/bin/service
# php config start passes special ENVs into # php config start passes special ENVs into
ENV PHP_ENV_CONFIG '/etc/lighttpd/conf-enabled/15-fastcgi-php.conf' ENV PHP_ENV_CONFIG '/etc/lighttpd/conf-enabled/15-fastcgi-php.conf'
ENV PHP_ERROR_LOG '/var/log/lighttpd/error.log' ENV PHP_ERROR_LOG '/var/log/lighttpd/error.log'
@ -41,6 +43,4 @@ ENV S6_LOGGING 0
ENV S6_KEEP_ENV 1 ENV S6_KEEP_ENV 1
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2 ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2
SHELL ["/bin/bash", "-c"] SHELL ["/bin/bash", "-c"]
RUN [ "cross-build-end" ]

View File

@ -17,7 +17,7 @@ validate_env() {
# Debian # Debian
nc_error='Name or service not known' nc_error='Name or service not known'
if [[ "$IMAGE" == 'alpine' ]] ; then if [[ "$TAG" == 'alpine' ]] ; then
nc_error='bad address' nc_error='bad address'
fi; fi;
@ -119,7 +119,7 @@ setup_dnsmasq_hostnames() {
} }
setup_lighttpd_bind() { setup_lighttpd_bind() {
if [[ "$IMAGE" == 'debian' ]] ; then if [[ "$TAG" == 'debian' ]] ; then
# if using '--net=host' only bind lighttpd on $ServerIP # 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 "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 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() { setup_php_env() {
case $IMAGE in case $TAG in
"debian") setup_php_env_debian ;; "debian") setup_php_env_debian ;;
"alpine") setup_php_env_alpine ;; "alpine") setup_php_env_alpine ;;
esac esac
@ -188,11 +188,12 @@ setup_web_password() {
fi fi
{ set +x; } 2>/dev/null { set +x; } 2>/dev/null
} }
setup_ipv4_ipv6() { setup_ipv4_ipv6() {
local ip_versions="IPv4 and IPv6" local ip_versions="IPv4 and IPv6"
if [ "$IPv6" != "True" ] ; then if [ "$IPv6" != "True" ] ; then
ip_versions="IPv4" ip_versions="IPv4"
case $IMAGE in case $TAG in
"debian") sed -i '/use-ipv6.pl/ d' /etc/lighttpd/lighttpd.conf ;; "debian") sed -i '/use-ipv6.pl/ d' /etc/lighttpd/lighttpd.conf ;;
"alpine") sed -i '/listen \[::\]:80/ d' /etc/nginx/nginx.conf ;; "alpine") sed -i '/listen \[::\]:80/ d' /etc/nginx/nginx.conf ;;
esac esac
@ -201,7 +202,7 @@ setup_ipv4_ipv6() {
} }
test_configs() { test_configs() {
case $IMAGE in case $TAG in
"debian") test_configs_debian ;; "debian") test_configs_debian ;;
"alpine") test_configs_alpine ;; "alpine") test_configs_alpine ;;
esac esac
@ -241,8 +242,8 @@ docker_main() {
echo -n '::: Starting up DNS and Webserver ...' echo -n '::: Starting up DNS and Webserver ...'
service dnsmasq restart # Just get DNS up. The webserver is down!!! service dnsmasq restart # Just get DNS up. The webserver is down!!!
IMAGE="$1" TAG="$1"
case $IMAGE in # Setup webserver case $TAG in # Setup webserver
"alpine") "alpine")
php-fpm5 php-fpm5
nginx nginx

View File

@ -2,7 +2,7 @@
mkdir -p /etc/pihole/ mkdir -p /etc/pihole/
export CORE_TAG='v3.1.4' export CORE_TAG='v3.1.4'
export WEB_TAG='v3.1' export WEB_TAG='v3.1'
export FTL_TAG='v2.10' export FTL_TAG='v2.11.1'
# Make pihole scripts fail searching for `systemctl`, # Make pihole scripts fail searching for `systemctl`,
# which fails pretty miserably in docker compared to `service` # 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 # Get the install functions
wget -O "$PIHOLE_INSTALL" https://raw.githubusercontent.com/pi-hole/pi-hole/${CORE_TAG}/automated%20install/basic-install.sh 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/ i\ echo "Hi Alpine"' "$PIHOLE_INSTALL"
sed -i '/OS distribution not supported/,+1d' "$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" 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 # Run only what we need from installer
export USER=pihole export USER=pihole
if [[ "$IMAGE" == 'debian' ]] ; then if [[ "$TAG" == 'debian' ]] ; then
distro_check distro_check
install_dependent_packages INSTALLER_DEPS[@] install_dependent_packages INSTALLER_DEPS[@]
install_dependent_packages PIHOLE_DEPS[@] install_dependent_packages PIHOLE_DEPS[@]
@ -44,7 +44,7 @@ if [[ "$IMAGE" == 'debian' ]] ; then
sed -i "/sleep 2/ d" /etc/init.d/dnsmasq # SLOW sed -i "/sleep 2/ d" /etc/init.d/dnsmasq # SLOW
# IPv6 support for nc openbsd better than traditional # IPv6 support for nc openbsd better than traditional
apt-get install -y --force-yes netcat-openbsd apt-get install -y --force-yes netcat-openbsd
elif [[ "$IMAGE" == 'alpine' ]] ; then elif [[ "$TAG" == 'alpine' ]] ; then
apk add \ apk add \
dnsmasq \ dnsmasq \
nginx \ nginx \
@ -74,8 +74,11 @@ tmpLog="${tmpLog}"
instalLogLoc="${instalLogLoc}" instalLogLoc="${instalLogLoc}"
installPihole | tee "${tmpLog}" installPihole | tee "${tmpLog}"
sed -i 's/readonly //g' /opt/pihole/webpage.sh 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 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 fi

View File

@ -3,3 +3,4 @@ pytest
pytest-cov pytest-cov
pytest-xdist pytest-xdist
testinfra==1.5.1 testinfra==1.5.1
jinja2

View File

@ -1,6 +1,6 @@
#!/bin/bash -e #!/bin/bash -e
# Dockerfile variables # Dockerfile variables
export IMAGE export TAG
export ServerIP export ServerIP
export ServerIPv6 export ServerIPv6
export PYTEST export PYTEST
@ -25,7 +25,7 @@ setup_dnsmasq "$DNS1" "$DNS2"
setup_php_env setup_php_env
setup_dnsmasq_hostnames "$ServerIP" "$ServerIPv6" "$HOSTNAME" setup_dnsmasq_hostnames "$ServerIP" "$ServerIPv6" "$HOSTNAME"
setup_ipv4_ipv6 setup_ipv4_ipv6
setup_lighttpd_bind "$ServerIP" "$IMAGE" setup_lighttpd_bind "$ServerIP" "$TAG"
test_configs test_configs
test_framework_stubbing test_framework_stubbing
echo "::: Docker start setup complete - beginning s6 services" echo "::: Docker start setup complete - beginning s6 services"

View File

@ -1,7 +1,7 @@
import pytest import pytest
import testinfra import testinfra
WEB_SERVER = { 'alpine': 'nginx', 'debian': 'lighttpd' } WEB_SERVER = { 'alpine_amd64': 'nginx', 'debian_amd64': 'lighttpd' }
check_output = testinfra.get_backend( check_output = testinfra.get_backend(
"local://" "local://"
@ -9,7 +9,7 @@ check_output = testinfra.get_backend(
def DockerGeneric(request, args, image, cmd): def DockerGeneric(request, args, image, cmd):
assert 'docker' in check_output('id'), "Are you in the docker group?" 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\"" 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) docker_run = "docker run -d {} {} {}".format(args, image, cmd)
print docker_run print docker_run
@ -56,17 +56,25 @@ def DockerPersist(request, persist_args, persist_image, persist_cmd, Dig):
def args(request): def args(request):
return '-e ServerIP="127.0.0.1" -e ServerIPv6="::1"' return '-e ServerIP="127.0.0.1" -e ServerIPv6="::1"'
@pytest.fixture(params=['alpine', 'debian']) @pytest.fixture(params=['amd64', 'armhf', 'aarch64'])
def tag(request): def arch(request):
return request.param 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 @pytest.fixture
def webserver(request, tag): def webserver(request, tag):
return WEB_SERVER[tag] return WEB_SERVER[tag]
@pytest.fixture() @pytest.fixture()
def image(request, tag): def image(request, tag):
return 'diginc/pi-hole:{}'.format(tag) return 'pi-hole:{}'.format(tag)
@pytest.fixture() @pytest.fixture()
def cmd(request): def cmd(request):
@ -76,7 +84,7 @@ def cmd(request):
def persist_args(request): def persist_args(request):
return '-e ServerIP="127.0.0.1" -e ServerIPv6="::1"' 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): def persist_tag(request):
return request.param return request.param
@ -86,7 +94,7 @@ def persist_webserver(request, persist_tag):
@pytest.fixture(scope='module') @pytest.fixture(scope='module')
def persist_image(request, persist_tag): def persist_image(request, persist_tag):
return 'diginc/pi-hole:{}'.format(persist_tag) return 'pi-hole:{}'.format(persist_tag)
@pytest.fixture(scope='module') @pytest.fixture(scope='module')
def persist_cmd(request): def persist_cmd(request):

View File

@ -1,19 +1,23 @@
''' This file starts with 000 to make it run first ''' ''' This file starts with 000 to make it run first '''
import pytest import pytest
import testinfra import testinfra
import DockerfileGeneration
run_local = testinfra.get_backend( run_local = testinfra.get_backend(
"local://" "local://"
).get_module("Command").run ).get_module("Command").run
@pytest.mark.parametrize("upstream,image,tag", [
( 'alpine:edge', 'alpine.docker', 'diginc/pi-hole:alpine' ), def test_generate_dockerfiles():
( 'debian:jessie', 'debian.docker', 'diginc/pi-hole:debian' ), DockerfileGeneration.generate_dockerfiles()
#( 'jsurf/rpi-raspbian', 'debian-armhf.docker', 'diginc/pi-hole:arm' ),
]) @pytest.mark.parametrize('arch', [ 'amd64', 'armhf', 'aarch64' ])
def test_build_pihole_image(upstream, image, tag): @pytest.mark.parametrize('os', [ 'debian', 'alpine' ])
run_local('docker pull {}'.format(upstream)) def test_build_pihole_image(os, arch):
build_cmd = run_local('docker build -f {} -t {} .'.format(image, tag)) ''' 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: if build_cmd.rc != 0:
print build_cmd.stdout print build_cmd.stdout
print build_cmd.stderr print build_cmd.stderr

View File

@ -9,7 +9,7 @@ DEFAULTARGS = '-e ServerIP="127.0.0.1" '
(DEFAULTARGS + '-e "IPv6=False"', False, 'IPv4'), (DEFAULTARGS + '-e "IPv6=False"', False, 'IPv4'),
(DEFAULTARGS + '-e "IPv6=foobar"', 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 ''' ''' When a user overrides IPv6=True they only get IPv4 listening webservers '''
IPV6_LINE = { 'alpine': 'listen [::]:80 default_server', IPV6_LINE = { 'alpine': 'listen [::]:80 default_server',
'debian': 'use-ipv6.pl' } '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') function = Docker.run('. /bash_functions.sh ; setup_ipv4_ipv6')
assert "Using {}".format(expected_stdout) in function.stdout assert "Using {}".format(expected_stdout) in function.stdout
config = Docker.run('cat {}'.format( WEB_CONFIG[tag])).stdout config = Docker.run('cat {}'.format( WEB_CONFIG[os])).stdout
assert (IPV6_LINE[tag] in config) == expected_ipv6 assert (IPV6_LINE[os] in config) == expected_ipv6
@pytest.mark.parametrize('args, expected_stdout, dns1, dns2', [ @pytest.mark.parametrize('args, expected_stdout, dns1, dns2', [
('-e ServerIP="1.2.3.4"', 'default DNS', '8.8.8.8', '8.8.4.4' ), ('-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"', '"ServerIP" => "127.0.0.1"',
'"PHP_ERROR_LOG" => "/var/log/lighttpd/error.log"' '"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, 1),
('debian', expected_debian_lines, 2) ('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 ''' ''' confirm all expected output is there and nothing else '''
stdout = '' stdout = ''
for i in range(repeat_function): for i in range(repeat_function):