mirror of
https://github.com/pi-hole/docker-pi-hole.git
synced 2025-12-20 02:18:51 +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
|
- `-w <branch>` / `--webbranch <branch>`: Specify Web branch
|
||||||
- `-p <branch>` / `--paddbranch <branch>`: Specify PADD branch
|
- `-p <branch>` / `--paddbranch <branch>`: Specify PADD branch
|
||||||
- `-t <tag>` / `--tag <tag>`: Specify Docker image tag (default: `pihole:local`)
|
- `-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)
|
- `use_cache`: Enable caching (by default `--no-cache` is used)
|
||||||
|
|
||||||
If no options are specified, the following command will be executed:
|
If no options are specified, the following command will be executed:
|
||||||
|
|||||||
28
build.sh
28
build.sh
@@ -4,12 +4,12 @@
|
|||||||
usage() {
|
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"
|
||||||
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)"
|
||||||
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 " use_cache Enable caching (by default --no-cache is used)"
|
||||||
echo ""
|
echo ""
|
||||||
echo "If no options are specified, the following command will be executed:"
|
echo "If no options are specified, the following command will be executed:"
|
||||||
@@ -20,11 +20,9 @@ usage() {
|
|||||||
# Set default values
|
# Set default values
|
||||||
TAG="pihole:local"
|
TAG="pihole:local"
|
||||||
DOCKER_BUILD_CMD="docker buildx build src/. --tag ${TAG} --load --no-cache"
|
DOCKER_BUILD_CMD="docker buildx build src/. --tag ${TAG} --load --no-cache"
|
||||||
FTL_FLAG=false
|
|
||||||
|
|
||||||
# Check if buildx is installed
|
# Check if buildx is installed
|
||||||
docker buildx version >/dev/null 2>&1
|
if ! docker buildx version >/dev/null 2>&1; then
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Error: Docker buildx is required to build this image. For installation instructions, see:"
|
echo "Error: Docker buildx is required to build this image. For installation instructions, see:"
|
||||||
echo " https://github.com/docker/buildx#installing"
|
echo " https://github.com/docker/buildx#installing"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -57,24 +55,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
|
|
||||||
case $key in
|
case $key in
|
||||||
-l | --local)
|
-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
|
|
||||||
DOCKER_BUILD_CMD+=" --build-arg FTL_SOURCE=local"
|
DOCKER_BUILD_CMD+=" --build-arg FTL_SOURCE=local"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-f | --ftlbranch)
|
-f | --ftlbranch)
|
||||||
if [ "$FTL_FLAG" = true ]; then
|
|
||||||
echo "Error: Both -l and -f cannot be used together."
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
FTL_FLAG=true
|
|
||||||
FTL_BRANCH="$2"
|
FTL_BRANCH="$2"
|
||||||
check_branch_exists "ftl" "$FTL_BRANCH"
|
check_branch_exists "ftl" "$FTL_BRANCH"
|
||||||
DOCKER_BUILD_CMD+=" --build-arg FTL_BRANCH=$FTL_BRANCH"
|
DOCKER_BUILD_CMD+=" --build-arg FTL_BRANCH=$FTL_BRANCH"
|
||||||
@@ -122,10 +106,8 @@ done
|
|||||||
|
|
||||||
# Execute the docker build command
|
# Execute the docker build command
|
||||||
echo "Executing command: $DOCKER_BUILD_CMD"
|
echo "Executing command: $DOCKER_BUILD_CMD"
|
||||||
eval "${DOCKER_BUILD_CMD}"
|
# Execute the docker build command and check its exit status
|
||||||
|
if ! eval "${DOCKER_BUILD_CMD}"; then
|
||||||
# Check exit code of previous command
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
||||||
echo "!! ERROR: Docker build failed, please review logs above !!"
|
echo "!! ERROR: Docker build failed, please review logs above !!"
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ EXPOSE 80
|
|||||||
EXPOSE 123/udp
|
EXPOSE 123/udp
|
||||||
EXPOSE 443
|
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
|
FROM base AS remote-ftl-install
|
||||||
# Default stage if FTL_SOURCE is not explicitly set to "local"
|
# 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) \
|
&& readelf -h /usr/bin/pihole-FTL || (echo "Error with downloaded FTL binary" && exit 1) \
|
||||||
&& /usr/bin/pihole-FTL -vv
|
&& /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
|
FROM base AS local-ftl-install
|
||||||
# pihole-FTL must be built from source and copied to the src directory first!
|
COPY --from=ftl-builder --chmod=0755 /ftlbuild/pihole-FTL /usr/bin/pihole-FTL
|
||||||
COPY --chmod=0755 pihole-FTL /usr/bin/pihole-FTL
|
|
||||||
RUN readelf -h /usr/bin/pihole-FTL || (echo "Error with local FTL binary" && exit 1)
|
|
||||||
|
|
||||||
# Use the appropriate FTL Install stage based on the FTL_SOURCE build-arg
|
# 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
|
||||||
|
|||||||
Reference in New Issue
Block a user