Skip to content

Commit

Permalink
Health checks & deployment slot
Browse files Browse the repository at this point in the history
  • Loading branch information
harryy94 committed Jan 27, 2025
1 parent 6afaa8c commit d7c0242
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,6 @@ jobs:
uses: azure/webapps-deploy@v2
with:
app-name: ${{ vars.DEV_AZURE_WEBAPP_NAME }}
slot-name: 'staging'
publish-profile: ${{ env.PUBLISHING_PROFILE }}
images: 'ghcr.io/${{ env.REPO }}:${{ github.sha }}'
8 changes: 8 additions & 0 deletions src/infrastructure/terraform/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ locals {
location = "westeurope"
frontdoor_name = "${local.service_prefix}-web-fd"
frontdoor_url = "${local.frontdoor_name}.azurefd.net"

web_app_settings = {
"ContentfulOptions__DeliveryApiKey" = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault_secret.contentful-delivery-api-key.versionless_id})"
"ContentfulOptions__PreviewApiKey" = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault_secret.contentful-preview-api-key.versionless_id})"
"ContentfulOptions__SpaceId" = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault_secret.contentful-space-id.versionless_id})"
"BaseUrl" = "https://${local.frontdoor_url}"
"ApplicationInsights__ConnectionString" = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault_secret.application-insights-connection-string.versionless_id})"
}
}
30 changes: 22 additions & 8 deletions src/infrastructure/terraform/web.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,29 @@ resource "azurerm_service_plan" "web-app-service-plan" {
name = "${local.service_prefix}-web-app-service-plan"
resource_group_name = azurerm_resource_group.web-rg.name
os_type = "Linux"
sku_name = "B1"
sku_name = "P0V3"

tags = local.common_tags
}

resource "azurerm_linux_web_app_slot" "web-app-service-staging" {
app_service_id = azurerm_linux_web_app.web-app-service.id
name = "staging"

site_config {
always_on = true

ip_restriction_default_action = "Deny"

ip_restriction {
name = "Access from Front Door"
service_tag = "AzureFrontDoor.Backend"
}
}

app_settings = local.web_app_settings
}

resource "azurerm_linux_web_app" "web-app-service" {
service_plan_id = azurerm_service_plan.web-app-service-plan.id
location = local.location
Expand All @@ -31,6 +49,8 @@ resource "azurerm_linux_web_app" "web-app-service" {
name = "Access from Front Door"
service_tag = "AzureFrontDoor.Backend"
}

health_check_path = "health"
}

identity {
Expand All @@ -40,13 +60,7 @@ resource "azurerm_linux_web_app" "web-app-service" {
]
}

app_settings = {
"ContentfulOptions__DeliveryApiKey" = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault_secret.contentful-delivery-api-key.versionless_id})"
"ContentfulOptions__PreviewApiKey" = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault_secret.contentful-preview-api-key.versionless_id})"
"ContentfulOptions__SpaceId" = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault_secret.contentful-space-id.versionless_id})"
"BaseUrl" = "https://${local.frontdoor_url}"
"ApplicationInsights__ConnectionString" = "@Microsoft.KeyVault(SecretUri=${azurerm_key_vault_secret.application-insights-connection-string.versionless_id})"
}
app_settings = local.web_app_settings

tags = local.common_tags
}
Expand Down
4 changes: 4 additions & 0 deletions src/web/CareLeavers.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

builder.Services.AddContentful(builder.Configuration);

builder.Services.AddHealthChecks();

builder.Services.AddTransient<HtmlRenderer>((c) =>
{
var renderer = new HtmlRenderer(new HtmlRendererOptions
Expand Down Expand Up @@ -99,6 +101,8 @@
app.UseRouting();

app.UseAuthorization();

app.MapHealthChecks("/health");

app.MapControllerRoute(
name: "default",
Expand Down

0 comments on commit d7c0242

Please sign in to comment.