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

Allow specification on NET Framework on slot for a webapp #74

Merged
merged 3 commits into from
Mar 19, 2024
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
15 changes: 15 additions & 0 deletions src/Farmer/Builders/Builders.WebApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Runtime =
static member DotNet50 = DotNet "5.0"
static member DotNet60 = DotNet "6.0"
static member DotNet70 = DotNet "7.0"
static member DotNet80 = DotNet "8.0"
static member AspNet47 = AspNet "4.0"
static member AspNet35 = AspNet "2.0"
static member Python27 = Python("2.7", "2.7")
Expand Down Expand Up @@ -110,6 +111,7 @@ type SlotConfig =
ApplyIPSecurityRestrictionsToScm: bool
EnablePublicNetworkAccess: bool option
AlwaysOn: bool option
Runtime: Runtime option
}

member this.ToSite(owner: Arm.Web.Site) =
Expand Down Expand Up @@ -137,6 +139,11 @@ type SlotConfig =
ApplyIPSecurityRestrictionsToScm = this.ApplyIPSecurityRestrictionsToScm
EnablePublicNetworkAccess = this.EnablePublicNetworkAccess
ZipDeployPath = None
NetFrameworkVersion = this.Runtime |> Option.map (fun r -> r |> function
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The joy of currying means you don't need to declare the lambda here, you can just use function directly which has a "dangling" second argument which is left to Option.map to fill in.

Suggested change
NetFrameworkVersion = this.Runtime |> Option.map (fun r -> r |> function
NetFrameworkVersion = this.Runtime |> Option.map (function

|AspNet version
| DotNet ("5.0" as version)
| DotNet version -> Some $"v{version}"
| _ -> None) |> Option.defaultValue owner.NetFrameworkVersion
PostDeployActions =
[
fun rg ->
Expand Down Expand Up @@ -217,6 +224,7 @@ type SlotBuilder() =
IpSecurityRestrictions = []
ApplyIPSecurityRestrictionsToScm = false
EnablePublicNetworkAccess = None
Runtime = None
AlwaysOn = None
}

Expand Down Expand Up @@ -369,6 +377,13 @@ type SlotBuilder() =
{ state with
EnablePublicNetworkAccess = Some true
}

/// Adds Runtime to the slot, to allow zero downtime deployments when changing runtime.
[<CustomOperation "runtime">]
member this.Runtime(state: SlotConfig, runtime : Runtime) =
{ state with
Runtime = Some runtime
}

interface ITaggable<SlotConfig> with
member _.Add state tags =
Expand Down
28 changes: 28 additions & 0 deletions src/Tests/WebApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2075,4 +2075,32 @@ let tests =
Expect.equal slot.Name.Value "webapp/deployment" "Slot name was not as expected"
Expect.equal slot.AlwaysOn false "Slot was not set to Always On -> false"
}
test "WebApp supports runtime on slot" {
let slot =
appSlot {
name "warm-up"
runtime Runtime.DotNet80
}

let app =
webApp {
name "webapp"
add_slot slot
}

Expect.isTrue (app.CommonWebConfig.Slots.ContainsKey "warm-up") "Config should contain slot"

let slots =
app
|> getResources
|> getResource<Arm.Web.Site>
|> List.filter (fun x -> x.ResourceType = Arm.Web.slots)
// Default "production" slot is not included as it is created automatically in Azure
Expect.hasLength slots 1 "Should only be 1 slot"

let netFrameworkVersion =
Expect.wantSome slots[0].NetFrameworkVersion "Net Framework version should be set"

Expect.equal netFrameworkVersion "v8.0" "Net Framework version should be set to 8.0"
}
]
Loading