Add return to Build ACR Command (#3695)
* add return * address feedback * fix formatting * add extra enum checks
This commit is contained in:
Родитель
b416f6446a
Коммит
38e47775b1
|
@ -5,12 +5,33 @@
|
|||
|
||||
import * as vscode from 'vscode';
|
||||
import { IActionContext, UserCancelledError } from '@microsoft/vscode-azext-utils';
|
||||
import type { Run } from '@azure/arm-containerregistry';
|
||||
import { scheduleRunRequest } from './scheduleRunRequest';
|
||||
import { delay } from '../../../../utils/promiseUtils';
|
||||
import { getArmContainerRegistry } from '../../../../utils/lazyPackages';
|
||||
|
||||
export async function buildImageInAzure(context: IActionContext, uri?: vscode.Uri | undefined): Promise<void> {
|
||||
const WAIT_MS = 5000;
|
||||
|
||||
export async function buildImageInAzure(context: IActionContext, uri?: vscode.Uri | undefined): Promise<Run | undefined> {
|
||||
if (!vscode.workspace.isTrusted) {
|
||||
throw new UserCancelledError('enforceTrust');
|
||||
}
|
||||
|
||||
await scheduleRunRequest(context, "DockerBuildRequest", uri);
|
||||
const getRun = await scheduleRunRequest(context, "DockerBuildRequest", uri);
|
||||
|
||||
let run = await getRun();
|
||||
const { KnownRunStatus } = await getArmContainerRegistry();
|
||||
while (
|
||||
run.status === KnownRunStatus.Started ||
|
||||
run.status === KnownRunStatus.Queued ||
|
||||
run.status === KnownRunStatus.Running
|
||||
) {
|
||||
await delay(WAIT_MS);
|
||||
run = await getRun();
|
||||
}
|
||||
|
||||
// we are returning the run so that other extensions can consume this with the vscode.commands.executeCommand
|
||||
// currently it is used by the ms-kubernetes-tools.aks-devx-tools extension (https://github.com/Azure/aks-devx-tools)
|
||||
return run;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import { getStorageBlob } from '../../../../utils/lazyPackages';
|
|||
const idPrecision = 6;
|
||||
const vcsIgnoreList = ['.git', '.gitignore', '.bzr', 'bzrignore', '.hg', '.hgignore', '.svn'];
|
||||
|
||||
export async function scheduleRunRequest(context: IActionContext, requestType: 'DockerBuildRequest' | 'FileTaskRunRequest', uri: vscode.Uri | undefined): Promise<void> {
|
||||
export async function scheduleRunRequest(context: IActionContext, requestType: 'DockerBuildRequest' | 'FileTaskRunRequest', uri: vscode.Uri | undefined): Promise<() => Promise<AcrRun>> {
|
||||
// Acquire information.
|
||||
let rootFolder: vscode.WorkspaceFolder;
|
||||
let fileItem: Item;
|
||||
|
@ -76,10 +76,14 @@ export async function scheduleRunRequest(context: IActionContext, requestType: '
|
|||
// Schedule the run and Clean up.
|
||||
ext.outputChannel.appendLine(localize('vscode-docker.commands.registries.azure.tasks.setUp', 'Set up run request'));
|
||||
|
||||
const run = await (await node.getClient(context)).registries.beginScheduleRunAndWait(node.resourceGroup, node.registryName, runRequest);
|
||||
const client = await node.getClient(context);
|
||||
const run = await client.registries.beginScheduleRunAndWait(node.resourceGroup, node.registryName, runRequest);
|
||||
ext.outputChannel.appendLine(localize('vscode-docker.commands.registries.azure.tasks.scheduledRun', 'Scheduled run {0}', run.runId));
|
||||
|
||||
void streamLogs(context, node, run);
|
||||
|
||||
// function returns the AcrRun info
|
||||
return async () => client.runs.get(node.resourceGroup, node.registryName, run.runId);
|
||||
} finally {
|
||||
if (await fse.pathExists(tarFilePath)) {
|
||||
await fse.unlink(tarFilePath);
|
||||
|
|
Загрузка…
Ссылка в новой задаче