-
Notifications
You must be signed in to change notification settings - Fork 24
Update NodeBuilder to Support Deployment of Nodejs Projects #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/Microsoft.Agents.A365.DevTools.Cli/Services/Helpers/BuilderHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.Agents.A365.DevTools.Cli.Services.Helpers | ||
| { | ||
| public class BuilderHelper | ||
| { | ||
| private readonly ILogger _logger; | ||
| private readonly CommandExecutor _executor; | ||
|
|
||
| public BuilderHelper(ILogger logger, CommandExecutor executor) | ||
| { | ||
| _logger = logger; | ||
| _executor = executor; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts .env file to Azure App Settings using a single az webapp config appsettings set command | ||
| /// </summary> | ||
| public async Task<bool> ConvertEnvToAzureAppSettingsIfExistsAsync( | ||
| string projectDir, | ||
| string resourceGroup, | ||
| string webAppName, | ||
| bool verbose) | ||
| { | ||
| var envFilePath = Path.Combine(projectDir, ".env"); | ||
| if (!File.Exists(envFilePath)) | ||
| { | ||
| _logger.LogInformation("No .env file found to convert to Azure App Settings"); | ||
| return true; // Not an error, just no env file | ||
| } | ||
|
|
||
| _logger.LogInformation("Converting .env file to Azure App Settings..."); | ||
|
|
||
| var envSettings = new List<string>(); | ||
| var lines = await File.ReadAllLinesAsync(envFilePath); | ||
|
|
||
| foreach (var line in lines) | ||
| { | ||
| // Skip empty lines and comments | ||
| if (string.IsNullOrWhiteSpace(line) || line.Trim().StartsWith("#")) | ||
| continue; | ||
|
|
||
| // Parse KEY=VALUE format | ||
| var equalIndex = line.IndexOf('='); | ||
| if (equalIndex > 0 && equalIndex < line.Length - 1) | ||
| { | ||
| var key = line.Substring(0, equalIndex).Trim(); | ||
| var value = line.Substring(equalIndex + 1).Trim(); | ||
|
|
||
| // Remove quotes if present | ||
| if ((value.StartsWith("\"") && value.EndsWith("\"")) || | ||
| (value.StartsWith("'") && value.EndsWith("'"))) | ||
| { | ||
| value = value.Substring(1, value.Length - 2); | ||
|
JesuTerraz marked this conversation as resolved.
|
||
| } | ||
|
|
||
| envSettings.Add($"{key}={value}"); | ||
| _logger.LogDebug("Found environment variable: {Key}", key); | ||
| } | ||
| } | ||
|
JesuTerraz marked this conversation as resolved.
JesuTerraz marked this conversation as resolved.
|
||
|
|
||
| if (envSettings.Count == 0) | ||
| { | ||
| _logger.LogInformation("No valid environment variables found in .env file"); | ||
| return true; | ||
| } | ||
|
|
||
| // Build single az webapp config appsettings set command with all variables | ||
| var settingsArgs = string.Join(" ", envSettings.Select(setting => $"\"{setting}\"")); | ||
| var azCommand = $"webapp config appsettings set -g {resourceGroup} -n {webAppName} --settings {settingsArgs}"; | ||
|
|
||
| _logger.LogInformation("Setting {Count} environment variables as Azure App Settings...", envSettings.Count); | ||
|
|
||
| var result = await ExecuteWithOutputAsync("az", azCommand, projectDir, verbose); | ||
| if (result.Success) | ||
| { | ||
| _logger.LogInformation("Successfully converted {Count} environment variables to Azure App Settings", envSettings.Count); | ||
| return true; | ||
| } | ||
| else | ||
| { | ||
| _logger.LogError("Failed to set Azure App Settings: {Error}", result.StandardError); | ||
| return false; | ||
| } | ||
| } | ||
|
JesuTerraz marked this conversation as resolved.
|
||
|
|
||
| public async Task<CommandResult> ExecuteWithOutputAsync(string command, string arguments, string workingDirectory, bool verbose) | ||
| { | ||
| var result = await _executor.ExecuteAsync(command, arguments, workingDirectory); | ||
|
|
||
| if (verbose || !result.Success) | ||
| { | ||
| if (!string.IsNullOrWhiteSpace(result.StandardOutput)) | ||
| { | ||
| _logger.LogInformation("Output:\n{Output}", result.StandardOutput); | ||
| } | ||
| if (!string.IsNullOrWhiteSpace(result.StandardError)) | ||
| { | ||
| _logger.LogWarning("Warnings/Errors:\n{Error}", result.StandardError); | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.