Redesign Dockerfiles using new ndn-cxx base images

Refs: #5303
Change-Id: I1a78db309e0443410f5b585f3b0318408e30f76d
diff --git a/.jenkins.d/00-deps.sh b/.jenkins.d/00-deps.sh
index df1e433..ad3828e 100755
--- a/.jenkins.d/00-deps.sh
+++ b/.jenkins.d/00-deps.sh
@@ -2,7 +2,8 @@
 set -eo pipefail
 
 APT_PKGS=(
-    build-essential
+    dpkg-dev
+    g++
     libboost-chrono-dev
     libboost-date-time-dev
     libboost-dev
@@ -17,7 +18,7 @@
     libssl-dev
     libsystemd-dev
     pkg-config
-    python3-minimal
+    python3
 )
 FORMULAE=(boost openssl pkg-config)
 PIP_PKGS=()
diff --git a/Dockerfile b/Dockerfile
index 0a917e4..1b53e3b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,45 +1,53 @@
-FROM ghcr.io/named-data/ndn-cxx:latest as builder
+# syntax=docker/dockerfile:1
 
-RUN apt-get update \
-    && apt-get install -y --no-install-recommends libpcap-dev \
+ARG NDN_CXX_VERSION=latest
+FROM ghcr.io/named-data/ndn-cxx-build:${NDN_CXX_VERSION} AS build
+ARG SOURCE_DATE_EPOCH
+
+RUN apt-get install -Uy --no-install-recommends \
+        libpcap-dev \
+    # use 'apt-get distclean' when we upgrade to ubuntu:24.04
     && rm -rf /var/lib/apt/lists/*
 
-COPY . /NFD
+RUN --mount=type=bind,rw,target=/src <<EOF
+set -eux
+cd /src
+./waf configure \
+    --prefix=/usr \
+    --libdir=/usr/lib \
+    --sysconfdir=/etc \
+    --localstatedir=/var \
+    --sharedstatedir=/var \
+    --without-systemd
+./waf build
+./waf install
 
-RUN cd /NFD \
-    && ./waf configure --without-pch --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
-    && ./waf \
-    && ./waf install \
-    # get list of dependencies
-    && mkdir -p /shlibdeps/debian && cd /shlibdeps && touch debian/control \
-    && dpkg-shlibdeps --ignore-missing-info /usr/lib/libndn-cxx.so* /usr/bin/nfdc /usr/bin/nfd \
-    && sed -n '/^shlibs:Depends=/ s|shlibs:Depends=||p' debian/substvars | sed -e 's|,||g' -e 's| ([^)]*)||g' > /deps.txt
+mkdir -p /deps/debian
+touch /deps/debian/control
+cd /deps
+for binary in nfd nfdc nfd-autoreg; do
+    dpkg-shlibdeps --ignore-missing-info "/usr/bin/${binary}" -O \
+        | sed -n 's|^shlibs:Depends=||p' | sed 's| ([^)]*),\?||g' > "${binary}"
+done
+EOF
 
-# use same base distro version as named-data/ndn-cxx
-FROM debian:bookworm
+FROM ghcr.io/named-data/ndn-cxx-runtime:${NDN_CXX_VERSION} AS nfd
+ARG SOURCE_DATE_EPOCH
 
-COPY --from=builder /deps.txt /
-RUN apt-get update \
-    && apt-get install -y --no-install-recommends $(cat /deps.txt) \
-    && rm -rf /var/lib/apt/lists/* /deps.txt
+RUN --mount=type=bind,from=build,source=/deps,target=/deps \
+    apt-get install -Uy --no-install-recommends $(cat /deps/nfd /deps/nfdc) \
+    && rm -rf /var/lib/apt/lists/*
 
-COPY --from=builder /usr/lib/libndn-cxx.so* /usr/lib/
-COPY --from=builder /usr/bin/nfd /usr/bin/
-COPY --from=builder /usr/bin/nfdc /usr/bin/
-
-COPY --from=builder /usr/bin/nfd-status-http-server /usr/bin/
-COPY --from=builder /usr/share/ndn/ /usr/share/ndn/
-
-COPY --from=builder /etc/ndn/nfd.conf.sample /config/nfd.conf
+COPY --link --from=build /usr/bin/nfd /usr/bin/
+COPY --link --from=build /usr/bin/nfdc /usr/bin/
+COPY --link --from=build /etc/ndn/nfd.conf.sample /config/nfd.conf
 
 ENV HOME=/config
 
 VOLUME /config
 VOLUME /run/nfd
 
-EXPOSE 6363/tcp
-EXPOSE 6363/udp
-EXPOSE 9696/tcp
+EXPOSE 6363/tcp 6363/udp 9696/tcp
 
 ENTRYPOINT ["/usr/bin/nfd"]
 CMD ["--config", "/config/nfd.conf"]
diff --git a/README.md b/README.md
index 28707da..1943065 100644
--- a/README.md
+++ b/README.md
@@ -6,10 +6,11 @@
 
 </div>
 
-[![CI](https://github.com/named-data/NFD/actions/workflows/ci.yml/badge.svg)](https://github.com/named-data/NFD/actions/workflows/ci.yml)
-[![Docs](https://github.com/named-data/NFD/actions/workflows/docs.yml/badge.svg)](https://github.com/named-data/NFD/actions/workflows/docs.yml)
-![Language](https://img.shields.io/badge/C%2B%2B-17-blue)
 ![Latest version](https://img.shields.io/github/v/tag/named-data/NFD?label=Latest%20version)
+![Language](https://img.shields.io/badge/C%2B%2B-17-blue)
+[![CI](https://github.com/named-data/NFD/actions/workflows/ci.yml/badge.svg)](https://github.com/named-data/NFD/actions/workflows/ci.yml)
+[![Docker](https://github.com/named-data/NFD/actions/workflows/docker.yml/badge.svg)](https://github.com/named-data/NFD/actions/workflows/docker.yml)
+[![Docs](https://github.com/named-data/NFD/actions/workflows/docs.yml/badge.svg)](https://github.com/named-data/NFD/actions/workflows/docs.yml)
 
 ## Overview
 
diff --git a/tools/Dockerfile.nfd-status-http-server b/tools/Dockerfile.nfd-status-http-server
index 62545ac..179f9a6 100644
--- a/tools/Dockerfile.nfd-status-http-server
+++ b/tools/Dockerfile.nfd-status-http-server
@@ -1,12 +1,22 @@
-FROM ghcr.io/named-data/nfd:latest
+# syntax=docker/dockerfile:1
 
-RUN apt-get update \
-    && apt-get install -y --no-install-recommends python3 \
+ARG NDN_CXX_VERSION=latest
+ARG NFD_VERSION=latest
+FROM ghcr.io/named-data/nfd-build:${NFD_VERSION} AS build
+
+FROM ghcr.io/named-data/ndn-cxx-runtime:${NDN_CXX_VERSION}
+
+RUN --mount=type=bind,from=build,source=/deps,target=/deps \
+    apt-get install -Uy --no-install-recommends $(cat /deps/nfdc) \
+        python3 \
     && rm -rf /var/lib/apt/lists/*
 
+COPY --link --from=build /usr/bin/nfdc /usr/bin/
+COPY --link --from=build /usr/bin/nfd-status-http-server /usr/bin/
+COPY --link --from=build /usr/share/ndn/ /usr/share/ndn/
+
 VOLUME /run/nfd
 
 EXPOSE 8080/tcp
 
-ENTRYPOINT ["/usr/bin/nfd-status-http-server"]
-CMD ["--address", "0.0.0.0", "--port", "8080"]
+ENTRYPOINT ["/usr/bin/nfd-status-http-server", "--address", "0.0.0.0"]