Skip to content

Commit 3dfb416

Browse files
committed
feat: optimize Docker build caching
- Use BuildKit cache mount for apk to avoid re-downloading packages - Add --link flag to ADD instructions so layers can be reordered independently - Enable cache-mode: max in CI workflow to maximize layer cache reuse - Reorder Dockerfile layers to push volatile steps (nightly debug tools, crontab) after stable ones, improving cache hit rates on normal builds
1 parent 850381a commit 3dfb416

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

.github/workflows/build-and-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
setup-qemu: true
6262
cache: true
6363
cache-scope: build
64+
cache-mode: max
6465
fail-fast: true
6566
context: src
6667
output: image

src/Dockerfile

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ ARG PIHOLE_GID=1000
2020
ENV DNSMASQ_USER=pihole
2121
ENV FTL_CMD=no-daemon
2222

23-
RUN apk add --no-cache \
23+
RUN --mount=type=cache,target=/var/cache/apk \
24+
apk add \
2425
bash \
2526
bash-completion \
2627
bind-tools \
@@ -43,21 +44,10 @@ RUN apk add --no-cache \
4344
unzip \
4445
wget
4546

46-
# For nightly images, we install gdb and screen for ease of debugging (this is
47-
# not included in the default image to keep it small), and also prepare the
48-
# system for a core dump. Furthermore, we already add the required signal
49-
# instructions to the gdb config file
50-
RUN if [ "${PIHOLE_DOCKER_TAG}" = "nightly" ]; then \
51-
apk add --no-cache gdb screen && \
52-
echo "ulimit -c unlimited" >> /etc/profile && \
53-
echo "handle SIGHUP nostop SIGPIPE nostop SIGTERM nostop SIG32 nostop SIG33 nostop SIG34 nostop SIG35 nostop SIG36 nostop SIG37 nostop SIG38 nostop SIG39 nostop SIG40 nostop SIG41 nostop" > /root/.gdbinit; \
54-
fi
55-
56-
ADD https://ftl.pi-hole.net/macvendor.db /macvendor.db
57-
COPY crontab.txt /crontab.txt
47+
ADD --link https://ftl.pi-hole.net/macvendor.db /macvendor.db
5848

5949
# Add PADD to the container, too.
60-
ADD --chmod=0755 https://raw.githubusercontent.com/${PADD_FORK}/PADD/${PADD_BRANCH}/padd.sh /usr/local/bin/padd
50+
ADD --link --chmod=0755 https://raw.githubusercontent.com/${PADD_FORK}/PADD/${PADD_BRANCH}/padd.sh /usr/local/bin/padd
6151

6252
# download a the main repos from github
6353
# if the branch is master we clone the latest tag as sometimes the master branch contains meta changes that have not been tagged
@@ -94,11 +84,22 @@ RUN cd /etc/.pihole && \
9484
install -Dm644 ./advanced/bash-completion/pihole-ftl.bash /etc/bash_completion.d/pihole-FTL && \
9585
install -T -m 0755 ./advanced/Templates/pihole-FTL-prestart.sh /opt/pihole/pihole-FTL-prestart.sh && \
9686
install -T -m 0755 ./advanced/Templates/pihole-FTL-poststop.sh /opt/pihole/pihole-FTL-poststop.sh && \
97-
addgroup -S pihole -g ${PIHOLE_GID} && adduser -S pihole -G pihole -u ${PIHOLE_UID} && \
98-
echo "${PIHOLE_DOCKER_TAG}" > /pihole.docker.tag
87+
addgroup -S pihole -g ${PIHOLE_GID} && adduser -S pihole -G pihole -u ${PIHOLE_UID}
9988

10089
COPY --chmod=0755 bash_functions.sh /usr/bin/bash_functions.sh
10190
COPY --chmod=0755 start.sh /usr/bin/start.sh
91+
COPY crontab.txt /crontab.txt
92+
93+
# For nightly images, we install gdb and screen for ease of debugging (this is
94+
# not included in the default image to keep it small), and also prepare the
95+
# system for a core dump. Furthermore, we already add the required signal
96+
# instructions to the gdb config file
97+
RUN if [ "${PIHOLE_DOCKER_TAG}" = "nightly" ]; then \
98+
apk add --no-cache gdb screen && \
99+
echo "ulimit -c unlimited" >> /etc/profile && \
100+
echo "handle SIGHUP nostop SIGPIPE nostop SIGTERM nostop SIG32 nostop SIG33 nostop SIG34 nostop SIG35 nostop SIG36 nostop SIG37 nostop SIG38 nostop SIG39 nostop SIG40 nostop SIG41 nostop" > /root/.gdbinit; \
101+
fi; \
102+
echo "${PIHOLE_DOCKER_TAG}" > /pihole.docker.tag
102103

103104
EXPOSE 53 53/udp
104105
EXPOSE 67/udp

0 commit comments

Comments
 (0)