mirror of
https://github.com/pi-hole/docker-pi-hole.git
synced 2025-12-19 18:08:35 +00:00
Make the -l flag clone and build FTL directly inside the image, rather than relying on the binary having already been build externally
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
@@ -274,7 +274,7 @@ The preferred method is to clone this repository and build the image locally wit
|
||||
- `-w <branch>` / `--webbranch <branch>`: Specify Web branch
|
||||
- `-p <branch>` / `--paddbranch <branch>`: Specify PADD branch
|
||||
- `-t <tag>` / `--tag <tag>`: Specify Docker image tag (default: `pihole:local`)
|
||||
- `-l` / `--local`: Use locally built FTL binary (requires `src/pihole-FTL` file)
|
||||
- `-l` / `--local`: Clones the FTL repository and builds the binary locally
|
||||
- `use_cache`: Enable caching (by default `--no-cache` is used)
|
||||
|
||||
If no options are specified, the following command will be executed:
|
||||
|
||||
32
build.sh
32
build.sh
@@ -4,12 +4,12 @@
|
||||
usage() {
|
||||
echo "Usage: $0 [-l] [-f <ftl_branch>] [-c <core_branch>] [-w <web_branch>] [-t <tag>] [use_cache]"
|
||||
echo "Options:"
|
||||
echo " -f, --ftlbranch <branch> Specify FTL branch (cannot be used in conjunction with -l)"
|
||||
echo " -f, --ftlbranch <branch> Specify FTL branch"
|
||||
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:local)"
|
||||
echo " -l, --local Use locally built FTL binary (requires src/pihole-FTL file)"
|
||||
echo " -l, --local Clones the FTL repository and builds the binary locally"
|
||||
echo " use_cache Enable caching (by default --no-cache is used)"
|
||||
echo ""
|
||||
echo "If no options are specified, the following command will be executed:"
|
||||
@@ -20,11 +20,9 @@ usage() {
|
||||
# Set default values
|
||||
TAG="pihole:local"
|
||||
DOCKER_BUILD_CMD="docker buildx build src/. --tag ${TAG} --load --no-cache"
|
||||
FTL_FLAG=false
|
||||
|
||||
# Check if buildx is installed
|
||||
docker buildx version >/dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
if ! docker buildx version >/dev/null 2>&1; then
|
||||
echo "Error: Docker buildx is required to build this image. For installation instructions, see:"
|
||||
echo " https://github.com/docker/buildx#installing"
|
||||
exit 1
|
||||
@@ -56,25 +54,11 @@ while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
|
||||
case $key in
|
||||
-l | --local)
|
||||
if [ ! -f "src/pihole-FTL" ]; then
|
||||
echo "File 'src/pihole-FTL' not found. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
if [ "$FTL_FLAG" = true ]; then
|
||||
echo "Error: Both -l and -f cannot be used together."
|
||||
usage
|
||||
fi
|
||||
FTL_FLAG=true
|
||||
-l | --local)
|
||||
DOCKER_BUILD_CMD+=" --build-arg FTL_SOURCE=local"
|
||||
shift
|
||||
;;
|
||||
-f | --ftlbranch)
|
||||
if [ "$FTL_FLAG" = true ]; then
|
||||
echo "Error: Both -l and -f cannot be used together."
|
||||
usage
|
||||
fi
|
||||
FTL_FLAG=true
|
||||
-f | --ftlbranch)
|
||||
FTL_BRANCH="$2"
|
||||
check_branch_exists "ftl" "$FTL_BRANCH"
|
||||
DOCKER_BUILD_CMD+=" --build-arg FTL_BRANCH=$FTL_BRANCH"
|
||||
@@ -122,10 +106,8 @@ done
|
||||
|
||||
# Execute the docker build command
|
||||
echo "Executing command: $DOCKER_BUILD_CMD"
|
||||
eval "${DOCKER_BUILD_CMD}"
|
||||
|
||||
# Check exit code of previous command
|
||||
if [ $? -ne 0 ]; then
|
||||
# Execute the docker build command and check its exit status
|
||||
if ! eval "${DOCKER_BUILD_CMD}"; then
|
||||
echo ""
|
||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||
echo "!! ERROR: Docker build failed, please review logs above !!"
|
||||
|
||||
@@ -86,7 +86,7 @@ EXPOSE 80
|
||||
EXPOSE 123/udp
|
||||
EXPOSE 443
|
||||
|
||||
## 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
|
||||
## Buildkit can do some fancy stuff and we can use it to either download FTL from ftl.pi-hole.net or build a local copy
|
||||
|
||||
FROM base AS remote-ftl-install
|
||||
# Default stage if FTL_SOURCE is not explicitly set to "local"
|
||||
@@ -106,10 +106,22 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then FTLARCH=amd64; \
|
||||
&& readelf -h /usr/bin/pihole-FTL || (echo "Error with downloaded FTL binary" && exit 1) \
|
||||
&& /usr/bin/pihole-FTL -vv
|
||||
|
||||
# This is only used if FTL_SOURCE is set to "local" (which will in turn use the local-ftl-install stage)
|
||||
FROM ghcr.io/pi-hole/ftl-build:v2.11 AS ftl-builder
|
||||
# Needs to be defaulted to something, but it will be overridden by the build-arg anyway
|
||||
ARG FTL_BRANCH="development"
|
||||
|
||||
RUN git clone --depth 1 --single-branch --branch ${FTL_BRANCH} https://github.com/pi-hole/ftl.git /ftlbuild && \
|
||||
cd /ftlbuild && \
|
||||
rm src/args.c && \
|
||||
./build.sh &&\
|
||||
# if the build fails, exit with and error code
|
||||
if [ $? -ne 0 ]; then echo "FTL build failed" && exit 1; fi && \
|
||||
# check if the binary is valid
|
||||
readelf -h /ftlbuild/pihole-FTL || (echo "Error with built FTL binary" && exit 1)
|
||||
|
||||
FROM base AS local-ftl-install
|
||||
# pihole-FTL must be built from source and copied to the src directory first!
|
||||
COPY --chmod=0755 pihole-FTL /usr/bin/pihole-FTL
|
||||
RUN readelf -h /usr/bin/pihole-FTL || (echo "Error with local FTL binary" && exit 1)
|
||||
COPY --from=ftl-builder --chmod=0755 /ftlbuild/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
|
||||
|
||||
Reference in New Issue
Block a user