Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
Added support for environment variables when using Azure Functions (#…
Browse files Browse the repository at this point in the history
…1171)

Co-authored-by: Chris Theodorson <chris.theodorson@halfords.co.uk>
  • Loading branch information
chris-theodorson and Chris Theodorson authored Sep 30, 2021
1 parent 2858fce commit e3e90d3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Microsoft.Tye.Core/ApplicationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ service is ProjectServiceBuilder project2 &&
{
executable.EnvironmentVariables.Add(envVar);
}
else if (service is AzureFunctionServiceBuilder azureFunction)
{
azureFunction.EnvironmentVariables.Add(envVar);
}
else if (service is ExternalServiceBuilder)
{
throw new CommandException("External services do not support environment variables.");
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.Tye.Core/AzureFunctionServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;

namespace Microsoft.Tye
{
public class AzureFunctionServiceBuilder : ServiceBuilder
Expand All @@ -17,5 +19,6 @@ public AzureFunctionServiceBuilder(string name, string path, ServiceSource sourc
public string FunctionPath { get; }
public string? FuncExecutablePath { get; set; }
public string? ProjectFile { get; set; }
public List<EnvironmentVariableBuilder> EnvironmentVariables { get; } = new List<EnvironmentVariableBuilder>();
}
}
5 changes: 5 additions & 0 deletions src/tye/ApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ public static Application ToHostingApplication(this ApplicationBuilder applicati
replicas = function.Replicas;
liveness = null;
readiness = null;

foreach (var entry in function.EnvironmentVariables)
{
env.Add(entry.ToHostingEnvironmentVariable());
}
}
else
{
Expand Down

0 comments on commit e3e90d3

Please sign in to comment.