Skip to content
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

Setting and depends_on for Azure Functions - #14 #15 #16

Merged
merged 2 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,7 @@ healthchecksdb
MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
.ionide/

# Rider working folder
.idea/
35 changes: 32 additions & 3 deletions src/Farmer/Builders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ module WebApp =
AutoCreateStorageAccount : bool
AppInsightsName : ResourceName option
WorkerRuntime : WorkerRuntime
OperatingSystem : OS }
OperatingSystem : OS
Settings : Map<string, string>
Dependencies : ResourceName list }
member this.PublishingPassword = publishingPassword this.Name
member this.StorageAccountKey = Storage.buildKey this.StorageAccountName
member this.AppInsightsKey = this.AppInsightsName |> Option.map Helpers.AppInsights.instrumentationKey
Expand Down Expand Up @@ -191,7 +193,9 @@ module WebApp =
StorageAccountName = ResourceName.Empty
AutoCreateStorageAccount = true
WorkerRuntime = DotNet
OperatingSystem = Windows }
OperatingSystem = Windows
Settings = Map.empty
Dependencies = [] }
member __.Run (state:FunctionsConfig) =
{ state with
ServicePlanName = state.ServicePlanName.IfEmpty (sprintf "%s-plan" state.Name.Value)
Expand All @@ -214,6 +218,13 @@ module WebApp =
member __.Runtime(state:FunctionsConfig, runtime) = { state with WorkerRuntime = runtime }
[<CustomOperation "operating_system">]
member __.OperatingSystem(state:FunctionsConfig, os) = { state with OperatingSystem = os }
/// Sets an app setting of the function app; use the `setting` keyword.
[<CustomOperation "setting">]
member __.AddSetting(state:FunctionsConfig, key, value) = { state with Settings = state.Settings.Add(key, value) }
/// Sets a dependency for the function app; use the `depends_on` keyword.
[<CustomOperation "depends_on">]
member __.DependsOn(state:FunctionsConfig, resourceName) =
{ state with Dependencies = resourceName :: state.Dependencies }

let webApp = WebAppBuilder()
let functions = FunctionsBuilder()
Expand All @@ -222,8 +233,15 @@ module WebApp =
module Extensions =
open WebApp
type WebAppBuilder with
member this.DependsOn(state:WebAppConfig, functionsConfig:FunctionsConfig) =
this.DependsOn(state, functionsConfig.Name)
member this.DependsOn(state:WebAppConfig, storageAccountConfig:StorageAccountConfig) =
this.DependsOn(state, storageAccountConfig.Name)
type FunctionsBuilder with
member this.DependsOn(state:FunctionsConfig, storageAccountConfig:StorageAccountConfig) =
this.DependsOn(state, storageAccountConfig.Name)
member this.DependsOn(state:FunctionsConfig, webAppConfig:WebAppConfig) =
this.DependsOn(state, webAppConfig.Name)

[<AutoOpen>]
module CosmosDb =
Expand Down Expand Up @@ -296,6 +314,9 @@ module CosmosDb =
type WebAppBuilder with
member this.DependsOn(state:WebAppConfig, cosmosDbConfig:CosmosDbConfig) =
this.DependsOn(state, cosmosDbConfig.DbName)
type FunctionsBuilder with
member this.DependsOn(state:FunctionsConfig, cosmosDbConfig:CosmosDbConfig) =
this.DependsOn(state, cosmosDbConfig.DbName)

let cosmosDb = CosmosDbBuilder()
let container = CosmosDbContainer()
Expand Down Expand Up @@ -379,6 +400,9 @@ module SqlAzure =
type WebAppBuilder with
member this.DependsOn(state:WebAppConfig, sqlDb:SqlAzureConfig) =
this.DependsOn(state, sqlDb.ServerName)
type FunctionsBuilder with
member this.DependsOn(state:FunctionsConfig, sqlDb:SqlAzureConfig) =
this.DependsOn(state, sqlDb.ServerName)

let sql = SqlBuilder()

Expand Down Expand Up @@ -685,7 +709,10 @@ module Search =
type WebAppBuilder with
member this.DependsOn(state:WebAppConfig, search:SearchConfig) =
this.DependsOn(state, search.Name)

type FunctionsBuilder with
member this.DependsOn(state:FunctionsConfig, search:SearchConfig) =
this.DependsOn(state, search.Name)

let search = SearchBuilder()

[<AutoOpen>]
Expand Down Expand Up @@ -802,6 +829,7 @@ module ArmBuilder =
ServerFarm = fns.ServicePlanName
Location = state.Location
AppSettings = [
yield! Map.toList fns.Settings
yield "FUNCTIONS_WORKER_RUNTIME", string fns.WorkerRuntime
yield "WEBSITE_NODE_DEFAULT_VERSION", "10.14.1"
yield "FUNCTIONS_EXTENSION_VERSION", "~2"
Expand All @@ -823,6 +851,7 @@ module ArmBuilder =
| Linux -> Some "functionapp,linux"
Extensions = Set.empty
Dependencies = [
yield! fns.Dependencies
match fns.AppInsightsName with
| Some appInsightsame -> yield appInsightsame
| None -> ()
Expand Down
2 changes: 2 additions & 0 deletions src/Farmer/Test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ let template (environment:string) storageSku webAppSku =
app_insights_name "isaacsuperai"
operating_system Windows
use_runtime DotNet
setting "myDbName" myCosmosDb.DbName.Value
depends_on myCosmosDb
}

let myWebApp = webApp {
Expand Down