A Docker-like CLI and HTTP API for managing headless VMs

Add Fedora CoreOS image URL handling and tests

+91 -5
+6 -1
deno.lock
··· 15 15 "jsr:@es-toolkit/es-toolkit@^1.41.0": "1.41.0", 16 16 "jsr:@soapbox/kysely-deno-sqlite@^2.2.0": "2.2.0", 17 17 "jsr:@std/assert@0.217": "0.217.0", 18 + "jsr:@std/assert@1": "1.0.15", 18 19 "jsr:@std/assert@~1.0.6": "1.0.15", 19 20 "jsr:@std/bytes@^1.0.5": "1.0.6", 20 21 "jsr:@std/collections@^1.1.3": "1.1.3", ··· 24 25 "jsr:@std/fmt@~1.0.2": "1.0.8", 25 26 "jsr:@std/fs@1": "1.0.19", 26 27 "jsr:@std/internal@^1.0.10": "1.0.12", 28 + "jsr:@std/internal@^1.0.12": "1.0.12", 27 29 "jsr:@std/internal@^1.0.9": "1.0.12", 28 30 "jsr:@std/io@~0.225.2": "0.225.2", 29 31 "jsr:@std/path@0.217": "0.217.0", ··· 121 123 "integrity": "c98e279362ca6982d5285c3b89517b757c1e3477ee9f14eb2fdf80a45aaa9642" 122 124 }, 123 125 "@std/assert@1.0.15": { 124 - "integrity": "d64018e951dbdfab9777335ecdb000c0b4e3df036984083be219ce5941e4703b" 126 + "integrity": "d64018e951dbdfab9777335ecdb000c0b4e3df036984083be219ce5941e4703b", 127 + "dependencies": [ 128 + "jsr:@std/internal@^1.0.12" 129 + ] 125 130 }, 126 131 "@std/bytes@1.0.6": { 127 132 "integrity": "f6ac6adbd8ccd99314045f5703e23af0a68d7f7e58364b47d2c7f408aeb5820a"
+6 -3
src/constants.ts
··· 5 5 export const CONFIG_FILE_NAME: string = "vmconfig.toml"; 6 6 export const IMAGE_DIR: string = `${CONFIG_DIR}/images`; 7 7 export const VOLUME_DIR: string = `${CONFIG_DIR}/volumes`; 8 - export const UBUNTU_ISO_URL: string = Deno.build.arch === "aarch64" 9 - ? "https://cdimage.ubuntu.com/releases/24.04/release/ubuntu-24.04.3-live-server-arm64.iso" 10 - : "https://releases.ubuntu.com/24.04.3/ubuntu-24.04.3-live-server-amd64.iso"; 8 + export const UBUNTU_ISO_URL: string = 9 + Deno.build.arch === "aarch64" 10 + ? "https://cdimage.ubuntu.com/releases/24.04/release/ubuntu-24.04.3-live-server-arm64.iso" 11 + : "https://releases.ubuntu.com/24.04.3/ubuntu-24.04.3-live-server-amd64.iso"; 12 + export const FEDORA_COREOS_DEFAULT_VERSION: string = "43.20251024.3.0"; 13 + export const FEDORA_COREOS_IMG_URL: string = `https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/${FEDORA_COREOS_DEFAULT_VERSION}/${Deno.build.arch}/fedora-coreos-${FEDORA_COREOS_DEFAULT_VERSION}-qemu.${Deno.build.arch}.qcow2.xz`;
+27 -1
src/utils.ts
··· 3 3 import chalk from "chalk"; 4 4 import { Data, Effect, pipe } from "effect"; 5 5 import Moniker from "moniker"; 6 - import { EMPTY_DISK_THRESHOLD_KB, LOGS_DIR } from "./constants.ts"; 6 + import { 7 + EMPTY_DISK_THRESHOLD_KB, 8 + FEDORA_COREOS_DEFAULT_VERSION, 9 + FEDORA_COREOS_IMG_URL, 10 + LOGS_DIR, 11 + } from "./constants.ts"; 7 12 import type { Image } from "./db.ts"; 8 13 import { generateRandomMacAddress } from "./network.ts"; 9 14 import { saveInstanceState, updateInstanceState } from "./state.ts"; ··· 535 540 try: () => Deno.stat(path), 536 541 catch: (error) => new NoSuchFileError({ cause: String(error) }), 537 542 }); 543 + 544 + export const constructCoreOSImageURL = ( 545 + image: string 546 + ): Effect.Effect<string, InvalidImageNameError, never> => { 547 + // detect with regex if image matches coreos pattern: fedora-coreos or fedora-coreos-<version> or coreos or coreos-<version> 548 + const coreosRegex = /^(fedora-coreos|coreos)(-(\d+\.\d+\.\d+\.\d+))?$/; 549 + const match = image.match(coreosRegex); 550 + if (match) { 551 + const version = match[3] || FEDORA_COREOS_DEFAULT_VERSION; 552 + return Effect.succeed( 553 + FEDORA_COREOS_IMG_URL.replaceAll(FEDORA_COREOS_DEFAULT_VERSION, version) 554 + ); 555 + } 556 + 557 + return Effect.fail( 558 + new InvalidImageNameError({ 559 + image, 560 + cause: "Image name does not match CoreOS naming conventions.", 561 + }) 562 + ); 563 + };
+52
src/utils_test.ts
··· 1 + import { assertEquals } from "@std/assert"; 2 + import { Effect, pipe } from "effect"; 3 + import { FEDORA_COREOS_IMG_URL } from "./constants.ts"; 4 + import { constructCoreOSImageURL } from "./utils.ts"; 5 + 6 + Deno.test("Test Default Fedora CoreOS Image URL", () => { 7 + const url = Effect.runSync( 8 + pipe( 9 + constructCoreOSImageURL("fedora-coreos"), 10 + Effect.catchAll((_error) => Effect.succeed(null as string | null)) 11 + ) 12 + ); 13 + 14 + assertEquals(url, FEDORA_COREOS_IMG_URL); 15 + }); 16 + 17 + Deno.test("Test Default Fedora CoreOS Image URL", () => { 18 + const url = Effect.runSync( 19 + pipe( 20 + constructCoreOSImageURL("coreos"), 21 + Effect.catchAll((_error) => Effect.succeed(null as string | null)) 22 + ) 23 + ); 24 + 25 + assertEquals(url, FEDORA_COREOS_IMG_URL); 26 + }); 27 + 28 + Deno.test("Test Specific Fedora CoreOS Version", () => { 29 + const url = Effect.runSync( 30 + pipe( 31 + constructCoreOSImageURL("fedora-coreos-43.20251024.2.0"), 32 + Effect.catchAll((_error) => Effect.succeed(null as string | null)) 33 + ) 34 + ); 35 + 36 + assertEquals( 37 + url, 38 + "https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/43.20251024.2.0/" + 39 + `${Deno.build.arch}/fedora-coreos-43.20251024.2.0-qemu.${Deno.build.arch}.qcow2.xz` 40 + ); 41 + }); 42 + 43 + Deno.test("Test invalid Fedora CoreOS Image Name", () => { 44 + const url = Effect.runSync( 45 + pipe( 46 + constructCoreOSImageURL("fedora-coreos-latest"), 47 + Effect.catchAll((_error) => Effect.succeed(null as string | null)) 48 + ) 49 + ); 50 + 51 + assertEquals(url, null); 52 + });