Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
"macadam.factory.machine.image-path": {
"type": "string",
"format": "file",
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"default": "",
"description": "Image Path"
},
"macadam.factory.machine.ssh-identity-path": {
"type": "string",
"format": "file",
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"default": "",
"description": "Ssh Identity Path"
},
Expand All @@ -34,7 +34,7 @@
"default": "HOST_HALF_CPU_CORES",
"minimum": 1,
"maximum": "HOST_TOTAL_CPU",
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"description": "CPU(s)"
},
"macadam.factory.machine.memory": {
Expand All @@ -43,7 +43,7 @@
"minimum": 1000000000,
"default": 4000000000,
"maximum": "HOST_TOTAL_MEMORY",
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"step": 500000000,
"description": "Memory"
},
Expand All @@ -54,14 +54,14 @@
"minimum": 10000000000,
"maximum": "HOST_TOTAL_DISKSIZE",
"step": 500000000,
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"description": "Disk size"
},
"macadam.factory.machine.win.provider": {
"type": "string",
"default": "wsl",
"enum": ["wsl", "hyperv"],
"scope": "ContainerProviderConnectionFactory",
"scope": "VmProviderConnectionFactory",
"description": "Provider Type",
"when": "macadam.wslHypervEnabled"
}
Expand All @@ -80,7 +80,6 @@
"watch": "vite build -w"
},
"dependencies": {
"@podman-desktop/api": "^1.16.0",
"compare-versions": "^6.1.1",
"semver": "^7.6.0",
"ssh2": "^1.16.0"
Expand Down
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 27 additions & 23 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
***********************************************************************/


import { dirname } from 'node:path';

import * as extensionApi from '@podman-desktop/api';

import { LoggerDelegator } from './logger';
Expand Down Expand Up @@ -119,32 +121,32 @@ async function timeout(time: number): Promise<void> {
}

async function getJSONMachineList(): Promise<MachineJSONListOutput> {
const containerMachineProviders: (string | undefined)[] = [];
const vmMachineProviders: (string | undefined)[] = [];
let hypervEnabled = false;
if (await isWSLEnabled()) {
wslEnabled = true;
containerMachineProviders.push('wsl');
vmMachineProviders.push('wsl');
} else {
wslEnabled = false;
}

if (await isHyperVEnabled()) {
hypervEnabled = true;
containerMachineProviders.push('hyperv');
vmMachineProviders.push('hyperv');
}
// update context "wsl-hyperv enabled" value
updateWSLHyperVEnabledContextValue(wslEnabled && hypervEnabled);

if (containerMachineProviders.length === 0) {
// in all other cases we set undefined so that it executes normally by using the default container provider
containerMachineProviders.push(undefined);
if (vmMachineProviders.length === 0) {
// in all other cases we set undefined so that it executes normally by using the default vm provider
vmMachineProviders.push(undefined);
}

const list: MachineJSON[] = [];
let error = '';

try {
for (const provider of containerMachineProviders) {
for (const provider of vmMachineProviders) {
const machineListOutput = await getJSONMachineListByProvider(provider);
list.push(...machineListOutput.list);
if (machineListOutput.error && machineListOutput.error.trim() !== '') {
Expand All @@ -158,8 +160,8 @@ async function getJSONMachineList(): Promise<MachineJSONListOutput> {
return { list, error };
}

export async function getJSONMachineListByProvider(containerMachineProvider?: string): Promise<MachineJSONListOutput> {
const { stdout, stderr } = await execMacadam(['list'], containerMachineProvider);
export async function getJSONMachineListByProvider(vmMachineProvider?: string): Promise<MachineJSONListOutput> {
const { stdout, stderr } = await execMacadam(['list'], vmMachineProvider);
return {
list: stdout ? JSON.parse(stdout) as MachineJSON[] : [],
error: stderr ,
Expand All @@ -177,8 +179,13 @@ async function startMachine(
const startTime = performance.now();

try {
const containersHelperBinaryDir = dirname((await macadam.getBinaryInfo()).path);
await execMacadam(['start'], machineInfo.vmType, {
logger: new LoggerDelegator(context, logger),
env: {
// we consider vfkit and gvproxy are installed in the same dir as macadam
'CONTAINERS_HELPER_BINARY_DIR': containersHelperBinaryDir,
},
});
provider.updateStatus('started');
} catch (err) {
Expand Down Expand Up @@ -242,30 +249,23 @@ async function registerProviderFor(
const providerConnectionShellAccess = new ProviderConnectionShellAccessImpl(machineInfo);
context.subscriptions.push(providerConnectionShellAccess);

// we are not really working with a containerProviderConnection of type podman
// however it offers most of the things we would need, so it is good for a POC
const containerProviderConnection: extensionApi.ContainerProviderConnection = {
const vmProviderConnection: extensionApi.VmProviderConnection = {
name: 'macadam',
displayName: 'Macadam',
type: 'podman',
status: () => macadamMachinesStatuses.get(machineInfo.image) ?? 'unknown',
shellAccess: providerConnectionShellAccess,
lifecycle,
endpoint: {
socketPath: 'no-socket',
},
};

const disposable = provider.registerContainerProviderConnection(containerProviderConnection);
const disposable = provider.registerVmProviderConnection(vmProviderConnection);
provider.updateStatus('ready');

// get configuration for this connection
const containerConfiguration = extensionApi.configuration.getConfiguration('macadam', containerProviderConnection);
const vmConfiguration = extensionApi.configuration.getConfiguration('macadam', vmProviderConnection);

// Set values for the machine
await containerConfiguration.update('machine.cpus', machineInfo.cpus);
await containerConfiguration.update('machine.memory', machineInfo.memory);
await containerConfiguration.update('machine.diskSize', machineInfo.diskSize);
await vmConfiguration.update('machine.cpus', machineInfo.cpus);
await vmConfiguration.update('machine.memory', machineInfo.memory);
await vmConfiguration.update('machine.diskSize', machineInfo.diskSize);

currentConnections.set(machineInfo.image, disposable);
/*storedExtensionContext?.subscriptions.push(disposable); */
Expand Down Expand Up @@ -433,7 +433,7 @@ async function createProvider(
extensionContext.subscriptions.push(provider);

// enable factory
provider.setContainerProviderConnectionFactory({
provider.setVmProviderConnectionFactory({
create: (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
params: { [key: string]: any },
Expand Down Expand Up @@ -499,9 +499,13 @@ async function createVM(

const startTime = performance.now();
try {
const containersHelperBinaryDir = dirname((await macadam.getBinaryInfo()).path);
await execMacadam(parameters, provider, {
logger,
token,
env: {
'CONTAINERS_HELPER_BINARY_DIR': containersHelperBinaryDir,
},
});
} catch (error) {
telemetryRecords.error = error;
Expand Down
Loading