|
| 1 | +name: Driver VM Linux |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + cargo-version: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + image-tag: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + checkout-ref: |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + packages: read |
| 19 | + |
| 20 | +defaults: |
| 21 | + run: |
| 22 | + shell: bash |
| 23 | + |
| 24 | +jobs: |
| 25 | + download-kernel-runtime: |
| 26 | + name: Download Kernel Runtime |
| 27 | + runs-on: build-amd64 |
| 28 | + timeout-minutes: 10 |
| 29 | + container: |
| 30 | + image: ghcr.io/nvidia/openshell/ci:latest |
| 31 | + credentials: |
| 32 | + username: ${{ github.actor }} |
| 33 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + ref: ${{ inputs['checkout-ref'] }} |
| 38 | + |
| 39 | + - name: Download Linux runtime tarballs |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + run: | |
| 43 | + set -euo pipefail |
| 44 | + mkdir -p runtime-artifacts |
| 45 | +
|
| 46 | + for platform in linux-aarch64 linux-x86_64; do |
| 47 | + asset="vm-runtime-${platform}.tar.zst" |
| 48 | + echo "Downloading ${asset}..." |
| 49 | + asset_url=$(curl -fsSL \ |
| 50 | + -H "Accept: application/vnd.github+json" \ |
| 51 | + -H "Authorization: Bearer ${GH_TOKEN}" \ |
| 52 | + "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/vm-dev" \ |
| 53 | + | jq -r --arg asset "$asset" '.assets[] | select(.name == $asset) | .browser_download_url' \ |
| 54 | + | head -n1) |
| 55 | + if [ -z "$asset_url" ]; then |
| 56 | + echo "::error::No ${asset} asset found on vm-dev release" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + curl -fL -o "runtime-artifacts/${asset}" "$asset_url" |
| 60 | + done |
| 61 | +
|
| 62 | + ls -lah runtime-artifacts/ |
| 63 | +
|
| 64 | + - name: Verify downloads |
| 65 | + run: | |
| 66 | + set -euo pipefail |
| 67 | + for platform in linux-aarch64 linux-x86_64; do |
| 68 | + test -f "runtime-artifacts/vm-runtime-${platform}.tar.zst" |
| 69 | + done |
| 70 | +
|
| 71 | + - name: Upload runtime artifacts |
| 72 | + uses: actions/upload-artifact@v4 |
| 73 | + with: |
| 74 | + name: driver-vm-kernel-runtime-tarballs |
| 75 | + path: runtime-artifacts/vm-runtime-*.tar.zst |
| 76 | + retention-days: 1 |
| 77 | + |
| 78 | + build-rootfs: |
| 79 | + name: Build Rootfs (${{ matrix.arch }}) |
| 80 | + strategy: |
| 81 | + matrix: |
| 82 | + include: |
| 83 | + - arch: arm64 |
| 84 | + runner: build-arm64 |
| 85 | + guest_arch: aarch64 |
| 86 | + - arch: amd64 |
| 87 | + runner: build-amd64 |
| 88 | + guest_arch: x86_64 |
| 89 | + runs-on: ${{ matrix.runner }} |
| 90 | + timeout-minutes: 30 |
| 91 | + container: |
| 92 | + image: ghcr.io/nvidia/openshell/ci:latest |
| 93 | + credentials: |
| 94 | + username: ${{ github.actor }} |
| 95 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + options: --privileged |
| 97 | + volumes: |
| 98 | + - /var/run/docker.sock:/var/run/docker.sock |
| 99 | + env: |
| 100 | + MISE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + OPENSHELL_IMAGE_TAG: ${{ inputs['image-tag'] }} |
| 102 | + steps: |
| 103 | + - uses: actions/checkout@v4 |
| 104 | + with: |
| 105 | + ref: ${{ inputs['checkout-ref'] }} |
| 106 | + |
| 107 | + - name: Mark workspace safe for git |
| 108 | + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 109 | + |
| 110 | + - name: Log in to GHCR |
| 111 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin |
| 112 | + |
| 113 | + - name: Install tools |
| 114 | + run: mise install --locked |
| 115 | + |
| 116 | + - name: Install zstd |
| 117 | + run: apt-get update && apt-get install -y --no-install-recommends zstd && rm -rf /var/lib/apt/lists/* |
| 118 | + |
| 119 | + - name: Build base rootfs tarball |
| 120 | + run: | |
| 121 | + set -euo pipefail |
| 122 | + crates/openshell-vm/scripts/build-rootfs.sh \ |
| 123 | + --base \ |
| 124 | + --arch ${{ matrix.guest_arch }} \ |
| 125 | + target/rootfs-build |
| 126 | +
|
| 127 | + mkdir -p target/vm-runtime-compressed |
| 128 | + tar -C target/rootfs-build -cf - . \ |
| 129 | + | zstd -19 -T0 -o target/vm-runtime-compressed/rootfs.tar.zst |
| 130 | +
|
| 131 | + - name: Upload rootfs artifact |
| 132 | + uses: actions/upload-artifact@v4 |
| 133 | + with: |
| 134 | + name: driver-vm-rootfs-${{ matrix.arch }} |
| 135 | + path: target/vm-runtime-compressed/rootfs.tar.zst |
| 136 | + retention-days: 1 |
| 137 | + |
| 138 | + build-driver-vm-linux: |
| 139 | + name: Build Driver VM (Linux ${{ matrix.arch }}) |
| 140 | + needs: [download-kernel-runtime, build-rootfs] |
| 141 | + strategy: |
| 142 | + matrix: |
| 143 | + include: |
| 144 | + - arch: arm64 |
| 145 | + runner: build-arm64 |
| 146 | + target: aarch64-unknown-linux-gnu |
| 147 | + platform: linux-aarch64 |
| 148 | + - arch: amd64 |
| 149 | + runner: build-amd64 |
| 150 | + target: x86_64-unknown-linux-gnu |
| 151 | + platform: linux-x86_64 |
| 152 | + runs-on: ${{ matrix.runner }} |
| 153 | + timeout-minutes: 30 |
| 154 | + container: |
| 155 | + image: ghcr.io/nvidia/openshell/ci:latest |
| 156 | + credentials: |
| 157 | + username: ${{ github.actor }} |
| 158 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 159 | + options: --privileged |
| 160 | + env: |
| 161 | + MISE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 162 | + SCCACHE_MEMCACHED_ENDPOINT: ${{ vars.SCCACHE_MEMCACHED_ENDPOINT }} |
| 163 | + OPENSHELL_IMAGE_TAG: ${{ inputs['image-tag'] }} |
| 164 | + steps: |
| 165 | + - uses: actions/checkout@v4 |
| 166 | + with: |
| 167 | + ref: ${{ inputs['checkout-ref'] }} |
| 168 | + fetch-depth: 0 |
| 169 | + |
| 170 | + - name: Mark workspace safe for git |
| 171 | + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 172 | + |
| 173 | + - name: Fetch tags |
| 174 | + run: git fetch --tags --force |
| 175 | + |
| 176 | + - name: Install tools |
| 177 | + run: mise install --locked |
| 178 | + |
| 179 | + - name: Cache Rust target and registry |
| 180 | + uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2 |
| 181 | + with: |
| 182 | + shared-key: driver-vm-linux-${{ matrix.arch }} |
| 183 | + cache-directories: .cache/sccache |
| 184 | + cache-targets: "true" |
| 185 | + |
| 186 | + - name: Install zstd |
| 187 | + run: apt-get update && apt-get install -y --no-install-recommends zstd && rm -rf /var/lib/apt/lists/* |
| 188 | + |
| 189 | + - name: Download kernel runtime tarball |
| 190 | + uses: actions/download-artifact@v4 |
| 191 | + with: |
| 192 | + name: driver-vm-kernel-runtime-tarballs |
| 193 | + path: runtime-download/ |
| 194 | + |
| 195 | + - name: Download rootfs tarball |
| 196 | + uses: actions/download-artifact@v4 |
| 197 | + with: |
| 198 | + name: driver-vm-rootfs-${{ matrix.arch }} |
| 199 | + path: rootfs-download/ |
| 200 | + |
| 201 | + - name: Stage compressed runtime for embedding |
| 202 | + run: | |
| 203 | + set -euo pipefail |
| 204 | + COMPRESSED_DIR="${PWD}/target/vm-runtime-compressed" |
| 205 | + mkdir -p "$COMPRESSED_DIR" |
| 206 | +
|
| 207 | + EXTRACT_DIR=$(mktemp -d) |
| 208 | + zstd -d "runtime-download/vm-runtime-${{ matrix.platform }}.tar.zst" --stdout \ |
| 209 | + | tar -xf - -C "$EXTRACT_DIR" |
| 210 | +
|
| 211 | + for file in "$EXTRACT_DIR"/*; do |
| 212 | + [ -f "$file" ] || continue |
| 213 | + name=$(basename "$file") |
| 214 | + [ "$name" = "provenance.json" ] && continue |
| 215 | + zstd -19 -f -q -T0 -o "${COMPRESSED_DIR}/${name}.zst" "$file" |
| 216 | + done |
| 217 | +
|
| 218 | + cp rootfs-download/rootfs.tar.zst "${COMPRESSED_DIR}/rootfs.tar.zst" |
| 219 | + ls -lah "$COMPRESSED_DIR" |
| 220 | +
|
| 221 | + - name: Scope workspace to driver-vm crates |
| 222 | + run: | |
| 223 | + set -euo pipefail |
| 224 | + sed -i 's|members = \["crates/\*"\]|members = ["crates/openshell-driver-vm", "crates/openshell-core"]|' Cargo.toml |
| 225 | +
|
| 226 | + - name: Patch workspace version |
| 227 | + if: ${{ inputs['cargo-version'] != '' }} |
| 228 | + run: | |
| 229 | + set -euo pipefail |
| 230 | + sed -i -E '/^\[workspace\.package\]/,/^\[/{s/^version[[:space:]]*=[[:space:]]*".*"/version = "'"${{ inputs['cargo-version'] }}"'"/}' Cargo.toml |
| 231 | +
|
| 232 | + - name: Build openshell-driver-vm |
| 233 | + run: | |
| 234 | + set -euo pipefail |
| 235 | + OPENSHELL_VM_RUNTIME_COMPRESSED_DIR="${PWD}/target/vm-runtime-compressed" \ |
| 236 | + mise x -- cargo build --release -p openshell-driver-vm |
| 237 | +
|
| 238 | + - name: sccache stats |
| 239 | + if: always() |
| 240 | + run: mise x -- sccache --show-stats |
| 241 | + |
| 242 | + - name: Package binary |
| 243 | + run: | |
| 244 | + set -euo pipefail |
| 245 | + mkdir -p artifacts |
| 246 | + tar -czf "artifacts/openshell-driver-vm-${{ matrix.target }}.tar.gz" \ |
| 247 | + -C target/release openshell-driver-vm |
| 248 | +
|
| 249 | + - name: Upload artifact |
| 250 | + uses: actions/upload-artifact@v4 |
| 251 | + with: |
| 252 | + name: driver-vm-linux-${{ matrix.arch }} |
| 253 | + path: artifacts/*.tar.gz |
| 254 | + retention-days: 5 |
0 commit comments