vscode-docker/commands/push-image.ts

80 строки
3.9 KiB
TypeScript
Исходник Обычный вид История

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
2016-09-16 00:49:32 +03:00
import vscode = require('vscode');
import { IActionContext, TelemetryProperties } from 'vscode-azureextensionui';
import { configurationKeys } from '../constants';
import { ImageNode } from '../explorer/models/imageNode';
2018-09-04 21:29:37 +03:00
import { RootNode } from '../explorer/models/rootNode';
import { ext } from '../extensionVariables';
import { reporter } from '../telemetry/telemetry';
import { askToSavePrefix } from './registrySettings';
import { addImageTaggingTelemetry, getOrAskForImageAndTag, IHasImageDescriptorAndLabel, tagImage } from './tag-image';
2017-03-04 04:13:14 +03:00
const teleCmdId: string = 'vscode-docker.image.push';
2018-03-20 08:23:37 +03:00
const teleAzureId: string = 'vscode-docker.image.push.azureContainerRegistry';
2016-09-16 00:49:32 +03:00
2018-09-04 21:29:37 +03:00
export async function pushImage(actionContext: IActionContext, context: ImageNode | RootNode | undefined): Promise<void> {
let properties: {
pushWithoutRepositoryAnswer?: string;
} & TelemetryProperties = actionContext.properties;
let [imageToPush, imageName] = await getOrAskForImageAndTag(actionContext, context instanceof RootNode ? undefined : context);
2017-06-06 03:55:05 +03:00
if (imageName.includes('/')) {
await askToSavePrefix(imageName);
} else {
//let addPrefixImagePush = "addPrefixImagePush";
let askToPushPrefix: boolean = true; // ext.context.workspaceState.get(addPrefixImagePush, true);
let defaultRegistryPath = vscode.workspace.getConfiguration('docker').get(configurationKeys.defaultRegistryPath);
if (askToPushPrefix && defaultRegistryPath) {
properties.pushWithoutRepositoryAnswer = 'Cancel';
// let alwaysPush: vscode.MessageItem = { title: "Always push" };
let tagFirst: vscode.MessageItem = { title: "Tag first" };
let pushAnyway: vscode.MessageItem = { title: "Push anyway" }
let options: vscode.MessageItem[] = [tagFirst, pushAnyway];
let response: vscode.MessageItem = await ext.ui.showWarningMessage(`This will attempt to push to the official public Docker Hub library (docker.io/library), which you may not have permissions for. To push to your own repository, you must tag the image like <docker-id-or-registry-server>/<imagename>`, ...options);
properties.pushWithoutRepositoryAnswer = response.title;
// if (response === alwaysPush) {
// ext.context.workspaceState.update(addPrefixImagePush, false);
// }
if (response === tagFirst) {
imageName = await tagImage(actionContext, <IHasImageDescriptorAndLabel>{ imageDesc: imageToPush, label: imageName }); //not passing this would ask the user a second time to pick an image
}
}
}
if (imageToPush) {
addImageTaggingTelemetry(actionContext, imageName, '');
const terminal = ext.terminalProvider.createTerminal(imageName);
terminal.sendText(`docker push ${imageName}`);
2017-06-06 03:55:05 +03:00
terminal.show();
if (reporter) {
/* __GDPR__
"command" : {
"command" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
2017-06-06 03:55:05 +03:00
reporter.sendTelemetryEvent('command', {
command: teleCmdId
});
2018-03-20 08:23:37 +03:00
2018-08-01 20:32:29 +03:00
if (imageName.toLowerCase().includes('azurecr.io')) {
2018-03-20 08:23:37 +03:00
/* __GDPR__
"command" : {
"command" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
}
*/
reporter.sendTelemetryEvent('command', {
2018-03-20 08:23:37 +03:00
command: teleAzureId
});
}
2017-06-06 03:55:05 +03:00
}
}
2018-07-07 02:49:46 +03:00
}