vscode-docker/commands/tag-image.ts

71 строка
2.3 KiB
TypeScript
Исходник Обычный вид История

2016-10-20 07:25:54 +03:00
import vscode = require('vscode');
import { ImageItem, quickPickImage } from './utils/quick-pick-image';
2016-10-21 01:58:48 +03:00
import { docker } from './utils/docker-endpoint';
2017-03-02 04:49:54 +03:00
import { reporter } from '../telemetry/telemetry';
import { DockerNode } from '../explorer/dockerExplorer';
2017-03-04 04:13:14 +03:00
const teleCmdId: string = 'vscode-docker.image.tag';
2016-10-20 07:25:54 +03:00
export async function tagImage(context?: DockerNode) {
2017-06-06 03:55:05 +03:00
let imageName: string;
let imageToTag: Docker.ImageDesc;
2016-10-20 07:25:54 +03:00
if (context && context.imageDesc) {
imageToTag = context.imageDesc;
imageName = context.label;
} else {
const selectedItem: ImageItem = await quickPickImage(false);
2016-10-20 07:25:54 +03:00
if (selectedItem) {
imageToTag = selectedItem.imageDesc
imageName = selectedItem.label;
}
2016-10-20 07:25:54 +03:00
}
2016-10-25 02:40:34 +03:00
if (imageToTag) {
2016-10-25 02:40:34 +03:00
const configOptions: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration('docker');
const defaultRegistryPath = configOptions.get('defaultRegistryPath', '');
if (defaultRegistryPath.length > 0) {
imageName = defaultRegistryPath + '/' + imageName;
}
const defaultRegistry = configOptions.get('defaultRegistry', '');
if (defaultRegistry.length > 0) {
imageName = defaultRegistry + '/' + imageName;
}
var opt: vscode.InputBoxOptions = {
ignoreFocusOut: true,
placeHolder: imageName,
prompt: 'Tag image as...',
value: imageName
};
2016-10-25 02:40:34 +03:00
const value: string = await vscode.window.showInputBox(opt);
if (value) {
let repo: string = value;
let tag: string = 'latest';
if (value.lastIndexOf(':') > 0) {
repo = value.slice(0, value.lastIndexOf(':'));
tag = value.slice(value.lastIndexOf(':') + 1);
2016-10-25 02:40:34 +03:00
}
2016-10-20 07:25:54 +03:00
const image = docker.getImage(imageToTag.Id);
image.tag({ repo: repo, tag: tag }, function (err: Error, data: any) {
if (err) {
vscode.window.showErrorMessage('Docker Tag error: ' + err.message);
2017-06-06 03:55:05 +03:00
}
});
if (reporter) {
reporter.sendTelemetryEvent('command', {
command: teleCmdId
2017-06-06 03:55:05 +03:00
});
}
}
};
2016-10-20 07:25:54 +03:00
}