Skip to content

Commit

Permalink
Merge branch 'v3.x' of github.com:Azure/azure-functions-core-tools in…
Browse files Browse the repository at this point in the history
…to gaaguiar/py312
  • Loading branch information
gavin-aguiar committed Oct 25, 2024
2 parents 7dad9e2 + 84a2a12 commit 070949e
Show file tree
Hide file tree
Showing 38 changed files with 1,636 additions and 696 deletions.
15 changes: 14 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"publish",
"${workspaceFolder}/src/Azure.Functions.Cli/Azure.Functions.Cli.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
"/consoleloggerparameters:NoSummary",
"--framework",
"${input:targetFramework}"
],
"problemMatcher": "$msCompile"
},
Expand All @@ -37,5 +39,16 @@
],
"problemMatcher": "$msCompile"
}
],
"inputs": [
{
"id": "targetFramework",
"type": "pickString",
"options": [
"net8.0",
"net6.0"
],
"description": "Target framework"
}
]
}
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
* @azure/azure-functions-core

# Adding codeowner for Language specific files such that GitHub automatically adds language owners as a reviewers.
src/Azure.Functions.Cli/Azure.Functions.Cli.csproj @azure/azure-functions-worker-owners
src/Azure.Functions.Cli/Azure.Functions.Cli.csproj @azure/azure-functions-worker-owners @azure/azure-functions-core
1 change: 1 addition & 0 deletions build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<ItemGroup>
<PackageReference Include="Colors.Net" Version="1.1.0" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
</Project>
38 changes: 22 additions & 16 deletions build/BuildSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,28 +764,34 @@ private static IEnumerable<string> GetAllRuntimesToSign()

public static void AddGoZip()
{
var runtimeToGoEnv = new Dictionary<string, (string GOOS, string GOARCH)>
{
{ "win-x86", ("windows", "386") },
{ "win-arm64", ("windows", "arm64") },
{ "win-x64", ("windows", "amd64") },
{ "linux-x64", ("linux", "amd64") },
{ "osx-arm64", ("darwin", "arm64") },
{ "osx-x64", ("darwin", "amd64") }
};
var combinedRuntimesToSign = GetAllTargetRuntimes();
foreach (var runtime in combinedRuntimesToSign)
{
var outputPath = Path.Combine(Settings.OutputDir, runtime, "gozip");
Environment.SetEnvironmentVariable("GOARCH", "amd64");
Environment.SetEnvironmentVariable("CGO_ENABLED", "0");
var goFile = Path.GetFullPath("../tools/go/gozip/main.go");

if (runtime.Contains("win"))
{
Environment.SetEnvironmentVariable("GOOS", "windows");
Shell.Run("go", $"build -o {outputPath}.exe {goFile}");
}
else if (runtime.Contains("linux"))
var runtimeId = GetRuntimeId(runtime);
// Remove the Net8ArtifactNameSuffix suffix if present
runtimeId = runtimeId.Replace(Net8ArtifactNameSuffix, "");
if (runtimeToGoEnv.TryGetValue(runtimeId, out var goEnv))
{
Environment.SetEnvironmentVariable("GOOS", "linux");
Shell.Run("go", $"build -o {outputPath} {goFile}");
Environment.SetEnvironmentVariable("CGO_ENABLED", "0");
Environment.SetEnvironmentVariable("GOOS", goEnv.GOOS);
Environment.SetEnvironmentVariable("GOARCH", goEnv.GOARCH);
var outputPath = Path.Combine(Settings.OutputDir, runtime, "gozip");
var output = runtimeId.Contains("win") ? $"{outputPath}.exe" : outputPath;
var goFile = Path.GetFullPath("../tools/go/gozip/main.go");
Shell.Run("go", $"build -o {output} {goFile}");
}
else if (runtime.Contains("osx"))
else
{
Environment.SetEnvironmentVariable("GOOS", "darwin");
Shell.Run("go", $"build -o {outputPath} {goFile}");
throw new Exception($"Unsupported runtime: {runtime}");
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions eng/ci/templates/official/jobs/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ jobs:
timeoutInMinutes: "180"
pool:
name: 1es-pool-azfunc
image: 1es-windows-2022
image: 1es-windows-2022
os: windows

variables:
devops_buildNumber: $[counter(format('1'), 6100)]
DEVOPS_REPO_BRANCH: $[coalesce(variables['System.PullRequest.TargetBranch'], variables['Build.SourceBranchName'])]
DEVOPS_REPO_COMMIT: $(Build.SourceVersion)
steps:
- pwsh: . "tools/start-emulators.ps1" -NoWait
displayName: "Start emulators (NoWait)"
- pwsh: |
$simulateReleaseBuild = $null
if (-not([bool]::TryParse($env:SimulateReleaseBuild, [ref] $simulateReleaseBuild)))
Expand Down Expand Up @@ -89,7 +91,7 @@ jobs:
- pwsh: |
.\check-vulnerabilities.ps1
displayName: "Check for security vulnerabilities"
- template: ci/sign-files.yml@eng
parameters:
displayName: 'Authenticode signing (dll)'
Expand Down Expand Up @@ -174,7 +176,7 @@ jobs:
"ToolVersion" : "1.0"
}
]
- pwsh: |
.\repackageBinaries.ps1
displayName: Repackage signed binaries
Expand All @@ -200,7 +202,7 @@ jobs:
TELEMETRY_INSTRUMENTATION_KEY: $(TELEMETRY_INSTRUMENTATION_KEY)
displayName: 'Generate MSI files'
condition: and(succeeded(), eq(variables['IsReleaseBuild'], 'true'))
- template: ci/sign-files.yml@eng
parameters:
displayName: 'MSI Code Signing'
Expand Down
4 changes: 3 additions & 1 deletion eng/ci/templates/public/jobs/build-test-public.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ jobs:
timeoutInMinutes: "180"
pool:
name: 1es-pool-azfunc-public
image: 1es-windows-2022
image: 1es-windows-2022
os: windows

variables:
devops_buildNumber: $[counter(format(''), 1500)]
DEVOPS_REPO_BRANCH: $[coalesce(variables['System.PullRequest.TargetBranch'], variables['Build.SourceBranchName'])]
DEVOPS_REPO_COMMIT: $(Build.SourceVersion)
steps:
- pwsh: . "tools/start-emulators.ps1" -NoWait
displayName: "Start emulators (NoWait)"
- pwsh: |
$isIntegrationBuild = $false
if ($env:INTEGRATIONBUILDNUMBER -like "PreRelease*-*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ private async Task<IDictionary<string, string>> ValidateFunctionAppPublish(Site
workerRuntimeStr = functionApp.FunctionAppConfig.runtime.name;
}

if (workerRuntime == WorkerRuntime.None)
{
throw new CliException($"Worker runtime is not set. Please set a valid runtime using {Constants.FunctionsWorkerRuntime}");
}

if ((functionApp.IsFlex && !string.IsNullOrEmpty(workerRuntimeStr) ||
(!functionApp.IsFlex && functionApp.AzureAppSettings.TryGetValue(Constants.FunctionsWorkerRuntime, out workerRuntimeStr))))
{
Expand Down
10 changes: 0 additions & 10 deletions src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ private async Task<IWebHost> BuildWebHost(ScriptApplicationHostOptions hostOptio
settings.AddRange(LanguageWorkerHelper.GetWorkerConfiguration(LanguageWorkerSetting));
_keyVaultReferencesManager.ResolveKeyVaultReferences(settings);
UpdateEnvironmentVariables(settings);
EnableWorkerIndexing(settings);

var defaultBuilder = Microsoft.AspNetCore.WebHost.CreateDefaultBuilder(Array.Empty<string>());

Expand Down Expand Up @@ -317,15 +316,6 @@ private void EnableDotNetWorkerStartup()
Environment.SetEnvironmentVariable("DOTNET_STARTUP_HOOKS", "Microsoft.Azure.Functions.Worker.Core");
}

private void EnableWorkerIndexing(IDictionary<string, string> secrets)
{
// Set only if the environment variable already doesn't exist and app setting doesn't have this setting.
if (Environment.GetEnvironmentVariable(Constants.EnableWorkerIndexEnvironmentVariableName) == null && !secrets.ContainsKey(Constants.EnableWorkerIndexEnvironmentVariableName))
{
Environment.SetEnvironmentVariable(Constants.EnableWorkerIndexEnvironmentVariableName, 1.ToString());
}
}

private void UpdateEnvironmentVariables(IDictionary<string, string> secrets)
{
foreach (var secret in secrets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override ICommandLineParserResult ParseArgs(string[] args)
SetFlag<bool>("write-configs", "Output the kubernetes configurations as YAML files instead of deploying", f => WriteConfigs = f);
SetFlag<string>("config-file", "if --write-configs is true, write configs to this file (default: 'functions.yaml')", f => ConfigFile = f);
SetFlag<string>("hash-files", "Files to hash to determine the image version", f => HashFilesPattern = f);
SetFlag<bool>("image-build", "If true, skip the docker build", f => BuildImage = f);
SetFlag<bool>("image-build", "If false, skip the docker build", f => BuildImage = f);

return base.ParseArgs(args);
}
Expand Down Expand Up @@ -295,4 +295,4 @@ private static Dictionary<string, JObject> ReadFunctionJsons(string functionsPat
throw new CliArgumentsException("either --image-name or --registry is required.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ private void ConfigureAuthorizationLevel(Template template)
else
{
var binding = bindings.Where(b => b["type"].ToString().Equals(HttpTriggerTemplateName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
binding["authLevel"] = AuthorizationLevel.ToString();
binding["authLevel"] = AuthorizationLevel.ToString().ToLowerInvariant();
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/Azure.Functions.Cli/Actions/LocalActions/InitAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,16 +394,20 @@ private static async Task WriteLocalSettingsJson(WorkerRuntime workerRuntime, Pr
localSettingsJsonContent = AddLocalSetting(localSettingsJsonContent, Constants.FunctionsWorkerRuntimeVersion, Constants.PowerShellWorkerDefaultVersion);
}

if ((workerRuntime == Helpers.WorkerRuntime.python && programmingModel == Common.ProgrammingModel.V2) || (workerRuntime == Helpers.WorkerRuntime.node && programmingModel == Common.ProgrammingModel.V4))
{
localSettingsJsonContent = AddLocalSetting(localSettingsJsonContent, Constants.AzureWebJobsFeatureFlags, Constants.EnableWorkerIndexing);
}

await FileSystemHelpers.WriteFileIfNotExists("local.settings.json", localSettingsJsonContent);
}

private static async Task WriteDockerfile(WorkerRuntime workerRuntime, string language, string targetFramework, bool csx)
{
if (WorkerRuntimeLanguageHelper.IsDotnet(workerRuntime) && string.IsNullOrEmpty(targetFramework) && !csx)
{
var functionAppRoot = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory);
if (functionAppRoot != null)
{
targetFramework = await DotnetHelpers.DetermineTargetFramework(functionAppRoot);
}
}

if (workerRuntime == Helpers.WorkerRuntime.dotnet)
{
if (csx)
Expand All @@ -429,6 +433,10 @@ private static async Task WriteDockerfile(WorkerRuntime workerRuntime, string la
{
await FileSystemHelpers.WriteFileIfNotExists("Dockerfile", await StaticResources.DockerfileDotnet8Isolated);
}
else if (targetFramework == Common.TargetFramework.net9)
{
await FileSystemHelpers.WriteFileIfNotExists("Dockerfile", await StaticResources.DockerfileDotnet9Isolated);
}
else
{
await FileSystemHelpers.WriteFileIfNotExists("Dockerfile", await StaticResources.DockerfileDotnetIsolated);
Expand Down
8 changes: 7 additions & 1 deletion src/Azure.Functions.Cli/Azure.Functions.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<EmbeddedResource Include="StaticResources\Dockerfile.dotnet8Isolated">
<LogicalName>$(AssemblyName).Dockerfile.dotnet8Isolated</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="StaticResources\Dockerfile.dotnet9Isolated">
<LogicalName>$(AssemblyName).Dockerfile.dotnet9Isolated</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="StaticResources\ExtensionsProj.csproj.template">
<LogicalName>$(AssemblyName).ExtensionsProj.csproj</LogicalName>
</EmbeddedResource>
Expand Down Expand Up @@ -277,7 +280,7 @@
<ItemGroup>
<PackageReference Include="Autofac" Version="4.6.2" />
<PackageReference Include="Azure.Identity" Version="1.11.4" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.2.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.7.0" />
<PackageReference Include="Colors.Net" Version="1.1.0" />
<PackageReference Include="AccentedCommandLineParser" Version="2.0.0" />
<PackageReference Include="DotNetZip" Version="1.13.3" />
Expand All @@ -292,6 +295,9 @@
<PackageReference Include="System.Formats.Asn1" Version="6.0.1" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.1" />
<PackageReference Include="YamlDotNet" Version="6.0.0" />

<!-- Transitive dependency -->
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>
<ItemGroup Condition="'$(NoWorkers)' != 'true'">
<PackageReference Include="Microsoft.Azure.Functions.JavaWorker" Version="2.14.0" />
Expand Down
1 change: 0 additions & 1 deletion src/Azure.Functions.Cli/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ internal static class Constants
public const string AuthLevelErrorMessage = "Unable to configure Authorization level. The selected template does not use Http Trigger";
public const string HttpTriggerTemplateName = "HttpTrigger";
public const string PowerShellWorkerDefaultVersion = "7.2";
public const string EnableWorkerIndexing = "EnableWorkerIndexing";
public const string UserSecretsIdElementName = "UserSecretsId";
public const string TargetFrameworkElementName = "TargetFramework";
public const string DisplayLogo = "FUNCTIONS_CORE_TOOLS_DISPLAY_LOGO";
Expand Down
Loading

0 comments on commit 070949e

Please sign in to comment.