Skip to content

Commit

Permalink
docker refresh and doco
Browse files Browse the repository at this point in the history
Expand dockerfile with docker-compose
doco DOCKER.md

add venv doco to README.md

add gitignore to exclude python venv

Signed-off-by: Nic Boet <[email protected]>
  • Loading branch information
nabbi authored and Trellmor committed Apr 3, 2023
1 parent bb54a11 commit 5515bcc
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
venv*
.cache/*
*.zone
49 changes: 49 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -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
```

19 changes: 12 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:

0 comments on commit 5515bcc

Please sign in to comment.