From ef3a8d351b4a330a1ee50d7f53ba46eb81e03808 Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Fri, 29 Sep 2023 00:07:06 -0700 Subject: [PATCH] Change command signature --- dist/index.js | 79 +++++++++++++++++----------------- src/ContainerAppHelper.ts | 67 ++++++++++++++-------------- src/ContainerRegistryHelper.ts | 6 +-- src/TelemetryHelper.ts | 2 +- src/Utility.ts | 2 +- 5 files changed, 79 insertions(+), 77 deletions(-) diff --git a/dist/index.js b/dist/index.js index b22c1d48..a3dd156e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4670,11 +4670,11 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command_1 = "containerapp create -n " + containerAppName + " -g " + resourceGroup + " -i " + imageToDeploy + " --environment " + environment; + command_1 = "az containerapp create -n " + containerAppName + " -g " + resourceGroup + " -i " + imageToDeploy + " --environment " + environment; optionalCmdArgs.forEach(function (val) { command_1 += " " + val; }); - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command_1 + "\"")]; + return [4 /*yield*/, util.executeAndThrowIfError(command_1)]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -4703,8 +4703,8 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command = "containerapp create -n " + containerAppName + " -g " + resourceGroup + " --yaml " + yamlConfigPath; - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command + "\"")]; + command = "az containerapp create -n " + containerAppName + " -g " + resourceGroup + " --yaml " + yamlConfigPath; + return [4 /*yield*/, util.executeAndThrowIfError(command)]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -4734,11 +4734,11 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command_2 = "containerapp update -n " + containerAppName + " -g " + resourceGroup + " -i " + imageToDeploy; + command_2 = "az containerapp update -n " + containerAppName + " -g " + resourceGroup + " -i " + imageToDeploy; optionalCmdArgs.forEach(function (val) { command_2 += " " + val; }); - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command_2 + "\"")]; + return [4 /*yield*/, util.executeAndThrowIfError(command_2)]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -4770,7 +4770,7 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command_3 = "containerapp up -n " + containerAppName + " -g " + resourceGroup + " -i " + imageToDeploy; + command_3 = "az containerapp up -n " + containerAppName + " -g " + resourceGroup + " -i " + imageToDeploy; optionalCmdArgs.forEach(function (val) { command_3 += " " + val; }); @@ -4780,7 +4780,7 @@ var ContainerAppHelper = /** @class */ (function () { if (!util.isNullOrEmpty(targetPort)) { command_3 += " --target-port " + targetPort; } - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command_3 + "\"")]; + return [4 /*yield*/, util.executeAndThrowIfError(command_3)]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -4809,8 +4809,8 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command = "containerapp update -n " + containerAppName + " -g " + resourceGroup + " --yaml " + yamlConfigPath; - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command + "\"")]; + command = "az containerapp update -n " + containerAppName + " -g " + resourceGroup + " --yaml " + yamlConfigPath; + return [4 /*yield*/, util.executeAndThrowIfError(command)]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -4839,8 +4839,8 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command = "containerapp show -n " + containerAppName + " -g " + resourceGroup + " -o none"; - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command + "\"")]; + command = "az containerapp show -n " + containerAppName + " -g " + resourceGroup + " -o none"; + return [4 /*yield*/, util.executeAndThrowIfError(command)]; case 2: executionResult = _a.sent(); return [2 /*return*/, executionResult.exitCode === 0]; @@ -4869,8 +4869,8 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command = "containerapp env show -n " + containerAppEnvironment + " -g " + resourceGroup + " -o none"; - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command + "\"")]; + command = "az containerapp env show -n " + containerAppEnvironment + " -g " + resourceGroup + " -o none"; + return [4 /*yield*/, util.executeAndThrowIfError(command)]; case 2: executionResult = _a.sent(); return [2 /*return*/, executionResult.exitCode === 0]; @@ -4898,8 +4898,8 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command = "group show -n " + resourceGroup + " -o none"; - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command + "\"")]; + command = "az group show -n " + resourceGroup + " -o none"; + return [4 /*yield*/, util.executeAndThrowIfError(command)]; case 2: executionResult = _a.sent(); return [2 /*return*/, executionResult.exitCode === 0]; @@ -4918,7 +4918,7 @@ var ContainerAppHelper = /** @class */ (function () { */ ContainerAppHelper.prototype.getDefaultContainerAppLocation = function () { return __awaiter(this, void 0, void 0, function () { - var executionResult, err_9; + var command, executionResult, err_9; return __generator(this, function (_a) { switch (_a.label) { case 0: @@ -4926,7 +4926,8 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, util.executeAndThrowIfError("az \"provider show -n Microsoft.App --query \"resourceTypes[?resourceType=='containerApps'].locations[] | [0]\"")]; + command = "az provider show -n Microsoft.App --query \"resourceTypes[?resourceType=='containerApps'].locations[] | [0]\""; + return [4 /*yield*/, util.executeAndThrowIfError(command)]; case 2: executionResult = _a.sent(); // If successful, strip out double quotes, spaces and parentheses from the first location returned @@ -4955,8 +4956,8 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command = "group create -n " + name + " -l " + location; - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command + "\"")]; + command = "az group create -n " + name + " -l " + location; + return [4 /*yield*/, util.executeAndThrowIfError(command)]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -4984,7 +4985,7 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, util.executeAndThrowIfError("az \"containerapp env list -g " + resourceGroup + " --query [0].name\"")]; + return [4 /*yield*/, util.executeAndThrowIfError("az containerapp env list -g " + resourceGroup + " --query [0].name")]; case 2: executionResult = _a.sent(); return [2 /*return*/, executionResult.exitCode === 0 ? executionResult.stdout : null]; @@ -5014,11 +5015,11 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command = "containerapp env create -n " + name + " -g " + resourceGroup; + command = "az containerapp env create -n " + name + " -g " + resourceGroup; if (!util.isNullOrEmpty(location)) { command += " -l " + location; } - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command + "\"")]; + return [4 /*yield*/, util.executeAndThrowIfError(command)]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -5046,8 +5047,8 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command = "containerapp ingress disable -n " + name + " -g " + resourceGroup; - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command + "\"")]; + command = "az containerapp ingress disable -n " + name + " -g " + resourceGroup; + return [4 /*yield*/, util.executeAndThrowIfError(command)]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -5078,8 +5079,8 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command = "containerapp registry set -n " + name + " -g " + resourceGroup + " --server " + acrName + ".azurecr.io --username " + acrUsername + " --password " + acrPassword; - return [4 /*yield*/, util.executeAndThrowIfError("az \"" + command + "\"")]; + command = "az containerapp registry set -n " + name + " -g " + resourceGroup + " --server " + acrName + ".azurecr.io --username " + acrUsername + " --password " + acrPassword; + return [4 /*yield*/, util.executeAndThrowIfError(command)]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -5113,7 +5114,7 @@ var ContainerAppHelper = /** @class */ (function () { telemetryArg = "ORYX_DISABLE_TELEMETRY=true"; } command = "build " + imageToDeploy + " --path " + appSourcePath + " --builder " + ORYX_BUILDER_IMAGE + " --run-image mcr.microsoft.com/oryx/" + runtimeStack + " --env " + telemetryArg; - return [4 /*yield*/, util.executeAndThrowIfError(PACK_CMD + " \"" + command + "\"")]; + return [4 /*yield*/, util.executeAndThrowIfError(PACK_CMD + " " + command)]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -5147,7 +5148,7 @@ var ContainerAppHelper = /** @class */ (function () { case 2: dockerTool = _a.sent(); command = "build --file " + dockerfilePath + " " + appSourcePath + " --tag " + imageToDeploy; - return [4 /*yield*/, util.executeAndThrowIfError(dockerTool + " \"" + command + "\"")]; + return [4 /*yield*/, util.executeAndThrowIfError(dockerTool + " " + command)]; case 3: _a.sent(); toolHelper.writeDebug("Successfully created runnable application image from the provided/found Dockerfile \"" + dockerfilePath + "\" with image name \"" + imageToDeploy + "\""); @@ -5181,7 +5182,7 @@ var ContainerAppHelper = /** @class */ (function () { dockerTool = _a.sent(); oryxDockerfileCommand = "oryx dockerfile " + appSourcePath + " | head -n 1 | sed 's/ARG RUNTIME=//' >> " + appSourcePath + "/oryx-runtime.txt"; command = "run --rm -v " + appSourcePath + ":/app " + ORYX_CLI_IMAGE + " /bin/bash -c " + oryxDockerfileCommand + "}"; - return [4 /*yield*/, util.executeAndThrowIfError(dockerTool + " \"" + command + "\"") + return [4 /*yield*/, util.executeAndThrowIfError(dockerTool + " " + command) // Read the temp file to get the runtime stack into a variable ]; case 3: @@ -5224,8 +5225,8 @@ var ContainerAppHelper = /** @class */ (function () { _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - command = "config default-builder " + ORYX_BUILDER_IMAGE; - return [4 /*yield*/, util.executeAndThrowIfError(PACK_CMD + " \"" + command + "\"")]; + command = "az config default-builder " + ORYX_BUILDER_IMAGE; + return [4 /*yield*/, util.executeAndThrowIfError(PACK_CMD + " " + command)]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -5262,11 +5263,11 @@ var ContainerAppHelper = /** @class */ (function () { } else { tgzSuffix = os.platform() == 'darwin' ? 'macos' : 'linux'; - command = "-c (curl -sSL \"https://github.com/buildpacks/pack/releases/download/v0.27.0/pack-v0.27.0-" + tgzSuffix + ".tgz\" | " + + command = "(curl -sSL \"https://github.com/buildpacks/pack/releases/download/v0.27.0/pack-v0.27.0-" + tgzSuffix + ".tgz\" | " + 'tar -C /usr/local/bin/ --no-same-owner -xzv pack)'; commandLine = 'bash'; } - return [4 /*yield*/, util.executeAndThrowIfError(commandLine + " \"" + command + "\"")]; + return [4 /*yield*/, util.executeAndThrowIfError(commandLine + " -c \"" + command + "\"")]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -5356,7 +5357,7 @@ var ContainerRegistryHelper = /** @class */ (function () { return [4 /*yield*/, toolHelper.which("docker", true)]; case 2: dockerTool = _a.sent(); - return [4 /*yield*/, util.executeAndThrowIfError(dockerTool + " \"login --username " + acrUsername + " --password " + acrPassword + " " + acrName + ".azurecr.io\"", [], Buffer.from(acrPassword))]; + return [4 /*yield*/, util.executeAndThrowIfError(dockerTool + " login --username " + acrUsername + " --password " + acrPassword + " " + acrName + ".azurecr.io", [], Buffer.from(acrPassword))]; case 3: _a.sent(); return [3 /*break*/, 5]; @@ -5385,7 +5386,7 @@ var ContainerRegistryHelper = /** @class */ (function () { case 1: _a.trys.push([1, 3, , 4]); commandLine = os.platform() === 'win32' ? 'pwsh' : 'bash'; - return [4 /*yield*/, util.executeAndThrowIfError(commandLine + "\"-c CA_ADO_TASK_ACR_ACCESS_TOKEN=$(az acr login --name " + acrName + " --output json --expose-token --only-show-errors | jq -r '.accessToken'); docker login " + acrName + ".azurecr.io -u 00000000-0000-0000-0000-000000000000 -p $CA_ADO_TASK_ACR_ACCESS_TOKEN > /dev/null 2>&1\"")]; + return [4 /*yield*/, util.executeAndThrowIfError(commandLine + " -c \"CA_ADO_TASK_ACR_ACCESS_TOKEN=$(az acr login --name " + acrName + " --output json --expose-token --only-show-errors | jq -r '.accessToken'); docker login " + acrName + ".azurecr.io -u 00000000-0000-0000-0000-000000000000 -p $CA_ADO_TASK_ACR_ACCESS_TOKEN > /dev/null 2>&1\"")]; case 2: _a.sent(); return [3 /*break*/, 4]; @@ -5415,7 +5416,7 @@ var ContainerRegistryHelper = /** @class */ (function () { return [4 /*yield*/, toolHelper.which("docker", true)]; case 2: dockerTool = _a.sent(); - return [4 /*yield*/, util.executeAndThrowIfError(dockerTool + " \"tag " + imageToPush + " " + imageToPush + "\"")]; + return [4 /*yield*/, util.executeAndThrowIfError(dockerTool + " tag " + imageToPush + " " + imageToPush)]; case 3: _a.sent(); return [3 /*break*/, 5]; @@ -5690,7 +5691,7 @@ var TelemetryHelper = /** @class */ (function () { return [4 /*yield*/, toolHelper.which("docker", true)]; case 2: dockerTool = _a.sent(); - return [4 /*yield*/, util.executeAndThrowIfError(dockerTool + " \"run --rm " + ORYX_CLI_IMAGE + " /bin/bash -c oryx telemetry --event-name " + eventName + " --processing-time " + taskLengthMilliseconds + " " + resultArg + " " + scenarioArg + " " + errorMessageArg + "\"")]; + return [4 /*yield*/, util.executeAndThrowIfError(dockerTool + " run --rm " + ORYX_CLI_IMAGE + " /bin/bash -c oryx telemetry --event-name " + eventName + " --processing-time " + taskLengthMilliseconds + " " + resultArg + " " + scenarioArg + " " + errorMessageArg)]; case 3: _a.sent(); return [3 /*break*/, 5]; @@ -5790,7 +5791,7 @@ var Utility = /** @class */ (function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this.executeAndThrowIfError("az \"config set extension.use_dynamic_install=yes_without_prompt\"")]; + case 0: return [4 /*yield*/, this.executeAndThrowIfError("az config set extension.use_dynamic_install=yes_without_prompt")]; case 1: _a.sent(); return [2 /*return*/]; diff --git a/src/ContainerAppHelper.ts b/src/ContainerAppHelper.ts index 826db6cd..537652e7 100644 --- a/src/ContainerAppHelper.ts +++ b/src/ContainerAppHelper.ts @@ -34,11 +34,11 @@ export class ContainerAppHelper { optionalCmdArgs: string[]) { toolHelper.writeDebug(`Attempting to create Container App with name "${containerAppName}" in resource group "${resourceGroup}" based from image "${imageToDeploy}"`); try { - let command = `containerapp create -n ${containerAppName} -g ${resourceGroup} -i ${imageToDeploy} --environment ${environment}`; + let command = `az containerapp create -n ${containerAppName} -g ${resourceGroup} -i ${imageToDeploy} --environment ${environment}`; optionalCmdArgs.forEach(function (val: string) { command += ` ${val}`; }); - await util.executeAndThrowIfError(`az "${command}"`); + await util.executeAndThrowIfError(command); } catch (err) { toolHelper.writeError(err.message); throw err; @@ -57,8 +57,8 @@ export class ContainerAppHelper { yamlConfigPath: string) { toolHelper.writeDebug(`Attempting to create Container App with name "${containerAppName}" in resource group "${resourceGroup}" from provided YAML "${yamlConfigPath}"`); try { - let command = `containerapp create -n ${containerAppName} -g ${resourceGroup} --yaml ${yamlConfigPath}`; - await util.executeAndThrowIfError(`az "${command}"`); + let command = `az containerapp create -n ${containerAppName} -g ${resourceGroup} --yaml ${yamlConfigPath}`; + await util.executeAndThrowIfError(command); } catch (err) { toolHelper.writeError(err.message); throw err; @@ -79,11 +79,11 @@ export class ContainerAppHelper { optionalCmdArgs: string[]) { toolHelper.writeDebug(`Attempting to update Container App with name "${containerAppName}" in resource group "${resourceGroup}" based from image "${imageToDeploy}"`); try { - let command = `containerapp update -n ${containerAppName} -g ${resourceGroup} -i ${imageToDeploy}`; + let command = `az containerapp update -n ${containerAppName} -g ${resourceGroup} -i ${imageToDeploy}`; optionalCmdArgs.forEach(function (val: string) { command += ` ${val}`; }); - await util.executeAndThrowIfError(`az "${command}"`); + await util.executeAndThrowIfError(command); } catch (err) { toolHelper.writeError(err.message); throw err; @@ -108,7 +108,7 @@ export class ContainerAppHelper { targetPort?: string) { toolHelper.writeDebug(`Attempting to update Container App with name "${containerAppName}" in resource group "${resourceGroup}" based from image "${imageToDeploy}"`); try { - let command = `containerapp up -n ${containerAppName} -g ${resourceGroup} -i ${imageToDeploy}`; + let command = `az containerapp up -n ${containerAppName} -g ${resourceGroup} -i ${imageToDeploy}`; optionalCmdArgs.forEach(function (val: string) { command += ` ${val}`; }); @@ -120,7 +120,7 @@ export class ContainerAppHelper { if (!util.isNullOrEmpty(targetPort)) { command += ` --target-port ${targetPort}`; } - await util.executeAndThrowIfError(`az "${command}"`); + await util.executeAndThrowIfError(command); } catch (err) { toolHelper.writeError(err.message); throw err; @@ -139,8 +139,8 @@ export class ContainerAppHelper { yamlConfigPath: string) { toolHelper.writeDebug(`Attempting to update Container App with name "${containerAppName}" in resource group "${resourceGroup}" from provided YAML "${yamlConfigPath}"`); try { - let command = `containerapp update -n ${containerAppName} -g ${resourceGroup} --yaml ${yamlConfigPath}`; - await util.executeAndThrowIfError(`az "${command}"`); + let command = `az containerapp update -n ${containerAppName} -g ${resourceGroup} --yaml ${yamlConfigPath}`; + await util.executeAndThrowIfError(command); } catch (err) { toolHelper.writeError(err.message); throw err; @@ -156,8 +156,8 @@ export class ContainerAppHelper { public async doesContainerAppExist(containerAppName: string, resourceGroup: string): Promise { toolHelper.writeDebug(`Attempting to determine if Container App with name "${containerAppName}" exists in resource group "${resourceGroup}"`); try { - let command = `containerapp show -n ${containerAppName} -g ${resourceGroup} -o none`; - let executionResult = await util.executeAndThrowIfError(`az "${command}"`); + let command = `az containerapp show -n ${containerAppName} -g ${resourceGroup} -o none`; + let executionResult = await util.executeAndThrowIfError(command); return executionResult.exitCode === 0; } catch (err) { toolHelper.writeWarning(err.message); @@ -174,8 +174,8 @@ export class ContainerAppHelper { public async doesContainerAppEnvironmentExist(containerAppEnvironment: string, resourceGroup: string): Promise { toolHelper.writeDebug(`Attempting to determine if Container App Environment with name "${containerAppEnvironment}" exists in resource group "${resourceGroup}"`); try { - let command = `containerapp env show -n ${containerAppEnvironment} -g ${resourceGroup} -o none`; - let executionResult = await util.executeAndThrowIfError(`az "${command}"`); + let command = `az containerapp env show -n ${containerAppEnvironment} -g ${resourceGroup} -o none`; + let executionResult = await util.executeAndThrowIfError(command); return executionResult.exitCode === 0; } catch (err) { toolHelper.writeWarning(err.message); @@ -191,8 +191,8 @@ export class ContainerAppHelper { public async doesResourceGroupExist(resourceGroup: string): Promise { toolHelper.writeDebug(`Attempting to determine if resource group "${resourceGroup}" exists`); try { - let command = `group show -n ${resourceGroup} -o none`; - let executionResult = await util.executeAndThrowIfError(`az "${command}"`); + let command = `az group show -n ${resourceGroup} -o none`; + let executionResult = await util.executeAndThrowIfError(command); return executionResult.exitCode === 0; } catch (err) { toolHelper.writeWarning(err.message); @@ -207,7 +207,8 @@ export class ContainerAppHelper { public async getDefaultContainerAppLocation(): Promise { toolHelper.writeDebug(`Attempting to get the default location for the Container App service for the subscription.`); try { - let executionResult = await util.executeAndThrowIfError(`az "provider show -n Microsoft.App --query "resourceTypes[?resourceType=='containerApps'].locations[] | [0]"`); + let command = `az provider show -n Microsoft.App --query \"resourceTypes[?resourceType=='containerApps'].locations[] | [0]\"` + let executionResult = await util.executeAndThrowIfError(command); // If successful, strip out double quotes, spaces and parentheses from the first location returned return executionResult.exitCode === 0 ? executionResult.stdout.toLowerCase().replace(/["() ]/g, "").trim() : `eastus2`; } catch (err) { @@ -224,8 +225,8 @@ export class ContainerAppHelper { public async createResourceGroup(name: string, location: string) { toolHelper.writeDebug(`Attempting to create resource group "${name}" in location "${location}"`); try { - let command = `group create -n ${name} -l ${location}`; - await util.executeAndThrowIfError(`az "${command}"`); + let command = `az group create -n ${name} -l ${location}`; + await util.executeAndThrowIfError(command); } catch (err) { toolHelper.writeError(err.message); throw err; @@ -240,7 +241,7 @@ export class ContainerAppHelper { public async getExistingContainerAppEnvironment(resourceGroup: string) { toolHelper.writeDebug(`Attempting to get the existing Container App Environment in resource group "${resourceGroup}"`); try { - let executionResult = await util.executeAndThrowIfError(`az "containerapp env list -g ${resourceGroup} --query [0].name"`); + let executionResult = await util.executeAndThrowIfError(`az containerapp env list -g ${resourceGroup} --query [0].name`); return executionResult.exitCode === 0 ? executionResult.stdout : null; } catch (err) { toolHelper.writeWarning(err.message); @@ -258,11 +259,11 @@ export class ContainerAppHelper { const util = new Utility(); toolHelper.writeDebug(`Attempting to create Container App Environment with name "${name}" in resource group "${resourceGroup}"`); try { - let command = `containerapp env create -n ${name} -g ${resourceGroup}`; + let command = `az containerapp env create -n ${name} -g ${resourceGroup}`; if (!util.isNullOrEmpty(location)) { command += ` -l ${location}`; } - await util.executeAndThrowIfError(`az "${command}"`); + await util.executeAndThrowIfError(command); } catch (err) { toolHelper.writeError(err.message); throw err; @@ -277,8 +278,8 @@ export class ContainerAppHelper { public async disableContainerAppIngress(name: string, resourceGroup: string) { toolHelper.writeDebug(`Attempting to disable ingress for Container App with name "${name}" in resource group "${resourceGroup}"`); try { - let command = `containerapp ingress disable -n ${name} -g ${resourceGroup}`; - await util.executeAndThrowIfError(`az "${command}"`); + let command = `az containerapp ingress disable -n ${name} -g ${resourceGroup}`; + await util.executeAndThrowIfError(command); } catch (err) { toolHelper.writeError(err.message); throw err; @@ -296,8 +297,8 @@ export class ContainerAppHelper { public async updateContainerAppRegistryDetails(name: string, resourceGroup: string, acrName: string, acrUsername: string, acrPassword: string) { toolHelper.writeDebug(`Attempting to set the ACR details for Container App with name "${name}" in resource group "${resourceGroup}"`); try { - let command = `containerapp registry set -n ${name} -g ${resourceGroup} --server ${acrName}.azurecr.io --username ${acrUsername} --password ${acrPassword}`; - await util.executeAndThrowIfError(`az "${command}"`); + let command = `az containerapp registry set -n ${name} -g ${resourceGroup} --server ${acrName}.azurecr.io --username ${acrUsername} --password ${acrPassword}`; + await util.executeAndThrowIfError(command); } catch (err) { toolHelper.writeError(err.message); throw err; @@ -321,7 +322,7 @@ export class ContainerAppHelper { telemetryArg = `ORYX_DISABLE_TELEMETRY=true`; } let command = `build ${imageToDeploy} --path ${appSourcePath} --builder ${ORYX_BUILDER_IMAGE} --run-image mcr.microsoft.com/oryx/${runtimeStack} --env ${telemetryArg}`; - await util.executeAndThrowIfError(`${PACK_CMD} "${command}"`); + await util.executeAndThrowIfError(`${PACK_CMD} ${command}`); } catch (err) { toolHelper.writeError(err.message); throw err; @@ -343,7 +344,7 @@ export class ContainerAppHelper { try { let dockerTool = await toolHelper.which("docker", true); let command = `build --file ${dockerfilePath} ${appSourcePath} --tag ${imageToDeploy}`; - await util.executeAndThrowIfError(`${dockerTool} "${command}"`); + await util.executeAndThrowIfError(`${dockerTool} ${command}`); toolHelper.writeDebug(`Successfully created runnable application image from the provided/found Dockerfile "${dockerfilePath}" with image name "${imageToDeploy}"`); } catch (err) { toolHelper.writeError(err.message); @@ -363,7 +364,7 @@ export class ContainerAppHelper { // Use 'oryx dockerfile' command to determine the runtime stack to use and write it to a temp file let oryxDockerfileCommand = `oryx dockerfile ${appSourcePath} | head -n 1 | sed 's/ARG RUNTIME=//' >> ${appSourcePath}/oryx-runtime.txt` let command = `run --rm -v ${appSourcePath}:/app ${ORYX_CLI_IMAGE} /bin/bash -c ${oryxDockerfileCommand}}` - await util.executeAndThrowIfError(`${dockerTool} "${command}"`) + await util.executeAndThrowIfError(`${dockerTool} ${command}`) // Read the temp file to get the runtime stack into a variable let oryxRuntimeTxtPath = path.join(appSourcePath, 'oryx-runtime.txt'); @@ -397,8 +398,8 @@ export class ContainerAppHelper { public async setDefaultBuilder() { toolHelper.writeInfo('Setting the Oryx++ Builder as the default builder via the pack CLI'); try { - let command = `config default-builder ${ORYX_BUILDER_IMAGE}` - await util.executeAndThrowIfError(`${PACK_CMD} "${command}"`); + let command = `az config default-builder ${ORYX_BUILDER_IMAGE}` + await util.executeAndThrowIfError(`${PACK_CMD} ${command}`); } catch (err) { toolHelper.writeError(err.message); @@ -422,11 +423,11 @@ export class ContainerAppHelper { commandLine = 'pwsh'; } else { let tgzSuffix = os.platform() == 'darwin' ? 'macos' : 'linux'; - command = `-c (curl -sSL \"https://github.com/buildpacks/pack/releases/download/v0.27.0/pack-v0.27.0-${tgzSuffix}.tgz\" | ` + + command = `(curl -sSL \"https://github.com/buildpacks/pack/releases/download/v0.27.0/pack-v0.27.0-${tgzSuffix}.tgz\" | ` + 'tar -C /usr/local/bin/ --no-same-owner -xzv pack)'; commandLine = 'bash'; } - await util.executeAndThrowIfError(`${commandLine} "${command}"`); + await util.executeAndThrowIfError(`${commandLine} -c "${command}"`); } catch (err) { toolHelper.writeError(`Unable to install the pack CLI. Error: ${err.message}`); throw err; diff --git a/src/ContainerRegistryHelper.ts b/src/ContainerRegistryHelper.ts index 783297b2..2a09fe84 100644 --- a/src/ContainerRegistryHelper.ts +++ b/src/ContainerRegistryHelper.ts @@ -16,7 +16,7 @@ export class ContainerRegistryHelper { toolHelper.writeDebug(`Attempting to log in to ACR instance "${acrName}" with username and password credentials`); try { let dockerTool = await toolHelper.which("docker", true); - await util.executeAndThrowIfError(`${dockerTool} "login --username ${acrUsername} --password ${acrPassword} ${acrName}.azurecr.io"`, [] , Buffer.from(acrPassword)); + await util.executeAndThrowIfError(`${dockerTool} login --username ${acrUsername} --password ${acrPassword} ${acrName}.azurecr.io`, [] , Buffer.from(acrPassword)); } catch (err) { toolHelper.writeError(`Failed to log in to ACR instance "${acrName}" with username and password credentials`); throw err; @@ -32,7 +32,7 @@ export class ContainerRegistryHelper { toolHelper.writeDebug(`Attempting to log in to ACR instance "${acrName}" with access token`); try { let commandLine = os.platform() === 'win32' ? 'pwsh' : 'bash'; - await util.executeAndThrowIfError(`${commandLine}"-c CA_ADO_TASK_ACR_ACCESS_TOKEN=$(az acr login --name ${acrName} --output json --expose-token --only-show-errors | jq -r '.accessToken'); docker login ${acrName}.azurecr.io -u 00000000-0000-0000-0000-000000000000 -p $CA_ADO_TASK_ACR_ACCESS_TOKEN > /dev/null 2>&1"`); + await util.executeAndThrowIfError(`${commandLine} -c "CA_ADO_TASK_ACR_ACCESS_TOKEN=$(az acr login --name ${acrName} --output json --expose-token --only-show-errors | jq -r '.accessToken'); docker login ${acrName}.azurecr.io -u 00000000-0000-0000-0000-000000000000 -p $CA_ADO_TASK_ACR_ACCESS_TOKEN > /dev/null 2>&1"`); } catch (err) { toolHelper.writeError(`Failed to log in to ACR instance "${acrName}" with access token`) throw err; @@ -47,7 +47,7 @@ export class ContainerRegistryHelper { toolHelper.writeDebug(`Attempting to push image "${imageToPush}" to ACR`); try { let dockerTool: string = await toolHelper.which("docker", true); - await util.executeAndThrowIfError(`${dockerTool} "tag ${imageToPush} ${imageToPush}"`); + await util.executeAndThrowIfError(`${dockerTool} tag ${imageToPush} ${imageToPush}`); } catch (err) { toolHelper.writeError(`Failed to push image "${imageToPush}" to ACR. Error: ${err.message}`); throw err; diff --git a/src/TelemetryHelper.ts b/src/TelemetryHelper.ts index 55c2e4bf..fbb92517 100644 --- a/src/TelemetryHelper.ts +++ b/src/TelemetryHelper.ts @@ -88,7 +88,7 @@ export class TelemetryHelper { let eventName = toolHelper.getEventName(); let dockerTool: string = await toolHelper.which("docker", true); - await util.executeAndThrowIfError(`${dockerTool} "run --rm ${ORYX_CLI_IMAGE} /bin/bash -c oryx telemetry --event-name ${eventName} --processing-time ${taskLengthMilliseconds} ${resultArg} ${scenarioArg} ${errorMessageArg}"`); + await util.executeAndThrowIfError(`${dockerTool} run --rm ${ORYX_CLI_IMAGE} /bin/bash -c oryx telemetry --event-name ${eventName} --processing-time ${taskLengthMilliseconds} ${resultArg} ${scenarioArg} ${errorMessageArg}`); } catch (err) { toolHelper.writeWarning(`Skipping telemetry logging due to the following exception: ${err.message}`); } diff --git a/src/Utility.ts b/src/Utility.ts index f1b1bdf5..03540885 100644 --- a/src/Utility.ts +++ b/src/Utility.ts @@ -24,7 +24,7 @@ export class Utility { * Azure Container Apps module being dynamically installed while it's still in preview. */ public async setAzureCliDynamicInstall() { - await this.executeAndThrowIfError(`az "config set extension.use_dynamic_install=yes_without_prompt"`); + await this.executeAndThrowIfError(`az config set extension.use_dynamic_install=yes_without_prompt`); } /**