From 0f15c4032ea0a6e0c56dbd18e8f0049ee413feea Mon Sep 17 00:00:00 2001 From: Charlie Drage Date: Wed, 10 Jan 2024 15:14:45 -0500 Subject: [PATCH 1/2] test --- package.json | 8 +++ src/extension.ts | 127 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 132 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index c2b58f93..940d6254 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,10 @@ { "command": "bootc.image.build", "title": "Build Disk Image" + }, + { + "command": "bootc.vfkit", + "title": "Launch VM" } ] }, @@ -24,6 +28,10 @@ { "command": "bootc.image.build", "title": "Build bootable disk image" + }, + { + "command": "bootc.vfkit", + "title": "Launch VM" } ], "icons": { diff --git a/src/extension.ts b/src/extension.ts index 220dd9fe..d44dde3e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -25,16 +25,23 @@ import { resolve } from 'node:path'; let bootc: BootC | undefined; const bootcImageBuilderContainerName = '-bootc-image-builder'; -const bootcImageBuilderName = 'quay.io/centos-bootc/bootc-image-builder'; +const bootcImageBuilderName = 'quay.io/centos-bootc/bootc-image-builder:latest-1704827181'; let diskImageBuildingName: string; export async function activate(extensionContext: ExtensionContext): Promise { bootc = new BootC(extensionContext); await bootc?.activate(); + + + extensionContext.subscriptions.push( + // Create another command that will simply launch vfkit + extensionApi.commands.registerCommand('bootc.vfkit', async () => { + launchVfkit('/Users/cdrage/bootc/image/disk.raw'); + }), extensionApi.commands.registerCommand('bootc.image.build', async image => { - const selectedType = await extensionApi.window.showQuickPick(['qcow2', 'ami', 'iso'], { + const selectedType = await extensionApi.window.showQuickPick(['qcow2', 'ami', 'raw', 'iso'], { placeHolder: 'Select image type', }); if (!selectedType) { @@ -51,7 +58,18 @@ export async function activate(extensionContext: ExtensionContext): Promise setTimeout(r, 1000)); } + + successful = true; fs.writeFileSync(logPath, logData, {flag: 'w'}); } catch (error) { @@ -124,14 +148,104 @@ export async function activate(extensionContext: ExtensionContext): Promise { + const command = 'qemu-img'; + const args = ['convert', '-f', 'qcow2', '-O', 'raw', imagePath, imagePathOutput]; + console.log(args); + try { + await extensionApi.process.exec(command, args); + } catch (error) { + console.error(error); + await extensionApi.window.showErrorMessage(`Unable to convert ${imagePath} to raw: ${error}`); + } +} + +/* + +Use this command with process.exec to launch a passed in image path file within vfkit +vfkit --cpus 2 --memory 2048 \ + --bootloader efi,variable-store=./efi-variable-store,create \ + --device virtio-blk,path=bootc.img \ + --device virtio-serial,stdio \ + --device virtio-net,nat,mac=72:20:43:d4:38:62 \ + --device virtio-rng \ + --device virtio-input,keyboard \ + --device virtio-input,pointing \ + --device virtio-gpu,width=1920,height=1080 \ + --gui +*/ +async function launchVfkit(imagePath: string): Promise { + // take image path replace last part (disk.qcow2 / disk.raw) with vfkit-serial.log + // this will be the log file path + const logFilePath = imagePath.replace(/[^/]+$/, '') + 'vfkit-serial.log'; + const command = 'vfkit'; + const args = [ + '--cpus', + '2', + '--memory', + '2048', + '--bootloader', + 'efi,variable-store=./efi-variable-store,create', + '--device', + 'virtio-blk,path=' + imagePath, + '--device', + 'virtio-serial,logFilePath=' + logFilePath, + '--device', + 'virtio-net,nat,mac=72:20:43:d4:38:62', + '--device', + 'virtio-rng', + '--device', + 'virtio-input,keyboard', + '--device', + 'virtio-input,pointing', + '--device', + 'virtio-gpu,width=1920,height=1080', + '--gui', + ]; + console.log(args); + try { + await extensionApi.process.exec(command, args); + } catch (error) { + console.error(error); + await extensionApi.window.showErrorMessage(`Unable to launch ${imagePath} with vfkit: ${error}`); + } +} + async function removePreviousBuildImage(image) { // TODO: Ignore if the container doesn't exist try { @@ -170,6 +284,13 @@ async function pullBootcImageBuilderImage() { } async function createImage(image, type, folder: string) { + + // TEMPORARY UNTIL PR IS MERGED IN BOOTC-IMAGE-BUILDER + // If type is raw, change it to ami + if (type === 'raw') { + type = 'ami'; + } + console.log('Building ' + diskImageBuildingName + ' to ' + type); /* From 267781c994561e3ce75e77636a06c02a487e742b Mon Sep 17 00:00:00 2001 From: Charlie Drage Date: Wed, 10 Jan 2024 15:42:25 -0500 Subject: [PATCH 2/2] add vfkit support Signed-off-by: Charlie Drage --- src/extension.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index d44dde3e..3acb0226 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -25,7 +25,7 @@ import { resolve } from 'node:path'; let bootc: BootC | undefined; const bootcImageBuilderContainerName = '-bootc-image-builder'; -const bootcImageBuilderName = 'quay.io/centos-bootc/bootc-image-builder:latest-1704827181'; +const bootcImageBuilderName = 'quay.io/centos-bootc/bootc-image-builder'; let diskImageBuildingName: string; export async function activate(extensionContext: ExtensionContext): Promise { @@ -37,6 +37,8 @@ export async function activate(extensionContext: ExtensionContext): Promise { launchVfkit('/Users/cdrage/bootc/image/disk.raw'); }), @@ -153,7 +155,7 @@ export async function activate(extensionContext: ExtensionContext): Promise