2018-08-17 03:17:28 +03:00
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* 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' ) ;
2018-09-01 04:57:32 +03:00
import { IActionContext , TelemetryProperties } from 'vscode-azureextensionui' ;
2018-09-01 02:19:53 +03:00
import { configurationKeys } from '../constants' ;
2017-10-10 20:12:19 +03:00
import { ImageNode } from '../explorer/models/imageNode' ;
2018-09-04 21:29:37 +03:00
import { RootNode } from '../explorer/models/rootNode' ;
2018-08-10 01:26:31 +03:00
import { ext } from '../extensionVariables' ;
2018-07-18 02:42:00 +03:00
import { reporter } from '../telemetry/telemetry' ;
2018-09-01 02:19:53 +03:00
import { askToSavePrefix } from './registrySettings' ;
2018-09-01 04:57:32 +03:00
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 > {
2018-09-01 04:57:32 +03:00
let properties : {
pushWithoutRepositoryAnswer? : string ;
} & TelemetryProperties = actionContext . properties ;
2018-08-25 02:25:38 +03:00
2018-09-04 21:29:37 +03:00
let [ imageToPush , imageName ] = await getOrAskForImageAndTag ( context instanceof RootNode ? undefined : context ) ;
2017-06-06 03:55:05 +03:00
2018-09-01 02:19:53 +03:00
if ( imageName . includes ( '/' ) ) {
await askToSavePrefix ( imageName ) ;
2017-08-11 09:17:33 +03:00
} else {
2018-09-01 02:19:53 +03:00
//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 ) {
2018-09-01 04:57:32 +03:00
properties . pushWithoutRepositoryAnswer = 'Cancel' ;
2018-09-01 02:19:53 +03:00
// 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 the image to the official public Docker Hub library (docker.io/library), which you may not have permissions for. If you want to push to one of your own repositories, you must push an image that has been tagged with your username or a registry server name. ` , . . . options ) ;
2018-09-01 04:57:32 +03:00
properties . pushWithoutRepositoryAnswer = response . title ;
2018-09-01 02:19:53 +03:00
// if (response === alwaysPush) {
// ext.context.workspaceState.update(addPrefixImagePush, false);
// }
if ( response === tagFirst ) {
2018-09-01 04:57:32 +03:00
imageName = await tagImage ( actionContext , < IHasImageDescriptorAndLabel > { imageDesc : imageToPush , label : imageName } ) ; //not passing this would ask the user a second time to pick an image
2018-09-01 02:19:53 +03:00
}
2017-08-11 09:17:33 +03:00
}
}
if ( imageToPush ) {
2018-09-01 04:57:32 +03:00
addImageTaggingTelemetry ( actionContext , imageName , '' ) ;
2018-08-10 01:26:31 +03:00
const terminal = ext . terminalProvider . createTerminal ( imageName ) ;
2017-08-11 09:17:33 +03:00
terminal . sendText ( ` docker push ${ imageName } ` ) ;
2017-06-06 03:55:05 +03:00
terminal . show ( ) ;
if ( reporter ) {
2017-11-25 07:11:19 +03:00
/ * _ _ G D P R _ _
"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
/ * _ _ G D P R _ _
"command" : {
"command" : { "classification" : "SystemMetaData" , "purpose" : "FeatureInsight" }
}
* /
2018-03-21 23:36:15 +03:00
reporter . sendTelemetryEvent ( 'command' , {
2018-03-20 08:23:37 +03:00
command : teleAzureId
} ) ;
}
2017-06-06 03:55:05 +03:00
}
2018-07-14 00:16:56 +03:00
}
2018-07-07 02:49:46 +03:00
}