From 8d998c1bb55de25f942bc72ddf91a02df0317553 Mon Sep 17 00:00:00 2001 From: Marketen Date: Thu, 19 Nov 2026 17:50:55 +0100 Subject: [PATCH 1/5] Let the ISO end-to-end tests run on a self-hosted runner The Debian and Ubuntu unattended ISO tests run on the runner named by the ISO_E2E_RUNNER repository variable, or on ubuntu-latest while it is unset. Pull requests from forks always stay on ubuntu-latest. A self-hosted host is reused between runs, so each job now: - uses its own TAP interface, subnet and MAC, so both can run on one host; - clears a leftover guest network before creating its own, and removes it and the build output afterwards; - takes back root-owned files a cancelled run left in the workspace. Removing the network also stops a dnsmasq whose pid file was lost. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/debian-iso-e2e.yml | 39 +++++++++++++++++++++++++--- .github/workflows/ubuntu-iso-e2e.yml | 39 +++++++++++++++++++++++++--- test/e2e_network.sh | 2 ++ 3 files changed, 72 insertions(+), 8 deletions(-) diff --git a/.github/workflows/debian-iso-e2e.yml b/.github/workflows/debian-iso-e2e.yml index 70ad716..5c60fbd 100644 --- a/.github/workflows/debian-iso-e2e.yml +++ b/.github/workflows/debian-iso-e2e.yml @@ -1,5 +1,10 @@ # Builds the unattended Debian ISO and installs it from UEFI USB media in QEMU. # It completes the required reboots and verifies the installed DAppNode system. +# +# Runs on the self-hosted runner named by the ISO_E2E_RUNNER repository variable, +# or on ubuntu-latest when it is unset. Pull requests from forks always use +# ubuntu-latest, so outside code never runs on our machines. +# A self-hosted runner needs /dev/kvm, Docker, apt and passwordless sudo. name: Debian unattended USB ISO end-to-end on: @@ -20,10 +25,22 @@ concurrency: jobs: install: name: Install Debian unattended ISO via UEFI USB - runs-on: ubuntu-latest + runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || vars.ISO_E2E_RUNNER || 'ubuntu-latest' }} timeout-minutes: 90 + env: + # Distinct from the Ubuntu job, so both can run on the same host at once. + E2E_TAP_IFACE: dne2e0 + E2E_HOST_IP: 192.168.77.1 + E2E_GUEST_IP: 192.168.77.10 + E2E_GUEST_MAC: "52:54:00:d4:00:10" steps: + # A cancelled run on a self-hosted runner can leave root-owned build output + # that would stop checkout from cleaning the workspace. + - name: Reclaim the workspace + if: runner.environment == 'self-hosted' + run: sudo chown -R "$(id -u):$(id -g)" "${GITHUB_WORKSPACE}" + - name: Checkout uses: actions/checkout@v6 @@ -44,20 +61,26 @@ jobs: run: | sudo apt-get update sudo apt-get install -y --no-install-recommends qemu-system-x86 qemu-utils ovmf socat sshpass dnsmasq-base - if [ -e /dev/kvm ]; then + if [ -e /dev/kvm ] && ! { [ -r /dev/kvm ] && [ -w /dev/kvm ]; }; then sudo chmod a+rw /dev/kvm fi + [ -e /dev/kvm ] || echo "::warning::/dev/kvm is missing; the install falls back to slow TCG emulation" - name: Create the guest network run: | mkdir -p test-output/debian-e2e - sudo E2E_NETWORK_STATE_DIR="${PWD}/test-output/debian-e2e/network" bash test/e2e_network.sh up + state_dir="${PWD}/test-output/debian-e2e/network" + # Clear anything a cancelled run left behind on a reused host. + sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ + E2E_NETWORK_STATE_DIR="${state_dir}" bash test/e2e_network.sh down + sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ + E2E_GUEST_IP="${E2E_GUEST_IP}" E2E_GUEST_MAC="${E2E_GUEST_MAC}" \ + E2E_NETWORK_STATE_DIR="${state_dir}" bash test/e2e_network.sh up - name: Complete Debian unattended UEFI USB installation env: E2E_BOOT_MODE: usb E2E_FIRMWARE: uefi - E2E_TAP_IFACE: dne2e0 run: | debian_iso=$(find images -maxdepth 1 -type f -name 'Dappnode-debian-*-amd64-netinst.iso' -print -quit) test -n "${debian_iso}" @@ -75,3 +98,11 @@ jobs: path: test-output/debian-e2e/ if-no-files-found: ignore retention-days: 7 + + # Ephemeral GitHub-hosted runners are discarded; a self-hosted host is not. + - name: Remove the guest network and build output + if: always() && runner.environment == 'self-hosted' + run: | + sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ + E2E_NETWORK_STATE_DIR="${PWD}/test-output/debian-e2e/network" bash test/e2e_network.sh down + sudo rm -rf images test-output diff --git a/.github/workflows/ubuntu-iso-e2e.yml b/.github/workflows/ubuntu-iso-e2e.yml index 5b034da..07ae663 100644 --- a/.github/workflows/ubuntu-iso-e2e.yml +++ b/.github/workflows/ubuntu-iso-e2e.yml @@ -1,5 +1,10 @@ # Builds the unattended Ubuntu ISO and installs it from UEFI USB media in QEMU. # It completes the required reboots and verifies the installed DAppNode system. +# +# Runs on the self-hosted runner named by the ISO_E2E_RUNNER repository variable, +# or on ubuntu-latest when it is unset. Pull requests from forks always use +# ubuntu-latest, so outside code never runs on our machines. +# A self-hosted runner needs /dev/kvm, Docker, apt and passwordless sudo. name: Ubuntu unattended USB ISO end-to-end on: @@ -20,10 +25,22 @@ concurrency: jobs: install: name: Install Ubuntu unattended ISO via UEFI USB - runs-on: ubuntu-latest + runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || vars.ISO_E2E_RUNNER || 'ubuntu-latest' }} timeout-minutes: 90 + env: + # Distinct from the Debian job, so both can run on the same host at once. + E2E_TAP_IFACE: dne2e1 + E2E_HOST_IP: 192.168.78.1 + E2E_GUEST_IP: 192.168.78.10 + E2E_GUEST_MAC: "52:54:00:d4:00:11" steps: + # A cancelled run on a self-hosted runner can leave root-owned build output + # that would stop checkout from cleaning the workspace. + - name: Reclaim the workspace + if: runner.environment == 'self-hosted' + run: sudo chown -R "$(id -u):$(id -g)" "${GITHUB_WORKSPACE}" + - name: Checkout uses: actions/checkout@v6 @@ -44,20 +61,26 @@ jobs: run: | sudo apt-get update sudo apt-get install -y --no-install-recommends qemu-system-x86 qemu-utils ovmf socat sshpass dnsmasq-base - if [ -e /dev/kvm ]; then + if [ -e /dev/kvm ] && ! { [ -r /dev/kvm ] && [ -w /dev/kvm ]; }; then sudo chmod a+rw /dev/kvm fi + [ -e /dev/kvm ] || echo "::warning::/dev/kvm is missing; the install falls back to slow TCG emulation" - name: Create the guest network run: | mkdir -p test-output/ubuntu-e2e - sudo E2E_NETWORK_STATE_DIR="${PWD}/test-output/ubuntu-e2e/network" bash test/e2e_network.sh up + state_dir="${PWD}/test-output/ubuntu-e2e/network" + # Clear anything a cancelled run left behind on a reused host. + sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ + E2E_NETWORK_STATE_DIR="${state_dir}" bash test/e2e_network.sh down + sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ + E2E_GUEST_IP="${E2E_GUEST_IP}" E2E_GUEST_MAC="${E2E_GUEST_MAC}" \ + E2E_NETWORK_STATE_DIR="${state_dir}" bash test/e2e_network.sh up - name: Complete Ubuntu unattended UEFI USB installation env: E2E_BOOT_MODE: usb E2E_FIRMWARE: uefi - E2E_TAP_IFACE: dne2e0 run: | ubuntu_iso=$(find images -maxdepth 1 -type f -name 'Dappnode-ubuntu-*-live-server-amd64.iso' -print -quit) test -n "${ubuntu_iso}" @@ -75,3 +98,11 @@ jobs: path: test-output/ubuntu-e2e/ if-no-files-found: ignore retention-days: 7 + + # Ephemeral GitHub-hosted runners are discarded; a self-hosted host is not. + - name: Remove the guest network and build output + if: always() && runner.environment == 'self-hosted' + run: | + sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ + E2E_NETWORK_STATE_DIR="${PWD}/test-output/ubuntu-e2e/network" bash test/e2e_network.sh down + sudo rm -rf images test-output diff --git a/test/e2e_network.sh b/test/e2e_network.sh index 5e3c5be..8d8ac56 100755 --- a/test/e2e_network.sh +++ b/test/e2e_network.sh @@ -65,6 +65,8 @@ network_down() { if [ -f "${STATE_DIR}/dnsmasq.pid" ]; then kill "$(cat "${STATE_DIR}/dnsmasq.pid")" 2>/dev/null || true fi + # A cancelled run may have lost its pid file; on a reused host its dnsmasq lives on. + pkill -f "^dnsmasq --interface=${E2E_TAP_IFACE} " 2>/dev/null || true iptables -D FORWARD -o "${E2E_TAP_IFACE}" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 2>/dev/null || true iptables -D FORWARD -i "${E2E_TAP_IFACE}" -j ACCEPT 2>/dev/null || true iptables -t nat -D PREROUTING -i "${E2E_TAP_IFACE}" -p icmp --icmp-type echo-request \ From 6cf97d080f15500aa7aa0d4ab6f6c74f1f976907 Mon Sep 17 00:00:00 2001 From: Marketen Date: Thu, 19 Nov 2026 18:00:02 +0100 Subject: [PATCH 2/5] Run the ISO end-to-end tests on the ipfs-dev-gateway runners Co-Authored-By: Claude Opus 5.5 --- .github/workflows/debian-iso-e2e.yml | 9 ++++----- .github/workflows/ubuntu-iso-e2e.yml | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/debian-iso-e2e.yml b/.github/workflows/debian-iso-e2e.yml index 5c60fbd..1f83f08 100644 --- a/.github/workflows/debian-iso-e2e.yml +++ b/.github/workflows/debian-iso-e2e.yml @@ -1,10 +1,9 @@ # Builds the unattended Debian ISO and installs it from UEFI USB media in QEMU. # It completes the required reboots and verifies the installed DAppNode system. # -# Runs on the self-hosted runner named by the ISO_E2E_RUNNER repository variable, -# or on ubuntu-latest when it is unset. Pull requests from forks always use -# ubuntu-latest, so outside code never runs on our machines. -# A self-hosted runner needs /dev/kvm, Docker, apt and passwordless sudo. +# Runs on our ipfs-dev-gateway org runners. Pull requests from forks use +# ubuntu-latest instead, so outside code never runs on our machines. +# The runner needs /dev/kvm, Docker, apt and passwordless sudo. name: Debian unattended USB ISO end-to-end on: @@ -25,7 +24,7 @@ concurrency: jobs: install: name: Install Debian unattended ISO via UEFI USB - runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || vars.ISO_E2E_RUNNER || 'ubuntu-latest' }} + runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || 'ipfs-dev-gateway' }} timeout-minutes: 90 env: # Distinct from the Ubuntu job, so both can run on the same host at once. diff --git a/.github/workflows/ubuntu-iso-e2e.yml b/.github/workflows/ubuntu-iso-e2e.yml index 07ae663..220ee4f 100644 --- a/.github/workflows/ubuntu-iso-e2e.yml +++ b/.github/workflows/ubuntu-iso-e2e.yml @@ -1,10 +1,9 @@ # Builds the unattended Ubuntu ISO and installs it from UEFI USB media in QEMU. # It completes the required reboots and verifies the installed DAppNode system. # -# Runs on the self-hosted runner named by the ISO_E2E_RUNNER repository variable, -# or on ubuntu-latest when it is unset. Pull requests from forks always use -# ubuntu-latest, so outside code never runs on our machines. -# A self-hosted runner needs /dev/kvm, Docker, apt and passwordless sudo. +# Runs on our ipfs-dev-gateway org runners. Pull requests from forks use +# ubuntu-latest instead, so outside code never runs on our machines. +# The runner needs /dev/kvm, Docker, apt and passwordless sudo. name: Ubuntu unattended USB ISO end-to-end on: @@ -25,7 +24,7 @@ concurrency: jobs: install: name: Install Ubuntu unattended ISO via UEFI USB - runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || vars.ISO_E2E_RUNNER || 'ubuntu-latest' }} + runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || 'ipfs-dev-gateway' }} timeout-minutes: 90 env: # Distinct from the Debian job, so both can run on the same host at once. From 7f7ed0fba1de282de0f4d218585f83fa8fc086a3 Mon Sep 17 00:00:00 2001 From: Marketen Date: Thu, 19 Nov 2026 18:00:45 +0100 Subject: [PATCH 3/5] Clean up the ISO tests' Docker leftovers on self-hosted runners Each ISO job gets its own Compose project, so the Debian and Ubuntu jobs cannot share or remove each other's installer container on one Docker host, and removes its installer container, network and image when it finishes. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/debian-iso-e2e.yml | 6 ++++++ .github/workflows/ubuntu-iso-e2e.yml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/debian-iso-e2e.yml b/.github/workflows/debian-iso-e2e.yml index 1f83f08..4c50424 100644 --- a/.github/workflows/debian-iso-e2e.yml +++ b/.github/workflows/debian-iso-e2e.yml @@ -27,6 +27,9 @@ jobs: runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || 'ipfs-dev-gateway' }} timeout-minutes: 90 env: + # Own Compose project, so a parallel ISO job on the same Docker host cannot + # reuse or remove this job's installer container. + COMPOSE_PROJECT_NAME: dappnode-iso-e2e-debian # Distinct from the Ubuntu job, so both can run on the same host at once. E2E_TAP_IFACE: dne2e0 E2E_HOST_IP: 192.168.77.1 @@ -102,6 +105,9 @@ jobs: - name: Remove the guest network and build output if: always() && runner.environment == 'self-hosted' run: | + # Only this project's installer container, network and image; the image is + # rebuilt from the checkout, so each commit would otherwise leave one behind. + docker compose down --rmi local --remove-orphans || true sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ E2E_NETWORK_STATE_DIR="${PWD}/test-output/debian-e2e/network" bash test/e2e_network.sh down sudo rm -rf images test-output diff --git a/.github/workflows/ubuntu-iso-e2e.yml b/.github/workflows/ubuntu-iso-e2e.yml index 220ee4f..6541405 100644 --- a/.github/workflows/ubuntu-iso-e2e.yml +++ b/.github/workflows/ubuntu-iso-e2e.yml @@ -27,6 +27,9 @@ jobs: runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || 'ipfs-dev-gateway' }} timeout-minutes: 90 env: + # Own Compose project, so a parallel ISO job on the same Docker host cannot + # reuse or remove this job's installer container. + COMPOSE_PROJECT_NAME: dappnode-iso-e2e-ubuntu # Distinct from the Debian job, so both can run on the same host at once. E2E_TAP_IFACE: dne2e1 E2E_HOST_IP: 192.168.78.1 @@ -102,6 +105,9 @@ jobs: - name: Remove the guest network and build output if: always() && runner.environment == 'self-hosted' run: | + # Only this project's installer container, network and image; the image is + # rebuilt from the checkout, so each commit would otherwise leave one behind. + docker compose down --rmi local --remove-orphans || true sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ E2E_NETWORK_STATE_DIR="${PWD}/test-output/ubuntu-e2e/network" bash test/e2e_network.sh down sudo rm -rf images test-output From 527ec00b1fb0e71c04aee8594321f672fbef064d Mon Sep 17 00:00:00 2001 From: Marketen Date: Thu, 19 Nov 2026 18:39:40 +0100 Subject: [PATCH 4/5] Run the ISO end-to-end tests on the archive-1 runners Co-Authored-By: Claude Opus 5.5 --- .github/workflows/debian-iso-e2e.yml | 4 ++-- .github/workflows/ubuntu-iso-e2e.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/debian-iso-e2e.yml b/.github/workflows/debian-iso-e2e.yml index 4c50424..43358c0 100644 --- a/.github/workflows/debian-iso-e2e.yml +++ b/.github/workflows/debian-iso-e2e.yml @@ -1,7 +1,7 @@ # Builds the unattended Debian ISO and installs it from UEFI USB media in QEMU. # It completes the required reboots and verifies the installed DAppNode system. # -# Runs on our ipfs-dev-gateway org runners. Pull requests from forks use +# Runs on our archive-1 org runners. Pull requests from forks use # ubuntu-latest instead, so outside code never runs on our machines. # The runner needs /dev/kvm, Docker, apt and passwordless sudo. name: Debian unattended USB ISO end-to-end @@ -24,7 +24,7 @@ concurrency: jobs: install: name: Install Debian unattended ISO via UEFI USB - runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || 'ipfs-dev-gateway' }} + runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || 'archive-1' }} timeout-minutes: 90 env: # Own Compose project, so a parallel ISO job on the same Docker host cannot diff --git a/.github/workflows/ubuntu-iso-e2e.yml b/.github/workflows/ubuntu-iso-e2e.yml index 6541405..c121efb 100644 --- a/.github/workflows/ubuntu-iso-e2e.yml +++ b/.github/workflows/ubuntu-iso-e2e.yml @@ -1,7 +1,7 @@ # Builds the unattended Ubuntu ISO and installs it from UEFI USB media in QEMU. # It completes the required reboots and verifies the installed DAppNode system. # -# Runs on our ipfs-dev-gateway org runners. Pull requests from forks use +# Runs on our archive-1 org runners. Pull requests from forks use # ubuntu-latest instead, so outside code never runs on our machines. # The runner needs /dev/kvm, Docker, apt and passwordless sudo. name: Ubuntu unattended USB ISO end-to-end @@ -24,7 +24,7 @@ concurrency: jobs: install: name: Install Ubuntu unattended ISO via UEFI USB - runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || 'ipfs-dev-gateway' }} + runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || 'archive-1' }} timeout-minutes: 90 env: # Own Compose project, so a parallel ISO job on the same Docker host cannot From a99c9212889ed21c934540c25db399e835c92ef9 Mon Sep 17 00:00:00 2001 From: 3alpha <15694175+3alpha@users.noreply.github.com> Date: Thu, 19 Nov 2026 19:33:27 +0100 Subject: [PATCH 5/5] Run the ISO end-to-end tests in a container of their own The guest network, QEMU and the test now run inside one Docker container per job, through test/e2e_in_docker.sh. The container is its own network namespace, so the TAP interface, NAT rules and dnsmasq keep fixed names and addresses, never clash with a parallel job on the same host, and go away with the container. The runner needs only Docker and /dev/kvm: no sudo, no apt, and no per-workflow interfaces, subnets or MACs. --- .github/workflows/debian-iso-e2e.yml | 57 +++++------------- .github/workflows/ubuntu-iso-e2e.yml | 57 +++++------------- test/e2e.Dockerfile | 8 +++ test/e2e_in_docker.sh | 90 ++++++++++++++++++++++++++++ test/e2e_network.sh | 5 +- 5 files changed, 130 insertions(+), 87 deletions(-) create mode 100644 test/e2e.Dockerfile create mode 100755 test/e2e_in_docker.sh diff --git a/.github/workflows/debian-iso-e2e.yml b/.github/workflows/debian-iso-e2e.yml index 43358c0..c78388e 100644 --- a/.github/workflows/debian-iso-e2e.yml +++ b/.github/workflows/debian-iso-e2e.yml @@ -3,7 +3,8 @@ # # Runs on our archive-1 org runners. Pull requests from forks use # ubuntu-latest instead, so outside code never runs on our machines. -# The runner needs /dev/kvm, Docker, apt and passwordless sudo. +# The runner needs only Docker and /dev/kvm: the test runs in a container of its +# own (test/e2e_in_docker.sh), so it needs no sudo and leaves nothing on the host. name: Debian unattended USB ISO end-to-end on: @@ -27,21 +28,15 @@ jobs: runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || 'archive-1' }} timeout-minutes: 90 env: - # Own Compose project, so a parallel ISO job on the same Docker host cannot - # reuse or remove this job's installer container. - COMPOSE_PROJECT_NAME: dappnode-iso-e2e-debian - # Distinct from the Ubuntu job, so both can run on the same host at once. - E2E_TAP_IFACE: dne2e0 - E2E_HOST_IP: 192.168.77.1 - E2E_GUEST_IP: 192.168.77.10 - E2E_GUEST_MAC: "52:54:00:d4:00:10" + # A Compose project per run, so parallel ISO builds on one Docker host never + # share or remove each other's installer container. + COMPOSE_PROJECT_NAME: dappnode-iso-${{ github.run_id }}-${{ github.run_attempt }} steps: # A cancelled run on a self-hosted runner can leave root-owned build output # that would stop checkout from cleaning the workspace. - name: Reclaim the workspace - if: runner.environment == 'self-hosted' - run: sudo chown -R "$(id -u):$(id -g)" "${GITHUB_WORKSPACE}" + run: docker run --rm -v "${GITHUB_WORKSPACE}:/workspace" ubuntu:24.04 chown -R "$(id -u):$(id -g)" /workspace - name: Checkout uses: actions/checkout@v6 @@ -59,38 +54,15 @@ jobs: done ls -lrt images/Dappnode-debian-*.iso - - name: Install QEMU test dependencies - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends qemu-system-x86 qemu-utils ovmf socat sshpass dnsmasq-base - if [ -e /dev/kvm ] && ! { [ -r /dev/kvm ] && [ -w /dev/kvm ]; }; then - sudo chmod a+rw /dev/kvm - fi - [ -e /dev/kvm ] || echo "::warning::/dev/kvm is missing; the install falls back to slow TCG emulation" - - - name: Create the guest network - run: | - mkdir -p test-output/debian-e2e - state_dir="${PWD}/test-output/debian-e2e/network" - # Clear anything a cancelled run left behind on a reused host. - sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ - E2E_NETWORK_STATE_DIR="${state_dir}" bash test/e2e_network.sh down - sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ - E2E_GUEST_IP="${E2E_GUEST_IP}" E2E_GUEST_MAC="${E2E_GUEST_MAC}" \ - E2E_NETWORK_STATE_DIR="${state_dir}" bash test/e2e_network.sh up - - name: Complete Debian unattended UEFI USB installation env: E2E_BOOT_MODE: usb E2E_FIRMWARE: uefi + E2E_NETWORK_STATE_DIR: ${{ github.workspace }}/test-output/debian-e2e/network run: | debian_iso=$(find images -maxdepth 1 -type f -name 'Dappnode-debian-*-amd64-netinst.iso' -print -quit) test -n "${debian_iso}" - bash test/e2e_debian_iso.sh "${debian_iso}" - - - name: Make network logs readable - if: always() - run: sudo chmod -R a+rX test-output || true + bash test/e2e_in_docker.sh test/e2e_debian_iso.sh "${debian_iso}" - name: Upload installation logs if: always() @@ -101,13 +73,12 @@ jobs: if-no-files-found: ignore retention-days: 7 - # Ephemeral GitHub-hosted runners are discarded; a self-hosted host is not. - - name: Remove the guest network and build output - if: always() && runner.environment == 'self-hosted' + # A self-hosted runner keeps its workspace and Docker state between jobs. + - name: Remove the build output + if: always() run: | - # Only this project's installer container, network and image; the image is + # Only this run's installer container, network and image; the image is # rebuilt from the checkout, so each commit would otherwise leave one behind. docker compose down --rmi local --remove-orphans || true - sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ - E2E_NETWORK_STATE_DIR="${PWD}/test-output/debian-e2e/network" bash test/e2e_network.sh down - sudo rm -rf images test-output + # The ISO build writes as root, so remove its output as root too. + docker run --rm -v "${GITHUB_WORKSPACE}:/workspace" ubuntu:24.04 rm -rf /workspace/images /workspace/test-output diff --git a/.github/workflows/ubuntu-iso-e2e.yml b/.github/workflows/ubuntu-iso-e2e.yml index c121efb..5c70583 100644 --- a/.github/workflows/ubuntu-iso-e2e.yml +++ b/.github/workflows/ubuntu-iso-e2e.yml @@ -3,7 +3,8 @@ # # Runs on our archive-1 org runners. Pull requests from forks use # ubuntu-latest instead, so outside code never runs on our machines. -# The runner needs /dev/kvm, Docker, apt and passwordless sudo. +# The runner needs only Docker and /dev/kvm: the test runs in a container of its +# own (test/e2e_in_docker.sh), so it needs no sudo and leaves nothing on the host. name: Ubuntu unattended USB ISO end-to-end on: @@ -27,21 +28,15 @@ jobs: runs-on: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) && 'ubuntu-latest' || 'archive-1' }} timeout-minutes: 90 env: - # Own Compose project, so a parallel ISO job on the same Docker host cannot - # reuse or remove this job's installer container. - COMPOSE_PROJECT_NAME: dappnode-iso-e2e-ubuntu - # Distinct from the Debian job, so both can run on the same host at once. - E2E_TAP_IFACE: dne2e1 - E2E_HOST_IP: 192.168.78.1 - E2E_GUEST_IP: 192.168.78.10 - E2E_GUEST_MAC: "52:54:00:d4:00:11" + # A Compose project per run, so parallel ISO builds on one Docker host never + # share or remove each other's installer container. + COMPOSE_PROJECT_NAME: dappnode-iso-${{ github.run_id }}-${{ github.run_attempt }} steps: # A cancelled run on a self-hosted runner can leave root-owned build output # that would stop checkout from cleaning the workspace. - name: Reclaim the workspace - if: runner.environment == 'self-hosted' - run: sudo chown -R "$(id -u):$(id -g)" "${GITHUB_WORKSPACE}" + run: docker run --rm -v "${GITHUB_WORKSPACE}:/workspace" ubuntu:24.04 chown -R "$(id -u):$(id -g)" /workspace - name: Checkout uses: actions/checkout@v6 @@ -59,38 +54,15 @@ jobs: done ls -lrt images/Dappnode-ubuntu-*.iso - - name: Install QEMU test dependencies - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends qemu-system-x86 qemu-utils ovmf socat sshpass dnsmasq-base - if [ -e /dev/kvm ] && ! { [ -r /dev/kvm ] && [ -w /dev/kvm ]; }; then - sudo chmod a+rw /dev/kvm - fi - [ -e /dev/kvm ] || echo "::warning::/dev/kvm is missing; the install falls back to slow TCG emulation" - - - name: Create the guest network - run: | - mkdir -p test-output/ubuntu-e2e - state_dir="${PWD}/test-output/ubuntu-e2e/network" - # Clear anything a cancelled run left behind on a reused host. - sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ - E2E_NETWORK_STATE_DIR="${state_dir}" bash test/e2e_network.sh down - sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ - E2E_GUEST_IP="${E2E_GUEST_IP}" E2E_GUEST_MAC="${E2E_GUEST_MAC}" \ - E2E_NETWORK_STATE_DIR="${state_dir}" bash test/e2e_network.sh up - - name: Complete Ubuntu unattended UEFI USB installation env: E2E_BOOT_MODE: usb E2E_FIRMWARE: uefi + E2E_NETWORK_STATE_DIR: ${{ github.workspace }}/test-output/ubuntu-e2e/network run: | ubuntu_iso=$(find images -maxdepth 1 -type f -name 'Dappnode-ubuntu-*-live-server-amd64.iso' -print -quit) test -n "${ubuntu_iso}" - bash test/e2e_ubuntu_iso.sh "${ubuntu_iso}" - - - name: Make network logs readable - if: always() - run: sudo chmod -R a+rX test-output || true + bash test/e2e_in_docker.sh test/e2e_ubuntu_iso.sh "${ubuntu_iso}" - name: Upload installation logs if: always() @@ -101,13 +73,12 @@ jobs: if-no-files-found: ignore retention-days: 7 - # Ephemeral GitHub-hosted runners are discarded; a self-hosted host is not. - - name: Remove the guest network and build output - if: always() && runner.environment == 'self-hosted' + # A self-hosted runner keeps its workspace and Docker state between jobs. + - name: Remove the build output + if: always() run: | - # Only this project's installer container, network and image; the image is + # Only this run's installer container, network and image; the image is # rebuilt from the checkout, so each commit would otherwise leave one behind. docker compose down --rmi local --remove-orphans || true - sudo E2E_TAP_IFACE="${E2E_TAP_IFACE}" E2E_HOST_IP="${E2E_HOST_IP}" \ - E2E_NETWORK_STATE_DIR="${PWD}/test-output/ubuntu-e2e/network" bash test/e2e_network.sh down - sudo rm -rf images test-output + # The ISO build writes as root, so remove its output as root too. + docker run --rm -v "${GITHUB_WORKSPACE}:/workspace" ubuntu:24.04 rm -rf /workspace/images /workspace/test-output diff --git a/test/e2e.Dockerfile b/test/e2e.Dockerfile new file mode 100644 index 0000000..00489f7 --- /dev/null +++ b/test/e2e.Dockerfile @@ -0,0 +1,8 @@ +# Tools the ISO end-to-end tests run with; see test/e2e_in_docker.sh. +FROM ubuntu:24.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + qemu-system-x86 qemu-utils ovmf socat sshpass openssh-client \ + dnsmasq-base iptables iproute2 && \ + rm -rf /var/lib/apt/lists/* diff --git a/test/e2e_in_docker.sh b/test/e2e_in_docker.sh new file mode 100755 index 0000000..480b1fc --- /dev/null +++ b/test/e2e_in_docker.sh @@ -0,0 +1,90 @@ +#!/bin/bash +# Runs an ISO end-to-end test inside a throwaway container: +# test/e2e_in_docker.sh test/e2e_debian_iso.sh images/Dappnode-debian-...iso +# +# The container is its own network namespace, so the guest network from +# test/e2e_network.sh keeps its fixed interface name and addresses and never +# clashes with another job on the same host. Its TAP interface, NAT rules and +# dnsmasq go away with the container. The host needs only Docker, plus /dev/kvm +# for a usable speed: no sudo, and no packages besides Docker. +# +# E2E_* variables are passed through to the test. Files the test writes into the +# repository are given back to the calling user. +set -Eeuo pipefail + +SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +REPO_ROOT=$(cd "${SCRIPT_DIR}/.." && pwd) + +if [ "$#" -eq 0 ]; then + echo "Usage: $0 [args...]" + exit 2 +fi + +give_back_output() { + chown -R "${E2E_HOST_UID}:${E2E_HOST_GID}" "${REPO_ROOT}/test-output" 2>/dev/null || true +} + +run_inside() { + # Some Docker hosts only load the legacy iptables modules, and a container + # cannot load the nf_tables ones itself. + if ! iptables -t nat -S >/dev/null 2>&1; then + update-alternatives --quiet --set iptables /usr/sbin/iptables-legacy + fi + + trap give_back_output EXIT + + bash "${SCRIPT_DIR}/e2e_network.sh" up + E2E_TAP_IFACE=${E2E_TAP_IFACE:-dne2e0} bash "$@" +} + +if [ "${1}" = "--inside" ]; then + shift + run_inside "$@" + exit +fi + +image=${E2E_DOCKER_IMAGE:-dappnode-iso-e2e-runner} +container="dappnode-iso-e2e-${GITHUB_RUN_ID:-local}-${GITHUB_JOB:-job}-$$" +# Stop the test from inside, so a container survives a killed runner by this at most. +time_limit=${E2E_DOCKER_TIME_LIMIT:-85m} + +docker build --quiet --tag "${image}" - <"${SCRIPT_DIR}/e2e.Dockerfile" >/dev/null + +device_args=(--device /dev/net/tun) +if [ -c /dev/kvm ]; then + device_args+=(--device /dev/kvm) +else + echo "[WARN] /dev/kvm is missing; the install falls back to slow TCG emulation" +fi + +env_args=( + --env RUNNER_TEMP=/var/tmp/e2e + --env E2E_HOST_UID="$(id -u)" + --env E2E_HOST_GID="$(id -g)" +) +while IFS= read -r name; do + env_args+=(--env "${name}") +done < <(compgen -e | grep -E '^(E2E_|KEEP_E2E_VM$)' || true) + +remove_container() { + docker rm --force --volumes "${container}" >/dev/null 2>&1 || true +} +trap remove_container EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + +# The repository is mounted at its own path, so paths in logs and arguments match +# the host. VM disks go to an anonymous volume (RUNNER_TEMP), which --rm removes. +docker run --rm --init \ + --name "${container}" \ + --cap-add NET_ADMIN \ + --sysctl net.ipv4.ip_forward=1 \ + "${device_args[@]}" \ + --mount type=volume,destination=/var/tmp/e2e \ + "${env_args[@]}" \ + --volume "${REPO_ROOT}:${REPO_ROOT}" \ + --workdir "${PWD}" \ + "${image}" \ + timeout "${time_limit}" bash "${SCRIPT_DIR}/e2e_in_docker.sh" --inside "$@" & +# In the background, so a signal to this script runs its traps straight away. +wait "$!" diff --git a/test/e2e_network.sh b/test/e2e_network.sh index 8d8ac56..0a9fb45 100755 --- a/test/e2e_network.sh +++ b/test/e2e_network.sh @@ -1,5 +1,7 @@ #!/bin/bash # Creates the TAP network the E2E guests boot on. Run as root: up | down +# CI runs it in a container of its own (test/e2e_in_docker.sh), so the fixed +# interface name and addresses never clash with another job on the host. # The guest gets DHCP, DNS and NAT like on a home LAN. CI providers drop outbound # ICMP, so echo requests from the guest are answered by this host instead: the # DAppNode first-boot check pings google.com and must see a reply. @@ -26,7 +28,8 @@ network_up() { ip addr add "${E2E_HOST_IP}/24" dev "${E2E_TAP_IFACE}" ip link set "${E2E_TAP_IFACE}" up - sysctl -q -w net.ipv4.ip_forward=1 + # In a container /proc/sys is read-only; docker run --sysctl turns this on instead. + [ "$(cat /proc/sys/net/ipv4/ip_forward)" = 1 ] || sysctl -q -w net.ipv4.ip_forward=1 iptables -t nat -A POSTROUTING -s "${SUBNET}" ! -o "${E2E_TAP_IFACE}" -j MASQUERADE iptables -t nat -A PREROUTING -i "${E2E_TAP_IFACE}" -p icmp --icmp-type echo-request \ -j DNAT --to-destination "${E2E_HOST_IP}"