Repository navigation
Expand file tree
/
Copy pathazure.yaml
More file actions
117 lines (108 loc) · 6.67 KB
/
Copy pathazure.yaml
File metadata and controls
117 lines (108 loc) · 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json
#
# Deploys the sample to Azure with the Azure Developer CLI:
#
# azd auth login
# az login
# azd up
#
# The hooks use the Azure CLI, which keeps its own sign-in separate from azd's, so sign in to both.
# azd provisions infra/azure/platform.bicep (AKS, container registry, managed identities). The hooks
# then set up the cluster (Radius, ingress, Entra app registrations) and deploy the app with Radius.
# azd has no service of its own to deploy here; Radius deploys the app from deploy/app.bicep.
#
# Optional settings, before azd up:
# azd env set DNS_LABEL <label> # public name <label>.<region>.cloudapp.azure.com; default oms-<env name>
# azd env set AKS_NODE_VM_SIZE <size> # if Standard_D4s_v7 isn't allowed in your subscription or region
# azd env set AKS_NODE_OS_UPGRADE_DAY <day> # weekly window for node security patches; default Sunday
# azd env set AKS_NODE_OS_UPGRADE_START <HH:mm> # its start in UTC, four hours long; default 02:00
# azd env set SQL_LOCATION <region> # if your subscription can't create Azure SQL in the main region
# azd env set POSTGRES_LOCATION <region> # if your subscription can't create PostgreSQL in the main region
# azd env set SERVICE_MANAGEMENT_REFERENCE <id> # if your Entra tenant requires it on app registrations
# azd env set ALERT_EMAIL <address> # who gets the alerts (dead-lettered order, stalled processor, low stock)
# azd env set PRIVATE_CA true # if Let's Encrypt can't reach the cluster (inbound internet blocked);
# # the app then uses a certificate from a CA kept in the cluster
# azd env set USE_PRIVATE_ENDPOINTS true # reach Blob Storage, Azure SQL and PostgreSQL through private endpoints,
# # with their public access off; set false and re-run azd up to undo
# azd env set HUB_VIRTUAL_NETWORK_ID <resource-id> # peer the cluster's virtual network with a hub in the same subscription
# azd env set AKS_VNET_ADDRESS_PREFIX <cidr> # the cluster's address ranges, fixed once it exists: virtual network
# azd env set AKS_POD_CIDR <cidr> # (default 10.224.0.0/16), pods (10.244.0.0/16), services (10.0.0.0/16)
# azd env set AKS_SERVICE_CIDR <cidr> # and cluster DNS (default the tenth address of the service range).
# azd env set AKS_DNS_SERVICE_IP <address> # None may overlap the others, the hub or an on-premises network.
#
# Each azd environment gets its own app registrations (oms-api-<env>, oms-spa-<env>, oms-inventory-<env>) and Radius
# workspace, so several can live side by side. azd down deletes the resource group, including what
# the Recipes created in it, and the app registrations.
name: order-management
infra:
provider: bicep
path: infra/azure
module: platform
hooks:
# Fails before anything is created when the Azure CLI, which the later hooks use, isn't signed in.
preprovision:
shell: pwsh
run: |
$subscription = @(if ($env:AZURE_SUBSCRIPTION_ID) { '--subscription', $env:AZURE_SUBSCRIPTION_ID })
az account show @subscription --output none 2>$null
if ($LASTEXITCODE -ne 0) {
throw "The Azure CLI can't use subscription '$env:AZURE_SUBSCRIPTION_ID'. Sign it in too: az login --tenant <tenant-id>"
}
# The cluster's address ranges can't change once it exists, so they're checked first.
. ./scripts/lib/network.ps1
Assert-OmsAddressRanges `
-VirtualNetworkAddressPrefix $(if ($env:AKS_VNET_ADDRESS_PREFIX) { $env:AKS_VNET_ADDRESS_PREFIX } else { '10.224.0.0/16' }) `
-PodCidr $(if ($env:AKS_POD_CIDR) { $env:AKS_POD_CIDR } else { '10.244.0.0/16' }) `
-ServiceCidr $(if ($env:AKS_SERVICE_CIDR) { $env:AKS_SERVICE_CIDR } else { '10.0.0.0/16' }) `
-HubVirtualNetworkId $env:HUB_VIRTUAL_NETWORK_ID
postprovision:
shell: pwsh
interactive: true
run: |
$ErrorActionPreference = 'Stop'
$label = if ($env:DNS_LABEL) { $env:DNS_LABEL } else { "oms-$env:AZURE_ENV_NAME" }
./scripts/infra/azure/provision-infra.ps1 -SkipTemplate `
-SubscriptionId $env:AZURE_SUBSCRIPTION_ID -Location $env:AZURE_LOCATION `
-ResourceGroup $env:resourceGroupName -ClusterName $env:clusterName -KubeContext $env:clusterName `
-RegistryName $env:registryName -WorkspaceName $env:AZURE_ENV_NAME
$ingressArgs = @{ KubeContext = $env:clusterName; DnsLabel = $label }
if ($env:PRIVATE_CA -eq 'true') { $ingressArgs.PrivateCa = $true }
./scripts/infra/azure/provision-ingress.ps1 @ingressArgs
$identityArgs = @{
SpaOrigins = @("https://$label.$env:AZURE_LOCATION.cloudapp.azure.com")
ApiAppName = "oms-api-$env:AZURE_ENV_NAME"
SpaAppName = "oms-spa-$env:AZURE_ENV_NAME"
InventoryAppName = "oms-inventory-$env:AZURE_ENV_NAME"
ResourceGroup = $env:resourceGroupName
Location = $env:AZURE_LOCATION
}
if ($env:SERVICE_MANAGEMENT_REFERENCE) { $identityArgs.ServiceManagementReference = $env:SERVICE_MANAGEMENT_REFERENCE }
./scripts/infra/azure/configure-app-identity.ps1 @identityArgs
postdeploy:
shell: pwsh
interactive: true
run: |
$ErrorActionPreference = 'Stop'
$deployArgs = @{
SubscriptionId = $env:AZURE_SUBSCRIPTION_ID
Location = $env:AZURE_LOCATION
Registry = $env:registryLoginServer
ResourceGroup = $env:resourceGroupName
ClusterName = $env:clusterName
KubeContext = $env:clusterName
WorkspaceName = $env:AZURE_ENV_NAME
OrdersApiAppName = "oms-api-$env:AZURE_ENV_NAME"
OrdersSpaAppName = "oms-spa-$env:AZURE_ENV_NAME"
InventoryAppName = "oms-inventory-$env:AZURE_ENV_NAME"
}
if ($env:SQL_LOCATION) { $deployArgs.SqlLocation = $env:SQL_LOCATION }
if ($env:POSTGRES_LOCATION) { $deployArgs.PostgresLocation = $env:POSTGRES_LOCATION }
if ($env:PRIVATE_CA -eq 'true') { $deployArgs.IngressCertIssuer = 'bcd-private-ca' }
./scripts/deploy/azure.ps1 @deployArgs
postdown:
shell: pwsh
run: |
foreach ($name in "oms-api-$env:AZURE_ENV_NAME", "oms-spa-$env:AZURE_ENV_NAME", "oms-inventory-$env:AZURE_ENV_NAME") {
$appId = az ad app list --display-name $name --query '[0].appId' --output tsv
if ($appId) { az ad app delete --id $appId; Write-Host "Deleted app registration $name" }
}