Skip to content

Commit 3e95ccd

Browse files
committed
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>
1 parent 1cc5197 commit 3e95ccd

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ The preferred method is to clone this repository and build the image locally wit
274274
- `-w <branch>` / `--webbranch <branch>`: Specify Web branch
275275
- `-p <branch>` / `--paddbranch <branch>`: Specify PADD branch
276276
- `-t <tag>` / `--tag <tag>`: Specify Docker image tag (default: `pihole:local`)
277-
- `-l` / `--local`: Use locally built FTL binary (requires `src/pihole-FTL` file)
277+
- `-l` / `--local`: Clones the FTL repository and builds the binary locally
278278
- `use_cache`: Enable caching (by default `--no-cache` is used)
279279
280280
If no options are specified, the following command will be executed:

build.sh

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
usage() {
55
echo "Usage: $0 [-l] [-f <ftl_branch>] [-c <core_branch>] [-w <web_branch>] [-t <tag>] [use_cache]"
66
echo "Options:"
7-
echo " -f, --ftlbranch <branch> Specify FTL branch (cannot be used in conjunction with -l)"
7+
echo " -f, --ftlbranch <branch> Specify FTL branch"
88
echo " -c, --corebranch <branch> Specify Core branch"
99
echo " -w, --webbranch <branch> Specify Web branch"
1010
echo " -p, --paddbranch <branch> Specify PADD branch"
1111
echo " -t, --tag <tag> Specify Docker image tag (default: pihole:local)"
12-
echo " -l, --local Use locally built FTL binary (requires src/pihole-FTL file)"
12+
echo " -l, --local Clones the FTL repository and builds the binary locally"
1313
echo " use_cache Enable caching (by default --no-cache is used)"
1414
echo ""
1515
echo "If no options are specified, the following command will be executed:"
@@ -20,11 +20,9 @@ usage() {
2020
# Set default values
2121
TAG="pihole:local"
2222
DOCKER_BUILD_CMD="docker buildx build src/. --tag ${TAG} --load --no-cache"
23-
FTL_FLAG=false
2423

2524
# Check if buildx is installed
26-
docker buildx version >/dev/null 2>&1
27-
if [ $? -ne 0 ]; then
25+
if ! docker buildx version >/dev/null 2>&1; then
2826
echo "Error: Docker buildx is required to build this image. For installation instructions, see:"
2927
echo " https://github.com/docker/buildx#installing"
3028
exit 1
@@ -56,25 +54,11 @@ while [[ $# -gt 0 ]]; do
5654
key="$1"
5755

5856
case $key in
59-
-l | --local)
60-
if [ ! -f "src/pihole-FTL" ]; then
61-
echo "File 'src/pihole-FTL' not found. Exiting."
62-
exit 1
63-
fi
64-
if [ "$FTL_FLAG" = true ]; then
65-
echo "Error: Both -l and -f cannot be used together."
66-
usage
67-
fi
68-
FTL_FLAG=true
57+
-l | --local)
6958
DOCKER_BUILD_CMD+=" --build-arg FTL_SOURCE=local"
7059
shift
7160
;;
72-
-f | --ftlbranch)
73-
if [ "$FTL_FLAG" = true ]; then
74-
echo "Error: Both -l and -f cannot be used together."
75-
usage
76-
fi
77-
FTL_FLAG=true
61+
-f | --ftlbranch)
7862
FTL_BRANCH="$2"
7963
check_branch_exists "ftl" "$FTL_BRANCH"
8064
DOCKER_BUILD_CMD+=" --build-arg FTL_BRANCH=$FTL_BRANCH"
@@ -122,10 +106,8 @@ done
122106

123107
# Execute the docker build command
124108
echo "Executing command: $DOCKER_BUILD_CMD"
125-
eval "${DOCKER_BUILD_CMD}"
126-
127-
# Check exit code of previous command
128-
if [ $? -ne 0 ]; then
109+
# Execute the docker build command and check its exit status
110+
if ! eval "${DOCKER_BUILD_CMD}"; then
129111
echo ""
130112
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
131113
echo "!! ERROR: Docker build failed, please review logs above !!"

src/Dockerfile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ EXPOSE 80
8686
EXPOSE 123/udp
8787
EXPOSE 443
8888

89-
## 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
89+
## 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
9090

9191
FROM base AS remote-ftl-install
9292
# Default stage if FTL_SOURCE is not explicitly set to "local"
@@ -106,10 +106,22 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then FTLARCH=amd64; \
106106
&& readelf -h /usr/bin/pihole-FTL || (echo "Error with downloaded FTL binary" && exit 1) \
107107
&& /usr/bin/pihole-FTL -vv
108108

109+
# This is only used if FTL_SOURCE is set to "local" (which will in turn use the local-ftl-install stage)
110+
FROM ghcr.io/pi-hole/ftl-build:v2.11 AS ftl-builder
111+
# Needs to be defaulted to something, but it will be overridden by the build-arg anyway
112+
ARG FTL_BRANCH="development"
113+
114+
RUN git clone --depth 1 --single-branch --branch ${FTL_BRANCH} https://github.com/pi-hole/ftl.git /ftlbuild && \
115+
cd /ftlbuild && \
116+
rm src/args.c && \
117+
./build.sh &&\
118+
# if the build fails, exit with and error code
119+
if [ $? -ne 0 ]; then echo "FTL build failed" && exit 1; fi && \
120+
# check if the binary is valid
121+
readelf -h /ftlbuild/pihole-FTL || (echo "Error with built FTL binary" && exit 1)
122+
109123
FROM base AS local-ftl-install
110-
# pihole-FTL must be built from source and copied to the src directory first!
111-
COPY --chmod=0755 pihole-FTL /usr/bin/pihole-FTL
112-
RUN readelf -h /usr/bin/pihole-FTL || (echo "Error with local FTL binary" && exit 1)
124+
COPY --from=ftl-builder --chmod=0755 /ftlbuild/pihole-FTL /usr/bin/pihole-FTL
113125

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

0 commit comments

Comments
 (0)