@cubocicloide/stack-react-fastapi 13.4.2 → 13.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2654 -329
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/templates/azure-aca/backend/Dockerfile.prod.hbs +29 -0
- package/templates/azure-aca/docs/docs/deploy.md.hbs +127 -0
- package/templates/azure-aca/frontend/Dockerfile.prod +36 -0
- package/templates/azure-aca/frontend/nginx.conf.template +47 -0
- package/templates/azure-aca/iac/README.md.hbs +286 -0
- package/templates/azure-aca/iac/_gitignore +19 -0
- package/templates/azure-aca/iac/runner/Dockerfile +51 -0
- package/templates/azure-aca/iac/terraform/bootstrap/main.tf.hbs +123 -0
- package/templates/azure-aca/iac/terraform/bootstrap/outputs.tf +24 -0
- package/templates/azure-aca/iac/terraform/bootstrap/variables.tf.hbs +23 -0
- package/templates/azure-aca/iac/terraform/environments/dev/backend.hcl.hbs +25 -0
- package/templates/azure-aca/iac/terraform/environments/dev/terraform.tfvars.hbs +69 -0
- package/templates/azure-aca/iac/terraform/main.tf.hbs +593 -0
- package/templates/azure-aca/iac/terraform/outputs.tf.hbs +72 -0
- package/templates/azure-aca/iac/terraform/providers.tf +16 -0
- package/templates/azure-aca/iac/terraform/variables.tf.hbs +200 -0
- package/templates/azure-aca/iac/terraform/versions.tf +21 -0
- package/templates/azure-aks/backend/Dockerfile.prod.hbs +29 -0
- package/templates/azure-aks/docs/docs/deploy.md.hbs +273 -0
- package/templates/azure-aks/frontend/Dockerfile.prod +32 -0
- package/templates/azure-aks/frontend/nginx.conf +20 -0
- package/templates/azure-aks/iac/README.md.hbs +472 -0
- package/templates/azure-aks/iac/_gitignore +29 -0
- package/templates/azure-aks/iac/helm/app/.helmignore +7 -0
- package/templates/azure-aks/iac/helm/app/Chart.yaml.hbs +6 -0
- package/templates/azure-aks/iac/helm/app/templates/NOTES.txt +32 -0
- package/templates/azure-aks/iac/helm/app/templates/backend-deployment.yaml +44 -0
- package/templates/azure-aks/iac/helm/app/templates/backend-service.yaml +16 -0
- package/templates/azure-aks/iac/helm/app/templates/celery-beat-deployment.yaml +34 -0
- package/templates/azure-aks/iac/helm/app/templates/celery-worker-deployment.yaml +31 -0
- package/templates/azure-aks/iac/helm/app/templates/configmap.yaml +15 -0
- package/templates/azure-aks/iac/helm/app/templates/flower-deployment.yaml +28 -0
- package/templates/azure-aks/iac/helm/app/templates/flower-service.yaml +19 -0
- package/templates/azure-aks/iac/helm/app/templates/frontend-deployment.yaml +34 -0
- package/templates/azure-aks/iac/helm/app/templates/frontend-service.yaml +16 -0
- package/templates/azure-aks/iac/helm/app/templates/helpers.tpl +90 -0
- package/templates/azure-aks/iac/helm/app/templates/hpa.yaml +23 -0
- package/templates/azure-aks/iac/helm/app/templates/ingress.yaml +35 -0
- package/templates/azure-aks/iac/helm/app/templates/migration-job.yaml +38 -0
- package/templates/azure-aks/iac/helm/app/templates/redis-deployment.yaml +33 -0
- package/templates/azure-aks/iac/helm/app/templates/redis-service.yaml +18 -0
- package/templates/azure-aks/iac/helm/app/templates/secret.yaml +17 -0
- package/templates/azure-aks/iac/helm/app/templates/serviceaccount.yaml +12 -0
- package/templates/azure-aks/iac/helm/app/values-dev.yaml.hbs +36 -0
- package/templates/azure-aks/iac/helm/app/values.yaml.hbs +147 -0
- package/templates/azure-aks/iac/runner/Dockerfile +61 -0
- package/templates/azure-aks/iac/terraform/bootstrap/main.tf.hbs +123 -0
- package/templates/azure-aks/iac/terraform/bootstrap/outputs.tf +24 -0
- package/templates/azure-aks/iac/terraform/bootstrap/variables.tf.hbs +23 -0
- package/templates/azure-aks/iac/terraform/environments/dev/backend.hcl.hbs +25 -0
- package/templates/azure-aks/iac/terraform/environments/dev/terraform.tfvars.hbs +65 -0
- package/templates/azure-aks/iac/terraform/main.tf.hbs +307 -0
- package/templates/azure-aks/iac/terraform/outputs.tf.hbs +57 -0
- package/templates/azure-aks/iac/terraform/providers.tf +35 -0
- package/templates/azure-aks/iac/terraform/variables.tf.hbs +157 -0
- package/templates/azure-aks/iac/terraform/versions.tf +29 -0
- package/templates/base/CLAUDE.md.hbs +7 -7
- package/templates/base/backend/pyproject.toml.hbs +1 -1
- package/templates/base/docs/docs/dude.md.hbs +1 -1
- package/templates/base/docs/docs/index.md.hbs +1 -1
- package/templates/base/docs/mkdocs.yml.hbs +1 -1
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
locals {
|
|
2
|
+
name = "${var.project_name}-${var.environment}"
|
|
3
|
+
|
|
4
|
+
backend_app = "${local.name}-backend"
|
|
5
|
+
frontend_app = "${local.name}-frontend"
|
|
6
|
+
{{#if withCelery}}
|
|
7
|
+
worker_app = "${local.name}-worker"
|
|
8
|
+
{{/if}}
|
|
9
|
+
{{#if withCeleryBeat}}
|
|
10
|
+
beat_app = "${local.name}-beat"
|
|
11
|
+
{{/if}}
|
|
12
|
+
{{#if withRedis}}
|
|
13
|
+
redis_app = "${local.name}-redis"
|
|
14
|
+
# Apps in one Container Apps environment resolve each other by app name, so
|
|
15
|
+
# the broker URL needs no FQDN and no output plumbing.
|
|
16
|
+
redis_url = "redis://${local.redis_app}:6379/0"
|
|
17
|
+
{{/if}}
|
|
18
|
+
|
|
19
|
+
backend_image = "${data.azurerm_container_registry.shared.login_server}/${var.project_name}-backend:${var.image_tag}"
|
|
20
|
+
frontend_image = "${data.azurerm_container_registry.shared.login_server}/${var.project_name}-frontend:${var.image_tag}"
|
|
21
|
+
|
|
22
|
+
# Non-sensitive configuration, applied to every app that runs application code.
|
|
23
|
+
# Each key is the ENV VAR NAME exactly as backend/app/core/config.py reads it,
|
|
24
|
+
# so adding a setting is a line here plus the field in config.py.
|
|
25
|
+
common_env = merge(
|
|
26
|
+
{
|
|
27
|
+
APP_TITLE = var.project_name
|
|
28
|
+
DEBUG = var.debug
|
|
29
|
+
},
|
|
30
|
+
{{#if withRedis}}
|
|
31
|
+
{
|
|
32
|
+
CELERY_BROKER_URL = local.redis_url
|
|
33
|
+
CELERY_RESULT_BACKEND = local.redis_url
|
|
34
|
+
REDIS_URL = local.redis_url
|
|
35
|
+
},
|
|
36
|
+
{{else}}
|
|
37
|
+
{},
|
|
38
|
+
{{/if}}
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
tags = {
|
|
42
|
+
Project = var.project_name
|
|
43
|
+
Environment = var.environment
|
|
44
|
+
ManagedBy = "terraform"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
resource "azurerm_resource_group" "this" {
|
|
49
|
+
name = "${local.name}-rg"
|
|
50
|
+
location = var.location
|
|
51
|
+
tags = local.tags
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
# ── Network ───────────────────────────────────────────────────────────────────
|
|
55
|
+
# The environment is VNet-injected so the application can reach a PostgreSQL
|
|
56
|
+
# server that has no public endpoint. Its public ingress is unaffected: the
|
|
57
|
+
# platform still publishes an internet-facing HTTPS endpoint for apps marked
|
|
58
|
+
# external.
|
|
59
|
+
resource "azurerm_virtual_network" "this" {
|
|
60
|
+
name = "${local.name}-vnet"
|
|
61
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
62
|
+
location = azurerm_resource_group.this.location
|
|
63
|
+
address_space = [var.vnet_cidr]
|
|
64
|
+
tags = local.tags
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
resource "azurerm_subnet" "aca" {
|
|
68
|
+
name = "${local.name}-aca-snet"
|
|
69
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
70
|
+
virtual_network_name = azurerm_virtual_network.this.name
|
|
71
|
+
address_prefixes = [var.aca_subnet_cidr]
|
|
72
|
+
|
|
73
|
+
delegation {
|
|
74
|
+
name = "containerapps"
|
|
75
|
+
service_delegation {
|
|
76
|
+
name = "Microsoft.App/environments"
|
|
77
|
+
actions = ["Microsoft.Network/virtualNetworks/subnets/join/action"]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
{{#if withPostgres}}
|
|
82
|
+
|
|
83
|
+
# Flexible Server with VNet integration requires a subnet delegated exclusively
|
|
84
|
+
# to it — the database gets a private address inside the VNet and is never
|
|
85
|
+
# exposed to the internet.
|
|
86
|
+
resource "azurerm_subnet" "db" {
|
|
87
|
+
name = "${local.name}-db-snet"
|
|
88
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
89
|
+
virtual_network_name = azurerm_virtual_network.this.name
|
|
90
|
+
address_prefixes = [var.db_subnet_cidr]
|
|
91
|
+
|
|
92
|
+
service_endpoints = ["Microsoft.Storage"]
|
|
93
|
+
|
|
94
|
+
delegation {
|
|
95
|
+
name = "postgres"
|
|
96
|
+
service_delegation {
|
|
97
|
+
name = "Microsoft.DBforPostgreSQL/flexibleServers"
|
|
98
|
+
actions = [
|
|
99
|
+
"Microsoft.Network/virtualNetworks/subnets/join/action",
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
{{/if}}
|
|
105
|
+
|
|
106
|
+
# ── Logging ───────────────────────────────────────────────────────────────────
|
|
107
|
+
# A Container Apps environment requires a Log Analytics workspace; it is also
|
|
108
|
+
# what `dude iac logs` reads.
|
|
109
|
+
resource "azurerm_log_analytics_workspace" "this" {
|
|
110
|
+
name = "${local.name}-logs"
|
|
111
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
112
|
+
location = azurerm_resource_group.this.location
|
|
113
|
+
sku = "PerGB2018"
|
|
114
|
+
retention_in_days = var.log_retention_days
|
|
115
|
+
tags = local.tags
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
# ── Container Apps environment ────────────────────────────────────────────────
|
|
119
|
+
resource "azurerm_container_app_environment" "this" {
|
|
120
|
+
name = "${local.name}-env"
|
|
121
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
122
|
+
location = azurerm_resource_group.this.location
|
|
123
|
+
log_analytics_workspace_id = azurerm_log_analytics_workspace.this.id
|
|
124
|
+
infrastructure_subnet_id = azurerm_subnet.aca.id
|
|
125
|
+
|
|
126
|
+
# false = the environment still gets a public ingress endpoint (with its
|
|
127
|
+
# Microsoft-managed certificate) while living inside the VNet. Setting it true
|
|
128
|
+
# would make every app reachable only from inside the network.
|
|
129
|
+
internal_load_balancer_enabled = false
|
|
130
|
+
|
|
131
|
+
tags = local.tags
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# ── Registry access ───────────────────────────────────────────────────────────
|
|
135
|
+
# The registry is shared across environments and owned by the bootstrap config
|
|
136
|
+
# (one image, promoted dev → staging → prod by tag), so it is read here, never
|
|
137
|
+
# created. A user-assigned identity with AcrPull is what lets the apps pull
|
|
138
|
+
# without an admin username/password stored on each one.
|
|
139
|
+
data "azurerm_container_registry" "shared" {
|
|
140
|
+
name = var.acr_name
|
|
141
|
+
resource_group_name = var.acr_resource_group
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
resource "azurerm_user_assigned_identity" "apps" {
|
|
145
|
+
name = "${local.name}-identity"
|
|
146
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
147
|
+
location = azurerm_resource_group.this.location
|
|
148
|
+
tags = local.tags
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
resource "azurerm_role_assignment" "acr_pull" {
|
|
152
|
+
scope = data.azurerm_container_registry.shared.id
|
|
153
|
+
role_definition_name = "AcrPull"
|
|
154
|
+
principal_id = azurerm_user_assigned_identity.apps.principal_id
|
|
155
|
+
skip_service_principal_aad_check = true
|
|
156
|
+
}
|
|
157
|
+
{{#if withPostgres}}
|
|
158
|
+
|
|
159
|
+
# ── Azure Database for PostgreSQL (Flexible Server) ───────────────────────────
|
|
160
|
+
# The admin password is generated here and surfaced through the `database_url`
|
|
161
|
+
# output (sensitive) — there is no Azure Key Vault in this path. `special = false`
|
|
162
|
+
# keeps it URL-safe (no characters that need percent-encoding).
|
|
163
|
+
resource "random_password" "db" {
|
|
164
|
+
length = 32
|
|
165
|
+
special = false
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
# The server has no public endpoint: it is reachable only from inside the VNet,
|
|
169
|
+
# which is where the Container Apps environment runs.
|
|
170
|
+
resource "azurerm_private_dns_zone" "postgres" {
|
|
171
|
+
name = "${local.name}.postgres.database.azure.com"
|
|
172
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
173
|
+
tags = local.tags
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
resource "azurerm_private_dns_zone_virtual_network_link" "postgres" {
|
|
177
|
+
name = "${local.name}-pg-link"
|
|
178
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
179
|
+
private_dns_zone_name = azurerm_private_dns_zone.postgres.name
|
|
180
|
+
virtual_network_id = azurerm_virtual_network.this.id
|
|
181
|
+
registration_enabled = false
|
|
182
|
+
tags = local.tags
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
resource "azurerm_postgresql_flexible_server" "this" {
|
|
186
|
+
name = "${local.name}-pg"
|
|
187
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
188
|
+
location = azurerm_resource_group.this.location
|
|
189
|
+
|
|
190
|
+
version = var.db_version
|
|
191
|
+
sku_name = var.db_sku_name
|
|
192
|
+
storage_mb = var.db_storage_mb
|
|
193
|
+
|
|
194
|
+
administrator_login = var.db_username
|
|
195
|
+
administrator_password = random_password.db.result
|
|
196
|
+
|
|
197
|
+
backup_retention_days = var.db_backup_retention_days
|
|
198
|
+
|
|
199
|
+
delegated_subnet_id = azurerm_subnet.db.id
|
|
200
|
+
private_dns_zone_id = azurerm_private_dns_zone.postgres.id
|
|
201
|
+
public_network_access_enabled = false
|
|
202
|
+
|
|
203
|
+
dynamic "high_availability" {
|
|
204
|
+
for_each = var.db_high_availability ? [1] : []
|
|
205
|
+
content {
|
|
206
|
+
mode = "ZoneRedundant"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
# `zone` is assigned by Azure when it isn't pinned, and it then shows up as a
|
|
211
|
+
# diff on every subsequent plan.
|
|
212
|
+
lifecycle {
|
|
213
|
+
ignore_changes = [zone]
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
tags = local.tags
|
|
217
|
+
|
|
218
|
+
depends_on = [azurerm_private_dns_zone_virtual_network_link.postgres]
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
resource "azurerm_postgresql_flexible_server_database" "app" {
|
|
222
|
+
name = var.db_name
|
|
223
|
+
server_id = azurerm_postgresql_flexible_server.this.id
|
|
224
|
+
collation = "en_US.utf8"
|
|
225
|
+
charset = "utf8"
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
locals {
|
|
229
|
+
database_url = "postgresql://${var.db_username}:${random_password.db.result}@${azurerm_postgresql_flexible_server.this.fqdn}:5432/${var.db_name}?sslmode=require"
|
|
230
|
+
}
|
|
231
|
+
{{/if}}
|
|
232
|
+
{{#if withRedis}}
|
|
233
|
+
|
|
234
|
+
# ── Redis (Celery broker + result backend) ────────────────────────────────────
|
|
235
|
+
# An in-environment container app rather than Azure Cache for Redis: the managed
|
|
236
|
+
# service starts around an order of magnitude more expensive per month, and this
|
|
237
|
+
# broker holds no data worth surviving a restart. Internal ingress with TCP
|
|
238
|
+
# transport, so only the apps in this environment can reach it.
|
|
239
|
+
resource "azurerm_container_app" "redis" {
|
|
240
|
+
name = local.redis_app
|
|
241
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
242
|
+
container_app_environment_id = azurerm_container_app_environment.this.id
|
|
243
|
+
revision_mode = "Single"
|
|
244
|
+
tags = local.tags
|
|
245
|
+
|
|
246
|
+
template {
|
|
247
|
+
min_replicas = 1
|
|
248
|
+
max_replicas = 1
|
|
249
|
+
|
|
250
|
+
container {
|
|
251
|
+
name = "redis"
|
|
252
|
+
image = var.redis_image
|
|
253
|
+
cpu = 0.25
|
|
254
|
+
memory = "0.5Gi"
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
ingress {
|
|
259
|
+
external_enabled = false
|
|
260
|
+
target_port = 6379
|
|
261
|
+
exposed_port = 6379
|
|
262
|
+
transport = "tcp"
|
|
263
|
+
|
|
264
|
+
traffic_weight {
|
|
265
|
+
latest_revision = true
|
|
266
|
+
percentage = 100
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
{{/if}}
|
|
271
|
+
|
|
272
|
+
# ── Backend ───────────────────────────────────────────────────────────────────
|
|
273
|
+
# Internal ingress: the backend is reachable from the frontend app (which proxies
|
|
274
|
+
# /api to it) but never directly from the internet.
|
|
275
|
+
resource "azurerm_container_app" "backend" {
|
|
276
|
+
name = local.backend_app
|
|
277
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
278
|
+
container_app_environment_id = azurerm_container_app_environment.this.id
|
|
279
|
+
revision_mode = "Single"
|
|
280
|
+
tags = local.tags
|
|
281
|
+
|
|
282
|
+
identity {
|
|
283
|
+
type = "UserAssigned"
|
|
284
|
+
identity_ids = [azurerm_user_assigned_identity.apps.id]
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
registry {
|
|
288
|
+
server = data.azurerm_container_registry.shared.login_server
|
|
289
|
+
identity = azurerm_user_assigned_identity.apps.id
|
|
290
|
+
}
|
|
291
|
+
{{#if withPostgres}}
|
|
292
|
+
|
|
293
|
+
secret {
|
|
294
|
+
name = "database-url"
|
|
295
|
+
value = local.database_url
|
|
296
|
+
}
|
|
297
|
+
{{/if}}
|
|
298
|
+
|
|
299
|
+
template {
|
|
300
|
+
min_replicas = var.backend_min_replicas
|
|
301
|
+
max_replicas = var.backend_max_replicas
|
|
302
|
+
|
|
303
|
+
container {
|
|
304
|
+
name = "backend"
|
|
305
|
+
image = local.backend_image
|
|
306
|
+
cpu = var.backend_cpu
|
|
307
|
+
memory = var.backend_memory
|
|
308
|
+
|
|
309
|
+
dynamic "env" {
|
|
310
|
+
for_each = local.common_env
|
|
311
|
+
content {
|
|
312
|
+
name = env.key
|
|
313
|
+
value = env.value
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
{{#if withPostgres}}
|
|
317
|
+
|
|
318
|
+
env {
|
|
319
|
+
name = "DATABASE_URL"
|
|
320
|
+
secret_name = "database-url"
|
|
321
|
+
}
|
|
322
|
+
{{/if}}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
ingress {
|
|
327
|
+
external_enabled = false
|
|
328
|
+
target_port = 8000
|
|
329
|
+
transport = "auto"
|
|
330
|
+
|
|
331
|
+
# Plain HTTP on the internal ingress: this traffic never leaves the
|
|
332
|
+
# environment's own network, and requiring TLS here would mean the frontend
|
|
333
|
+
# proxying to https:// and validating a certificate for a hostname it only
|
|
334
|
+
# learns at deploy time — cost with no attacker to defend against.
|
|
335
|
+
allow_insecure_connections = true
|
|
336
|
+
|
|
337
|
+
traffic_weight {
|
|
338
|
+
latest_revision = true
|
|
339
|
+
percentage = 100
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
depends_on = [azurerm_role_assignment.acr_pull]
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
# ── Frontend ──────────────────────────────────────────────────────────────────
|
|
347
|
+
# The one externally reachable app. Container Apps gives it an HTTPS endpoint on
|
|
348
|
+
# the environment's domain with a Microsoft-managed certificate — no domain and
|
|
349
|
+
# no certificate authority involved. It proxies /api to the backend over the
|
|
350
|
+
# environment's internal network (see frontend/nginx.conf.template).
|
|
351
|
+
resource "azurerm_container_app" "frontend" {
|
|
352
|
+
name = local.frontend_app
|
|
353
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
354
|
+
container_app_environment_id = azurerm_container_app_environment.this.id
|
|
355
|
+
revision_mode = "Single"
|
|
356
|
+
tags = local.tags
|
|
357
|
+
|
|
358
|
+
identity {
|
|
359
|
+
type = "UserAssigned"
|
|
360
|
+
identity_ids = [azurerm_user_assigned_identity.apps.id]
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
registry {
|
|
364
|
+
server = data.azurerm_container_registry.shared.login_server
|
|
365
|
+
identity = azurerm_user_assigned_identity.apps.id
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
template {
|
|
369
|
+
min_replicas = var.frontend_min_replicas
|
|
370
|
+
max_replicas = var.frontend_max_replicas
|
|
371
|
+
|
|
372
|
+
container {
|
|
373
|
+
name = "frontend"
|
|
374
|
+
image = local.frontend_image
|
|
375
|
+
cpu = var.frontend_cpu
|
|
376
|
+
memory = var.frontend_memory
|
|
377
|
+
|
|
378
|
+
# The backend's full internal FQDN, not its short name: Container Apps
|
|
379
|
+
# routes by Host header, and nginx derives the Host it sends from this
|
|
380
|
+
# value. A short name resolves but produces a Host the platform's internal
|
|
381
|
+
# edge cannot map back to an app, which it answers with its own 404.
|
|
382
|
+
env {
|
|
383
|
+
name = "BACKEND_URL"
|
|
384
|
+
value = "http://${azurerm_container_app.backend.ingress[0].fqdn}"
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
ingress {
|
|
390
|
+
external_enabled = true
|
|
391
|
+
target_port = 8080
|
|
392
|
+
transport = "auto"
|
|
393
|
+
allow_insecure_connections = false
|
|
394
|
+
|
|
395
|
+
traffic_weight {
|
|
396
|
+
latest_revision = true
|
|
397
|
+
percentage = 100
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
depends_on = [azurerm_role_assignment.acr_pull, azurerm_container_app.backend]
|
|
402
|
+
}
|
|
403
|
+
{{#if withCelery}}
|
|
404
|
+
|
|
405
|
+
# ── Celery worker ─────────────────────────────────────────────────────────────
|
|
406
|
+
# No ingress: nothing connects to a worker, it pulls from the broker. Replicas
|
|
407
|
+
# are fixed rather than autoscaled — scaling on queue depth needs a KEDA rule
|
|
408
|
+
# tuned to the workload, which is a decision this scaffold should not make for
|
|
409
|
+
# you.
|
|
410
|
+
resource "azurerm_container_app" "worker" {
|
|
411
|
+
name = local.worker_app
|
|
412
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
413
|
+
container_app_environment_id = azurerm_container_app_environment.this.id
|
|
414
|
+
revision_mode = "Single"
|
|
415
|
+
tags = local.tags
|
|
416
|
+
|
|
417
|
+
identity {
|
|
418
|
+
type = "UserAssigned"
|
|
419
|
+
identity_ids = [azurerm_user_assigned_identity.apps.id]
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
registry {
|
|
423
|
+
server = data.azurerm_container_registry.shared.login_server
|
|
424
|
+
identity = azurerm_user_assigned_identity.apps.id
|
|
425
|
+
}
|
|
426
|
+
{{#if withPostgres}}
|
|
427
|
+
|
|
428
|
+
secret {
|
|
429
|
+
name = "database-url"
|
|
430
|
+
value = local.database_url
|
|
431
|
+
}
|
|
432
|
+
{{/if}}
|
|
433
|
+
|
|
434
|
+
template {
|
|
435
|
+
min_replicas = var.worker_replicas
|
|
436
|
+
max_replicas = var.worker_replicas
|
|
437
|
+
|
|
438
|
+
# `uv run`, and not a bare `celery`: the production image installs its
|
|
439
|
+
# dependencies into a uv-managed virtualenv that is not on PATH, which is
|
|
440
|
+
# why its own CMD is `uv run uvicorn …` too.
|
|
441
|
+
container {
|
|
442
|
+
name = "worker"
|
|
443
|
+
image = local.backend_image
|
|
444
|
+
cpu = var.worker_cpu
|
|
445
|
+
memory = var.worker_memory
|
|
446
|
+
command = ["uv"]
|
|
447
|
+
args = ["run", "celery", "-A", "app.worker.celery_app", "worker", "--loglevel=info"]
|
|
448
|
+
|
|
449
|
+
dynamic "env" {
|
|
450
|
+
for_each = local.common_env
|
|
451
|
+
content {
|
|
452
|
+
name = env.key
|
|
453
|
+
value = env.value
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
{{#if withPostgres}}
|
|
457
|
+
|
|
458
|
+
env {
|
|
459
|
+
name = "DATABASE_URL"
|
|
460
|
+
secret_name = "database-url"
|
|
461
|
+
}
|
|
462
|
+
{{/if}}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
depends_on = [azurerm_role_assignment.acr_pull]
|
|
467
|
+
}
|
|
468
|
+
{{/if}}
|
|
469
|
+
{{#if withCeleryBeat}}
|
|
470
|
+
|
|
471
|
+
# ── Celery Beat ───────────────────────────────────────────────────────────────
|
|
472
|
+
# Exactly one replica, always: beat is a scheduler, and a second instance would
|
|
473
|
+
# emit every periodic task twice.
|
|
474
|
+
resource "azurerm_container_app" "beat" {
|
|
475
|
+
name = local.beat_app
|
|
476
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
477
|
+
container_app_environment_id = azurerm_container_app_environment.this.id
|
|
478
|
+
revision_mode = "Single"
|
|
479
|
+
tags = local.tags
|
|
480
|
+
|
|
481
|
+
identity {
|
|
482
|
+
type = "UserAssigned"
|
|
483
|
+
identity_ids = [azurerm_user_assigned_identity.apps.id]
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
registry {
|
|
487
|
+
server = data.azurerm_container_registry.shared.login_server
|
|
488
|
+
identity = azurerm_user_assigned_identity.apps.id
|
|
489
|
+
}
|
|
490
|
+
{{#if withPostgres}}
|
|
491
|
+
|
|
492
|
+
secret {
|
|
493
|
+
name = "database-url"
|
|
494
|
+
value = local.database_url
|
|
495
|
+
}
|
|
496
|
+
{{/if}}
|
|
497
|
+
|
|
498
|
+
template {
|
|
499
|
+
min_replicas = 1
|
|
500
|
+
max_replicas = 1
|
|
501
|
+
|
|
502
|
+
container {
|
|
503
|
+
name = "beat"
|
|
504
|
+
image = local.backend_image
|
|
505
|
+
cpu = 0.25
|
|
506
|
+
memory = "0.5Gi"
|
|
507
|
+
command = ["uv"]
|
|
508
|
+
args = ["run", "celery", "-A", "app.worker.celery_app", "beat", "--loglevel=info"]
|
|
509
|
+
|
|
510
|
+
dynamic "env" {
|
|
511
|
+
for_each = local.common_env
|
|
512
|
+
content {
|
|
513
|
+
name = env.key
|
|
514
|
+
value = env.value
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
{{#if withPostgres}}
|
|
518
|
+
|
|
519
|
+
env {
|
|
520
|
+
name = "DATABASE_URL"
|
|
521
|
+
secret_name = "database-url"
|
|
522
|
+
}
|
|
523
|
+
{{/if}}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
depends_on = [azurerm_role_assignment.acr_pull]
|
|
528
|
+
}
|
|
529
|
+
{{/if}}
|
|
530
|
+
{{#if withPostgres}}
|
|
531
|
+
|
|
532
|
+
# ── Migration job ─────────────────────────────────────────────────────────────
|
|
533
|
+
# A manually-triggered Container Apps job rather than a startup step in the
|
|
534
|
+
# backend: with more than one replica, a migration on start-up races itself, and
|
|
535
|
+
# a failure would be discovered in application logs instead of failing the
|
|
536
|
+
# deploy. `dude iac deploy`/`ship` starts this and waits for it.
|
|
537
|
+
resource "azurerm_container_app_job" "migrate" {
|
|
538
|
+
name = "${local.name}-migrate"
|
|
539
|
+
resource_group_name = azurerm_resource_group.this.name
|
|
540
|
+
location = azurerm_resource_group.this.location
|
|
541
|
+
container_app_environment_id = azurerm_container_app_environment.this.id
|
|
542
|
+
tags = local.tags
|
|
543
|
+
|
|
544
|
+
replica_timeout_in_seconds = 600
|
|
545
|
+
replica_retry_limit = 0
|
|
546
|
+
|
|
547
|
+
manual_trigger_config {
|
|
548
|
+
parallelism = 1
|
|
549
|
+
replica_completion_count = 1
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
identity {
|
|
553
|
+
type = "UserAssigned"
|
|
554
|
+
identity_ids = [azurerm_user_assigned_identity.apps.id]
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
registry {
|
|
558
|
+
server = data.azurerm_container_registry.shared.login_server
|
|
559
|
+
identity = azurerm_user_assigned_identity.apps.id
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
secret {
|
|
563
|
+
name = "database-url"
|
|
564
|
+
value = local.database_url
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
template {
|
|
568
|
+
container {
|
|
569
|
+
name = "migrate"
|
|
570
|
+
image = local.backend_image
|
|
571
|
+
cpu = 0.5
|
|
572
|
+
memory = "1Gi"
|
|
573
|
+
command = ["uv"]
|
|
574
|
+
args = ["run", "alembic", "upgrade", "head"]
|
|
575
|
+
|
|
576
|
+
dynamic "env" {
|
|
577
|
+
for_each = local.common_env
|
|
578
|
+
content {
|
|
579
|
+
name = env.key
|
|
580
|
+
value = env.value
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
env {
|
|
585
|
+
name = "DATABASE_URL"
|
|
586
|
+
secret_name = "database-url"
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
depends_on = [azurerm_role_assignment.acr_pull]
|
|
592
|
+
}
|
|
593
|
+
{{/if}}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
output "location" {
|
|
2
|
+
description = "Azure region the environment runs in."
|
|
3
|
+
value = var.location
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
output "resource_group_name" {
|
|
7
|
+
description = "Resource group holding this environment."
|
|
8
|
+
value = azurerm_resource_group.this.name
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
output "environment_name" {
|
|
12
|
+
description = "Container Apps environment name."
|
|
13
|
+
value = azurerm_container_app_environment.this.name
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
output "acr_login_server" {
|
|
17
|
+
description = "Shared container registry host (owned by the bootstrap config)."
|
|
18
|
+
value = data.azurerm_container_registry.shared.login_server
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
output "acr_backend_repository_url" {
|
|
22
|
+
description = "Registry repository for the backend image."
|
|
23
|
+
value = "${data.azurerm_container_registry.shared.login_server}/${var.project_name}-backend"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
output "acr_frontend_repository_url" {
|
|
27
|
+
description = "Registry repository for the frontend image."
|
|
28
|
+
value = "${data.azurerm_container_registry.shared.login_server}/${var.project_name}-frontend"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
output "image_tag" {
|
|
32
|
+
description = "Image tag currently deployed. `dude iac deploy`/`ship` rewrites it in terraform.tfvars."
|
|
33
|
+
value = var.image_tag
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
output "app_host" {
|
|
37
|
+
description = "Public hostname Azure serves the app on."
|
|
38
|
+
value = azurerm_container_app.frontend.ingress[0].fqdn
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
output "app_url" {
|
|
42
|
+
description = "Public URL of the application. HTTPS with a Microsoft-managed certificate — no domain required."
|
|
43
|
+
value = "https://${azurerm_container_app.frontend.ingress[0].fqdn}/"
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
output "backend_app_name" {
|
|
47
|
+
description = "Container app running the API (internal ingress only)."
|
|
48
|
+
value = azurerm_container_app.backend.name
|
|
49
|
+
}
|
|
50
|
+
{{#if withPostgres}}
|
|
51
|
+
|
|
52
|
+
output "migrate_job_name" {
|
|
53
|
+
description = "Container Apps job that runs `alembic upgrade head`. `dude iac migrate` starts it."
|
|
54
|
+
value = azurerm_container_app_job.migrate.name
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
output "postgres_fqdn" {
|
|
58
|
+
description = "Private FQDN of the PostgreSQL Flexible Server (reachable from inside the VNet only)."
|
|
59
|
+
value = azurerm_postgresql_flexible_server.this.fqdn
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
output "database_name" {
|
|
63
|
+
description = "Initial database name."
|
|
64
|
+
value = var.db_name
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
output "database_url" {
|
|
68
|
+
description = "Full PostgreSQL connection string. Terraform wires it into every app as a secret; this output is for debugging."
|
|
69
|
+
value = local.database_url
|
|
70
|
+
sensitive = true
|
|
71
|
+
}
|
|
72
|
+
{{/if}}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
provider "azurerm" {
|
|
2
|
+
features {
|
|
3
|
+
resource_group {
|
|
4
|
+
# `dude iac destroy` tears an environment down as a whole, and the Container
|
|
5
|
+
# Apps platform adds resources to the group that Terraform does not track.
|
|
6
|
+
# Without this, the destroy fails on "resource group is not empty" for
|
|
7
|
+
# resources Terraform itself cannot name.
|
|
8
|
+
prevent_deletion_if_contains_resources = false
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
# Empty = fall back to ARM_SUBSCRIPTION_ID, which `dude iac` exports from the
|
|
13
|
+
# environment's resolved subscription. Set `subscription_id` in the env's
|
|
14
|
+
# terraform.tfvars to pin it instead.
|
|
15
|
+
subscription_id = var.subscription_id != "" ? var.subscription_id : null
|
|
16
|
+
}
|