change directory before running the actual command (#117)
This commit is contained in:
Родитель
489e303c61
Коммит
bf7e87c56d
|
@ -11,7 +11,7 @@ export abstract class BaseShell {
|
|||
this.initShellInternal();
|
||||
}
|
||||
|
||||
public abstract runTerraformCmd(tfCommand: string, workingDir: string);
|
||||
public abstract runTerraformCmd(tfCommand: string);
|
||||
|
||||
public abstract runTerraformTests(testType: string, workingDirectory: string);
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import { aciConfig, Constants, exportContainerCmd, exportTestScript } from "./co
|
|||
import { azFilePush, escapeFile, TerminalType, TestOption, TFTerminal } from "./shared";
|
||||
import { terraformChannel } from "./terraformChannel";
|
||||
import { DialogOption, DialogType, promptForOpenOutputChannel } from "./utils/uiUtils";
|
||||
import { selectWorkspaceFolder } from "./utils/workspaceUtils";
|
||||
|
||||
const tempFile = path.join(os.tmpdir(), "cloudshell" + vscode.env.sessionId + ".log");
|
||||
|
||||
|
@ -30,7 +31,7 @@ export class CloudShell extends BaseShell {
|
|||
|
||||
try {
|
||||
await Promise.all(promises);
|
||||
await vscode.window.showInformationMessage("Synced all matched files in the current workspace to CloudShell");
|
||||
vscode.window.showInformationMessage("Synced all matched files in the current workspace to CloudShell");
|
||||
} catch (error) {
|
||||
terraformChannel.appendLine(error);
|
||||
await promptForOpenOutputChannel("Failed to push files to the cloud. Please open the output channel for more details.", DialogType.error);
|
||||
|
@ -51,48 +52,56 @@ export class CloudShell extends BaseShell {
|
|||
}
|
||||
|
||||
const workspaceName: string = path.basename(workingDirectory);
|
||||
const cloudDrivePath: string = `${workspaceName}/.TFTesting`;
|
||||
const setupFilesFolder: string = `${workspaceName}/.TFTesting`;
|
||||
const localPath: string = path.join(workingDirectory, ".TFTesting");
|
||||
const CREATE_ACI_SCRIPT: string = "createacitest.sh";
|
||||
const CONTAINER_CMD_SCRIPT: string = "containercmd.sh";
|
||||
const createAciScript: string = "createacitest.sh";
|
||||
const containerCommandScript: string = "containercmd.sh";
|
||||
const resourceGroup: string = vscode.workspace.getConfiguration("tf-azure").get("aci-ResGroup");
|
||||
const aciName: string = vscode.workspace.getConfiguration("tf-azure").get("aci-name");
|
||||
const aciGroup: string = vscode.workspace.getConfiguration("tf-azure").get("aci-group");
|
||||
|
||||
const TFConfiguration = escapeFile(aciConfig(
|
||||
vscode.workspace.getConfiguration("tf-azure").get("aci-ResGroup"),
|
||||
vscode.workspace.getConfiguration("tf-azure").get("aci-name"),
|
||||
vscode.workspace.getConfiguration("tf-azure").get("aci-group"),
|
||||
this.tfTerminal.storageAccountName, this.tfTerminal.fileShareName,
|
||||
resourceGroup,
|
||||
aciName,
|
||||
aciGroup,
|
||||
this.tfTerminal.storageAccountName,
|
||||
this.tfTerminal.fileShareName,
|
||||
vscode.workspace.getConfiguration("tf-azure").get("test-location"),
|
||||
vscode.workspace.getConfiguration("tf-azure").get("test-container"),
|
||||
workspaceName,
|
||||
));
|
||||
|
||||
const shellscript = exportTestScript("lint", TFConfiguration, this.tfTerminal.ResourceGroup, this.tfTerminal.storageAccountName, this.tfTerminal.fileShareName, cloudDrivePath);
|
||||
const shellscript = exportTestScript("lint", TFConfiguration, this.tfTerminal.ResourceGroup, this.tfTerminal.storageAccountName, this.tfTerminal.fileShareName, setupFilesFolder);
|
||||
|
||||
await Promise.all([
|
||||
fsExtra.outputFile(path.join(localPath, CREATE_ACI_SCRIPT), shellscript),
|
||||
fsExtra.outputFile(path.join(localPath, CONTAINER_CMD_SCRIPT), exportContainerCmd(workspaceName, await this.resolveContainerCmd(testType))),
|
||||
fsExtra.outputFile(path.join(localPath, createAciScript), shellscript),
|
||||
fsExtra.outputFile(path.join(localPath, containerCommandScript), exportContainerCmd(workspaceName, await this.resolveContainerCmd(testType))),
|
||||
]);
|
||||
|
||||
await Promise.all([
|
||||
azFilePush(workspaceName, this.tfTerminal.storageAccountName, this.tfTerminal.storageAccountKey, this.tfTerminal.fileShareName, path.join(localPath, CREATE_ACI_SCRIPT)),
|
||||
azFilePush(workspaceName, this.tfTerminal.storageAccountName, this.tfTerminal.storageAccountKey, this.tfTerminal.fileShareName, path.join(localPath, CONTAINER_CMD_SCRIPT)),
|
||||
azFilePush(workspaceName, this.tfTerminal.storageAccountName, this.tfTerminal.storageAccountKey, this.tfTerminal.fileShareName, path.join(localPath, createAciScript)),
|
||||
azFilePush(workspaceName, this.tfTerminal.storageAccountName, this.tfTerminal.storageAccountKey, this.tfTerminal.fileShareName, path.join(localPath, containerCommandScript)),
|
||||
]);
|
||||
|
||||
const sentToTerminal: boolean = await this.runTFCommand(`cd ~/clouddrive/${cloudDrivePath} && source ${CREATE_ACI_SCRIPT} && terraform fmt && terraform init && terraform apply -auto-approve && terraform taint azurerm_container_group.TFTest && \
|
||||
echo "\nRun the following command to get the logs from the ACI container: az container logs -g ${vscode.workspace.getConfiguration("tf-azure").get("aci-ResGroup")} -n ${vscode.workspace.getConfiguration("tf-azure").get("aci-name")}\n"`, cloudDrivePath);
|
||||
const sentToTerminal: boolean = await this.runTFCommand(
|
||||
`source ${createAciScript} && terraform fmt && terraform init && terraform apply -auto-approve && terraform taint azurerm_container_group.TFTest && \
|
||||
echo "\nRun the following command to get the logs from the ACI container: az container logs -g ${resourceGroup} -n ${aciName}\n"`,
|
||||
`${Constants.clouddrive}/${setupFilesFolder}`,
|
||||
);
|
||||
if (sentToTerminal) {
|
||||
vscode.window.showInformationMessage(`An Azure Container Instance will be created in the Resource Group '${vscode.workspace.getConfiguration("tf-azure").get("aci-ResGroup")}' if the command executes successfully.`);
|
||||
vscode.window.showInformationMessage(`An Azure Container Instance will be created in the Resource Group '${resourceGroup}' if the command executes successfully.`);
|
||||
} else {
|
||||
vscode.window.showErrorMessage("Failed to send the command to terminal, please try it again.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async runTerraformCmd(tfCommand: string, workingDir: string): Promise<void> {
|
||||
public async runTerraformCmd(tfCommand: string): Promise<void> {
|
||||
// Workaround the TLS error
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||
if (await this.connectedToCloudShell()) {
|
||||
await this.runTFCommand(tfCommand, workingDir);
|
||||
const workingDirectory: string = await selectWorkspaceFolder();
|
||||
await this.runTFCommand(tfCommand, workingDirectory ? `${Constants.clouddrive}/${path.basename(workingDirectory)}` : "");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,6 +132,9 @@ export class CloudShell extends BaseShell {
|
|||
if (await fsExtra.pathExists(tempFile)) {
|
||||
if (this.tfTerminal.terminal) {
|
||||
this.tfTerminal.terminal.show();
|
||||
if (workdir) {
|
||||
this.tfTerminal.terminal.sendText(`cd "${workdir}"`);
|
||||
}
|
||||
this.tfTerminal.terminal.sendText(`${command}`);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ export class Constants {
|
|||
public static TerraformTerminalName = "Terraform";
|
||||
public static UserAgentName = "VSCODEEXT_USER_AGENT";
|
||||
public static TestContainer = "microsoft/terraform-test";
|
||||
public static clouddrive = "~/clouddrive";
|
||||
public static clouddrive = "$HOME/clouddrive";
|
||||
}
|
||||
|
||||
export function aciConfig(resourceGroup: string, aciName: string, aciGroup: string, storageAccountName: string, storageAccountShare: string, location: string, testContainer: string, projectName: string): string {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
import * as vscode from "vscode";
|
||||
import { BaseShell } from "./baseShell";
|
||||
import { CloudShell } from "./cloudShell";
|
||||
import { Constants } from "./constants";
|
||||
import { IntegratedShell } from "./integratedShell";
|
||||
import { TestOption } from "./shared";
|
||||
import { DialogOption } from "./utils/uiUtils";
|
||||
|
@ -24,27 +23,27 @@ export function activate(ctx: vscode.ExtensionContext) {
|
|||
integratedShell = new IntegratedShell();
|
||||
|
||||
ctx.subscriptions.push(vscode.commands.registerCommand("vscode-terraform-azure.init", () => {
|
||||
getShell().runTerraformCmd("terraform init", Constants.clouddrive);
|
||||
getShell().runTerraformCmd("terraform init");
|
||||
}));
|
||||
|
||||
ctx.subscriptions.push(vscode.commands.registerCommand("vscode-terraform-azure.plan", () => {
|
||||
getShell().runTerraformCmd("terraform plan", Constants.clouddrive);
|
||||
getShell().runTerraformCmd("terraform plan");
|
||||
}));
|
||||
|
||||
ctx.subscriptions.push(vscode.commands.registerCommand("vscode-terraform-azure.apply", () => {
|
||||
getShell().runTerraformCmd("terraform apply", Constants.clouddrive);
|
||||
getShell().runTerraformCmd("terraform apply");
|
||||
}));
|
||||
|
||||
ctx.subscriptions.push(vscode.commands.registerCommand("vscode-terraform-azure.destroy", () => {
|
||||
getShell().runTerraformCmd("terraform destroy", Constants.clouddrive);
|
||||
getShell().runTerraformCmd("terraform destroy");
|
||||
}));
|
||||
|
||||
ctx.subscriptions.push(vscode.commands.registerCommand("vscode-terraform-azure.refresh", () => {
|
||||
getShell().runTerraformCmd("terraform refresh", Constants.clouddrive);
|
||||
getShell().runTerraformCmd("terraform refresh");
|
||||
}));
|
||||
|
||||
ctx.subscriptions.push(vscode.commands.registerCommand("vscode-terraform-azure.validate", () => {
|
||||
getShell().runTerraformCmd("terraform validate", Constants.clouddrive);
|
||||
getShell().runTerraformCmd("terraform validate");
|
||||
}));
|
||||
|
||||
ctx.subscriptions.push(vscode.commands.registerCommand("vscode-terraform-azure.visualize", async () => {
|
||||
|
|
|
@ -100,7 +100,7 @@ export class IntegratedShell extends BaseShell {
|
|||
}
|
||||
}
|
||||
|
||||
public runTerraformCmd(tfCommand: string, workingDir: string): void {
|
||||
public runTerraformCmd(tfCommand: string): void {
|
||||
this.checkCreateTerminal();
|
||||
const term = this.tfTerminal.terminal;
|
||||
term.show();
|
||||
|
|
Загрузка…
Ссылка в новой задаче