Skip to content

Commit

Permalink
Merge pull request #74 from codatio/add-runtime-to-slot
Browse files Browse the repository at this point in the history
Allow specification on NET Framework on slot for a webapp
  • Loading branch information
nkuzmincodat authored Mar 19, 2024
2 parents ccb9ff2 + 82b7f23 commit c09c4f3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
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
|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"
}
]

0 comments on commit c09c4f3

Please sign in to comment.