Skip to content

Commit

Permalink
Merge pull request #12 from mlops-club/feature/containerization
Browse files Browse the repository at this point in the history
Enable `bentoml containerize` in the sidebar.
  • Loading branch information
shilongjaycui authored Apr 2, 2024
2 parents 247ef55 + 89197cd commit aa1e088
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bentoml",
"publisher": "mlops-club",
"version": "0.0.7",
"version": "0.0.8",
"displayName": "BentoML",
"icon": "src/resources/bentoml-logo.png",
"author": {
Expand Down Expand Up @@ -91,7 +91,7 @@
},
{
"id": "bentoml-serve",
"name": "Serve"
"name": "Services"
}
]
},
Expand Down Expand Up @@ -161,6 +161,11 @@
"command": "bentoml.serve",
"title": "Serve Model",
"icon": "$(play)"
},
{
"command": "bentoml.containerizeBento",
"title": "Containerize Bento",
"icon": "$(primitive-square)"
}
],
"menus": {
Expand Down Expand Up @@ -221,6 +226,11 @@
"command": "bentoml.serve",
"when": "view == bentoml-serve && viewItem == top-level-bentoml-serve-tree-item",
"group": "inline"
},
{
"command": "bentoml.containerizeBento",
"when": "view == bentoml-bentos && viewItem == top-level-bentoml-bento-tree-item",
"group": "inline"
}
]
}
Expand Down
14 changes: 11 additions & 3 deletions src/common/bentoml/cli-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export async function serve(bentoDirectory: string): Promise<string> {
return response.logs;
}

export async function containerize(bentoTag: string): Promise<string> {
const interpreterFpath = (await tryGetPathToActivePythonInterpreter()) as string;
console.log(`command: ${interpreterFpath} -m bentoml containerize ${bentoTag}`);
const response = await tryRunShellCommand(interpreterFpath, ['-m', 'bentoml', 'containerize', bentoTag]);
return response.logs;
}

export const tryRunShellCommand = async (
interpreterFpath: string,
args: string[]
Expand All @@ -84,9 +91,10 @@ export const tryRunShellCommand = async (
if (response.exitCode !== 0) {
vscode.window.showErrorMessage(
`[${consts.EXTENSION_NAME}] Command failed with exit code ${response.exitCode}:\n\n${response.logs}`
);
throw new Error(`Command failed with exit code ${response.exitCode}: ${response.logs}`);
}
);
throw new Error(`Command failed with exit code ${response.exitCode}: ${response.logs}`);
}
console.log(`log: ${response.logs}`);
return response;
};

Expand Down
14 changes: 14 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getBentoInfo,
getModelInfo,
serve,
containerize,
} from '@/common/bentoml/cli-client';
import {
BentoMlModelsTreeDataProvider,
Expand Down Expand Up @@ -191,6 +192,19 @@ export async function activate(context: vscode.ExtensionContext) {
}
});

vscode.commands.registerCommand(`${consts.EXTENSION_ID}.containerizeBento`, async (bento: BentoMlBento) => {
const bentoTag = bento.bento.tag;
try {
const result = await containerize(bentoTag);
if (result.toLowerCase().includes('error')) {
throw new Error(result);
}
await vscode.window.showInformationMessage(`[${consts.EXTENSION_NAME}] Started containerizing ${bentoTag}!`);
} catch (e) {
await vscode.window.showErrorMessage(`[${consts.EXTENSION_NAME}] Failed to containerize ${bentoTag}: ${e}`);
}
});

let dependencyInstallationDisposable = vscode.commands.registerCommand(`${consts.EXTENSION_ID}.installPythonDependencies`, async () => {
// The code you place here will be executed every time your command is executed
await ensureBentoMlCliIsAvailable();
Expand Down

0 comments on commit aa1e088

Please sign in to comment.