Skip to content

Commit

Permalink
feat: generated images should have a specific icon (#248)
Browse files Browse the repository at this point in the history
Fixes #162

Signed-off-by: Jeff MAURY <[email protected]>
  • Loading branch information
jeffmaury authored Feb 9, 2024
1 parent d23e549 commit 14a38ce
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
"when": "ai-studio-model-id in containerLabelKeys",
"icon": "${brain-icon}"
}
],
"icons/image": [
{
"when": "ai-studio-recipe-id in imageLabelKeys",
"icon": "${brain-icon}"
}
]
}
},
Expand Down
26 changes: 19 additions & 7 deletions packages/backend/src/managers/applicationManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ import { goarch } from '../utils/arch';
import * as utils from '../utils/utils';
import type { Webview, TelemetryLogger } from '@podman-desktop/api';
import type { CatalogManager } from './catalogManager';
import { LABEL_RECIPE_ID } from '@shared/src/StudioAPI';

const mocks = vi.hoisted(() => {
return {
parseYamlFileMock: vi.fn(),
builImageMock: vi.fn(),
buildImageMock: vi.fn(),
listImagesMock: vi.fn(),
getImageInspectMock: vi.fn(),
createPodMock: vi.fn(),
Expand All @@ -56,7 +57,7 @@ vi.mock('../models/AIConfig', () => ({
}));
vi.mock('@podman-desktop/api', () => ({
containerEngine: {
buildImage: mocks.builImageMock,
buildImage: mocks.buildImageMock,
listImages: mocks.listImagesMock,
getImageInspect: mocks.getImageInspectMock,
createPod: mocks.createPodMock,
Expand Down Expand Up @@ -145,7 +146,7 @@ describe('pullApplication', () => {
Running: true,
},
});
mocks.builImageMock.mockResolvedValue(undefined);
mocks.buildImageMock.mockResolvedValue(undefined);
mocks.listImagesMock.mockResolvedValue([
{
RepoTags: ['container1:latest'],
Expand Down Expand Up @@ -225,7 +226,18 @@ describe('pullApplication', () => {
expect(cloneRepositoryMock).toHaveBeenNthCalledWith(1, gitCloneOptions);
}
expect(doDownloadModelWrapperSpy).toHaveBeenCalledOnce();
expect(mocks.builImageMock).toHaveBeenCalledOnce();
expect(mocks.buildImageMock).toHaveBeenCalledOnce();
expect(mocks.buildImageMock).toHaveBeenCalledWith(
`${gitCloneOptions.targetDirectory}${path.sep}contextdir1`,
expect.anything(),
{
containerFile: 'Containerfile',
tag: 'container1:latest',
labels: {
[LABEL_RECIPE_ID]: 'recipe1',
},
},
);
expect(mocks.logUsageMock).toHaveBeenNthCalledWith(1, 'model.download', {
'model.id': 'model1',
durationSeconds: 99,
Expand Down Expand Up @@ -616,7 +628,7 @@ describe('buildImages', () => {
});
test('setTaskState should be called with error if buildImage executon fails', async () => {
vi.spyOn(fs, 'existsSync').mockReturnValue(true);
mocks.builImageMock.mockRejectedValue('error');
mocks.buildImageMock.mockRejectedValue('error');
mocks.listImagesMock.mockRejectedValue([]);
await expect(manager.buildImages(containers, 'config', taskUtils)).rejects.toThrow(
'Something went wrong while building the image: error',
Expand All @@ -625,7 +637,7 @@ describe('buildImages', () => {
});
test('setTaskState should be called with error if unable to find the image after built', async () => {
vi.spyOn(fs, 'existsSync').mockReturnValue(true);
mocks.builImageMock.mockResolvedValue({});
mocks.buildImageMock.mockResolvedValue({});
mocks.listImagesMock.mockResolvedValue([]);
await expect(manager.buildImages(containers, 'config', taskUtils)).rejects.toThrow(
'no image found for container1:latest',
Expand All @@ -634,7 +646,7 @@ describe('buildImages', () => {
});
test('succeed if building image do not fail', async () => {
vi.spyOn(fs, 'existsSync').mockReturnValue(true);
mocks.builImageMock.mockResolvedValue({});
mocks.buildImageMock.mockResolvedValue({});
mocks.listImagesMock.mockResolvedValue([
{
RepoTags: ['container1:latest'],
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/managers/applicationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type { ModelsManager } from './modelsManager';
import { getPortsInfo } from '../utils/ports';
import { goarch } from '../utils/arch';
import { getDurationSecondsSince, isEndpointAlive, timeout } from '../utils/utils';
import { LABEL_RECIPE_ID } from '@shared/src/StudioAPI';

export const LABEL_RECIPE_ID = 'ai-studio-recipe-id';

Expand Down Expand Up @@ -375,6 +376,9 @@ export class ApplicationManager {
const buildOptions = {
containerFile: container.containerfile,
tag: `${container.name}:latest`,
labels: {
[LABEL_RECIPE_ID]: taskUtil.toRecipeStatus().recipeId,
},
};

return containerEngine
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/StudioAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ export abstract class StudioAPI {
abstract telemetryLogUsage(eventName: string, data?: Record<string, unknown | TelemetryTrustedValue>): Promise<void>;
abstract telemetryLogError(eventName: string, data?: Record<string, unknown | TelemetryTrustedValue>): Promise<void>;
}

export const LABEL_RECIPE_ID = 'ai-studio-recipe-id';

0 comments on commit 14a38ce

Please sign in to comment.