Merge pull request #1915 from pi-hole/development

Development -> master
This commit is contained in:
Adam Warner
2025-10-25 11:15:21 +01:00
committed by GitHub
25 changed files with 274 additions and 251 deletions

20
.editorconfig Normal file
View File

@@ -0,0 +1,20 @@
# EditorConfig is awesome: https://editorconfig.org/
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = tab
tab_width = 4
charset = utf-8
trim_trailing_whitespace = true
[*.yml]
tab_width = 2
[*.md]
tab_width = 2

View File

@@ -12,31 +12,31 @@ assignees: ''
<!-- IMPORTANT Complete the entire template please, the info gathered here is usually needed to debug issues anyway so it saves time in the long run. Incomplete/stock template issues may be closed --> <!-- IMPORTANT Complete the entire template please, the info gathered here is usually needed to debug issues anyway so it saves time in the long run. Incomplete/stock template issues may be closed -->
<!-- pick ONE: Bug, <!-- pick ONE: Bug,
Feature Request, Feature Request,
Run Issue (running Pi-hole container failing), Run Issue (running Pi-hole container failing),
Build Issue (Building image failing) Build Issue (Building image failing)
Enter in line below: --> Enter in line below: -->
This is a: **FILL ME IN** This is a: **FILL ME IN**
## Details ## Details
<!-- Provide a more detailed introduction to the issue or feature, try not to duplicate info from lower sections by reviewing the entire template first --> <!-- Provide a more detailed introduction to the issue or feature, try not to duplicate info from lower sections by reviewing the entire template first -->
## Related Issues ## Related Issues
- [ ] I have searched this repository/Pi-hole forums for existing issues and pull requests that look similar - [ ] I have searched this repository/Pi-hole forums for existing issues and pull requests that look similar
<!-- Add links below! --> <!-- Add links below! -->
<!------- FEATURE REQUESTS CAN STOP FILLING IN TEMPLATE HERE --------> <!------- FEATURE REQUESTS CAN STOP FILLING IN TEMPLATE HERE -------->
<!------- ISSUES SHOULD FILL OUT REMAINDER OF TEMPLATE --------> <!------- ISSUES SHOULD FILL OUT REMAINDER OF TEMPLATE -------->
## How to reproduce the issue ## How to reproduce the issue
1. Environment data 1. Environment data
* Operating System: **ENTER HERE** <!-- Debian, Ubuntu, Rasbian, etc --> * Operating System: **ENTER HERE** <!-- Debian, Ubuntu, Rasbian, etc -->
* Hardware: <!-- PC, RasPi B/2B/3B/4B, Mac, Synology, QNAP, etc --> * Hardware: <!-- PC, RasPi B/2B/3B/4B, Mac, Synology, QNAP, etc -->
* Kernel Architecture: <!-- x86/amd64, ArmV7, ArmV8 32bit, ArmV8 64bit, etc --> * Kernel Architecture: <!-- x86/amd64, ArmV7, ArmV8 32bit, ArmV8 64bit, etc -->
* Docker Install Info and version: * Docker Install Info and version:
- Software source: <!-- official docker-ce, OS provided package, Hypriot --> - Software source: <!-- official docker-ce, OS provided package, Hypriot -->
- Supplimentary Software: <!-- synology, portainer, etc --> - Supplimentary Software: <!-- synology, portainer, etc -->
* Hardware architecture: <!-- ARMv7, x86 --> * Hardware architecture: <!-- ARMv7, x86 -->

View File

@@ -9,4 +9,4 @@ contact_links:
- name: Documentation - name: Documentation
url: https://docs.pi-hole.net url: https://docs.pi-hole.net
about: Documentation and guides. about: Documentation and guides.

View File

@@ -2,7 +2,7 @@ version: 2
updates: updates:
# Maintain dependencies for GitHub Actions # Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions" - package-ecosystem: "github-actions"
directories: directories:
- "/" - "/"
schedule: schedule:
interval: "weekly" interval: "weekly"

View File

@@ -12,7 +12,7 @@ on:
env: env:
dockerhub: ${{ secrets.DOCKERHUB_NAMESPACE }}/pihole dockerhub: ${{ secrets.DOCKERHUB_NAMESPACE }}/pihole
ghcr: ghcr.io/${{ github.repository_owner }}/pihole ghcr: ghcr.io/${{ github.repository_owner }}/pihole
components_branch: ${{ github.event_name == 'schedule' && 'development' || 'master' }} components_branch: ${{ github.event_name == 'release' && 'master' || 'development' }}
jobs: jobs:
build: build:
@@ -33,72 +33,77 @@ jobs:
runner: ubuntu-24.04-arm runner: ubuntu-24.04-arm
- platform: linux/riscv64 - platform: linux/riscv64
runner: ubuntu-24.04-arm runner: ubuntu-24.04-arm
steps: steps:
- name: Prepare name for digest up/download - name: Prepare name for digest up/download
run: | run: |
platform=${{ matrix.platform }} platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout Repo - &checkout-repo
name: Checkout Repo
if: github.event_name != 'schedule' if: github.event_name != 'schedule'
uses: actions/checkout@v4 uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
- name: Checkout dev branch if scheduled - &checkout-dev
name: Checkout dev branch if scheduled
if: github.event_name == 'schedule' if: github.event_name == 'schedule'
uses: actions/checkout@v4 uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
with: with:
ref: development ref: development
- name: Docker meta - &docker-meta
name: Docker meta
id: meta id: meta
uses: docker/metadata-action@v5 uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f #v5.8.0
with: with:
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
images: | images: |
${{ env.dockerhub }} ${{ env.dockerhub }}
${{ env.ghcr }} ${{ env.ghcr }}
flavor: | flavor: |
latest=${{ startsWith(github.ref, 'refs/tags/') }} latest=${{ startsWith(github.ref, 'refs/tags/') }}
tags: | tags: |
type=schedule,pattern=nightly type=schedule,pattern=nightly
type=ref,event=branch,enable=${{ github.event_name != 'schedule' }} type=raw,value=nightly,enable=${{ github.event_name == 'push' }}
type=ref,event=tag type=ref,event=tag
- - &login-dockerhub
name: Login to Docker Hub name: Login to Docker Hub
uses: docker/login-action@v3 uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef #v3.6.0
with: with:
registry: docker.io registry: docker.io
username: ${{ secrets.DOCKERHUB_USER }} username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASS }} password: ${{ secrets.DOCKERHUB_PASS }}
-
- &login-ghcr
name: Login to GitHub Container Registry name: Login to GitHub Container Registry
uses: docker/login-action@v3 uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef #v3.6.0
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 #v3.6.0
with: with:
platforms: ${{ matrix.platform}} platforms: ${{ matrix.platform}}
- name: Set up Docker Buildx - &setup-buildx
uses: docker/setup-buildx-action@v3 name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 #v3.11.1
- name: Build container and push by digest - name: Build container and push by digest
id: build id: build
uses: docker/build-push-action@v6 uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 #v6.18.0
with: with:
context: ./src/ context: ./src/
platforms: ${{ matrix.platform }} platforms: ${{ matrix.platform }}
build-args: | build-args: |
PIHOLE_DOCKER_TAG=${{ steps.meta.outputs.version }} PIHOLE_DOCKER_TAG=${{ steps.meta.outputs.version }}
FTL_BRANCH=${{ env.components_branch }} FTL_BRANCH=${{ env.components_branch }}
CORE_BRANCH=${{ env.components_branch }} CORE_BRANCH=${{ env.components_branch }}
WEB_BRANCH=${{ env.components_branch }} WEB_BRANCH=${{ env.components_branch }}
PADD_BRANCH=${{ env.components_branch }} PADD_BRANCH=${{ env.components_branch }}
labels: ${{ steps.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
outputs: | outputs: |
@@ -111,7 +116,7 @@ jobs:
touch "/tmp/digests/${digest_docker#sha256:}" touch "/tmp/digests/${digest_docker#sha256:}"
- name: Upload digest - name: Upload digest
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 #v5.0.0
with: with:
name: digests-${{ env.PLATFORM_PAIR }} name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/* path: /tmp/digests/*
@@ -126,55 +131,20 @@ jobs:
needs: needs:
- build - build
steps: steps:
- name: Checkout Repo - *checkout-repo
if: github.event_name != 'schedule' - *checkout-dev
uses: actions/checkout@v4
- name: Checkout dev branch if scheduled
if: github.event_name == 'schedule'
uses: actions/checkout@v4
with:
ref: development
- name: Download digests - name: Download digests
uses: actions/download-artifact@v4 uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 #v6.0.0
with: with:
path: /tmp/digests path: /tmp/digests
pattern: digests-* pattern: digests-*
merge-multiple: true merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta - *setup-buildx
id: meta - *docker-meta
uses: docker/metadata-action@v5 - *login-dockerhub
with: - *login-ghcr
github-token: ${{ secrets.GITHUB_TOKEN }}
images: |
${{ env.dockerhub }}
${{ env.ghcr }}
flavor: |
latest=${{ startsWith(github.ref, 'refs/tags/') }}
tags: |
type=schedule,pattern=nightly
type=ref,event=branch,enable=${{ github.event_name != 'schedule' }}
type=ref,event=tag
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASS }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push (DockerHub and GitHub Container Registry) - name: Create manifest list and push (DockerHub and GitHub Container Registry)
working-directory: /tmp/digests working-directory: /tmp/digests
@@ -187,4 +157,4 @@ jobs:
- name: Inspect images - name: Inspect images
run: | run: |
docker buildx imagetools inspect ${{ env.dockerhub }}:${{ steps.meta.outputs.version }} docker buildx imagetools inspect ${{ env.dockerhub }}:${{ steps.meta.outputs.version }}
docker buildx imagetools inspect ${{ env.ghcr }}:${{ steps.meta.outputs.version }} docker buildx imagetools inspect ${{ env.ghcr }}:${{ steps.meta.outputs.version }}

View File

@@ -25,16 +25,16 @@ jobs:
CI_ARCH: ${{ matrix.platform }} CI_ARCH: ${{ matrix.platform }}
steps: steps:
- name: Checkout Repo - name: Checkout Repo
uses: actions/checkout@v4 uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 #v3.6.0
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v5.6.0 uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c #v6.0.0
with: with:
python-version: "3.13" python-version: "3.13"
- name: Run black formatter - name: Run black formatter
run: | run: |
pip install black pip install black

View File

@@ -10,9 +10,9 @@ jobs:
steps: steps:
- -
name: Checkout repository name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
- -
name: Spell-Checking name: Spell-Checking
uses: codespell-project/actions-codespell@master uses: codespell-project/actions-codespell@406322ec52dd7b488e48c1c4b82e2a8b3a1bf630 #v2.1
with: with:
ignore_words_file: .codespellignore ignore_words_file: .codespellignore

18
.github/workflows/editorconfig.yml vendored Normal file
View File

@@ -0,0 +1,18 @@
name: Editorconfig-Checker
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
jobs:
editorconfig-checker:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
- name: Get editorconfig-checker
uses: editorconfig-checker/action-editorconfig-checker@4b6cd6190d435e7e084fb35e36a096e98506f7b9 # tag v2. is really out of date
- name: Run editorconfig-checker
run: editorconfig-checker

View File

@@ -1,6 +1,8 @@
name: housekeeping name: Remove untagged images from registry
on: on:
workflow_dispatch: workflow_dispatch:
schedule:
- cron: "0 0 * * *"
jobs: jobs:
housekeeping: housekeeping:
@@ -8,11 +10,11 @@ jobs:
steps: steps:
- -
name: Delete all containers from repository without tags name: Delete all containers from repository without tags
uses: Chizkiyahu/delete-untagged-ghcr-action@v6 uses: Chizkiyahu/delete-untagged-ghcr-action@68758dd8caf1d9dbaed1fe9cc1a1f8fcea1c4cf0 #v6.1.0
with: with:
token: ${{ secrets.PAT_TOKEN }} token: ${{ secrets.PAT_TOKEN }}
repository_owner: ${{ github.repository_owner }} repository_owner: ${{ github.repository_owner }}
repository: ${{ github.repository }} repository: ${{ github.repository }}
untagged_only: true untagged_only: true
owner_type: org # or user owner_type: org # or user
except_untagged_multiplatform: true except_untagged_multiplatform: true

View File

@@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check if PRs are have merge conflicts - name: Check if PRs are have merge conflicts
uses: eps1lon/actions-label-merge-conflict@v3.0.3 uses: eps1lon/actions-label-merge-conflict@1df065ebe6e3310545d4f4c4e862e43bdca146f0 #v3.0.3
with: with:
dirtyLabel: "Merge Conflict" dirtyLabel: "Merge Conflict"
repoToken: "${{ secrets.GITHUB_TOKEN }}" repoToken: "${{ secrets.GITHUB_TOKEN }}"

View File

@@ -17,7 +17,7 @@ jobs:
issues: write issues: write
steps: steps:
- uses: actions/stale@v9.1.0 - uses: actions/stale@5f858e3efba33a5ca4407a664cc011ad407f2008 #v10.1.0
with: with:
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 30 days-before-stale: 30
@@ -41,7 +41,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
- name: Remove 'stale' label - name: Remove 'stale' label
run: gh issue edit ${{ github.event.issue.number }} --remove-label ${{ env.stale_label }} run: gh issue edit ${{ github.event.issue.number }} --remove-label ${{ env.stale_label }}
env: env:

View File

@@ -17,7 +17,7 @@ jobs:
pull-requests: write pull-requests: write
steps: steps:
- uses: actions/stale@v9.1.0 - uses: actions/stale@5f858e3efba33a5ca4407a664cc011ad407f2008 #v10.1.0
with: with:
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
# Do not automatically mark PR/issue as stale # Do not automatically mark PR/issue as stale

View File

@@ -11,7 +11,7 @@ jobs:
name: Syncing branches name: Syncing branches
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
- name: Opening pull request - name: Opening pull request
run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal'
env: env:

4
.gitignore vendored
View File

@@ -13,9 +13,11 @@ docker-compose.yml
etc-dnsmasq.d/ etc-dnsmasq.d/
etc-pihole/ etc-pihole/
var-log/ var-log/
.vscode/
.pytest_cache/
# WIP/test stuff # WIP/test stuff
doco.yml doco.yml
# Ignore FTL Binary if it exists # Ignore FTL Binary if it exists
src/pihole-FTL src/pihole-FTL

View File

@@ -1,5 +0,0 @@
{
"github-actions.workflows.pinned.workflows": [
".github/workflows/v6-alpine-play.yml"
]
}

View File

@@ -200,12 +200,11 @@ Release notes will always contain full details of changes in the container, incl
| tag | description | tag | description
|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------| |---------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `latest` | Always latest release | | `latest` | Always the latest release |
| `2022.04.0` | Date-based release | | `2022.04.0` | Date-based release |
| `2022.04.1` | Second release in a given month | | `2022.04.1` | Second release in a given month |
| `development` | Similar to `latest`, but for the development branch (pushed occasionally) |
| `*beta` | Early beta releases of upcoming versions - here be dragons | | `*beta` | Early beta releases of upcoming versions - here be dragons |
| `nightly` | Like `development` but pushed every night and pulls from the latest `development` branches of the core Pi-hole components (Pi-hole, web, FTL) | | `nightly` | Built and pushed whenever there are changes on the `development` branch and additionally produced by the scheduled nightly job. These are the most experimental development images and may change frequently |
## Upgrading, Persistence, and Customizations ## Upgrading, Persistence, and Customizations

View File

@@ -5,7 +5,7 @@ usage() {
echo "Usage: $0 [-l] [-f <ftl_branch>] [-c <core_branch>] [-w <web_branch>] [-t <tag>] [use_cache]" echo "Usage: $0 [-l] [-f <ftl_branch>] [-c <core_branch>] [-w <web_branch>] [-t <tag>] [use_cache]"
echo "Options:" echo "Options:"
echo " -f, --ftlbranch <branch> Specify FTL branch (cannot be used in conjunction with -l)" echo " -f, --ftlbranch <branch> Specify FTL branch (cannot be used in conjunction with -l)"
echo " -c, --corebranch <branch> Specify Core branch" echo " -c, --corebranch <branch> Specify Core branch"
echo " -w, --webbranch <branch> Specify Web branch" echo " -w, --webbranch <branch> Specify Web branch"
echo " -p, --paddbranch <branch> Specify PADD branch" echo " -p, --paddbranch <branch> Specify PADD branch"
echo " -t, --tag <tag> Specify Docker image tag (default: pihole:local)" echo " -t, --tag <tag> Specify Docker image tag (default: pihole:local)"
@@ -91,7 +91,7 @@ while [[ $# -gt 0 ]]; do
DOCKER_BUILD_CMD+=" --build-arg CORE_BRANCH=$CORE_BRANCH" DOCKER_BUILD_CMD+=" --build-arg CORE_BRANCH=$CORE_BRANCH"
shift shift
shift shift
;; ;;
-w | --webbranch) -w | --webbranch)
WEB_BRANCH="$2" WEB_BRANCH="$2"
check_branch_exists "web" "$WEB_BRANCH" "$WEB_FORK" check_branch_exists "web" "$WEB_BRANCH" "$WEB_FORK"

View File

@@ -34,13 +34,13 @@ services:
# Set the appropriate timezone for your location (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones), e.g: # Set the appropriate timezone for your location (https://en.wikipedia.org/wiki/List_of_tz_database_time_zones), e.g:
TZ: 'Europe/London' TZ: 'Europe/London'
# Set a password to access the web interface. Not setting one will result in a random password being assigned # Set a password to access the web interface. Not setting one will result in a random password being assigned
FTLCONF_webserver_api_password: 'correct horse battery staple' FTLCONF_webserver_api_password: 'correct horse battery staple'
# Volumes store your data between container upgrades # Volumes store your data between container upgrades
volumes: volumes:
# For persisting Pi-hole's databases and common configuration file # For persisting Pi-hole's databases and common configuration file
- './etc-pihole:/etc/pihole' - './etc-pihole:/etc/pihole'
# Uncomment the below if you have custom dnsmasq config files that you want to persist. Not needed for most. # Uncomment the below if you have custom dnsmasq config files that you want to persist. Not needed for most.
#- './etc-dnsmasq.d:/etc/dnsmasq.d' #- './etc-dnsmasq.d:/etc/dnsmasq.d'
cap_add: cap_add:
# See https://github.com/pi-hole/docker-pi-hole#note-on-capabilities # See https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
# Required if you are using Pi-hole as your DHCP server, else not needed # Required if you are using Pi-hole as your DHCP server, else not needed

View File

@@ -59,9 +59,9 @@ COPY crontab.txt /crontab.txt
# Add PADD to the container, too. # Add PADD to the container, too.
ADD --chmod=0755 https://raw.githubusercontent.com/${PADD_FORK}/PADD/${PADD_BRANCH}/padd.sh /usr/local/bin/padd ADD --chmod=0755 https://raw.githubusercontent.com/${PADD_FORK}/PADD/${PADD_BRANCH}/padd.sh /usr/local/bin/padd
# download a the main repos from github # download a the main repos from github
# if the branch is master we clone the latest tag as sometimes the master branch contains meta changes that have not been tagged # if the branch is master we clone the latest tag as sometimes the master branch contains meta changes that have not been tagged
# (we need to create a new "master" branch to avoid the "detached HEAD" state for the version check to work correctly) # (we need to create a new "master" branch to avoid the "detached HEAD" state for the version check to work correctly)
RUN clone_repo() { \ RUN clone_repo() { \
FORK="$1"; \ FORK="$1"; \
@@ -90,7 +90,8 @@ RUN cd /etc/.pihole && \
install -Dm755 -d /var/log/pihole && \ install -Dm755 -d /var/log/pihole && \
install -Dm755 -d /var/lib/logrotate && \ install -Dm755 -d /var/lib/logrotate && \
install -Dm755 -t /usr/local/bin pihole && \ install -Dm755 -t /usr/local/bin pihole && \
install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole && \ install -Dm644 ./advanced/bash-completion/pihole.bash /etc/bash_completion.d/pihole && \
install -Dm644 ./advanced/bash-completion/pihole-ftl.bash /etc/bash_completion.d/pihole-FTL && \
install -T -m 0755 ./advanced/Templates/pihole-FTL-prestart.sh /opt/pihole/pihole-FTL-prestart.sh && \ install -T -m 0755 ./advanced/Templates/pihole-FTL-prestart.sh /opt/pihole/pihole-FTL-prestart.sh && \
install -T -m 0755 ./advanced/Templates/pihole-FTL-poststop.sh /opt/pihole/pihole-FTL-poststop.sh && \ install -T -m 0755 ./advanced/Templates/pihole-FTL-poststop.sh /opt/pihole/pihole-FTL-poststop.sh && \
addgroup -S pihole -g ${PIHOLE_GID} && adduser -S pihole -G pihole -u ${PIHOLE_UID} && \ addgroup -S pihole -g ${PIHOLE_GID} && adduser -S pihole -G pihole -u ${PIHOLE_UID} && \

View File

@@ -104,11 +104,9 @@ migrate_gravity() {
echo " [i] Gravity migration checks" echo " [i] Gravity migration checks"
gravityDBfile=$(getFTLConfigValue files.gravity) gravityDBfile=$(getFTLConfigValue files.gravity)
if [[ -z "${PYTEST}" ]]; then if [[ ! -f /etc/pihole/adlists.list ]]; then
if [[ ! -f /etc/pihole/adlists.list ]]; then echo " [i] No adlist file found, creating one with a default blocklist"
echo " [i] No adlist file found, creating one with a default blocklist" echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" >/etc/pihole/adlists.list
echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" >/etc/pihole/adlists.list
fi
fi fi
if [ ! -f "${gravityDBfile}" ]; then if [ ! -f "${gravityDBfile}" ]; then

View File

@@ -1,12 +1,12 @@
#!/bin/bash #!/bin/bash
if [ ! -x /bin/sh ]; then if [ ! -x /bin/sh ]; then
echo "Executable test for /bin/sh failed. Your Docker version is too old to run Alpine 3.14+ and Pi-hole. You must upgrade Docker."; echo "Executable test for /bin/sh failed. Your Docker version is too old to run Alpine 3.14+ and Pi-hole. You must upgrade Docker.";
exit 1; exit 1;
fi fi
if [ "${PH_VERBOSE:-0}" -gt 0 ]; then if [ "${PH_VERBOSE:-0}" -gt 0 ]; then
set -x set -x
fi fi
trap stop TERM INT QUIT HUP ERR trap stop TERM INT QUIT HUP ERR
@@ -16,140 +16,137 @@ TRAP_TRIGGERED=0
start() { start() {
# The below functions are all contained in bash_functions.sh # The below functions are all contained in bash_functions.sh
# shellcheck source=/dev/null # shellcheck source=/dev/null
. /usr/bin/bash_functions.sh . /usr/bin/bash_functions.sh
# If the file /etc/pihole/setupVars.conf exists, but /etc/pihole/pihole.toml does not, then we are migrating v5->v6 # If the file /etc/pihole/setupVars.conf exists, but /etc/pihole/pihole.toml does not, then we are migrating v5->v6
# FTL Will handle the migration of the config files # FTL Will handle the migration of the config files
if [[ -f /etc/pihole/setupVars.conf && ! -f /etc/pihole/pihole.toml ]]; then if [[ -f /etc/pihole/setupVars.conf && ! -f /etc/pihole/pihole.toml ]]; then
echo " [i] v5 files detected that have not yet been migrated to v6" echo " [i] v5 files detected that have not yet been migrated to v6"
echo ""
migrate_v5_configs
fi
# ===========================
# Initial checks
# ===========================
# If PIHOLE_UID is set, modify the pihole user's id to match
set_uid_gid
# Configure FTL with any environment variables if needed
echo " [i] Starting FTL configuration"
ftl_config
# Install additional packages inside the container if requested
install_additional_packages
# Start crond for scheduled scripts (logrotate, pihole flush, gravity update etc)
start_cron
# Install the logrotate config file
install_logrotate
#migrate Gravity Database if needed:
migrate_gravity
echo " [i] pihole-FTL pre-start checks"
# Run the post stop script to cleanup any remaining artifacts from a previous run
sh /opt/pihole/pihole-FTL-poststop.sh
fix_capabilities
sh /opt/pihole/pihole-FTL-prestart.sh
echo " [i] Starting pihole-FTL ($FTL_CMD) as ${DNSMASQ_USER}"
echo "" echo ""
migrate_v5_configs
fi
# =========================== capsh --user="${DNSMASQ_USER}" --keep=1 -- -c "/usr/bin/pihole-FTL $FTL_CMD >/dev/null" &
# Initial checks # Notes on above:
# =========================== # - DNSMASQ_USER default of pihole is in Dockerfile & can be overwritten by runtime container env
# - /var/log/pihole/pihole*.log has FTL's output that no-daemon would normally print in FG too
# prevent duplicating it in docker logs by sending to dev null
# If PIHOLE_UID is set, modify the pihole user's id to match # We need the PID of the capsh process so that we can wait for it to finish
set_uid_gid CAPSH_PID=$!
# Configure FTL with any environment variables if needed # Wait until the log file exists before continuing
echo " [i] Starting FTL configuration" while [ ! -f /var/log/pihole/FTL.log ]; do
ftl_config sleep 0.5
done
# Install additional packages inside the container if requested # Wait until the FTL log contains the "FTL started" message before continuing, timeout after 10 seconds
install_additional_packages # exit if we do not find it
pihole-FTL wait-for '########## FTL started' /var/log/pihole/FTL.log 10 0 > /dev/null
if [ $? -ne 0 ]; then
echo " [✗] FTL did not start - stopping container"
exit 1
fi
# Start crond for scheduled scripts (logrotate, pihole flush, gravity update etc) pihole updatechecker
start_cron local versionsOutput
versionsOutput=$(pihole -v)
echo " [i] Version info:"
printf "%b" "${versionsOutput}\\n" | sed 's/^/ /'
echo ""
# Install the logrotate config file if [ "${TAIL_FTL_LOG:-1}" -eq 1 ]; then
install_logrotate # Start tailing the FTL log from the most recent "FTL Started" message
# Get the line number
startFrom=$(grep -n '########## FTL started' /var/log/pihole/FTL.log | tail -1 | cut -d: -f1)
# Start the tail from the line number and background it
tail --follow=name -n +"${startFrom}" /var/log/pihole/FTL.log &
else
echo " [i] FTL log output is disabled. Remove the Environment variable TAIL_FTL_LOG, or set it to 1 to enable FTL log output."
fi
#migrate Gravity Database if needed: # Wait for the capsh process (which spawned FTL) to finish
migrate_gravity wait $CAPSH_PID
FTL_EXIT_CODE=$?
echo " [i] pihole-FTL pre-start checks"
# Run the post stop script to cleanup any remaining artifacts from a previous run
sh /opt/pihole/pihole-FTL-poststop.sh
fix_capabilities # If we are here, then FTL has exited.
sh /opt/pihole/pihole-FTL-prestart.sh # If the trap was triggered, then stop will have already been called
if [ $TRAP_TRIGGERED -eq 0 ]; then
echo " [i] Starting pihole-FTL ($FTL_CMD) as ${DNSMASQ_USER}" # Pass the exit code through to the stop function
echo "" stop $FTL_EXIT_CODE
fi
capsh --user="${DNSMASQ_USER}" --keep=1 -- -c "/usr/bin/pihole-FTL $FTL_CMD >/dev/null" &
# Notes on above:
# - DNSMASQ_USER default of pihole is in Dockerfile & can be overwritten by runtime container env
# - /var/log/pihole/pihole*.log has FTL's output that no-daemon would normally print in FG too
# prevent duplicating it in docker logs by sending to dev null
# We need the PID of the capsh process so that we can wait for it to finish
CAPSH_PID=$!
# Wait until the log file exists before continuing
while [ ! -f /var/log/pihole/FTL.log ]; do
sleep 0.5
done
# Wait until the FTL log contains the "FTL started" message before continuing
while ! grep -q '########## FTL started' /var/log/pihole/FTL.log; do
sleep 0.5
done
pihole updatechecker
local versionsOutput
versionsOutput=$(pihole -v)
echo " [i] Version info:"
printf "%b" "${versionsOutput}\\n" | sed 's/^/ /'
echo ""
if [ "${TAIL_FTL_LOG:-1}" -eq 1 ]; then
# Start tailing the FTL log from the most recent "FTL Started" message
# Get the line number
startFrom=$(grep -n '########## FTL started' /var/log/pihole/FTL.log | tail -1 | cut -d: -f1)
# Start the tail from the line number and background it
tail --follow=name -n +"${startFrom}" /var/log/pihole/FTL.log &
else
echo " [i] FTL log output is disabled. Remove the Environment variable TAIL_FTL_LOG, or set it to 1 to enable FTL log output."
fi
# Wait for the capsh process (which spawned FTL) to finish
wait $CAPSH_PID
FTL_EXIT_CODE=$?
# If we are here, then FTL has exited.
# If the trap was triggered, then stop will have already been called
if [ $TRAP_TRIGGERED -eq 0 ]; then
# Pass the exit code through to the stop function
stop $FTL_EXIT_CODE
fi
} }
stop() { stop() {
local FTL_EXIT_CODE=$1 local FTL_EXIT_CODE=$1
# if we have nothing in FTL_EXIT_CODE, then have been called by the trap. Close FTL and wait for the CAPSH_PID to finish
if [ -z "${FTL_EXIT_CODE}" ]; then
TRAP_TRIGGERED=1
echo ""
echo " [i] Container stop requested..."
echo " [i] pihole-FTL is running - Attempting to shut it down cleanly"
echo ""
killall --signal 15 pihole-FTL
wait $CAPSH_PID
FTL_EXIT_CODE=$?
fi
# Wait for a few seconds to allow the FTL log tail to catch up before exiting the container
sleep 2
# ensure the exit code is an integer, if not set it to 1
if ! [[ "${FTL_EXIT_CODE}" =~ ^[0-9]+$ ]]; then
FTL_EXIT_CODE=1
fi
sh /opt/pihole/pihole-FTL-poststop.sh
# if we have nothing in FTL_EXIT_CODE, then have been called by the trap. Close FTL and wait for the CAPSH_PID to finish
if [ -z "${FTL_EXIT_CODE}" ]; then
TRAP_TRIGGERED=1
echo "" echo ""
echo " [i] Container stop requested..." echo " [i] pihole-FTL exited with status $FTL_EXIT_CODE"
echo " [i] pihole-FTL is running - Attempting to shut it down cleanly" echo ""
echo " [i] Container will now stop or restart depending on your restart policy"
echo " https://docs.docker.com/engine/containers/start-containers-automatically/#use-a-restart-policy"
echo "" echo ""
killall --signal 15 pihole-FTL
wait $CAPSH_PID exit "${FTL_EXIT_CODE}"
FTL_EXIT_CODE=$?
fi
# Wait for a few seconds to allow the FTL log tail to catch up before exiting the container
sleep 2
# ensure the exit code is an integer, if not set it to 1
if ! [[ "${FTL_EXIT_CODE}" =~ ^[0-9]+$ ]]; then
FTL_EXIT_CODE=1
fi
sh /opt/pihole/pihole-FTL-poststop.sh
echo ""
echo " [i] pihole-FTL exited with status $FTL_EXIT_CODE"
echo ""
echo " [i] Container will now stop or restart depending on your restart policy"
echo " https://docs.docker.com/engine/containers/start-containers-automatically/#use-a-restart-policy"
echo ""
# If we are running pytest, keep the container alive for a little longer
# to allow the tests to complete
if [[ ${PYTEST} ]]; then
sleep 10
fi
exit "${FTL_EXIT_CODE}"
} }

View File

@@ -1,6 +1,6 @@
pytest == 8.4.1 pytest == 8.4.2
pytest-testinfra == 10.2.2 pytest-testinfra == 10.2.2
pytest-clarity == 1.0.1 pytest-clarity == 1.0.1
tox == 4.28.4 tox == 4.32.0
# Not adding pytest-xdist as using pytest with n > 1 cores # Not adding pytest-xdist as using pytest with n > 1 cores
# causes random issues with the emulated architectures # causes random issues with the emulated architectures

View File

@@ -45,10 +45,6 @@ def docker(request):
for env_var in env_vars: for env_var in env_vars:
cmd.extend(["-e", env_var]) cmd.extend(["-e", env_var])
# ensure PYTEST=1 is set
if not any("PYTEST=1" in arg for arg in cmd):
cmd.extend(["-e", "PYTEST=1"])
# add default TZ if not already set # add default TZ if not already set
if not any("TZ=" in arg for arg in cmd): if not any("TZ=" in arg for arg in cmd):
cmd.extend(["-e", 'TZ="Europe/London"']) cmd.extend(["-e", 'TZ="Europe/London"'])

View File

@@ -49,19 +49,44 @@ def test_pihole_ftl_architecture(docker):
assert platform in func.stdout assert platform in func.stdout
# Wait 5 seconds for startup, then kill the start.sh script # Wait for FTL to start up, then stop the container gracefully
# Finally, grep the FTL log to see if it has been shut down cleanly # Finally, check the container logs to see if FTL was shut down cleanly
def test_pihole_ftl_clean_shutdown(docker): def test_pihole_ftl_starts_and_shuts_down_cleanly(docker):
func = docker.run( import subprocess
""" import time
sleep 5
killall --signal 15 start.sh # Get the container ID from the docker fixture
sleep 5 container_id = docker.backend.name
grep 'terminated' /var/log/pihole/FTL.log
""" # Wait for FTL to fully start up by checking logs
max_wait_time = 60 # Maximum wait time in seconds
start_time = time.time()
ftl_started = False
while time.time() - start_time < max_wait_time:
result = subprocess.run(
["docker", "logs", container_id], capture_output=True, text=True
)
if "########## FTL started" in result.stdout:
ftl_started = True
break
time.sleep(1) # Check every second
assert ftl_started, f"FTL did not start within {max_wait_time} seconds"
# Stop the container gracefully (sends SIGTERM)
subprocess.run(["docker", "stop", container_id], check=True)
# Get the container logs
result = subprocess.run(
["docker", "logs", container_id], capture_output=True, text=True
) )
assert "INFO: ########## FTL terminated after" in func.stdout
assert "(code 0)" in func.stdout # Check for clean shutdown messages in the logs
assert "INFO: ########## FTL terminated after" in result.stdout
assert "(code 0)" in result.stdout
def test_cronfile_valid(docker): def test_cronfile_valid(docker):

View File

@@ -7,10 +7,10 @@ deps = -rrequirements.txt
passenv = CIPLATFORM passenv = CIPLATFORM
setenv = setenv =
COLUMNS=120 COLUMNS=120
PY_COLORS=1 PY_COLORS=1
commands = # Build the Docker image for testing depending on the architecture, fall back to 'local' if not set commands = # Build the Docker image for testing depending on the architecture, fall back to 'local' if not set
# This allows us to run the tests on the host architecture if not on CI # This allows us to run the tests on the host architecture if not on CI
docker buildx build --load --platform={env:CIPLATFORM:local} --progress plain -f ../src/Dockerfile -t pihole:CI_container ../src/ docker buildx build --load --platform={env:CIPLATFORM:local} --progress plain -f ../src/Dockerfile -t pihole:CI_container ../src/
# run the tests # run the tests
# # Not using > 1 cores as it causes random issues with the emulated architectures # # Not using > 1 cores as it causes random issues with the emulated architectures
pytest {posargs:-vv} ./tests/ pytest {posargs:-vv} ./tests/