diff --git a/packages/backend/src/managers/applicationManager.ts b/packages/backend/src/managers/applicationManager.ts index 7dd31722f..8b0a39d7e 100644 --- a/packages/backend/src/managers/applicationManager.ts +++ b/packages/backend/src/managers/applicationManager.ts @@ -26,11 +26,12 @@ import { type TelemetryLogger, type PodInfo, type Webview, + HostConfig, } from '@podman-desktop/api'; import type { AIConfig, AIConfigFile, ContainerConfig } from '../models/AIConfig'; import { parseYamlFile } from '../models/AIConfig'; import type { Task } from '@shared/src/models/ITask'; -import { getParentDirectory } from '../utils/pathUtils'; +import { getMappedPathInPodmanMachine, getParentDirectory } from '../utils/pathUtils'; import type { ModelInfo } from '@shared/src/models/IModelInfo'; import type { ModelsManager } from './modelsManager'; import { getPortsInfo } from '../utils/ports'; @@ -259,26 +260,24 @@ export class ApplicationManager extends Publisher { const containers: ContainerAttachedInfo[] = []; await Promise.all( images.map(async image => { - let hostConfig: unknown; + let hostConfig: HostConfig; let envs: string[] = []; // if it's a model service we mount the model as a volume if (image.modelService) { const modelName = path.basename(modelPath); + const mappedMountPath = getMappedPathInPodmanMachine(modelPath); hostConfig = { - AutoRemove: true, Mounts: [ { Target: `/${modelName}`, - Source: modelPath, + Source: mappedMountPath, Type: 'bind', + Mode: 'Z', }, ], }; envs = [`MODEL_PATH=/${modelName}`]; } else { - hostConfig = { - AutoRemove: true, - }; // TODO: remove static port const modelService = images.find(image => image.modelService); if (modelService && modelService.ports.length > 0) { @@ -286,35 +285,22 @@ export class ApplicationManager extends Publisher { envs = [`MODEL_ENDPOINT=${endPoint}`]; } } - const createdContainer = await containerEngine.createContainer(podInfo.engineId, { + + const podifiedName = this.getRandomName(`${image.appName}-podified`); + await containerEngine.createContainer(podInfo.engineId, { Image: image.id, + name: podifiedName, Detach: true, HostConfig: hostConfig, Env: envs, start: false, + pod: podInfo.Id, + }); + containers.push({ + name: podifiedName, + modelService: image.modelService, + ports: image.ports, }); - - // now, for each container, put it in the pod - if (createdContainer) { - const podifiedName = this.getRandomName(`${image.appName}-podified`); - await containerEngine.replicatePodmanContainer( - { - id: createdContainer.id, - engineId: podInfo.engineId, - }, - { engineId: podInfo.engineId }, - { pod: podInfo.Id, name: podifiedName }, - ); - containers.push({ - name: podifiedName, - modelService: image.modelService, - ports: image.ports, - }); - // remove the external container - await containerEngine.deleteContainer(podInfo.engineId, createdContainer.id); - } else { - throw new Error(`failed at creating container for image ${image.id}`); - } }), ); return containers; diff --git a/packages/backend/src/utils/pathUtils.ts b/packages/backend/src/utils/pathUtils.ts index f3fb60d6b..bd0111e2f 100644 --- a/packages/backend/src/utils/pathUtils.ts +++ b/packages/backend/src/utils/pathUtils.ts @@ -16,6 +16,7 @@ * SPDX-License-Identifier: Apache-2.0 ***********************************************************************/ +import { env } from '@podman-desktop/api'; import path from 'path'; export function getParentDirectory(filePath: string): string { @@ -25,3 +26,11 @@ export function getParentDirectory(filePath: string): string { // Get the directory name using path.dirname return path.dirname(normalizedPath); } + +export function getMappedPathInPodmanMachine(path: string): string { + if (env.isWindows) { + path = path.replace(':', '').replace(/\\/g, '/').toLowerCase(); + return `/mnt/${path}`; + } + return path; +} \ No newline at end of file