diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9df976e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv* +.cache/* +*.zone diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 0000000..d1b7f53 --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,49 @@ +# Docker + +Dockerfile and docker-compose.yml provide alternative for installations and development + +Some tweaking is expected to suit a production deployment + +## Build + +```shell +docker-compose build +``` + +## AdBlock Zone + +The example container writes the generated rpz-adblocker.zone file under /bind-adblock + +Docker-compose file has an options for using either a volume (i.e containerized bind9 integration) or host mount point (i.e. bind9 running on the docker host os) for that path. + +## Deploy + +```shell +docker-compose up -d +``` + +## Running Considerations + +### Cron + +The current image runs the python script at startup and then exits. +There is no cron scheduler provided at this time. + +### On Demand + +Once deployed, issuing a run will start the container again, run the update script, then exit after writing the zone file. + +```shell +docker run bind-adblock_updater +``` + +### Bind9 Zone reloads + +You might wish to combine bind-adblock and bind9 into the same container in which a cron service controls executing this python script and in turn can trigger named to reload the zone. + +An aggressive workaround is start the adblock updater container then fully restart the bind9 container. + +```shell +docker-compose up updater >/dev/null 2>&1 && docker-compose restart bind9 >/dev/null 2>&1 +``` + diff --git a/Dockerfile b/Dockerfile index 388cc28..57a6406 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,19 @@ FROM python:latest -ENV SRC="." +WORKDIR /root -VOLUME /bind-adblock +COPY blocklist.txt . +COPY config.yml . +COPY update-zonefile.py . +COPY requirements.txt . -COPY ${SRC}/blocklist.txt ./ -COPY ${SRC}/config.yml ./ -COPY ${SRC}/update-zonefile.py ./ -COPY ${SRC}/requirements.txt ./ +ENV VIRTUAL_ENV=/opt/venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" -RUN pip install -r requirements.txt +RUN pip install --upgrade pip && \ + pip install -r requirements.txt + +RUN mkdir /bind-adblock CMD ["python3", "./update-zonefile.py", "--no-bind", "/bind-adblock/rpz-adblocker.zone", "rpz.adblocker"] diff --git a/README.md b/README.md index 26bd9ef..ac3348e 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,9 @@ See [requirements.txt](requirements.txt) To install ``` +python3 -m venv venv +source venv/bin/activate +pip install --upgrade pip pip install -r requirements.txt ``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..489af99 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +--- +version: "3" + +services: + updater: + container_name: adblock + build: + context: . + volumes: + - 'bind9-zones:/bind-adblock' + # - '/var/bind:/bind-adblock' + +volumes: + bind9-zones: