Skip to content

Commit

Permalink
Merge pull request #84 from diginc/v2.11.1
Browse files Browse the repository at this point in the history
V2.11.1+ update - from github official repo & installer rather than sub modules.
  • Loading branch information
diginc committed Jan 18, 2017
2 parents 6c90bab + 52a0764 commit 2a2530d
Show file tree
Hide file tree
Showing 24 changed files with 279 additions and 263 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
@@ -1,6 +0,0 @@
[submodule "pi-hole"]
path = pi-hole
url = https://github.com/pi-hole/pi-hole.git
[submodule "AdminLTE"]
path = AdminLTE
url = https://github.com/pi-hole/AdminLTE.git
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -7,4 +7,4 @@ python:
install:
- pip install -r requirements.txt

script: py.test -vv
script: py.test -vv test/
1 change: 0 additions & 1 deletion AdminLTE
Submodule AdminLTE deleted from 3e6955
1 change: 0 additions & 1 deletion AdminLTE_version.txt

This file was deleted.

12 changes: 6 additions & 6 deletions README.md
@@ -1,4 +1,4 @@
A [Docker](https://www.docker.com/what-docker) project to make lightweight x86 and ARM continer with [pi-hole](https://pi-hole.net) functionality. Why? Maybe you don't have a Raspberry Pi lying around but you do have a Docker server.
A [Docker](https://www.docker.com/what-docker) project to make lightweight x86 and ARM container with [pi-hole](https://pi-hole.net) functionality. Why? Maybe you don't have a Raspberry Pi lying around but you do have a Docker server.

**Now with ARM (actual docker-pi) support!** Just install docker on your Rasberry-Pi and run docker image `diginc/pi-hole:arm` tag (see below for full required command).

Expand All @@ -16,8 +16,8 @@ One crucial thing to know before starting is the docker-pi-hole container needs

```
IMAGE='diginc/pi-hole'
NIC='eth0'
IP=$(ip addr show $NIC | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
IP_LOOKUP="$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')" # May not work for VPN / tun0
IP="${IP:-$IP_LOOKUP}" # use $IP, if set, otherwise IP_LOOKUP
docker run -p 53:53/tcp -p 53:53/udp -p 80:80 --cap-add=NET_ADMIN -e ServerIP="$IP" --name pihole -d $IMAGE
# Recommended auto ad list updates & log rotation:
Expand Down Expand Up @@ -46,8 +46,8 @@ In addition to the required environment variable you saw above (`-e ServerIP="$I
* Port conflicts? Stop your server's existing DNS / Web services.
* Ubuntu users especially may need to shutoff dnsmasq on your docker server so it can run in the container on port 53
* Don't forget to stop your services from auto-starting again after you reboot
* Port 80 is required because if you have another site/service using port 80 by default then the ads may not transform into blank ads correctly. To make sure docker-pi-hole plays nicely with an exising webserver you run you'll probably need a reverse proxy websever config if you don't have one already. Pi-Hole has to be the default web app on said proxy e.g. if you goto your host by IP instead of domain pi-hole is served out instead of any other sites hosted by the proxy. This behavior is taken advantage of so any ad domain can be directed to your webserver and get blank html/images/videos instead of ads.
* [Here is an example of running with jwilder/proxy](https://github.com/diginc/docker-pi-hole/blob/master/jwilder-proxy-example-doco.yml) (an nginx auto-configuring docker reverse proxy for docker) on my port 80 with pihole on another port. Pi-hole needs to be `DEFAULT_HOST` env in jwilder/proxy and you need to set the matching `VIRTUAL_HOST` for the pihole's container. Please read jwilder/proxy readme for more info if you have trouble. I tested this basic exmaple which is based off what I run.
* Port 80 is required because if you have another site/service using port 80 by default then the ads may not transform into blank ads correctly. To make sure docker-pi-hole plays nicely with an existing webserver you run you'll probably need a reverse proxy webserver config if you don't have one already. Pi-Hole has to be the default web app on said proxy e.g. if you goto your host by IP instead of domain pi-hole is served out instead of any other sites hosted by the proxy. This behavior is taken advantage of so any ad domain can be directed to your webserver and get blank html/images/videos instead of ads.
* [Here is an example of running with jwilder/proxy](https://github.com/diginc/docker-pi-hole/blob/master/jwilder-proxy-example-doco.yml) (an nginx auto-configuring docker reverse proxy for docker) on my port 80 with pihole on another port. Pi-hole needs to be `DEFAULT_HOST` env in jwilder/proxy and you need to set the matching `VIRTUAL_HOST` for the pihole's container. Please read jwilder/proxy readme for more info if you have trouble. I tested this basic example which is based off what I run.

## Volume Mounts
Here are some useful volume mount options to persist your history of stats in the admin interface, or add custom whitelists/blacklists. **Create these files on the docker host first or you'll get errors**:
Expand Down Expand Up @@ -84,7 +84,7 @@ Alpine doesn't have an arm cross compileable image at this time.

## Upgrading, Persistence, and Customizations

The standard pi-hole customization abilities apply to this docker, but with docker twists such as using docker volume mounts to map host stored file configurations over the container defaults. Volumes are also important to persist the configuration incase you have remove the pi-hole container which is a typical docker upgrade pattern.
The standard pi-hole customization abilities apply to this docker, but with docker twists such as using docker volume mounts to map host stored file configurations over the container defaults. Volumes are also important to persist the configuration in case you have removed the pi-hole container which is a typical docker upgrade pattern.

### Upgrading

Expand Down
67 changes: 25 additions & 42 deletions alpine.docker
Expand Up @@ -2,42 +2,29 @@ FROM alpine:edge
MAINTAINER adam@diginc.us <adam@diginc.us>

ENV IMAGE alpine

RUN apk add --update \
dnsmasq \
nginx \
ca-certificates \
php5-fpm php5-json php5-openssl libxml2 \
bc bash curl perl sudo && \
apk add --update --repository http://dl-1.alpinelinux.org/alpine/edge/testing/ tini && \
ENV PATH /opt/pihole:${PATH}

COPY install.sh /install.sh
COPY ./alpine/service /usr/local/bin/service
ENV setupVars /etc/pihole/setupVars.conf
ENV PIHOLE_INSTALL /tmp/ph_install.sh

ENV TINI_VERSION v0.13.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static /tini
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static.asc /tini.asc

# Tini and package requirements
RUN apk add --update 'gnupg<2.1.17-r0' && \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 0527A9B7 && \
gpg --verify /tini.asc && \
chmod +x /tini && \
apk add wget bash && \
/install.sh && \
rm -rf /var/cache/apk/*

# Customized from submodules
COPY ./pi-hole/gravity.sh /usr/local/bin/
COPY ./pi-hole/advanced/Scripts/* /usr/local/bin/
COPY ./pi-hole/pihole /usr/local/bin/
RUN sed -i 's|service dnsmasq restart|kill -9 $(pidof dnsmasq); dnsmasq -7 /etc/dnsmasq.d|g' \
/usr/local/bin/pihole \
/usr/local/bin/gravity.sh \
/usr/local/bin/list.sh
RUN sed -i 's|service dnsmasq start|dnsmasq -7 /etc/dnsmasq.d|g' \
/usr/local/bin/pihole \
/usr/local/bin/gravity.sh \
/usr/local/bin/list.sh
COPY ./alpine/nginx.conf /etc/nginx/nginx.conf

# Original upstream pihole code being used
COPY ./pi-hole/adlists.default /etc/pihole/
COPY ./pi-hole/adlists.default /etc/.pihole/
RUN mkdir -p /opt/ && ln -s /usr/local/bin /opt/pihole
COPY ./pi-hole/advanced/dnsmasq.conf.original /etc/dnsmasq.conf
COPY ./pi-hole/advanced/01-pihole.conf /etc/dnsmasq.d/
COPY ./pi-hole/advanced/index* /var/www/html/pihole/
COPY ./pi-hole/advanced/pihole.sudo /etc/sudoers.d/pihole
COPY ./AdminLTE /var/www/html/admin
COPY ./AdminLTE_version.txt /etc/
COPY ./pi-hole_version.txt /etc/

# Things installer did and fix alpine+nginx differences
ENV WEBLOGDIR /var/log/nginx
ENV PHP_CONFIG '/etc/php5/php-fpm.conf'
Expand All @@ -53,16 +40,11 @@ RUN mkdir -p /etc/pihole/ && \
chmod 644 /var/log/pihole.log && \
chown dnsmasq:root /var/log/pihole.log && \
sed -i "s/@INT@/eth0/" /etc/dnsmasq.d/01-pihole.conf && \
sed -i 's|"cd /etc/.pihole/ && git describe --tags --abbrev=0"|"cat /etc/pi-hole_version.txt"|g' /var/www/html/admin/footer.php && \
sed -i 's|"git describe --tags --abbrev=0"|"cat /etc/AdminLTE_version.txt"|g' /var/www/html/admin/footer.php && \
sed -i 's|www-data|nginx|g' /etc/sudoers.d/pihole && \
/bin/true # placeholder

# This chould be eliminated if all (upstream) files were +x in git
RUN chmod +x /usr/local/bin/*.sh
echo 'Done!'

# Fix dnsmasq in docker
RUN grep -q '^user=root' || echo 'user=root' >> /etc/dnsmasq.conf
#sed -i 's|"cd /etc/.pihole/ && git describe --tags --abbrev=0"|"cat /etc/pi-hole_version.txt"|g' /var/www/html/admin/footer.php && \
#sed -i 's|"git describe --tags --abbrev=0"|"cat /etc/AdminLTE_version.txt"|g' /var/www/html/admin/footer.php && \
#sed -i 's|www-data|nginx|g' /etc/sudoers.d/pihole && \

# php config start passes special ENVs into
ENV PHP_ENV_CONFIG '/etc/php5/fpm.d/envs.conf'
Expand All @@ -76,5 +58,6 @@ ENV IPv6 True
EXPOSE 53 53/udp
EXPOSE 80

ENTRYPOINT ["tini", "--"]
CMD /start.sh
SHELL ["/bin/bash", "-c"]
ENTRYPOINT ["/tini", "--"]
CMD [ "/start.sh" ]
25 changes: 13 additions & 12 deletions alpine/nginx.conf
Expand Up @@ -15,25 +15,26 @@ http {
listen 80;
listen [::]:80;
root /var/www/html;
index index.php pihole/index.html;
error_page 404 =200 /pihole/index.html;

location ~ ^/admin/ {
add_header X-Pi-hole "The Pi-hole Web interface is working!";

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
index pihole/index.php index.php;
error_page 404 =200 /pihole/index.php;

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;
}

location /*.js {
index pihole/index.js
error_page 404 =200 /pihole/index.js;
}

location ~ ^/admin/ {
add_header X-Pi-hole "The Pi-hole Web interface is working!";
}

location / {
add_header X-Pi-hole "A black hole for Internet advertisements." always;
}
Expand Down
55 changes: 55 additions & 0 deletions alpine/service
@@ -0,0 +1,55 @@
#!/bin/bash
# lazy cheap service script patch for alpine
dnsmasq_start() {
dnsmasq -7 /etc/dnsmasq.d
}

dnsmasq_stop() {
kill -9 $(pidof dnsmasq)
}

dnsmasq_restart() {
dnsmasq_stop; dnsmasq_start;
}

status() {
if pidof $service 2&>1 > /dev/null ; then
echo "$service running"
else
echo "$service not running"
fi;
}

nginx_start() {
nginx -t && \
nginx
}
nginx_stop() {
nginx -t && \
kill -9 $(pidof nginx)
}
nginx_restart() {
nginx_stop
nginx_start
}
dnsmasq_status() {
status
}
nginx_status() {
status
}

service="$1"
command="$2"
if [[ "$service" == 'lighttpd' ]] ; then
echo -e "Lighttpd replaced by nginx in diginc/pi-hole:alpine\nrunning service nginx $command instead";
service='nginx'
fi;


if [[ "$service" == 'dnsmasq' ]] || [[ "$service" == 'nginx' ]] ; then
${service}_${command} || echo "Unknown option $command"
else
echo "$service service wrapper not patched into alpine container"
exit 1
fi
50 changes: 25 additions & 25 deletions bash_functions.sh
@@ -1,18 +1,14 @@
. /opt/pihole/webpage.sh

validate_env() {
if [ -z "$ServerIP" ] ; then
echo "ERROR: To function correctly you must pass an environment variables of 'ServerIP' into the docker container with the IP of your docker host from which you are passing web (80) and dns (53) ports from"
exit 1
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" > /etc/pihole/setupVars.conf;
echo "IPv6_address=$ServerIPv6" >> /etc/pihole/setupVars.conf;
}

setup_dnsmasq_dns() {
. /opt/pihole/webpage.sh
local DNS1="${1:-8.8.8.8}"
local DNS2="${2:-8.8.4.4}"
local dnsType='default'
Expand All @@ -21,14 +17,15 @@ setup_dnsmasq_dns() {
fi;

echo "Using $dnsType DNS servers: $DNS1 & $DNS2"
sed -i "s/@DNS1@/$DNS1/" /etc/dnsmasq.d/01-pihole.conf && \
sed -i "s/@DNS2@/$DNS2/" /etc/dnsmasq.d/01-pihole.conf
[ -n "$DNS1" ] && change_setting "PIHOLE_DNS_1" "${DNS1}"
[ -n "$DNS2" ] && change_setting "PIHOLE_DNS_2" "${DNS2}"
ProcessDNSSettings
}

setup_dnsmasq_hostnames() {
# largely borrowed from automated install/basic-install.sh
local IPv4_address="${1}"
local IPv6_address="${2}"
local IPV4_ADDRESS="${1}"
local IPV6_ADDRESS="${2}"
local hostname="${3}"
local dnsmasq_pihole_01_location="/etc/dnsmasq.d/01-pihole.conf"

Expand All @@ -40,16 +37,16 @@ setup_dnsmasq_hostnames() {
fi
fi;

if [[ "${IPv4_address}" != "" ]]; then
tmp=${IPv4_address%/*}
sed -i "s/@IPv4@/$tmp/" ${dnsmasq_pihole_01_location}
if [[ "${IPV4_ADDRESS}" != "" ]]; then
tmp=${IPV4_ADDRESS%/*}
sed -i "s/@IPV4@/$tmp/" ${dnsmasq_pihole_01_location}
else
sed -i '/^address=\/pi.hole\/@IPv4@/d' ${dnsmasq_pihole_01_location}
sed -i '/^address=\/@HOSTNAME@\/@IPv4@/d' ${dnsmasq_pihole_01_location}
sed -i '/^address=\/pi.hole\/@IPV4@/d' ${dnsmasq_pihole_01_location}
sed -i '/^address=\/@HOSTNAME@\/@IPV4@/d' ${dnsmasq_pihole_01_location}
fi

if [[ "${IPv6_address}" != "" ]]; then
sed -i "s/@IPv6@/$IPv6_address/" ${dnsmasq_pihole_01_location}
if [[ "${IPV6_ADDRESS}" != "" ]]; then
sed -i "s/@IPv6@/$IPV6_ADDRESS/" ${dnsmasq_pihole_01_location}
else
sed -i '/^address=\/pi.hole\/@IPv6@/d' ${dnsmasq_pihole_01_location}
sed -i '/^address=\/@HOSTNAME@\/@IPv6@/d' ${dnsmasq_pihole_01_location}
Expand Down Expand Up @@ -152,18 +149,21 @@ 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 ...'
service dnsmasq restart # Just get DNS up. The webserver is down!!!

IMAGE="$1"
case $IMAGE in
case $IMAGE in # Setup webserver
"alpine")
gravity.sh # dnsmasq start included
php-fpm
nginx
php-fpm
nginx
;;
"debian")
gravity.sh # dnsmasq start included
service lighttpd start
service lighttpd start
;;
esac

gravity.sh # Finally lets update and be awesome.
tail -F "${WEBLOGDIR}"/*.log /var/log/pihole.log
}

0 comments on commit 2a2530d

Please sign in to comment.