From 1cf3cfa323c1ad87d9877dcba7448218cc0069e7 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Wed, 11 Dec 2024 08:42:28 +0100 Subject: [PATCH 1/2] Switch to Fedora for nettest and use packaged netperf netperf currently fails to build with the latest Alpine images, even with _GNU_SOURCE fixes. To allow building the nettest image again, this switches to Fedora, where netperf is available as a package (so we don't need to deal with building it). The image size is more than doubled, from 24.2MiB with Alpine to 59.8MiB with Fedora. This ends up with nmap ncat rather than busybox ncat, so the nettest scripts are adjusted to suit, and a busybox nc emulation script is included for other users of nc. Signed-off-by: Stephen Kitt (cherry picked from commit a00788004b811a4c0d88075a5dc71200e36ea38b) --- package/Dockerfile.nettest | 34 +++++++----------- scripts/nettest/metricsproxy | 4 +++ scripts/nettest/nc | 50 ++++++++++++++++++++++++++ scripts/nettest/simpleserver | 2 +- scripts/shared/dnf_install | 68 ++++++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 22 deletions(-) create mode 100755 scripts/nettest/metricsproxy create mode 100755 scripts/nettest/nc create mode 100755 scripts/shared/dnf_install diff --git a/package/Dockerfile.nettest b/package/Dockerfile.nettest index 0d884e582..09cac2dee 100644 --- a/package/Dockerfile.nettest +++ b/package/Dockerfile.nettest @@ -1,30 +1,22 @@ -FROM alpine +ARG FEDORA_VERSION=41 -WORKDIR /app +FROM --platform=${BUILDPLATFORM} fedora:${FEDORA_VERSION} AS base +ARG FEDORA_VERSION +ARG TARGETPLATFORM -RUN apk add --update --no-cache gcc libc-dev make git automake autoconf +COPY scripts/shared/dnf_install / -RUN git clone --depth 1 https://github.com/HewlettPackard/netperf \ - && git -C netperf reset --hard 3bc455b23f901dae377ca0a558e1e32aa56b31c4 -RUN cd netperf \ - && ./autogen.sh \ - && ./configure CFLAGS=-fcommon \ - && make -C src && make -C src install +RUN /dnf_install -a ${TARGETPLATFORM} -v ${FEDORA_VERSION} -r /output/nettest \ + glibc bash glibc-minimal-langpack coreutils-single libcurl-minimal \ + bind-utils curl-minimal iperf3 iputils netperf nmap-ncat tcpdump +FROM scratch +ARG TARGETPLATFORM -FROM alpine +COPY --from=base /output/nettest / -WORKDIR /app - -RUN apk add --no-cache \ - bash \ - bind-tools \ - curl \ - iputils \ - iperf3 \ - tcpdump - -COPY --from=0 /usr/local/bin/net* /usr/local/bin/ COPY scripts/nettest/* /app/ +RUN echo ${VERSION} >> /app/version + CMD ["/bin/bash","-l"] diff --git a/scripts/nettest/metricsproxy b/scripts/nettest/metricsproxy new file mode 100755 index 000000000..215c01b05 --- /dev/null +++ b/scripts/nettest/metricsproxy @@ -0,0 +1,4 @@ +#!/bin/sh + +# Arguments: source-port target-IP target-port +exec /usr/bin/ncat -v -lk -p "$1" -c "/usr/bin/ncat $2 $3" diff --git a/scripts/nettest/nc b/scripts/nettest/nc new file mode 100755 index 000000000..149a4e41d --- /dev/null +++ b/scripts/nettest/nc @@ -0,0 +1,50 @@ +#!/bin/bash + +# This wrapper converts Busybox syntax to nmap ncat: +# * -e becomes -c +# * -w and -i need a s suffix on their argument +# * with -l, -p XX and -s YY become YY XX + +args=() +listening= +sourceport= +sourceaddress= +while [ -n "$1" ] && [ "$1" != "-e" ]; do + case "$1" in + -w|-i) + args+=("$1" "$2"s) + shift 2;; + -l|-lk) + listening=1 + args+=("$1") + shift;; + -p) + sourceport="$2" + shift 2;; + -s) + sourceaddress="$2" + shift 2;; + *) + args+=("$1") + shift;; + esac +done + +if [ -n "$listening" ]; then + args+=(-l ${sourceaddress:+"$sourceaddress"} ${sourceport:+"$sourceport"}) +else + if [ -n "$sourceaddress" ]; then + args+=(-s "$sourceaddress") + fi + if [ -n "$sourceport" ]; then + args+=(-p "$sourceport") + fi +fi + +cmd="" +if [ "$1" = "-e" ]; then + shift + cmd="$*" +fi + +exec /usr/bin/ncat "${args[@]}" ${cmd:+"-c $cmd"} diff --git a/scripts/nettest/simpleserver b/scripts/nettest/simpleserver index c7aaf43e8..92e094f44 100755 --- a/scripts/nettest/simpleserver +++ b/scripts/nettest/simpleserver @@ -3,5 +3,5 @@ set -e while true do - echo -e "HTTP/1.1 200 OK\r\n\r\nHello World" | nc -l -p 8080 + echo -e "HTTP/1.1 200 OK\r\n\r\nHello World" | /usr/bin/ncat -l 8080 done diff --git a/scripts/shared/dnf_install b/scripts/shared/dnf_install new file mode 100755 index 000000000..9a786b2cf --- /dev/null +++ b/scripts/shared/dnf_install @@ -0,0 +1,68 @@ +#!/bin/bash + +# Installs packages using dnf to a named root: +# -a arch - use arch instead of the native arch +# -k - keep the package cache +# -r root - install to the named root instead of /output/base +# -v ver - use the given Fedora version (required) +# +# %arch in the package references will be replaced with the chosen arch + +set -e + +INSTALL_ROOT=/output/base + +# Limit the number of files so that dnf doesn't spend ages processing fds +if [[ $(ulimit -n) -gt 1048576 ]]; then + ulimit -n 1048576 +fi + +while getopts a:kr:v: o +do + case "$o" in + a) + ARCH="$OPTARG" + ;; + k) + KEEP_CACHE=true + ;; + r) + INSTALL_ROOT="$OPTARG" + ;; + v) + FEDORA_VERSION="$OPTARG" + ;; + *) + echo "$0 doesn't support $o" >&2 + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +arch_args=() + +if [[ -n "${ARCH}" ]]; then + # Convert container arch to Fedora arch + ARCH="${ARCH##*/}" + case "${ARCH}" in + amd64) ARCH=x86_64;; + arm64) ARCH=aarch64;; + esac + arch_args=(--forcearch "${ARCH}") +else + # This will be used later, but we won't force + ARCH="$(rpm -q --qf "%{arch}" rpm)" +fi + +[[ -z "${FEDORA_VERSION}" ]] && echo I need to know which version of Fedora to install, specify it with -v >&2 && exit 1 + +if [[ "${INSTALL_ROOT}" != /output/base ]] && [[ ! -d "${INSTALL_ROOT}" ]] && [[ -d /output/base ]]; then + cp -a /output/base "${INSTALL_ROOT}" +fi + +dnf -y --setopt=install_weak_deps=0 --nodocs --use-host-config "${arch_args[@]}" \ + --installroot "${INSTALL_ROOT}" --releasever "${FEDORA_VERSION}" \ + install "${@//\%arch/${ARCH}}" + +[[ "${KEEP_CACHE}" == true ]] || dnf -y "${arch_args[@]}" --installroot "${INSTALL_ROOT}" --releasever "${FEDORA_VERSION}" clean all From 08f94a84faa2b36e26db47e27d756b830c813d46 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Mon, 16 Dec 2024 17:03:31 +0100 Subject: [PATCH 2/2] Add /app to the PATH This ensures that the Busybox compatible nc script is used instead of ncat. Signed-off-by: Stephen Kitt (cherry picked from commit 0e27d4db5de34395224dc2d0c1b8193e9b21e36a) --- package/Dockerfile.nettest | 1 + 1 file changed, 1 insertion(+) diff --git a/package/Dockerfile.nettest b/package/Dockerfile.nettest index 09cac2dee..eede463be 100644 --- a/package/Dockerfile.nettest +++ b/package/Dockerfile.nettest @@ -12,6 +12,7 @@ RUN /dnf_install -a ${TARGETPLATFORM} -v ${FEDORA_VERSION} -r /output/nettest \ FROM scratch ARG TARGETPLATFORM +ENV PATH="/app:$PATH" COPY --from=base /output/nettest /