Skip to content

Commit

Permalink
Add task for pushing images
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <[email protected]>
  • Loading branch information
evidolob authored and gbraad committed May 5, 2023
1 parent 5a63890 commit 9d20e0e
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 158 deletions.
63 changes: 36 additions & 27 deletions src/image-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,41 @@ export async function pushImageToCrcCluster(image: ImageInfo): Promise<void> {
if (!image.name) {
throw new Error('Image selection not supported yet');
}

const filename = path.join(os.tmpdir(), image.name ? image.name.replaceAll('/', '') : image.engineId);
try {
let name = image.name;
if (image.tag) {
name = name + ':' + image.tag;
}
await extensionApi.containerEngine.saveImage(image.engineId, name, filename);
const result = await runCliCommand(getPodmanCli(), [
'--url=ssh://[email protected]:2222/run/podman/podman.sock',
`--identity=${os.homedir()}/.crc/machines/crc/id_ecdsa`,
'load',
'-i',
filename,
]);

if (result.exitCode !== 0) {
throw new Error(result.stdErr);
}
extensionApi.window.showNotification({
body: `Image ${image.name} pushed to ${productName} cluster`,
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : '' + error;
throw new Error(`Error while pushing image ${image.name} to ${productName} cluster: ${errorMessage}`);
} finally {
fs.promises.rm(filename);
let name = image.name;
if (image.tag) {
name = name + ':' + image.tag;
}

return extensionApi.window.withProgress(
{ location: extensionApi.ProgressLocation.TASK_WIDGET, title: `Pushing ${name}...` },
async progress => {
progress.report({ increment: 0 });
const filename = path.join(os.tmpdir(), image.name ? image.name.replaceAll('/', '') : image.engineId);
try {
await extensionApi.containerEngine.saveImage(image.engineId, name, filename);
progress.report({ increment: 50 });
const result = await runCliCommand(getPodmanCli(), [
'--url=ssh://[email protected]:2222/run/podman/podman.sock',
`--identity=${os.homedir()}/.crc/machines/crc/id_ecdsa`,
'load',
'-i',
filename,
]);
progress.report({ increment: 100 });
if (result.exitCode !== 0) {
throw new Error(result.stdErr);
}
extensionApi.window.showNotification({
body: `Image ${image.name} pushed to ${productName} cluster`,
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : '' + error;
progress.report({
message: `Error while pushing image ${image.name} to ${productName} cluster: ${errorMessage}`,
});
} finally {
fs.promises.rm(filename);
}
},
);
}
Loading

0 comments on commit 9d20e0e

Please sign in to comment.