From 00b067f3db60df3f04de926f8aea97a2b1f7b884 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 2 Dec 2026 20:13:28 +0100 Subject: [PATCH 1/2] ci: build the VM driver and the VM runtimes Build openshell-driver-vm for x86_64 and aarch64 Linux and for aarch64 macOS, with the guest init the Linux binaries workflow builds, the VM runtime from the flake, and openshell-sandbox and openshell-supervisor from OpenShell: the Linux ones from the published test-inputs bundle, the macOS one from an OpenShell run, as the bundle has no macOS artifacts. Adapt the imported VM kernel workflow to this repository and build the Linux ARM64 and macOS ARM64 runtimes in it, drop the temporary exemptions for it from the header check and zizmor, and adapt the VM runtime scripts to take openshell-sandbox and openshell-supervisor from a checkout of OpenShell. Signed-off-by: Evan Lezar --- .github/workflows/build-vm-driver-linux.yml | 107 +++++++++++++++++++ .github/workflows/build-vm-driver-macos.yml | 111 ++++++++++++++++++++ .github/workflows/build-vm-init.yml | 59 +++++++++++ .github/workflows/ci.yml | 3 - .github/workflows/driver-build-test.yml | 49 ++++++++- .github/workflows/release-vm-kernel.yml | 48 ++++----- .github/zizmor.yml | 8 -- README.md | 16 +-- flake.nix | 3 +- mise.toml | 4 + nix/pkgs/vm-runtime.nix | 67 ++++++++++++ tasks/scripts/build-env.sh | 72 +++++++++++++ tasks/scripts/vm/build-supervisor-bundle.sh | 28 +++-- tasks/scripts/vm/download-kernel-runtime.sh | 6 +- tasks/scripts/vm/smoke-orphan-cleanup.sh | 11 +- 15 files changed, 527 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/build-vm-driver-linux.yml create mode 100644 .github/workflows/build-vm-driver-macos.yml create mode 100644 .github/workflows/build-vm-init.yml delete mode 100644 .github/zizmor.yml create mode 100644 nix/pkgs/vm-runtime.nix create mode 100755 tasks/scripts/build-env.sh diff --git a/.github/workflows/build-vm-driver-linux.yml b/.github/workflows/build-vm-driver-linux.yml new file mode 100644 index 0000000..80aac6c --- /dev/null +++ b/.github/workflows/build-vm-driver-linux.yml @@ -0,0 +1,107 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Builds the Linux VM driver as OpenShell's build-vm-driver-linux.yml does: the VM runtime from the +# flake (the hash-pinned vm-runtime release), the guest init built by build-vm-init.yml in +# the same run, and openshell-sandbox and openshell-supervisor from OpenShell's published +# test-inputs bundle (openshell-test-inputs): nothing from OpenShell is built here. + +name: Build Linux VM Driver + +on: + workflow_call: + inputs: + openshell-test-inputs: + description: ai-openshell/openshell commit whose published test-inputs bundle provides openshell-sandbox and openshell-supervisor + required: true + type: string + cargo-version: + required: false + type: string + default: "0.0.0" + checkout-ref: + required: false + type: string + default: "" + secrets: + CACHIX_AUTH_TOKEN: + required: false + OPENSHELL_ARTIFACTS_TOKEN: + required: false + +permissions: + contents: read + packages: read + +jobs: + build: + name: openshell-driver-vm (${{ matrix.triple }}) + strategy: + matrix: + include: + - arch: x86_64 + triple: x86_64-unknown-linux-gnu + runner: ubuntu-24.04 + - arch: aarch64 + triple: aarch64-unknown-linux-gnu + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} + timeout-minutes: 60 + defaults: + run: + shell: nix develop -c bash -euo pipefail {0} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + ref: ${{ inputs.checkout-ref || github.sha }} + + - uses: ./.github/actions/setup-nix + with: + prepare-shell: "true" + cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }} + + - name: Download OpenShell's test inputs + uses: ./.github/actions/pull-test-inputs + with: + test-inputs: ${{ inputs.openshell-test-inputs }} + token: ${{ secrets.OPENSHELL_ARTIFACTS_TOKEN || github.token }} + directory: ${{ runner.temp }}/openshell-test-inputs + + - name: Stage openshell-sandbox and openshell-supervisor + env: + BUNDLE: ${{ runner.temp }}/openshell-test-inputs + ARCH: ${{ matrix.arch }} + run: | + mkdir -p sandbox supervisor + cp "${BUNDLE}/runtime/openshell-sandbox-${ARCH}-unknown-linux-musl/openshell-sandbox" sandbox/ + cp "${BUNDLE}/runtime/openshell-supervisor-${ARCH}-unknown-linux-gnu/openshell-supervisor" supervisor/ + + - name: Download VM guest init + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: openshell-vm-init-${{ matrix.arch }}-unknown-linux-musl + path: vm-init + + - name: Build VM runtime + run: | + # HTTP 416 is not retried by Nix; restart the build once on failure. + nix build .#vm-runtime || nix build .#vm-runtime + + - name: Assemble compressed VM runtime + run: | + compressed_dir="${RUNNER_TEMP}/vm-runtime-compressed" + install -d "$compressed_dir" + cp result/compressed/*.zst "$compressed_dir/" + zstd -19 -T1 sandbox/openshell-sandbox -o "$compressed_dir/openshell-sandbox.zst" + zstd -19 -T1 supervisor/openshell-supervisor -o "$compressed_dir/openshell-supervisor.zst" + zstd -19 -T1 vm-init/openshell-vm-init -o "$compressed_dir/openshell-vm-init.zst" + + - name: Build openshell-driver-vm + uses: ./.github/actions/build-rust-binary + env: + OPENSHELL_VM_RUNTIME_COMPRESSED_DIR: ${{ runner.temp }}/vm-runtime-compressed + with: + package: openshell-driver-vm + binary: openshell-driver-vm + triple: ${{ matrix.triple }} + cargo-version: ${{ inputs.cargo-version }} diff --git a/.github/workflows/build-vm-driver-macos.yml b/.github/workflows/build-vm-driver-macos.yml new file mode 100644 index 0000000..8e7eb10 --- /dev/null +++ b/.github/workflows/build-vm-driver-macos.yml @@ -0,0 +1,111 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Builds the macOS VM driver as OpenShell's build-vm-driver-macos.yml does: the VM runtime from the +# flake (the hash-pinned vm-runtime release), the guest init built by build-vm-init.yml in +# the same run (a Linux musl guest, cross-built), and openshell-sandbox and openshell-supervisor from the OpenShell Branch E2E run +# given by openshell-run-id: nothing from OpenShell is built here. + +name: Build macOS VM Driver + +on: + workflow_call: + inputs: + openshell-run-id: + description: ai-openshell/openshell Branch E2E run whose openshell-sandbox and the macOS openshell-supervisor artifacts to use + required: true + type: string + cargo-version: + required: false + type: string + default: "0.0.0" + checkout-ref: + required: false + type: string + default: "" + secrets: + CACHIX_AUTH_TOKEN: + required: false + OPENSHELL_ARTIFACTS_TOKEN: + required: false + +permissions: + contents: read + +jobs: + build: + name: openshell-driver-vm (${{ matrix.triple }}) + strategy: + matrix: + include: + - arch: aarch64 + triple: aarch64-apple-darwin + runs-on: macos-15 + timeout-minutes: 60 + defaults: + run: + shell: nix develop -c bash -euo pipefail {0} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + ref: ${{ inputs.checkout-ref || github.sha }} + + - uses: ./.github/actions/setup-nix + with: + prepare-shell: "true" + cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }} + + - name: Download openshell-sandbox + env: + GH_TOKEN: ${{ secrets.OPENSHELL_ARTIFACTS_TOKEN || github.token }} + OPENSHELL_RUN_ID: ${{ inputs.openshell-run-id }} + ARCH: ${{ matrix.arch }} + run: | + if [ -z "${OPENSHELL_RUN_ID}" ]; then + echo "::error::No OpenShell Branch E2E run id was given" + exit 1 + fi + gh run download "${OPENSHELL_RUN_ID}" -R ai-openshell/openshell -n "openshell-sandbox-${ARCH}-unknown-linux-musl" -D sandbox + + - name: Download openshell-supervisor + env: + GH_TOKEN: ${{ secrets.OPENSHELL_ARTIFACTS_TOKEN || github.token }} + OPENSHELL_RUN_ID: ${{ inputs.openshell-run-id }} + ARCH: ${{ matrix.arch }} + run: | + if [ -z "${OPENSHELL_RUN_ID}" ]; then + echo "::error::No OpenShell Branch E2E run id was given" + exit 1 + fi + gh run download "${OPENSHELL_RUN_ID}" -R ai-openshell/openshell -n "openshell-supervisor-${ARCH}-apple-darwin" -D supervisor + + - name: Download VM guest init + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: openshell-vm-init-${{ matrix.arch }}-unknown-linux-musl + path: vm-init + + - name: Build VM runtime + run: | + # HTTP 416 is not retried by Nix; restart the build once on failure. + nix build .#vm-runtime || nix build .#vm-runtime + + - name: Assemble compressed VM runtime + run: | + compressed_dir="${RUNNER_TEMP}/vm-runtime-compressed" + install -d "$compressed_dir" + cp result/compressed/*.zst "$compressed_dir/" + zstd -19 -T1 sandbox/openshell-sandbox -o "$compressed_dir/openshell-sandbox.zst" + zstd -19 -T1 supervisor/openshell-supervisor -o "$compressed_dir/openshell-supervisor.zst" + zstd -19 -T1 vm-init/openshell-vm-init -o "$compressed_dir/openshell-vm-init.zst" + + - name: Build openshell-driver-vm + uses: ./.github/actions/build-rust-binary + env: + OPENSHELL_VM_RUNTIME_COMPRESSED_DIR: ${{ runner.temp }}/vm-runtime-compressed + with: + package: openshell-driver-vm + binary: openshell-driver-vm + triple: ${{ matrix.triple }} + cargo-version: ${{ inputs.cargo-version }} + entitlements-file: crates/openshell-driver-vm/entitlements.plist diff --git a/.github/workflows/build-vm-init.yml b/.github/workflows/build-vm-init.yml new file mode 100644 index 0000000..18808af --- /dev/null +++ b/.github/workflows/build-vm-init.yml @@ -0,0 +1,59 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Builds the VM guest init, embedded in the VM driver, with the same toolchain as the other Linux +# binaries (build-binaries-linux.yml). It is cross-built for x86_64 and aarch64 on an x86_64 +# runner, as the VM driver builds only need the binary. Kept apart from the drivers so the VM +# builds do not wait for them. + +name: Build VM Init + +on: + workflow_call: + inputs: + cargo-version: + required: false + type: string + default: "0.0.0" + checkout-ref: + required: false + type: string + default: "" + secrets: + CACHIX_AUTH_TOKEN: + required: false + +permissions: + contents: read + +jobs: + # The VM guest init, embedded in the VM driver. The aarch64 one is cross-built here for the + # macOS driver, so it cannot be run to check it. + vm-init: + name: openshell-vm-init (${{ matrix.triple }}) + strategy: + fail-fast: false + matrix: + include: + - triple: x86_64-unknown-linux-musl + run-check: "true" + - triple: aarch64-unknown-linux-musl + run-check: "false" + runs-on: ubuntu-24.04 + timeout-minutes: 60 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + ref: ${{ inputs.checkout-ref || github.sha }} + - uses: ./.github/actions/setup-nix + with: + prepare-shell: "true" + cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }} + - uses: ./.github/actions/build-rust-binary + with: + package: openshell-driver-vm + binary: openshell-vm-init + triple: ${{ matrix.triple }} + cargo-version: ${{ inputs.cargo-version }} + extra-cargo-flags: --no-default-features + run-check: ${{ matrix.run-check }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e03bed..ae60735 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,14 +25,11 @@ jobs: with: persist-credentials: false - # release-vm-kernel.yml is imported unchanged and has no header; drop it from the exclude - # list when the workflow is adapted for this repository. - name: Check license headers uses: ai-openshell/workflows/spdx-check@0b051efd25c3f7319634fed863d2e03e1bd55d7b with: include: >- *.rs *.sh *.toml *.yml *.yaml *.json - exclude: .github/workflows/release-vm-kernel.yml rust: name: Rust checks diff --git a/.github/workflows/driver-build-test.yml b/.github/workflows/driver-build-test.yml index 0e4626c..3310159 100644 --- a/.github/workflows/driver-build-test.yml +++ b/.github/workflows/driver-build-test.yml @@ -16,6 +16,10 @@ on: description: ai-openshell/openshell commit that provides tmachine, the gateway and the conformance suite required: false type: string + openshell-run-id: + description: ai-openshell/openshell Branch E2E run of openshell-rev, for the macOS VM driver build (macOS inputs are not in the test-inputs bundle) + required: false + type: string openshell-test-inputs: description: ai-openshell/openshell commit whose published test-inputs bundle (ghcr) to reuse required: false @@ -50,6 +54,16 @@ jobs: secrets: CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + # The VM guest init, embedded in the VM driver; separate so the VM builds do not wait for the + # drivers above. + build-vm-init: + name: Build VM init + permissions: + contents: read + uses: ./.github/workflows/build-vm-init.yml + secrets: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + # The drivers that run on a macOS host. build-binaries-macos: name: Build macOS binaries @@ -59,6 +73,39 @@ jobs: secrets: CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + # The Linux VM driver, from the flake's hash-pinned VM runtime, the guest init built above, and + # openshell-sandbox and openshell-supervisor from OpenShell's published test-inputs bundle, which + # does not expire. The env context is not available in `with`, so the default is repeated from + # OPENSHELL_TEST_INPUTS above; keep them together. + build-vm-driver-linux: + name: Build Linux VM driver + needs: build-vm-init + permissions: + contents: read + packages: read + uses: ./.github/workflows/build-vm-driver-linux.yml + with: + openshell-test-inputs: ${{ inputs.openshell-test-inputs || '9972314fa89320860e734f533e08d6994407d5fe' }} + secrets: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + OPENSHELL_ARTIFACTS_TOKEN: ${{ secrets.OPENSHELL_ARTIFACTS_TOKEN }} + + # The macOS VM driver needs the macOS supervisor, which is not in the test-inputs bundle, so it + # takes openshell-sandbox and openshell-supervisor from an OpenShell Branch E2E run. Its artifacts + # expire (5 days): dispatch Branch E2E on OpenShell main and set its run id (the Release Dev run + # of a main commit also works) here, or pass openshell-run-id through workflow_dispatch. + build-vm-driver-macos: + name: Build macOS VM driver + needs: build-vm-init + permissions: + contents: read + uses: ./.github/workflows/build-vm-driver-macos.yml + with: + openshell-run-id: ${{ inputs.openshell-run-id || '46885022931' }} + secrets: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + OPENSHELL_ARTIFACTS_TOKEN: ${{ secrets.OPENSHELL_ARTIFACTS_TOKEN }} + # Stages the inputs the way OpenShell's prepare-integration job does: its packaged gateway and # CLI, runtime images and test workload image, its prebuilt openshell-conformance, with the # drivers built here put into its deb and rpm, uploaded as one artifact. Nothing from OpenShell is @@ -192,7 +239,7 @@ jobs: required: name: Required checks if: always() - needs: [build-binaries-linux, build-binaries-macos, conformance-integration] + needs: [build-binaries-linux, build-vm-init, build-binaries-macos, build-vm-driver-linux, build-vm-driver-macos, conformance-integration] runs-on: ubuntu-24.04 steps: - name: Fail unless every job succeeded diff --git a/.github/workflows/release-vm-kernel.yml b/.github/workflows/release-vm-kernel.yml index deeff72..fbbd0db 100644 --- a/.github/workflows/release-vm-kernel.yml +++ b/.github/workflows/release-vm-kernel.yml @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + name: Release VM Kernel # Build custom libkrunfw (kernel firmware) + libkrun (VMM) for all @@ -5,10 +8,7 @@ name: Release VM Kernel # rolling "vm-runtime" GitHub Release and consumed by normal dev/tag release # workflows when building the openshell-driver-vm binary. # -# The Linux kernel is compiled once on aarch64 Linux. The resulting kernel.c -# (a C source file containing the kernel as a byte array) is shared with the -# macOS job, which only needs to compile it into a .dylib — no krunvm, no -# Fedora VM, no kernel rebuild. This cuts macOS CI from ~45 min to ~5 min. +# The aarch64 kernel is built on an arm64 Linux runner; its kernel.c is compiled into the macOS dylib. # # This workflow runs on demand when kernel config or pins change. It is # intentionally decoupled from the per-commit VM binary build because the @@ -38,16 +38,10 @@ jobs: name: Build Runtime (Linux ARM64) runs-on: ubuntu-24.04-arm timeout-minutes: 60 - container: - image: ghcr.io/ai-openshell/openshell/ci:82e753ba3ffdfb40c118e7cb416ced7f350381d5@sha256:d816f3b4b2de675928e2ecfd26ec6b937be35fe9986542c87d440bc3de5a29de - credentials: - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - options: --privileged - env: - MISE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Mark workspace safe for git run: git config --global --add safe.directory "$GITHUB_WORKSPACE" @@ -69,9 +63,9 @@ jobs: path: artifacts/vm-runtime-linux-aarch64.tar.zst retention-days: 5 - # Export kernel.c + ABI_VERSION for the macOS job. kernel.c contains - # the aarch64 Linux kernel as a byte array — it is OS-agnostic and can - # be compiled into a .dylib by Apple's cc without rebuilding the kernel. + # Export kernel.c + ABI_VERSION for the macOS job. kernel.c contains the aarch64 Linux + # kernel as a byte array: it is OS-agnostic and is compiled into a .dylib by Apple's cc + # without rebuilding the kernel. - name: Upload kernel.c for macOS build uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 with: @@ -89,16 +83,10 @@ jobs: name: Build Runtime (Linux AMD64) runs-on: ubuntu-24.04 timeout-minutes: 60 - container: - image: ghcr.io/ai-openshell/openshell/ci:82e753ba3ffdfb40c118e7cb416ced7f350381d5@sha256:d816f3b4b2de675928e2ecfd26ec6b937be35fe9986542c87d440bc3de5a29de - credentials: - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - options: --privileged - env: - MISE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Mark workspace safe for git run: git config --global --add safe.directory "$GITHUB_WORKSPACE" @@ -121,17 +109,19 @@ jobs: retention-days: 5 # --------------------------------------------------------------------------- - # macOS ARM64 — uses pre-built kernel.c from Linux ARM64 job + # macOS ARM64 — uses pre-built kernel.c from the Linux ARM64 job # --------------------------------------------------------------------------- build-runtime-macos-arm64: name: Build Runtime (macOS ARM64) needs: [build-runtime-linux-arm64] - runs-on: macos-latest-xlarge + runs-on: macos-15 timeout-minutes: 30 env: RUSTC_WRAPPER: "" steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Install dependencies run: | @@ -180,6 +170,8 @@ jobs: artifact-metadata: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Download all runtime artifacts uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 @@ -251,15 +243,15 @@ jobs: | Platform | Artifact | |----------|----------| - | Linux ARM64 | `vm-runtime-linux-aarch64.tar.zst` | | Linux x86_64 | `vm-runtime-linux-x86_64.tar.zst` | + | Linux ARM64 | `vm-runtime-linux-aarch64.tar.zst` | | macOS ARM64 | `vm-runtime-darwin-aarch64.tar.zst` | ### Verify ```bash - gh release download vm-runtime -R ai-openshell/openshell -p vm-runtime-linux-x86_64.tar.zst - gh attestation verify vm-runtime-linux-x86_64.tar.zst -R ai-openshell/openshell + gh release download vm-runtime -R ${{ github.repository }} -p vm-runtime-linux-x86_64.tar.zst + gh attestation verify vm-runtime-linux-x86_64.tar.zst -R ${{ github.repository }} ``` files: | diff --git a/.github/zizmor.yml b/.github/zizmor.yml deleted file mode 100644 index bd50dea..0000000 --- a/.github/zizmor.yml +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -rules: - artipacked: - ignore: - # Imported unchanged from ai-openshell/openshell; its checkouts keep credentials. Remove this - # when the workflow is adapted for this repository. - - release-vm-kernel.yml diff --git a/README.md b/README.md index f892f20..6e5f317 100644 --- a/README.md +++ b/README.md @@ -19,10 +19,10 @@ The VM driver's tests build ext4 images and need `mke2fs` (e2fsprogs 1.43 or new ## CI `ci.yml` checks the license headers, runs `cargo fmt`, `cargo clippy` and `cargo test`, and lints the -workflows. `driver-build-test.yml` builds the Docker and Podman drivers as OpenShell builds its release -binaries (in the flake's dev shell, with its cross toolchains) for x86_64 and aarch64 Linux and for -aarch64 macOS. It then runs OpenShell's conformance suite on OpenShell's tmachine, with the drivers -built here replacing the ones in OpenShell's packaged gateway: the Docker driver on +workflows. `driver-build-test.yml` builds the Docker and Podman drivers and the VM guest init as OpenShell +builds its release binaries (in the flake's dev shell, with its cross toolchains), and the VM driver +on Linux and macOS. It then runs OpenShell's conformance suite on OpenShell's tmachine, with the +drivers built here replacing the ones in OpenShell's packaged gateway: the Docker driver on `ubuntu-docker-rootful` with the deb, and the Podman driver on `fedora-podman-rootful` and `fedora-podman-rootless` with the rpm. The packaged gateway launches the replaced driver from `/usr/libexec/openshell`. @@ -30,6 +30,8 @@ built here replacing the ones in OpenShell's packaged gateway: the Docker driver Nothing from OpenShell is built here. The gateway packages, the runtime images and `openshell-conformance` come from OpenShell's published test-inputs bundle (`ghcr.io/ai-openshell/openshell/test-inputs:`, which does not expire), selected by -`OPENSHELL_TEST_INPUTS` in `driver-build-test.yml`; tmachine is checked out at `OPENSHELL_REV`. Keep the pins -together: the `rev` of the OpenShell git dependencies in `Cargo.toml`, `OPENSHELL_REV` and -`OPENSHELL_TEST_INPUTS`. +`OPENSHELL_TEST_INPUTS` in `driver-build-test.yml`; tmachine is checked out at `OPENSHELL_REV`. The VM driver +build takes `openshell-sandbox` and `openshell-supervisor` from an OpenShell run whose id is the +default of `openshell-run-id` in `driver-build-test.yml` (two places); those artifacts expire after about five days, so pass a recent +run's id as the `openshell-run-id` input when they are gone. Keep the pins together: the `rev` of +the OpenShell git dependencies in `Cargo.toml`, `OPENSHELL_REV` and `OPENSHELL_TEST_INPUTS`. diff --git a/flake.nix b/flake.nix index 6676649..0dd93f8 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ # The build environment for the desktop drivers, taken from ai-openshell/openshell's flake: the # development shell with its cross toolchains (gnu and musl for x86_64 and aarch64, native on -# macOS). The CI builds the drivers in this shell, as OpenShell +# macOS) and the hash-pinned VM runtime. The CI builds the drivers in this shell, as OpenShell # builds its release binaries. Keep nixpkgs and rust-overlay in step with OpenShell's flake.lock # so its Cachix cache applies. { @@ -92,6 +92,7 @@ }; in { + packages.vm-runtime = pkgs.callPackage ./nix/pkgs/vm-runtime.nix { }; devShells.default = pkgs.mkShellNoCC { packages = [ rustToolchain ] ++ devShellPackages; diff --git a/mise.toml b/mise.toml index 129e6ff..3dcf562 100644 --- a/mise.toml +++ b/mise.toml @@ -6,9 +6,13 @@ min_version = { soft = "2026.9.9" } [settings] +experimental = true lockfile = true lockfile_platforms = ["linux-x64", "linux-arm64", "macos-arm64"] +[task_config] +includes = ["tasks/*.toml"] + [tools] actionlint = "1.7.12" shellcheck = "0.11.0" diff --git a/nix/pkgs/vm-runtime.nix b/nix/pkgs/vm-runtime.nix new file mode 100644 index 0000000..c537486 --- /dev/null +++ b/nix/pkgs/vm-runtime.nix @@ -0,0 +1,67 @@ +# SPDX-License-Identifier: Apache-2.0 + +{ + fetchurl, + lib, + stdenv, + zstd, +}: + +let + runtime = + { + x86_64-linux = { + platform = "linux-x86_64"; + hash = "sha256-mZwSUhs9IZ0pPLxzVs4AbRLdYWkUlHwP4lmfsbeiUGw="; + artifacts = [ + "libkrun.so" + "libkrunfw.so.5" + "umoci" + ]; + }; + aarch64-linux = { + platform = "linux-aarch64"; + hash = "sha256-Yk5Rxn6JWxMu82Vkyx3eSAxh5/mnfUwcNDNeDIQJz4c="; + artifacts = [ + "libkrun.so" + "libkrunfw.so.5" + "umoci" + ]; + }; + aarch64-darwin = { + platform = "darwin-aarch64"; + hash = "sha256-Sm0zwSkctPETKd46zqOqDO02jLapQ3ST1hafqIVkVjU="; + artifacts = [ + "libkrun.dylib" + "libkrunfw.5.dylib" + "umoci" + ]; + }; + } + .${stdenv.hostPlatform.system}; + archive = fetchurl { + url = "https://github.com/ai-openshell/openshell/releases/download/vm-runtime/vm-runtime-${runtime.platform}.tar.zst"; + inherit (runtime) hash; + }; +in +stdenv.mkDerivation { + name = "openshell-vm-runtime-${runtime.platform}"; + + nativeBuildInputs = [ zstd ]; + dontUnpack = true; + + installPhase = '' + runHook preInstall + + mkdir -p "$out" + tar --extract --file ${archive} --directory "$out" + mkdir -p "$out/compressed" + for artifact in ${lib.escapeShellArgs runtime.artifacts}; do + zstd -19 -T1 "$out/$artifact" -o "$out/compressed/$artifact.zst" + test -s "$out/compressed/$artifact.zst" + zstd --test --quiet "$out/compressed/$artifact.zst" + done + + runHook postInstall + ''; +} diff --git a/tasks/scripts/build-env.sh b/tasks/scripts/build-env.sh new file mode 100755 index 0000000..f454d8b --- /dev/null +++ b/tasks/scripts/build-env.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +# SPDX-License-Identifier: Apache-2.0 + +# Shared build-environment helpers for host-side Rust builds. +# +# Source this file (do not execute it) and call the helpers before invoking +# Cargo on the host. + +# ensure_build_nofile_limit raises the per-process open-file limit before a +# host Rust build. Sccache and static *-unknown-linux-musl links can each open +# hundreds of files simultaneously, exceeding macOS's default soft limit of +# 256. The raised limit propagates to the Cargo children the caller spawns. +# +# The limit is read from OPENSHELL_BUILD_NOFILE_LIMIT (default 8192), honoring +# the legacy OPENSHELL_VM_BUILD_NOFILE_LIMIT for back-compat. This is a no-op +# on Linux, so it must be safe to call unconditionally. +ensure_build_nofile_limit() { + local desired="${OPENSHELL_BUILD_NOFILE_LIMIT:-${OPENSHELL_VM_BUILD_NOFILE_LIMIT:-8192}}" + local minimum=1024 + local current="" + local hard="" + local target="" + + [ "$(uname -s)" = "Darwin" ] || return 0 + current="$(ulimit -Sn 2>/dev/null || echo "")" + case "${current}" in + ''|*[!0-9]*) + return 0 + ;; + esac + + if [ "${current}" -ge "${desired}" ]; then + return 0 + fi + + hard="$(ulimit -Hn 2>/dev/null || echo "")" + target="${desired}" + case "${hard}" in + ''|unlimited|infinity) + ;; + *[!0-9]*) + ;; + *) + if [ "${hard}" -lt "${target}" ]; then + target="${hard}" + fi + ;; + esac + + if [ "${target}" -gt "${current}" ] && ulimit -Sn "${target}" 2>/dev/null; then + echo "==> Raised open file limit for host Cargo build: ${current} -> $(ulimit -Sn)" + fi + + current="$(ulimit -Sn 2>/dev/null || echo "${current}")" + case "${current}" in + ''|*[!0-9]*) + return 0 + ;; + esac + + if [ "${current}" -lt "${desired}" ]; then + echo "WARNING: Open file limit is ${current}; host Cargo builds are more reliable at ${desired}+ on macOS." + fi + + if [ "${current}" -lt "${minimum}" ]; then + echo "ERROR: Open file limit (${current}) is too low for host Cargo builds on macOS." >&2 + echo " Run: ulimit -Sn ${desired}" >&2 + echo " Then re-run this script." >&2 + exit 1 + fi +} diff --git a/tasks/scripts/vm/build-supervisor-bundle.sh b/tasks/scripts/vm/build-supervisor-bundle.sh index ced808f..d78a094 100755 --- a/tasks/scripts/vm/build-supervisor-bundle.sh +++ b/tasks/scripts/vm/build-supervisor-bundle.sh @@ -10,6 +10,14 @@ OUTPUT_DIR="${OPENSHELL_VM_RUNTIME_COMPRESSED_DIR:-${ROOT}/target/vm-runtime-com # shellcheck source=tasks/scripts/build-env.sh source "${ROOT}/tasks/scripts/build-env.sh" +# openshell-sandbox and openshell-supervisor live in ai-openshell/openshell, not in this repository. +# Build them from a checkout of OpenShell at the revision pinned in Cargo.toml. +if [ -z "${OPENSHELL_DIR:-}" ] || [ ! -f "${OPENSHELL_DIR}/Cargo.toml" ]; then + PIN="$(sed -nE 's#^openshell-core = .*rev = "([0-9a-f]+)".*#\1#p' "${ROOT}/Cargo.toml")" + echo "ERROR: set OPENSHELL_DIR to a checkout of ai-openshell/openshell at ${PIN:-the pinned revision}" >&2 + exit 1 +fi + GUEST_ARCH="" while [[ $# -gt 0 ]]; do case "$1" in @@ -58,11 +66,11 @@ case "${GUEST_ARCH}" in ;; esac -SUPERVISOR_BIN="${ROOT}/target/${SANDBOX_RUST_TARGET}/release/openshell-sandbox" +SUPERVISOR_BIN="${OPENSHELL_DIR}/target/${SANDBOX_RUST_TARGET}/release/openshell-sandbox" SUPERVISOR_OUTPUT="${OUTPUT_DIR}/openshell-sandbox.zst" VM_INIT_BIN="${ROOT}/target/${SANDBOX_RUST_TARGET}/release/openshell-vm-init" VM_INIT_OUTPUT="${OUTPUT_DIR}/openshell-vm-init.zst" -HOST_SUPERVISOR_BIN="${ROOT}/target/release/openshell-supervisor" +HOST_SUPERVISOR_BIN="${OPENSHELL_DIR}/target/release/openshell-supervisor" HOST_SUPERVISOR_OUTPUT="${OUTPUT_DIR}/openshell-supervisor.zst" echo "==> Building openshell-sandbox supervisor bundle" @@ -83,20 +91,18 @@ run_supervisor_build() { cargo_prefix=(env -u RUSTC_WRAPPER) fi + local build=(cargo build) if command -v cargo-zigbuild >/dev/null 2>&1; then - ${cargo_prefix[@]+"${cargo_prefix[@]}"} cargo zigbuild --release -p openshell-sandbox --target "${SANDBOX_RUST_TARGET}" \ - --manifest-path "${ROOT}/Cargo.toml" - ${cargo_prefix[@]+"${cargo_prefix[@]}"} cargo zigbuild --release -p openshell-driver-vm --bin openshell-vm-init --no-default-features --target "${SANDBOX_RUST_TARGET}" \ - --manifest-path "${ROOT}/Cargo.toml" + build=(cargo zigbuild) else echo " cargo-zigbuild not found, falling back to cargo build..." - ${cargo_prefix[@]+"${cargo_prefix[@]}"} cargo build --release -p openshell-sandbox --target "${SANDBOX_RUST_TARGET}" \ - --manifest-path "${ROOT}/Cargo.toml" - ${cargo_prefix[@]+"${cargo_prefix[@]}"} cargo build --release -p openshell-driver-vm --bin openshell-vm-init --no-default-features --target "${SANDBOX_RUST_TARGET}" \ - --manifest-path "${ROOT}/Cargo.toml" fi - ${cargo_prefix[@]+"${cargo_prefix[@]}"} cargo build --release -p openshell-supervisor \ + ${cargo_prefix[@]+"${cargo_prefix[@]}"} "${build[@]}" --release -p openshell-sandbox --target "${SANDBOX_RUST_TARGET}" \ + --manifest-path "${OPENSHELL_DIR}/Cargo.toml" + ${cargo_prefix[@]+"${cargo_prefix[@]}"} "${build[@]}" --release -p openshell-driver-vm --bin openshell-vm-init --no-default-features --target "${SANDBOX_RUST_TARGET}" \ --manifest-path "${ROOT}/Cargo.toml" + ${cargo_prefix[@]+"${cargo_prefix[@]}"} cargo build --release -p openshell-supervisor \ + --manifest-path "${OPENSHELL_DIR}/Cargo.toml" } print_build_failure() { diff --git a/tasks/scripts/vm/download-kernel-runtime.sh b/tasks/scripts/vm/download-kernel-runtime.sh index 1b2b27b..045fa63 100755 --- a/tasks/scripts/vm/download-kernel-runtime.sh +++ b/tasks/scripts/vm/download-kernel-runtime.sh @@ -14,7 +14,7 @@ # # Environment: # VM_RUNTIME_RELEASE_TAG - GitHub Release tag (default: vm-runtime) -# GITHUB_REPOSITORY - owner/repo (default: ai-openshell/openshell) +# VM_RUNTIME_REPOSITORY - owner/repo that publishes the release (default: ai-openshell/openshell) # OPENSHELL_VM_RUNTIME_COMPRESSED_DIR - Output directory (default: target/vm-runtime-compressed) # # Platforms: linux-aarch64, linux-x86_64, darwin-aarch64 @@ -27,7 +27,7 @@ ROOT="$(vm_lib_root)" source "${ROOT}/crates/openshell-driver-vm/runtime/pins.env" RELEASE_TAG="${VM_RUNTIME_RELEASE_TAG:-vm-runtime}" -REPO="${GITHUB_REPOSITORY:-ai-openshell/openshell}" +REPO="${VM_RUNTIME_REPOSITORY:-ai-openshell/openshell}" OUTPUT_DIR="${OPENSHELL_VM_RUNTIME_COMPRESSED_DIR:-${ROOT}/target/vm-runtime-compressed}" # ── Auto-detect platform (detect_platform from _lib.sh) ───────────────── @@ -46,7 +46,7 @@ while [[ $# -gt 0 ]]; do echo "" echo "Environment:" echo " VM_RUNTIME_RELEASE_TAG Release tag (default: vm-runtime)" - echo " GITHUB_REPOSITORY owner/repo (default: ai-openshell/openshell)" + echo " VM_RUNTIME_REPOSITORY owner/repo (default: ai-openshell/openshell)" echo " OPENSHELL_VM_RUNTIME_COMPRESSED_DIR Output directory" exit 0 ;; diff --git a/tasks/scripts/vm/smoke-orphan-cleanup.sh b/tasks/scripts/vm/smoke-orphan-cleanup.sh index 2024ce3..bee37a5 100755 --- a/tasks/scripts/vm/smoke-orphan-cleanup.sh +++ b/tasks/scripts/vm/smoke-orphan-cleanup.sh @@ -36,8 +36,13 @@ trap cleanup_stray EXIT build_binaries() { echo "==> Ensuring binaries are built" - if [ ! -x "$ROOT/target/debug/openshell-gateway" ] || [ ! -x "$ROOT/target/debug/openshell-driver-vm" ]; then - cargo build -p openshell-gateway -p openshell-driver-vm >&2 + # The gateway lives in ai-openshell/openshell; build it from a checkout at the pinned revision. + : "${OPENSHELL_DIR:?set OPENSHELL_DIR to a checkout of ai-openshell/openshell at the pinned revision}" + if [ ! -x "$OPENSHELL_DIR/target/debug/openshell-gateway" ]; then + cargo build --manifest-path "$OPENSHELL_DIR/Cargo.toml" -p openshell-gateway >&2 + fi + if [ ! -x "$ROOT/target/debug/openshell-driver-vm" ]; then + cargo build -p openshell-driver-vm >&2 fi if [ "$(uname -s)" = "Darwin" ]; then codesign \ @@ -71,7 +76,7 @@ EOF OPENSHELL_COMPUTE_DRIVER=vm \ OPENSHELL_GATEWAY_CONFIG="$config" \ OPENSHELL_VM_RUNTIME_COMPRESSED_DIR="$ROOT/target/vm-runtime-compressed" \ - nohup "$ROOT/target/debug/openshell-gateway" --disable-tls \ + nohup "$OPENSHELL_DIR/target/debug/openshell-gateway" --disable-tls \ > "$LOG" 2>&1 & GATEWAY_PID=$! echo "gateway pid=$GATEWAY_PID" From 3b18ede691900a50bb4af97894a52097a5ed0c1c Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 2 Dec 2026 22:34:08 +0100 Subject: [PATCH 2/2] ci: run OpenShell's conformance suite against the VM driver Install OpenShell's packaged gateway on the runner, configure it to launch the VM driver built in the same run, and run OpenShell's prebuilt conformance program against the installed gateway. The runner is used, as the driver needs KVM. The package comes from the integration inputs, the program and the host supervisor from the published test-inputs bundle. This does for the VM driver what tmachine's deb installer does for the Docker driver, on the host, until tmachine can describe the host it runs on. Signed-off-by: Evan Lezar --- .github/workflows/conformance-vm.yml | 123 ++++++++++++++++++++++ .github/workflows/driver-build-test.yml | 19 +++- flake.nix | 2 + tasks/scripts/vm/conformance.sh | 131 ++++++++++++++++++++++++ 4 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/conformance-vm.yml create mode 100755 tasks/scripts/vm/conformance.sh diff --git a/.github/workflows/conformance-vm.yml b/.github/workflows/conformance-vm.yml new file mode 100644 index 0000000..7e53d6f --- /dev/null +++ b/.github/workflows/conformance-vm.yml @@ -0,0 +1,123 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Runs OpenShell's conformance suite against the VM driver built in this run, on the runner itself +# (it has KVM): tasks/scripts/vm/conformance.sh installs OpenShell's packaged gateway, configures +# it to launch the driver and runs the prebuilt openshell-conformance program against the +# installed gateway. Nothing from OpenShell is built here: the package comes from the +# integration inputs, the program and the host supervisor from its published test-inputs bundle. +# +# Interim: the other drivers run their suites in a tmachine guest (e2e-suites.yml). The VM driver +# needs KVM itself, so it runs on the host until tmachine can describe the machine it runs on. + +name: VM Conformance + +on: + workflow_call: + inputs: + openshell-rev: + description: ai-openshell/openshell commit that provides the unsupported-test list and the nextest profile; it must be the commit the inputs were built at + required: true + type: string + openshell-test-inputs: + description: ai-openshell/openshell commit whose published test-inputs bundle provides the host supervisor + required: true + type: string + secrets: + CACHIX_AUTH_TOKEN: + required: false + OPENSHELL_ARTIFACTS_TOKEN: + required: false + +permissions: + contents: read + packages: read + +jobs: + conformance: + name: VM driver conformance + runs-on: ubuntu-24.04 + timeout-minutes: 90 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + # tests/suites/unsupported.yaml and the nextest profile, from the commit the inputs were built at. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: ai-openshell/openshell + ref: ${{ inputs.openshell-rev }} + path: openshell + persist-credentials: false + + - name: Enable KVM access + run: | + set -euo pipefail + if [[ ! -c /dev/kvm ]]; then + echo "::error::The runner did not expose /dev/kvm" + exit 1 + fi + sudo chmod 0666 /dev/kvm + exec 3<>/dev/kvm + exec 3>&- + + - name: Install host tools + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends e2fsprogs openssh-client socat zstd + # tasks/scripts/suite-unsupported.sh needs mikefarah yq, which the runner image has. + yq --version | grep -q mikefarah + + - uses: ./.github/actions/setup-nix + with: + prepare-shell: "true" + cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }} + + - name: Download OpenShell's test inputs + uses: ./.github/actions/pull-test-inputs + with: + test-inputs: ${{ inputs.openshell-test-inputs }} + token: ${{ secrets.OPENSHELL_ARTIFACTS_TOKEN || github.token }} + directory: ${{ runner.temp }}/openshell-test-inputs + + - name: Download the VM driver + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: openshell-driver-vm-x86_64-unknown-linux-gnu + path: ${{ runner.temp }}/vm-driver + + # OpenShell's packaged gateway and CLI, with the drivers under test, as built by prepare-inputs. + - name: Download the integration inputs + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: tmachine-inputs + path: ${{ runner.temp }}/integration-inputs + + - name: Install OpenShell and run the conformance suite + shell: bash + env: + BUNDLE: ${{ runner.temp }}/openshell-test-inputs + INPUTS: ${{ runner.temp }}/integration-inputs + DRIVER: ${{ runner.temp }}/vm-driver + OPENSHELL_DIR: ${{ github.workspace }}/openshell + RESULTS_DIR: ${{ github.workspace }}/results + run: | + set -euo pipefail + export OPENSHELL_DEB="${INPUTS}/packages/openshell.deb" + export OPENSHELL_VM_DRIVER_BIN="${DRIVER}/openshell-driver-vm" + export OPENSHELL_VM_SUPERVISOR_BIN="${BUNDLE}/runtime/openshell-supervisor-x86_64-unknown-linux-gnu/openshell-supervisor" + export OPENSHELL_CONFORMANCE_BIN="${BUNDLE}/conformance/openshell-conformance-x86_64-unknown-linux-musl/openshell-conformance" + chmod +x "$OPENSHELL_VM_DRIVER_BIN" "$OPENSHELL_VM_SUPERVISOR_BIN" "$OPENSHELL_CONFORMANCE_BIN" + "$OPENSHELL_VM_DRIVER_BIN" --version + "$OPENSHELL_CONFORMANCE_BIN" list > /dev/null + # The script changes the machine, and cargo-nextest comes from the Nix development shell. + nix develop "${GITHUB_WORKSPACE}" -c tasks/scripts/vm/conformance.sh + + - name: Upload results + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + with: + name: e2e-results-vm-conformance + path: results + if-no-files-found: ignore + retention-days: 7 diff --git a/.github/workflows/driver-build-test.yml b/.github/workflows/driver-build-test.yml index 3310159..6e6e97c 100644 --- a/.github/workflows/driver-build-test.yml +++ b/.github/workflows/driver-build-test.yml @@ -236,10 +236,27 @@ jobs: family: conformance openshell-rev: ${{ inputs.openshell-rev || '9972314fa89320860e734f533e08d6994407d5fe' }} + # OpenShell's conformance suite against the VM driver, on the runner (the driver needs KVM). It + # takes the gateway and the CLI from the packaged deb in the integration inputs. The revision + # defaults are repeated from OPENSHELL_REV and OPENSHELL_TEST_INPUTS above; keep them together. + conformance-vm: + name: VM conformance + needs: [build-vm-driver-linux, prepare-inputs] + permissions: + contents: read + packages: read + uses: ./.github/workflows/conformance-vm.yml + with: + openshell-rev: ${{ inputs.openshell-rev || '9972314fa89320860e734f533e08d6994407d5fe' }} + openshell-test-inputs: ${{ inputs.openshell-test-inputs || '9972314fa89320860e734f533e08d6994407d5fe' }} + secrets: + CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }} + OPENSHELL_ARTIFACTS_TOKEN: ${{ secrets.OPENSHELL_ARTIFACTS_TOKEN }} + required: name: Required checks if: always() - needs: [build-binaries-linux, build-vm-init, build-binaries-macos, build-vm-driver-linux, build-vm-driver-macos, conformance-integration] + needs: [build-binaries-linux, build-vm-init, build-binaries-macos, build-vm-driver-linux, build-vm-driver-macos, conformance-integration, conformance-vm] runs-on: ubuntu-24.04 steps: - name: Fail unless every job succeeded diff --git a/flake.nix b/flake.nix index 0dd93f8..aa704ae 100644 --- a/flake.nix +++ b/flake.nix @@ -40,6 +40,8 @@ }; devShellPackages = with pkgs; [ cargo-auditable + # Runs OpenShell's prebuilt conformance program in the VM driver conformance lane. + cargo-nextest # Build and inspect ext4 images in VM driver tests. e2fsprogs gh diff --git a/tasks/scripts/vm/conformance.sh b/tasks/scripts/vm/conformance.sh new file mode 100755 index 0000000..6890d90 --- /dev/null +++ b/tasks/scripts/vm/conformance.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 +# +# Installs OpenShell's packaged gateway on this machine, configures it to launch the VM driver under +# test, and runs OpenShell's prebuilt conformance program against the installed gateway. The machine is changed (packages, a systemd user manager, services): run it on a +# throwaway CI runner with KVM, never on a workstation. +# +# Interim: the conformance suites of the other drivers run in a tmachine guest. This does what +# tmachine's `deb` installer does for the Docker driver, on the host, +# until tmachine can describe the host it runs on. +# +# Inputs (environment): +# OPENSHELL_DEB OpenShell's gateway deb +# OPENSHELL_VM_DRIVER_BIN the VM driver under test +# OPENSHELL_VM_SUPERVISOR_BIN the host supervisor, installed next to the driver +# OPENSHELL_CONFORMANCE_BIN OpenShell's prebuilt openshell-conformance program +# OPENSHELL_DIR a checkout of ai-openshell/openshell at the commit of the inputs +# RESULTS_DIR where the JUnit report goes + +set -euo pipefail + +: "${OPENSHELL_DEB:?}" "${OPENSHELL_VM_DRIVER_BIN:?}" "${OPENSHELL_VM_SUPERVISOR_BIN:?}" +: "${OPENSHELL_CONFORMANCE_BIN:?}" "${OPENSHELL_DIR:?}" "${RESULTS_DIR:?}" + +GATEWAY_NAME=openshell +GATEWAY_PORT=17670 +# A pullable image for the tests that need a Python workload, as in OpenShell's e2e/support/conformance.sh. +PYTHON_IMAGE="ghcr.io/astral-sh/uv:0.12.17-python3.12-trixie-slim@sha256:9a59bb7206905ccaae4f7dab222fbac47c125a21e5fc16f43f427cd6c940ade3" + +uid="$(id -u)" +gid="$(id -g)" +tls_dir="${HOME}/.local/state/openshell/tls" +config_dir="${HOME}/.config/openshell" +state_dir="$(mktemp -d /tmp/openshell-vm-XXXXXX)" + +diagnostics() { + local status=$? + if [ "$status" -ne 0 ]; then + echo "=== openshell-gateway.service ===" || true + journalctl --user -u openshell-gateway.service --no-pager 2>&1 | tail -n 200 || true + # The packaged preflight reports every failure as a malformed config; starting the gateway + # directly reports the cause. + if ! systemctl --user is-active --quiet openshell-gateway.service; then + echo "=== openshell-gateway, started directly ===" + (set -a; . "${config_dir}/gateway.env"; set +a + OPENSHELL_LOCAL_TLS_DIR="$tls_dir" timeout 10 /usr/bin/openshell-gateway 2>&1 | tail -n 40) || true + fi + find "$state_dir" -name 'rootfs-console.log' 2>/dev/null | while IFS= read -r console; do + echo "=== VM console log: ${console} ===" + cat "$console" || true + done + fi +} +trap diagnostics EXIT + +echo "==> Installing OpenShell's package and the VM driver" +sudo apt-get install -y --no-install-recommends "$OPENSHELL_DEB" +# The gateway launches the driver from driver_dir, and the driver prefers a native supervisor next +# to it. +driver_dir=/usr/local/libexec/openshell +sudo install -d "$driver_dir" +sudo install -m 0755 "$OPENSHELL_VM_DRIVER_BIN" "${driver_dir}/openshell-driver-vm" +sudo install -m 0755 "$OPENSHELL_VM_SUPERVISOR_BIN" "${driver_dir}/openshell-supervisor" + +echo "==> Starting the user service manager" +sudo loginctl enable-linger "$USER" +sudo systemctl start "user@${uid}.service" +export XDG_RUNTIME_DIR="/run/user/${uid}" +export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus" +for _ in $(seq 1 30); do + [ -S "${XDG_RUNTIME_DIR}/bus" ] && break + sleep 1 +done +[ -S "${XDG_RUNTIME_DIR}/bus" ] || { echo "::error::The user service manager did not start." >&2; exit 1; } + +echo "==> Configuring the gateway" +# The sandboxes need the gateway's CA, so generate the certificates before the gateway starts. +/usr/bin/openshell-gateway generate-certs --output-dir "$tls_dir" --server-san host.openshell.internal +mkdir -p "${config_dir}/gateway.d" +printf 'OPENSHELL_COMPUTE_DRIVER=vm\n' > "${config_dir}/gateway.env" +# The settings of OpenShell's own VM lane for a gateway-managed driver (e2e/rust/e2e-vm.sh). +cat > "${config_dir}/gateway.d/90-vm.toml" < Starting the gateway" +systemctl --user daemon-reload +systemctl --user start openshell-gateway.service +for _ in $(seq 1 60); do + (exec 3<>"/dev/tcp/127.0.0.1/${GATEWAY_PORT}") 2>/dev/null && break + sleep 1 +done +openshell gateway add "https://127.0.0.1:${GATEWAY_PORT}" --local --name "$GATEWAY_NAME" + +echo "==> Running OpenShell's conformance suite against the VM driver" +export OPENSHELL_GATEWAY="$GATEWAY_NAME" +export OPENSHELL_BIN=/usr/bin/openshell +export OPENSHELL_TEST_PYTHON_IMAGE="$PYTHON_IMAGE" +# Cold sandbox VMs take about 15 s after image preparation; allow for slower runners. +export OPENSHELL_PROVISION_TIMEOUT=180 +OPENSHELL_TEST_UNSUPPORTED="$("${OPENSHELL_DIR}/tasks/scripts/suite-unsupported.sh" vm)" +export OPENSHELL_TEST_UNSUPPORTED + +"$OPENSHELL_CONFORMANCE_BIN" ready +work="$(mktemp -d)" +"$OPENSHELL_CONFORMANCE_BIN" nextest-metadata "$work" +status=0 +cargo-nextest nextest run \ + --cargo-metadata "${work}/cargo-metadata.json" \ + --binaries-metadata "${work}/binaries-metadata.json" \ + --config-file "${OPENSHELL_DIR}/tests/runner/src/program-nextest.toml" \ + --profile openshell --no-tests fail || status=$? +mkdir -p "$RESULTS_DIR" +if [ -f "${work}/target/nextest/openshell/junit.xml" ]; then + mv "${work}/target/nextest/openshell/junit.xml" "${RESULTS_DIR}/conformance-vm.xml" +fi +exit "$status"