diff --git a/packages/backend/src/managers/applicationManager.ts b/packages/backend/src/managers/applicationManager.ts index 72d24d420..0d8c5f473 100644 --- a/packages/backend/src/managers/applicationManager.ts +++ b/packages/backend/src/managers/applicationManager.ts @@ -20,13 +20,13 @@ import type { Recipe } from '@shared/src/models/IRecipe'; import type { GitCloneInfo, GitManager } from './gitManager'; import fs from 'fs'; import * as path from 'node:path'; -import { type PodCreatePortOptions, containerEngine } from '@podman-desktop/api'; +import { type PodCreatePortOptions, containerEngine, HostConfig } from '@podman-desktop/api'; import type { RecipeStatusRegistry } from '../registries/RecipeStatusRegistry'; import type { AIConfig, AIConfigFile, ContainerConfig } from '../models/AIConfig'; import { parseYaml } from '../models/AIConfig'; import type { Task } from '@shared/src/models/ITask'; import { RecipeStatusUtils } from '../utils/recipeStatusUtils'; -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'; @@ -214,26 +214,27 @@ export class ApplicationManager { 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', + BindOptions: { + Propagation: 'rprivate', + }, + ReadOnly: false, }, ], - }; + } 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) { @@ -241,35 +242,24 @@ export class ApplicationManager { envs = [`MODEL_ENDPOINT=${endPoint}`]; } } - const createdContainer = await containerEngine.createContainer(podInfo.engineId, { - Image: image.id, - Detach: true, - HostConfig: hostConfig, - Env: envs, - start: false, - }); - - // 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 }, - ); + const podifiedName = this.getRandomName(`${image.appName}-podified`); + try { + await containerEngine.createContainer(podInfo.engineId, { + Image: image.id, + Env: envs, + name: podifiedName, + pod: podInfo.Id, + HostConfig: hostConfig, + }); 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}`); + } catch(e) { + console.error(e) } + }), ); return containers; diff --git a/packages/backend/src/utils/pathUtils.ts b/packages/backend/src/utils/pathUtils.ts index f3fb60d6b..a1637a087 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; +}