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-08-25 02:25:38 +03:00
import { DialogResponses } from 'vscode-azureextensionui' ;
2017-10-10 20:12:19 +03:00
import { ImageNode } from '../explorer/models/imageNode' ;
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' ;
import { ImageItem , quickPickImage } from './utils/quick-pick-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-07-18 02:41:39 +03:00
export async function pushImage ( context? : ImageNode ) : Promise < void > {
2018-08-25 02:25:38 +03:00
const configOptions : vscode.WorkspaceConfiguration = vscode . workspace . getConfiguration ( 'docker' ) ;
let askToSaveRegistryPath : boolean = configOptions . get < boolean > ( 'askToSaveRegistryPath' ) ;
let prefix = "" ;
2017-08-11 09:17:33 +03:00
let imageToPush : Docker.ImageDesc ;
let imageName : string = "" ;
2017-06-06 03:55:05 +03:00
2017-08-11 09:17:33 +03:00
if ( context && context . imageDesc ) {
imageToPush = context . imageDesc ;
imageName = context . label ;
} else {
const selectedItem : ImageItem = await quickPickImage ( ) ;
if ( selectedItem ) {
imageToPush = selectedItem . imageDesc ;
imageName = selectedItem . label ;
}
}
2018-08-25 02:25:38 +03:00
if ( imageName . includes ( '/' ) ) {
prefix = imageName . substring ( 0 , imageName . lastIndexOf ( '/' ) ) ;
}
if ( prefix && askToSaveRegistryPath !== false ) { //account for undefined
let userPrefixPreference : vscode.MessageItem = await ext . ui . showWarningMessage ( ` Would you like to save ' ${ prefix } ' as your default registry path? ` , DialogResponses . yes , DialogResponses . no , DialogResponses . skipForNow ) ;
if ( userPrefixPreference === DialogResponses . yes || userPrefixPreference === DialogResponses . no ) {
askToSaveRegistryPath = false ;
await configOptions . update ( 'askToSaveRegistryPath' , false , vscode . ConfigurationTarget . Workspace ) ;
}
if ( userPrefixPreference === DialogResponses . yes ) {
await configOptions . update ( 'defaultRegistryPath' , prefix , vscode . ConfigurationTarget . Workspace ) ;
vscode . window . showInformationMessage ( 'Default registry path saved. You can change this value at any time via the docker.defaultRegistryPath setting.' ) ;
}
}
2017-08-11 09:17:33 +03:00
if ( imageToPush ) {
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
}