pull the latest image before docker run (#105)

* pull the latest image before docker run

* prompt user to open output channel

* fix typos
This commit is contained in:
Sheng Chen 2018-02-07 15:42:07 +08:00 коммит произвёл GitHub
Родитель 268289664c
Коммит 7adca4ec8e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 47 добавлений и 4 удалений

Просмотреть файл

@ -11,7 +11,7 @@ import { TerminalType, TestOption, TFTerminal } from "./shared";
import { terraformChannel } from "./terraformChannel";
import { isServicePrincipalSetInEnv } from "./utils/azureUtils";
import { executeCommand } from "./utils/cpUtils";
import { isDockerInstalled, runE2EInDocker, runLintInDocker } from "./utils/dockerUtils";
import { isDockerInstalled, latestTestingImagePulled, runE2EInDocker, runLintInDocker } from "./utils/dockerUtils";
import { drawGraph } from "./utils/dotUtils";
import { selectWorkspaceFolder } from "./utils/workspaceUtils";
@ -58,6 +58,11 @@ export class IntegratedShell extends BaseShell {
return;
}
terraformChannel.appendLine("Pulling the latest image of 'microsoft/terraform-test'...");
if (!await latestTestingImagePulled()) {
return;
}
switch (TestType) {
case TestOption.lint: {
await runLintInDocker(

Просмотреть файл

@ -1,7 +1,7 @@
"use strict";
import { executeCommand } from "./cpUtils";
import { openUrlHint } from "./uiUtils";
import { DialogType, openUrlHint, promptForOpenOutputChannel } from "./uiUtils";
export async function isDockerInstalled(): Promise<boolean> {
try {
@ -13,6 +13,16 @@ export async function isDockerInstalled(): Promise<boolean> {
}
}
export async function latestTestingImagePulled(): Promise<boolean> {
try {
await executeCommand("docker", ["pull", "microsoft/terraform-test:latest"], { shell: true });
return true;
} catch (error) {
promptForOpenOutputChannel("Failed to pull the latest image: microsoft/terraform-test. Please open the output channel for more details.", DialogType.error);
return false;
}
}
export async function runLintInDocker(volumn: string, containerName: string): Promise<void> {
try {
await executeCommand(
@ -31,7 +41,7 @@ export async function runLintInDocker(volumn: string, containerName: string): Pr
{ shell: true },
);
} catch (error) {
throw new Error("Run lint task in Docker failed, Please switch to output channel for more details.");
promptForOpenOutputChannel("Failed to run lint task in Docker. Please open the output channel for more details.", DialogType.error);
}
}
@ -64,7 +74,7 @@ export async function runE2EInDocker(volumn: string[], containerName: string): P
{ shell: true },
);
} catch (error) {
throw new Error("Run E2E test in Docker failed, Please switch to output channel for more details.");
promptForOpenOutputChannel("Failed to run end to end tests in Docker. Please open the output channel for more details.", DialogType.error);
}
}

Просмотреть файл

@ -2,6 +2,7 @@
import * as opn from "opn";
import * as vscode from "vscode";
import { terraformChannel } from "../terraformChannel";
export async function openUrlHint(message: string, url: string): Promise<void> {
const response = await vscode.window.showInformationMessage(`${message} (See: ${url})`, DialogOption.OPEN, DialogOption.CANCEL);
@ -26,8 +27,35 @@ export async function showFolderDialog(): Promise<vscode.Uri | undefined> {
return result[0];
}
export async function promptForOpenOutputChannel(message: string, type: DialogType): Promise<void> {
let result: vscode.MessageItem;
switch (type) {
case DialogType.info:
result = await vscode.window.showInformationMessage(message, DialogOption.OPEN, DialogOption.CANCEL);
break;
case DialogType.warning:
result = await vscode.window.showWarningMessage(message, DialogOption.OPEN, DialogOption.CANCEL);
break;
case DialogType.error:
result = await vscode.window.showErrorMessage(message, DialogOption.OPEN, DialogOption.CANCEL);
break;
default:
break;
}
if (result === DialogOption.OPEN) {
terraformChannel.show();
}
}
export namespace DialogOption {
export const OK: vscode.MessageItem = { title: "OK" };
export const CANCEL: vscode.MessageItem = { title: "Cancel", isCloseAffordance: true };
export const OPEN: vscode.MessageItem = { title: "Open" };
}
export enum DialogType {
info = "info",
warning = "warning",
error = "error",
}