Skip to content

Commit

Permalink
Merge pull request #1607 from pi-hole/tweaks
Browse files Browse the repository at this point in the history
Add support for choosing PADD branch in build script
  • Loading branch information
PromoFaux authored Jun 24, 2024
2 parents 56c110a + d28c37e commit 9520967
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.platform}}
platforms: ${{ matrix.platform }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Run Tests
run: |
echo "Building image to test"
PLATFORM=${{ matrix.platform}} ./build-and-test.sh
PLATFORM=${{ matrix.platform }} ./build-and-test.sh
5 changes: 3 additions & 2 deletions build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
set -ex

if [[ "$1" == "enter" ]]; then
enter="-it --entrypoint=sh"
enter="-it"
cmd="sh"
fi

GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed "s/\//-/g")
Expand All @@ -20,4 +21,4 @@ docker run --rm \
--env GIT_TAG="${GIT_TAG}" \
--env PY_COLORS=1 \
--env TARGETPLATFORM="${PLATFORM}" \
${enter} image_pipenv
${enter} image_pipenv ${cmd}
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ usage() {
echo " -f, --ftlbranch <branch> Specify FTL branch (cannot be used in conjunction with -l)"
echo " -c, --corebranch <branch> Specify Core branch"
echo " -w, --webbranch <branch> Specify Web branch"
echo " -p, --paddbranch <branch> Specify PADD branch"
echo " -t, --tag <tag> Specify Docker image tag (default: pihole)"
echo " -l, --local Use locally built FTL binary (requires src/pihole-FTL file)"
echo " use_cache Enable caching (by default --no-cache is used)"
Expand Down Expand Up @@ -61,6 +62,12 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
-p | --paddbranch)
PADD_BRANCH="$2"
DOCKER_BUILD_CMD+=" --build-arg PADD_BRANCH=$PADD_BRANCH"
shift
shift
;;
-t | --tag)
TAG="$2"
DOCKER_BUILD_CMD=${DOCKER_BUILD_CMD/pihole/$TAG}
Expand Down
8 changes: 4 additions & 4 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1
ARG FTL_SOURCE=remote
ARG alpine_version="3.19"
FROM alpine:${alpine_version} as base
FROM alpine:${alpine_version} AS base
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope

ARG TARGETPLATFORM
Expand Down Expand Up @@ -69,7 +69,7 @@ COPY --chmod=0755 start.sh /usr/bin/start.sh

## Buildkit can do some fancy stuff and we can use it to either download FTL from ftl.pi-hole.net or use a local copy

FROM base as remote-ftl-install
FROM base AS remote-ftl-install
# Default stage if FTL_SOURCE is not explicitly set to "local"
# Download the latest version of pihole-FTL for the correct architecture
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then FTLARCH=amd64; \
Expand All @@ -85,12 +85,12 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then FTLARCH=amd64; \
&& chmod +x /usr/bin/pihole-FTL \
&& readelf -h /usr/bin/pihole-FTL || cat /usr/bin/pihole-FTL

FROM base as local-ftl-install
FROM base AS local-ftl-install
# pihole-FTL must be built from source and copied to the build directory first!
COPY --chmod=0755 pihole-FTL /usr/bin/pihole-FTL

# Use the appropriate FTL Install stage based on the FTL_SOURCE build-arg
FROM ${FTL_SOURCE}-ftl-install as final
FROM ${FTL_SOURCE}-ftl-install AS final

HEALTHCHECK CMD dig +short +norecurse +retry=0 @127.0.0.1 pi.hole || exit 1

Expand Down
5 changes: 2 additions & 3 deletions test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ ARG docker_version="25.0.4"
FROM docker:${docker_version}-cli-alpine${alpine_version}

COPY --chmod=0755 ./cmd.sh /usr/local/bin/cmd.sh
COPY --chmod=0755 ./entrypoint.sh /usr/local/bin/entrypoint.sh
COPY requirements.txt /root/
WORKDIR /root

Expand All @@ -18,5 +17,5 @@ RUN apk add --no-cache \
# Tests fall over without it. Investigate later.
&& sed -i 's|/bin/sh|/bin/bash|g' /usr/lib/python3.11/site-packages/testinfra/backend/docker.py

ENTRYPOINT entrypoint.sh
CMD cmd.sh
SHELL ["/bin/sh", "-c"]
CMD ["cmd.sh"]
1 change: 0 additions & 1 deletion test/entrypoint.sh

This file was deleted.

2 changes: 1 addition & 1 deletion test/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytest == 7.4.
pytest == 7.4
pytest-xdist == 3.5.0
pytest-testinfra == 10.0.0
black == 23.12.0

0 comments on commit 9520967

Please sign in to comment.