From f856a69312dbefe1602df5a4a8b944d18220c4e5 Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Thu, 3 Oct 2024 16:13:21 -0700 Subject: [PATCH] Install socket_vmnet 1.1.5 from upstream release The only thing we still use from the lima-and-qemu tarball is QEMU itself. Signed-off-by: Jan Dubois --- .github/actions/spelling/expect.txt | 1 + pkg/rancher-desktop/assets/dependencies.yaml | 1 + scripts/dependencies/lima.ts | 45 ++++++++++++++++++-- scripts/dependencies/tools.ts | 22 +--------- scripts/lib/dependencies.ts | 23 ++++++++++ scripts/postinstall.ts | 3 +- scripts/rddepman.ts | 3 +- 7 files changed, 72 insertions(+), 26 deletions(-) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 3a0d8db1705..c5131e494b1 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -840,6 +840,7 @@ varnamelen vcenter vcpus vcs +vde ventura VERSIONSTRING vertificate diff --git a/pkg/rancher-desktop/assets/dependencies.yaml b/pkg/rancher-desktop/assets/dependencies.yaml index 414136ae43a..fe668575469 100644 --- a/pkg/rancher-desktop/assets/dependencies.yaml +++ b/pkg/rancher-desktop/assets/dependencies.yaml @@ -1,5 +1,6 @@ lima: 0.21.0.rd2 limaAndQemu: 1.31.3 +socketVMNet: 1.1.5 alpineLimaISO: isoVersion: 0.2.39.rd4 alpineVersion: 3.20.0 diff --git a/scripts/dependencies/lima.ts b/scripts/dependencies/lima.ts index 216bef90511..a9f4540e20a 100644 --- a/scripts/dependencies/lima.ts +++ b/scripts/dependencies/lima.ts @@ -7,10 +7,10 @@ import path from 'path'; import semver from 'semver'; -import { download, getResource } from '../lib/download'; +import { download, downloadTarGZ, getResource } from '../lib/download'; import { - DownloadContext, Dependency, AlpineLimaISOVersion, getOctokit, GitHubDependency, getPublishedReleaseTagNames, GitHubRelease, + DownloadContext, Dependency, AlpineLimaISOVersion, findChecksum, getOctokit, GitHubDependency, getPublishedReleaseTagNames, GitHubRelease, } from 'scripts/lib/dependencies'; /** @@ -165,7 +165,8 @@ export class LimaAndQemu implements Dependency, GitHubDependency { }); await fs.promises.mkdir(limaDir, { recursive: true }); - const child = childProcess.spawn('/usr/bin/tar', ['-xf', tarPath, '--exclude', 'lima*'], + const child = childProcess.spawn('/usr/bin/tar', + ['-xf', tarPath, '--exclude', 'lima*', '--exclude', 'vde/bin', '--exclude', 'vde/lib', '--exclude', 'socket_vmnet'], { cwd: limaDir, stdio: 'inherit' }); await new Promise((resolve, reject) => { @@ -201,6 +202,44 @@ export class LimaAndQemu implements Dependency, GitHubDependency { } } +export class SocketVMNet implements Dependency, GitHubDependency { + name = 'socketVMNet'; + githubOwner = 'lima-vm'; + githubRepo = 'socket_vmnet'; + + async download(context: DownloadContext): Promise { + const arch = context.isM1 ? 'arm64' : 'x86_64'; + const baseURL = `https://github.com/${ this.githubOwner }/${ this.githubRepo }/releases/download/v${ context.versions.socketVMNet }`; + const archiveName = `socket_vmnet-${ context.versions.socketVMNet }-${ arch }.tar.gz`; + const expectedChecksum = await findChecksum(`${ baseURL }/SHA256SUMS`, archiveName); + + await downloadTarGZ(`${ baseURL }/${ archiveName }`, + path.join(context.resourcesDir, context.platform, 'lima', 'socket_vmnet', 'bin', 'socket_vmnet'), + { expectedChecksum, entryName: './opt/socket_vmnet/bin/socket_vmnet' }); + } + + async getAvailableVersions(): Promise { + const tagNames = await getPublishedReleaseTagNames(this.githubOwner, this.githubRepo); + + return tagNames.map((tagName: string) => tagName.replace(/^v/, '')); + } + + versionToTagName(version: string): string { + return `v${ version }`; + } + + rcompareVersions(version1: string, version2: string): -1 | 0 | 1 { + const semver1 = semver.coerce(version1); + const semver2 = semver.coerce(version2); + + if (semver1 === null || semver2 === null) { + throw new Error(`One of ${ version1 } and ${ version2 } failed to be coerced to semver`); + } + + return semver.rcompare(semver1, semver2); + } +} + export class AlpineLimaISO implements Dependency, GitHubDependency { name = 'alpineLimaISO'; githubOwner = 'rancher-sandbox'; diff --git a/scripts/dependencies/tools.ts b/scripts/dependencies/tools.ts index 0ee6b290342..59a44eabbb4 100644 --- a/scripts/dependencies/tools.ts +++ b/scripts/dependencies/tools.ts @@ -9,7 +9,7 @@ import { } from '../lib/download'; import { - DownloadContext, Dependency, GitHubDependency, getPublishedReleaseTagNames, getPublishedVersions, + DownloadContext, Dependency, GitHubDependency, findChecksum, getPublishedReleaseTagNames, getPublishedVersions, } from 'scripts/lib/dependencies'; import { simpleSpawn } from 'scripts/simple_process'; @@ -19,26 +19,6 @@ function exeName(context: DownloadContext, name: string) { return `${ name }${ onWindows ? '.exe' : '' }`; } -/** - * Download the given checksum file (which contains multiple checksums) and find - * the correct checksum for the given executable name. - * @param checksumURL The URL to download the checksum from. - * @param executableName The name of the executable expected. - * @returns The checksum. - */ -async function findChecksum(checksumURL: string, executableName: string): Promise { - const allChecksums = await getResource(checksumURL); - const desiredChecksums = allChecksums.split(/\r?\n/).filter(line => line.endsWith(executableName)); - - if (desiredChecksums.length < 1) { - throw new Error(`Couldn't find a matching SHA for [${ executableName }] in [${ allChecksums }]`); - } - if (desiredChecksums.length === 1) { - return desiredChecksums[0].split(/\s+/, 1)[0]; - } - throw new Error(`Matched ${ desiredChecksums.length } hits, not exactly 1, for ${ executableName } in [${ allChecksums }]`); -} - export class KuberlrAndKubectl implements Dependency { name = 'kuberlr'; githubOwner = 'flavio'; diff --git a/scripts/lib/dependencies.ts b/scripts/lib/dependencies.ts index a5c3bd8cfbf..0af8ce08e5e 100644 --- a/scripts/lib/dependencies.ts +++ b/scripts/lib/dependencies.ts @@ -5,6 +5,8 @@ import { Octokit } from 'octokit'; import semver from 'semver'; import YAML from 'yaml'; +import { getResource } from './download'; + export type DependencyPlatform = 'wsl' | 'linux' | 'darwin' | 'win32'; export type Platform = 'linux' | 'darwin' | 'win32'; export type GoPlatform = 'linux' | 'darwin' | 'windows'; @@ -36,6 +38,7 @@ export type AlpineLimaISOVersion = { export type DependencyVersions = { lima: string; limaAndQemu: string; + socketVMNet: string; alpineLimaISO: AlpineLimaISOVersion; WSLDistro: string; kuberlr: string; @@ -59,6 +62,26 @@ export type DependencyVersions = { spinCLI: string; }; +/** + * Download the given checksum file (which contains multiple checksums) and find + * the correct checksum for the given executable name. + * @param checksumURL The URL to download the checksum from. + * @param executableName The name of the executable expected. + * @returns The checksum. + */ +export async function findChecksum(checksumURL: string, executableName: string): Promise { + const allChecksums = await getResource(checksumURL); + const desiredChecksums = allChecksums.split(/\r?\n/).filter(line => line.endsWith(executableName)); + + if (desiredChecksums.length < 1) { + throw new Error(`Couldn't find a matching SHA for [${ executableName }] in [${ allChecksums }]`); + } + if (desiredChecksums.length === 1) { + return desiredChecksums[0].split(/\s+/, 1)[0]; + } + throw new Error(`Matched ${ desiredChecksums.length } hits, not exactly 1, for ${ executableName } in [${ allChecksums }]`); +} + export async function readDependencyVersions(path: string): Promise { const rawContents = await fs.promises.readFile(path, 'utf-8'); diff --git a/scripts/postinstall.ts b/scripts/postinstall.ts index 90a141ddba9..48de7f50553 100644 --- a/scripts/postinstall.ts +++ b/scripts/postinstall.ts @@ -3,7 +3,7 @@ import os from 'os'; import path from 'path'; import * as goUtils from 'scripts/dependencies/go-source'; -import { Lima, LimaAndQemu, AlpineLimaISO } from 'scripts/dependencies/lima'; +import { Lima, LimaAndQemu, SocketVMNet, AlpineLimaISO } from 'scripts/dependencies/lima'; import { MobyOpenAPISpec } from 'scripts/dependencies/moby-openapi'; import { SudoPrompt } from 'scripts/dependencies/sudo-prompt'; import { ExtensionProxyImage, WSLDistroImage } from 'scripts/dependencies/tar-archives'; @@ -49,6 +49,7 @@ const unixDependencies = [ // Dependencies that are specific to macOS hosts. const macOSDependencies = [ + new SocketVMNet(), new SudoPrompt(), ]; diff --git a/scripts/rddepman.ts b/scripts/rddepman.ts index c2facb85008..c1d8c64f481 100644 --- a/scripts/rddepman.ts +++ b/scripts/rddepman.ts @@ -5,7 +5,7 @@ import path from 'path'; import { Octokit } from 'octokit'; -import { Lima, LimaAndQemu, AlpineLimaISO } from 'scripts/dependencies/lima'; +import { Lima, LimaAndQemu, SocketVMNet, AlpineLimaISO } from 'scripts/dependencies/lima'; import { MobyOpenAPISpec } from 'scripts/dependencies/moby-openapi'; import * as tools from 'scripts/dependencies/tools'; import { Wix } from 'scripts/dependencies/wix'; @@ -39,6 +39,7 @@ const dependencies: Dependency[] = [ new tools.ECRCredHelper(), new Lima(), new LimaAndQemu(), + new SocketVMNet(), new AlpineLimaISO(), new WSLDistro(), new Wix(),