From 6c3da9c228a717ef0590f3954a87d1005890e1a6 Mon Sep 17 00:00:00 2001 From: Rolv Apneseth Date: Fri, 10 Jul 2026 20:52:47 +0100 Subject: [PATCH] test/system: Use a random port for the local temporary Docker registry Hard coding the port to 50000 can cause intermittent failures when the port happens to already be in use, and prevents running the test suite more than once at the same time. Let Podman pick a random available port and persist it to a file so test processes in the same run can find it. https://github.com/containers/toolbox/pull/1822 Signed-off-by: Rolv Apneseth --- test/system/libs/helpers.bash | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/system/libs/helpers.bash b/test/system/libs/helpers.bash index 84aab2ad5..3f289f4ea 100644 --- a/test/system/libs/helpers.bash +++ b/test/system/libs/helpers.bash @@ -31,8 +31,12 @@ readonly ROOTLESS_PODMAN_RUNROOT_DIR="$BATS_SUITE_TMPDIR/runroot" readonly DOCKER_REG_ROOT="$BATS_SUITE_TMPDIR/docker-registry-root" readonly DOCKER_REG_CERTS_DIR="$BATS_SUITE_TMPDIR/certs" readonly DOCKER_REG_AUTH_DIR="$BATS_SUITE_TMPDIR/auth" -readonly DOCKER_REG_URI="localhost:50000" readonly DOCKER_REG_NAME="docker-registry" +# Store the registry URI in a file so that loading this script from different +# test processes will still use the same URI for the same test suite run. The +# contents of the file are set when setting up the local Docker registry. +readonly DOCKER_REG_URI_FILE="$BATS_SUITE_TMPDIR/docker-reg-uri" +DOCKER_REG_URI="$(cat "$DOCKER_REG_URI_FILE" 2>/dev/null || true)" # Podman and Toolbx commands to run readonly TOOLBX="${TOOLBX:-$(command -v toolbox)}" @@ -163,10 +167,6 @@ function _setup_docker_registry() { -subj '/' \ -out "${DOCKER_REG_CERTS_DIR}"/domain.crt - # Add certificate to Podman's trusted certificates (rootless) - mkdir --parents "$HOME"/.config/containers/certs.d/"${DOCKER_REG_URI}" - cp "${DOCKER_REG_CERTS_DIR}"/domain.crt "$HOME"/.config/containers/certs.d/"${DOCKER_REG_URI}"/domain.crt - # Create a registry user # username: user; password: user mkdir --parents "${DOCKER_REG_AUTH_DIR}" @@ -188,12 +188,22 @@ function _setup_docker_registry() { --env REGISTRY_HTTP_TLS_KEY=/certs/domain.key \ --name "${DOCKER_REG_NAME}" \ --privileged \ - --publish 50000:5000 \ + --publish 5000 \ --rm \ --volume "${DOCKER_REG_AUTH_DIR}":/auth \ --volume "${DOCKER_REG_CERTS_DIR}":/certs \ "${IMAGES[docker-reg]}" + # Determine the randomly assigned host port and persist the DOCKER_REG_URI to a file + local docker_reg_port + docker_reg_port="$(podman --root "${DOCKER_REG_ROOT}" port "${DOCKER_REG_NAME}" 5000)" + DOCKER_REG_URI="localhost:${docker_reg_port##*:}" + echo "$DOCKER_REG_URI" > "$DOCKER_REG_URI_FILE" + + # Add certificate to Podman's trusted certificates (rootless) + mkdir --parents "$HOME"/.config/containers/certs.d/"${DOCKER_REG_URI}" + cp "${DOCKER_REG_CERTS_DIR}"/domain.crt "$HOME"/.config/containers/certs.d/"${DOCKER_REG_URI}"/domain.crt + _wait_for_docker_registry podman login --authfile "${BATS_SUITE_TMPDIR}/authfile.json" --username user --password user "${DOCKER_REG_URI}"