@cubocicloide/stack-react-fastapi 13.4.1 → 13.5.0

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.
Files changed (63) hide show
  1. package/dist/index.js +2654 -329
  2. package/dist/index.js.map +1 -1
  3. package/package.json +2 -2
  4. package/templates/azure-aca/backend/Dockerfile.prod.hbs +29 -0
  5. package/templates/azure-aca/docs/docs/deploy.md.hbs +127 -0
  6. package/templates/azure-aca/frontend/Dockerfile.prod +36 -0
  7. package/templates/azure-aca/frontend/nginx.conf.template +47 -0
  8. package/templates/azure-aca/iac/README.md.hbs +286 -0
  9. package/templates/azure-aca/iac/_gitignore +19 -0
  10. package/templates/azure-aca/iac/runner/Dockerfile +51 -0
  11. package/templates/azure-aca/iac/terraform/bootstrap/main.tf.hbs +123 -0
  12. package/templates/azure-aca/iac/terraform/bootstrap/outputs.tf +24 -0
  13. package/templates/azure-aca/iac/terraform/bootstrap/variables.tf.hbs +23 -0
  14. package/templates/azure-aca/iac/terraform/environments/dev/backend.hcl.hbs +25 -0
  15. package/templates/azure-aca/iac/terraform/environments/dev/terraform.tfvars.hbs +69 -0
  16. package/templates/azure-aca/iac/terraform/main.tf.hbs +593 -0
  17. package/templates/azure-aca/iac/terraform/outputs.tf.hbs +72 -0
  18. package/templates/azure-aca/iac/terraform/providers.tf +16 -0
  19. package/templates/azure-aca/iac/terraform/variables.tf.hbs +200 -0
  20. package/templates/azure-aca/iac/terraform/versions.tf +21 -0
  21. package/templates/azure-aks/backend/Dockerfile.prod.hbs +29 -0
  22. package/templates/azure-aks/docs/docs/deploy.md.hbs +273 -0
  23. package/templates/azure-aks/frontend/Dockerfile.prod +32 -0
  24. package/templates/azure-aks/frontend/nginx.conf +20 -0
  25. package/templates/azure-aks/iac/README.md.hbs +472 -0
  26. package/templates/azure-aks/iac/_gitignore +29 -0
  27. package/templates/azure-aks/iac/helm/app/.helmignore +7 -0
  28. package/templates/azure-aks/iac/helm/app/Chart.yaml.hbs +6 -0
  29. package/templates/azure-aks/iac/helm/app/templates/NOTES.txt +32 -0
  30. package/templates/azure-aks/iac/helm/app/templates/backend-deployment.yaml +44 -0
  31. package/templates/azure-aks/iac/helm/app/templates/backend-service.yaml +16 -0
  32. package/templates/azure-aks/iac/helm/app/templates/celery-beat-deployment.yaml +34 -0
  33. package/templates/azure-aks/iac/helm/app/templates/celery-worker-deployment.yaml +31 -0
  34. package/templates/azure-aks/iac/helm/app/templates/configmap.yaml +15 -0
  35. package/templates/azure-aks/iac/helm/app/templates/flower-deployment.yaml +28 -0
  36. package/templates/azure-aks/iac/helm/app/templates/flower-service.yaml +19 -0
  37. package/templates/azure-aks/iac/helm/app/templates/frontend-deployment.yaml +34 -0
  38. package/templates/azure-aks/iac/helm/app/templates/frontend-service.yaml +16 -0
  39. package/templates/azure-aks/iac/helm/app/templates/helpers.tpl +90 -0
  40. package/templates/azure-aks/iac/helm/app/templates/hpa.yaml +23 -0
  41. package/templates/azure-aks/iac/helm/app/templates/ingress.yaml +35 -0
  42. package/templates/azure-aks/iac/helm/app/templates/migration-job.yaml +38 -0
  43. package/templates/azure-aks/iac/helm/app/templates/redis-deployment.yaml +33 -0
  44. package/templates/azure-aks/iac/helm/app/templates/redis-service.yaml +18 -0
  45. package/templates/azure-aks/iac/helm/app/templates/secret.yaml +17 -0
  46. package/templates/azure-aks/iac/helm/app/templates/serviceaccount.yaml +12 -0
  47. package/templates/azure-aks/iac/helm/app/values-dev.yaml.hbs +36 -0
  48. package/templates/azure-aks/iac/helm/app/values.yaml.hbs +147 -0
  49. package/templates/azure-aks/iac/runner/Dockerfile +61 -0
  50. package/templates/azure-aks/iac/terraform/bootstrap/main.tf.hbs +123 -0
  51. package/templates/azure-aks/iac/terraform/bootstrap/outputs.tf +24 -0
  52. package/templates/azure-aks/iac/terraform/bootstrap/variables.tf.hbs +23 -0
  53. package/templates/azure-aks/iac/terraform/environments/dev/backend.hcl.hbs +25 -0
  54. package/templates/azure-aks/iac/terraform/environments/dev/terraform.tfvars.hbs +65 -0
  55. package/templates/azure-aks/iac/terraform/main.tf.hbs +307 -0
  56. package/templates/azure-aks/iac/terraform/outputs.tf.hbs +57 -0
  57. package/templates/azure-aks/iac/terraform/providers.tf +35 -0
  58. package/templates/azure-aks/iac/terraform/variables.tf.hbs +157 -0
  59. package/templates/azure-aks/iac/terraform/versions.tf +29 -0
  60. package/templates/base/CLAUDE.md.hbs +7 -7
  61. package/templates/base/docs/docs/dude.md.hbs +1 -1
  62. package/templates/base/docs/docs/index.md.hbs +1 -1
  63. package/templates/base/docs/mkdocs.yml.hbs +1 -1
@@ -0,0 +1,472 @@
1
+ # Infrastructure as Code — {{projectName}} on Azure
2
+
3
+ Deploys {{projectName}} to **Azure Kubernetes Service** with **Terraform**
4
+ (infrastructure) and **Helm** (the application). Everything is
5
+ environment-scoped and driven by `dude iac …`, which works identically on your
6
+ laptop and in CI/CD.
7
+
8
+ **If you just want it deployed, follow [Part 1](#part-1-first-deploy-start-to-finish)
9
+ top to bottom.** The rest of this file is reference.
10
+
11
+ ```
12
+ iac/
13
+ ├── terraform/
14
+ │ ├── versions.tf # providers + azurerm backend (partial)
15
+ │ ├── providers.tf # azurerm / kubernetes / helm
16
+ │ ├── variables.tf # all inputs (sane defaults)
17
+ │ ├── main.tf # resource group + VNet + AKS + ingress-nginx{{#if withPostgres}} + PostgreSQL{{/if}}
18
+ │ ├── outputs.tf # cluster, registry URLs, app URL{{#if withPostgres}}, database{{/if}}
19
+ │ ├── bootstrap/ # one-time shared infra: state storage account + container registry
20
+ │ └── environments/
21
+ │ └── dev/
22
+ │ ├── backend.hcl # remote-state location for this env
23
+ │ └── terraform.tfvars # this env's sizing/knobs
24
+ ├── runner/
25
+ │ └── Dockerfile # the toolchain `dude iac` runs in — yours to edit
26
+ └── helm/
27
+ └── app/ # the application chart (backend, frontend,{{#if withRedis}} redis,{{/if}}{{#if withCelery}} celery,{{/if}} ingress…)
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Part 1 — first deploy, start to finish
33
+
34
+ Nine steps, in order. Steps 0–3 are once per machine / once per project; 4–8 are
35
+ the deploy.
36
+
37
+ ### Step 0 — install two things
38
+
39
+ | Tool | Why | Install |
40
+ | ---- | --- | ------- |
41
+ | **Docker** | `dude iac` runs terraform/kubectl/helm/k9s inside a container, so you don't install them | [docs.docker.com](https://docs.docker.com/get-docker/) |
42
+ | **Azure CLI** (`az`) | signing in needs a browser, which a container doesn't have | `brew install azure-cli` · [other platforms](https://learn.microsoft.com/cli/azure/install-azure-cli) |
43
+
44
+ That is the whole list. You do **not** need terraform, kubectl, helm or k9s on
45
+ your machine.
46
+
47
+ ### Step 1 — have the right access in Azure
48
+
49
+ You need an Azure subscription where your account can:
50
+
51
+ - **create resource groups** (role: *Contributor*), and
52
+ - **assign roles** (role: *User Access Administrator*).
53
+
54
+ *Owner* covers both. The role assignment matters because the cluster is granted
55
+ `AcrPull` on the container registry — that is what lets pods pull images without
56
+ a Kubernetes pull secret. If your account can't assign roles, `dude iac apply`
57
+ fails on `azurerm_role_assignment.acr_pull`; ask whoever administers the
58
+ subscription for *User Access Administrator*, or to pre-create the assignment.
59
+
60
+ Check which subscriptions you can see:
61
+
62
+ ```bash
63
+ az login
64
+ az account list --output table
65
+ ```
66
+
67
+ On a brand-new subscription, also register the resource providers this scaffold
68
+ uses (free, once per subscription, takes a couple of minutes to propagate):
69
+
70
+ ```bash
71
+ for p in Compute Network Storage ContainerService ContainerRegistry \
72
+ DBforPostgreSQL ManagedIdentity Authorization; do
73
+ az provider register --namespace Microsoft.$p
74
+ done
75
+ ```
76
+
77
+ And check the node quota, because Azure grants vCPUs **per VM family** and
78
+ several newer families start at a limit of zero:
79
+
80
+ ```bash
81
+ az vm list-usage --location northeurope -o table | grep -E "Total Regional|Dsv3|BS Family"
82
+ ```
83
+
84
+ The default node pool is `Standard_D2s_v3` precisely because the Dsv3 family is
85
+ one a fresh subscription reliably gets. You need 8 vCPUs free (`node_max_count`
86
+ × 2) in both that family and `Total Regional vCPUs`. A family at `Limit 0` fails
87
+ the apply several minutes in, not at plan time.
88
+
89
+ ### Step 2 — sign in for this environment
90
+
91
+ ```bash
92
+ dude iac login --env dev
93
+ ```
94
+
95
+ This runs `az login` if you aren't signed in, then prints the subscription the
96
+ `dev` environment will deploy into, and the id to pin it with. Pin it — an
97
+ unpinned environment silently follows whatever `az account set` was run last:
98
+
99
+ ```hcl
100
+ # iac/terraform/environments/dev/terraform.tfvars
101
+ subscription_id = "00000000-0000-0000-0000-000000000000"
102
+ ```
103
+
104
+ > On a machine with no browser, use `az login --use-device-code` first, then
105
+ > re-run `dude iac login --env dev`.
106
+
107
+ ### Step 3 — create the shared resources (once per project)
108
+
109
+ ```bash
110
+ dude iac bootstrap --state-prefix <yourorg> --location northeurope --env dev --yes
111
+ ```
112
+
113
+ This creates, in a resource group `{{projectName}}-shared-rg`:
114
+
115
+ - a **storage account** + `tfstate` blob container, holding the Terraform remote
116
+ state for *every* environment, and
117
+ - an **Azure Container Registry**, holding the app images for *every* environment.
118
+
119
+ then writes their names into `environments/dev/{backend.hcl,terraform.tfvars}` for
120
+ you. No copy-paste.
121
+
122
+ It also records what you passed in `iac/terraform/bootstrap/bootstrap.auto.tfvars`
123
+ — **commit that file**. Terraform auto-loads it on every command, which is how
124
+ `dude iac destroy` later reproduces the same resource names without being told
125
+ the original prefix. It holds a project slug, a region and a name prefix; no
126
+ secrets.
127
+
128
+ **About `--state-prefix`**: storage account and registry names are globally
129
+ unique across all of Azure and allow only lowercase letters and digits — no
130
+ hyphens, 24 characters max for the storage account. Use a short org slug
131
+ (`acme`, `unicc`). If the name is taken you'll get a clear error; pick another
132
+ prefix and re-run.
133
+
134
+ You run this **once per project**, not once per environment.
135
+
136
+ ### Step 4 — initialise Terraform
137
+
138
+ ```bash
139
+ dude iac init --env dev
140
+ ```
141
+
142
+ Points Terraform at the remote state created in step 3.
143
+
144
+ ### Step 5 — provision the infrastructure
145
+
146
+ ```bash
147
+ dude iac plan --env dev # review what will be created
148
+ dude iac apply --env dev # create it (add --yes to skip the prompt)
149
+ ```
150
+
151
+ **This takes around 10 minutes.** The AKS cluster is most of it; the load
152
+ balancer and its public IP add a couple of minutes at the end — `apply`
153
+ deliberately waits for them, so that when it returns the hostname already
154
+ resolves.
155
+
156
+ What you get: a resource group, a virtual network, an AKS cluster with an
157
+ autoscaling node pool, ingress-nginx behind a public IP with an Azure DNS
158
+ label{{#if withPostgres}}, and a private PostgreSQL Flexible Server{{/if}}.
159
+
160
+ ### Step 6 — point kubectl at the cluster
161
+
162
+ ```bash
163
+ dude iac kubeconfig --env dev
164
+ ```
165
+
166
+ ### Step 7 — ship the application
167
+
168
+ ```bash
169
+ dude iac ship --env dev
170
+ ```
171
+
172
+ Builds both production images, pushes them to the registry, and runs
173
+ `helm upgrade --install`. The registry host, the image tag and the public
174
+ hostname are wired in automatically.
175
+
176
+ ### Step 8 — open it
177
+
178
+ ```bash
179
+ dude iac output --env dev # look for app_url
180
+ dude iac status --env dev # helm release + pods
181
+ ```
182
+
183
+ ```
184
+ http://{{projectName}}-dev.northeurope.cloudapp.azure.com/
185
+ ```
186
+
187
+ The API is served under `/api`{{#if withPostgres}}; database migrations ran as a
188
+ Helm pre-upgrade hook{{/if}}.
189
+
190
+ **If the page doesn't load yet**, give the load balancer a minute and check the
191
+ pods are up:
192
+
193
+ ```bash
194
+ dude iac status --env dev
195
+ dude iac shell --env dev # then: kubectl describe ingress -n dev
196
+ ```
197
+
198
+ ---
199
+
200
+ ## The public hostname (and why there's no HTTPS)
201
+
202
+ You do not need to own a domain. ingress-nginx asks Azure for a public IP **with
203
+ a DNS label**, and Azure publishes it at:
204
+
205
+ ```
206
+ <dns_label>.<location>.cloudapp.azure.com
207
+ ```
208
+
209
+ `dns_label` defaults to `{{projectName}}-<env>` and lives in the environment's
210
+ `terraform.tfvars`. It must be unique **within the region** — if `apply` reports
211
+ the name is taken, change it there and re-apply. `dude iac deploy`/`ship` then
212
+ reads the resulting hostname from the `app_host` Terraform output and sets it on
213
+ the Ingress, which is why `ingress.host` is empty in the committed values file:
214
+ it's a deploy-time fact, not a committed one.
215
+
216
+ ### HTTPS / TLS
217
+
218
+ **That hostname is HTTP-only, and no setting changes it.**
219
+ `cloudapp.azure.com` is not on the [Public Suffix List](https://publicsuffix.org/),
220
+ so Let's Encrypt attributes any certificate for it to `azure.com` — a single rate
221
+ limit shared by every Azure customer, permanently exhausted. There is no free
222
+ trusted certificate for an Azure-assigned AKS hostname.
223
+
224
+ Two real options:
225
+
226
+ **a) Use a domain you own** (what this scaffold supports). Create a CNAME from
227
+ your hostname to `<dns_label>.<location>.cloudapp.azure.com`, then:
228
+
229
+ ```hcl
230
+ # iac/terraform/environments/dev/terraform.tfvars
231
+ letsencrypt_email = "ops@example.com"
232
+ ```
233
+
234
+ ```bash
235
+ dude iac apply --env dev # installs cert-manager + a letsencrypt-prod ClusterIssuer
236
+ ```
237
+
238
+ ```yaml
239
+ # iac/helm/app/values-dev.yaml
240
+ ingress:
241
+ host: app.example.com
242
+ tls:
243
+ enabled: true
244
+ clusterIssuer: letsencrypt-prod
245
+ ```
246
+
247
+ ```bash
248
+ dude iac deploy --env dev
249
+ ```
250
+
251
+ The certificate is issued over HTTP-01 through the same ingress — nothing else
252
+ to open, and it renews itself.
253
+
254
+ **b) Front it with a service that brings its own certificate.** Azure Front Door
255
+ Standard serves `*.azurefd.net` with a Microsoft-managed certificate and needs no
256
+ domain. It is not provisioned here and has a monthly base cost.
257
+
258
+ Until one of those is in place, the HTTP URL is fine for a demo or an internal
259
+ review and not for anything handling real credentials.
260
+
261
+ ---
262
+
263
+ ## The IaC runner (Docker)
264
+
265
+ `dude iac *` runs terraform / kubectl / helm / k9s inside a pinned container so
266
+ you don't have to install or version-match any of them locally. The image is
267
+ built on first use from `iac/runner/Dockerfile` — **which is yours to edit** (bump
268
+ a tool version, add a CLI). The image is tagged by a hash of that file, so any
269
+ change rebuilds automatically on the next command.
270
+
271
+ - **Credentials** are never copied in: your `~/.azure` is mounted and the
272
+ environment's subscription is passed through, so your `az login` session keeps
273
+ working. That mount is read-**write** on purpose — the Azure CLI rewrites its
274
+ token cache when it refreshes an access token, and a read-only mount breaks
275
+ authentication as soon as the cached token expires. `~/.kube` is mounted
276
+ read-only as a fallback context.
277
+ - **`dude iac login`** is the one command that stays on the host (it needs a
278
+ browser); it writes the token the container then reads.
279
+ - **`dude iac build`/`push`** use the host Docker daemon (they build app images);
280
+ everything else runs in the container.
281
+ - **Escape hatch**: set `DUDE_IAC_RUNNER=host` to run the tools natively from
282
+ your PATH instead. If Docker isn't running, `dude iac` falls back to native
283
+ tools automatically.
284
+ - **`dude iac shell --env <env>`** drops you into the runner with all tools + k9s,
285
+ the env's subscription and cluster already wired — handy for ad-hoc inspection.
286
+
287
+ ## Subscriptions per environment
288
+
289
+ Each `dude iac …` command is environment-scoped via `--env`, which is
290
+ **required** — there is no default, so you never act on the wrong environment by
291
+ accident. Run any command without it to list the environments discovered under
292
+ `iac/terraform/environments/`. Each env resolves an **Azure subscription**, so
293
+ different environments can live in different subscriptions. The precedence:
294
+
295
+ 1. an explicit `--subscription <id>` flag,
296
+ 2. `subscription_id` in the environment's `terraform.tfvars`,
297
+ 3. an already-exported `ARM_SUBSCRIPTION_ID` / `AZURE_SUBSCRIPTION_ID`,
298
+ 4. whatever `az account show` reports as your signed-in default.
299
+
300
+ Pin it at level 2 for anything beyond a first experiment: it is the only level
301
+ that is committed, reviewed, and the same for everyone on the team.
302
+
303
+ ## Build, push & deploy
304
+
305
+ `dude` drives the whole release. The registry is read from Terraform outputs and
306
+ the image tag defaults to the **git short SHA** (with a `-dirty-<hash>` suffix if
307
+ you have uncommitted changes), so every deploy is traceable to an exact commit.
308
+ Override with `--tag <tag>` (e.g. `--tag v1.2.3`).
309
+
310
+ The fast inner loop:
311
+
312
+ ```bash
313
+ dude iac ship --env dev # build → push → helm upgrade --install
314
+ dude iac status --env dev # release status + pods
315
+ ```
316
+
317
+ Or run the stages individually (handy in CI, where each is a separate stage):
318
+
319
+ ```bash
320
+ dude iac build --env dev # docker build BE+FE (linux/amd64) for the registry
321
+ dude iac push --env dev # ACR login + docker push BE+FE
322
+ dude iac deploy --env dev # helm upgrade --install (auto-sets registry, tag, host)
323
+ ```
324
+
325
+ > **Platform** — images are built for `linux/amd64` by default to match the AKS
326
+ > x86 node pool. Building on Apple Silicon without this flag yields arm64 images
327
+ > that crash on the cluster with `exec format error`. Override with `--platform`
328
+ > if you move the node pool to Arm (`Standard_D2pds_v5` and friends).
329
+
330
+ > **Overwriting a tag** — unlike ECR, a Basic-tier Azure registry lets a tag be
331
+ > rewritten. `push`/`ship` warn when the tag already exists rather than refusing,
332
+ > since re-shipping the same working tree is legitimate. To *promote* an existing
333
+ > image instead of rebuilding it, use `dude iac deploy --env <env> --tag <tag>`.
334
+
335
+ `deploy` injects `image.registry`, the image tags and `ingress.host` via `--set`,
336
+ so you do not hand-edit them into `values-dev.yaml` — that file is still layered
337
+ for the rest (resources, replicas{{#if withPostgres}}, secrets{{/if}}…).
338
+
339
+ > **Config & secrets** — every app container loads its env via `envFrom` from a
340
+ > ConfigMap (`.Values.config`) and a Secret (`.Values.secrets`). Each key is the
341
+ > ENV VAR NAME exactly as `app/core/config.py` reads it, so adding a variable is
342
+ > one line under `config:` / `secrets:` plus the field in `config.py`. Per-env
343
+ > `values-<env>.yaml` files are **gitignored** (they may hold secrets like API
344
+ > keys); the committed `values.yaml` is the documented reference.
345
+
346
+ {{#if withPostgres}}`secrets.DATABASE_URL` must be present (the chart refuses to deploy otherwise),
347
+ but you don't set it by hand: `dude iac ship`/`deploy` injects it via
348
+ `--set-string` from the Terraform `database_url` output. The database has **no
349
+ public endpoint** — it is reachable only from inside the VNet, which is why
350
+ `psql` from your laptop won't connect. To reach it, port-forward through a pod or
351
+ use `dude iac shell`.
352
+
353
+ {{/if}}## Add a new environment
354
+
355
+ ```bash
356
+ dude iac new-env --env prod # copies dev by default; use --from <env> to pick the source
357
+ ```
358
+
359
+ This scaffolds `iac/terraform/environments/prod/{backend.hcl,terraform.tfvars}`,
360
+ setting `environment = "prod"`, a per-env state `key`, and a fresh `dns_label`
361
+ (left at the source env's value, the new environment would collide with — or
362
+ quietly take over — the old one's URL). The storage account, the state container
363
+ **and the registry** are **shared** across environments, so you don't bootstrap
364
+ again unless this is the first env on a brand-new backend. It also copies the
365
+ source env's gitignored `iac/helm/app/values-<from>.yaml` to `values-prod.yaml`
366
+ when present, so the new env starts from the same Helm overrides + secrets
367
+ instead of the bare `values.yaml` defaults.
368
+
369
+ Then edit `environments/prod/terraform.tfvars` (bigger nodes,{{#if withPostgres}} a
370
+ General Purpose `db_sku_name`, `db_high_availability = true`,{{/if}} `sku_tier`,
371
+ …) and `iac/helm/app/values-prod.yaml` (replicas, autoscaling, secrets, …), and
372
+ run every command with `--env prod`:
373
+
374
+ ```bash
375
+ dude iac init --env prod && dude iac apply --env prod && dude iac ship --env prod
376
+ ```
377
+
378
+ ## Local vs CI/CD
379
+
380
+ The exact same commands run in CI — state is remote (Azure Blob Storage) and auth
381
+ is the Azure CLI/SDK chain, so no kubeconfig file is committed. In a pipeline,
382
+ authenticate with a service principal or workload identity federation by
383
+ exporting `ARM_CLIENT_ID`, `ARM_TENANT_ID`, `ARM_SUBSCRIPTION_ID` and either
384
+ `ARM_CLIENT_SECRET` or OIDC; the Terraform provider picks them up with no flag
385
+ changes. A pipeline typically runs: `dude iac init/plan/apply` → `dude iac build`
386
+ → `dude iac push` → `dude iac deploy` (or `dude iac ship` to collapse the last
387
+ three). Pass an explicit `--tag $CI_COMMIT_SHA` so the pipeline controls
388
+ provenance.
389
+
390
+ ## Tear down
391
+
392
+ ```bash
393
+ dude iac destroy --env dev
394
+ ```
395
+
396
+ `destroy` tears down **everything** for the environment, in order:
397
+
398
+ 1. uninstalls the Helm release and waits for the Ingress to go, so the ingress
399
+ controller releases the Azure load balancer and public IP cleanly;
400
+ 2. `terraform destroy` of the environment — which removes its whole resource
401
+ group, cluster{{#if withPostgres}}, database{{/if}} and network;
402
+ 3. re-checks that the resource group is actually gone (a delete still in flight,
403
+ or a resource lock, otherwise leaves it quietly billing);
404
+ 4. tears down the bootstrap — the shared state storage account **and** the shared
405
+ registry — but **only if no other environment still uses it** (see below).
406
+
407
+ Flags for finer control:
408
+
409
+ | Flag | Effect |
410
+ | ---------------- | ------------------------------------------------------------------- |
411
+ | `--keep-backend` | Keep the shared bootstrap (state storage account **+ container registry**). It is kept automatically while another environment still uses it; pass this to force-keep it even when destroying the last environment. |
412
+ | `--skip-helm` | Skip the Helm uninstall (the release is already gone). |
413
+ | `--skip-tf` | Skip the per-env `terraform destroy` — only run the Helm uninstall + backend teardown. |
414
+
415
+ > The bootstrap holds the project-wide shared resources — the Terraform state
416
+ > storage account **and** the container registry — used by every environment
417
+ > (they differ only by their state `key`). To protect the other environments'
418
+ > state *and registry*, `destroy` automatically **keeps** the bootstrap whenever
419
+ > another environment is **still provisioned**, and only tears it down when
420
+ > you're destroying the **last** one. Whether a sibling is "still provisioned" is
421
+ > read from its remote Terraform state (empty after a destroy), not from its
422
+ > folder on disk — so a leftover env folder you already destroyed won't keep the
423
+ > backend alive. Pass `--keep-backend` to force-keep it even then.
424
+
425
+ ## Commands
426
+
427
+ | Command | Wraps |
428
+ |---------|-------|
429
+ | `dude iac login` | `az login` (when needed) + `az account show` for the env's subscription |
430
+ | `dude iac new-env` | scaffolds `environments/<name>/` from an existing env (`--env <name>`, `--from <src>`) |
431
+ | `dude iac bootstrap` | `terraform init/apply` in `bootstrap/`, patches `backend.hcl` + `terraform.tfvars` |
432
+ | `dude iac init` | `terraform init` (azurerm backend per env) |
433
+ | `dude iac plan` | `terraform plan` |
434
+ | `dude iac apply` | `terraform apply` (`--yes` to auto-approve) |
435
+ | `dude iac destroy` | helm uninstall + `terraform destroy` + bootstrap teardown (`--yes`, `--keep-backend`, `--skip-helm`, `--skip-tf`) |
436
+ | `dude iac output` | `terraform output` (`--json`) |
437
+ | `dude iac fmt` | `terraform fmt -recursive` |
438
+ | `dude iac validate` | `terraform validate` |
439
+ | `dude iac build` | `docker build` BE+FE prod images (`linux/amd64`) |
440
+ | `dude iac push` | ACR token login + `docker push` BE+FE |
441
+ | `dude iac kubeconfig`| `az aks get-credentials` from outputs |
442
+ | `dude iac deploy` | `helm upgrade --install` (auto-sets registry + tag + host{{#if withPostgres}} + DATABASE_URL{{/if}}) |
443
+ | `dude iac ship` | `build` + `push` + `deploy` |
444
+ | `dude iac status` | `helm status` + `kubectl get pods` |
445
+ | `dude iac shell` | interactive shell in the IaC runner container (terraform, kubectl, helm, k9s, az) |
446
+
447
+ All commands take `--env <name>` (**required**; autodiscovered from
448
+ `environments/*`) and `--subscription <id>` (overrides the env's resolved
449
+ subscription). `build`/`push`/`deploy`/`ship` take `--tag <tag>` (default: git
450
+ short SHA, `-dirty-<hash>` if uncommitted); `build`/`ship` also take `--platform`
451
+ (default `linux/amd64`). `bootstrap` accepts `--state-prefix` (required) and
452
+ `--location` (default `northeurope`).
453
+
454
+ ## Troubleshooting
455
+
456
+ | Symptom | Cause / fix |
457
+ | ------- | ----------- |
458
+ | `apply` fails on `azurerm_role_assignment.acr_pull` with *AuthorizationFailed* | Your account can't assign roles. Ask for **User Access Administrator** (or Owner) on the subscription. |
459
+ | `apply` fails: *Operation could not be completed as it results in exceeding approved quota* | The node VM family has no quota in that region. `az vm list-usage --location <region> -o table`, then pick a family with headroom (`node_vm_size`) or request an increase. |
460
+ | `apply` fails: *The subscription is not registered to use namespace …* | Resource providers not registered — see the `az provider register` loop in Step 1. |
461
+ | `apply` fails: DNS label already in use | Another Azure resource in that region took it. Change `dns_label` in the env's `terraform.tfvars` and re-apply. |
462
+ | `bootstrap` fails: *RequestDisallowedByAzure … region is currently not accepting new customers* | That region is capacity-closed to your (new) subscription — West Europe commonly is. Use another region: `--location northeurope` **and** `location` in the env's terraform.tfvars. The resource group may already exist in the old region; re-running bootstrap moves it. |
463
+ | `bootstrap` fails: *ParentResourceNotFound … storageAccounts/fileServices* | A read race inside the azurerm provider right after the account is created — the account itself is fine. `bootstrap` is idempotent: run it again and it reconciles. |
464
+ | `init` fails: *ListBlobs … 404 ResourceNotFound* | A brand-new storage account's blob endpoint takes a few minutes to answer. `bootstrap` now waits for it; if you hit this anyway, re-run `dude iac init --env <env>` a minute later. |
465
+ | `bootstrap` fails: storage account name taken | The name is global across Azure. Re-run with a different `--state-prefix`. |
466
+ | App URL doesn't resolve | The load balancer and its DNS label take a couple of minutes after `apply`. Re-check `dude iac output --env <env>`. |
467
+ | Pods stuck in `ImagePullBackOff` | The `AcrPull` role assignment hasn't propagated yet (up to a few minutes), or `apply` never created it. `dude iac shell --env <env>` then `kubectl describe pod <pod> -n <env>`. |
468
+ | `init` fails with *AuthorizationPermissionMismatch* | You switched the backend to `use_azuread_auth`. That needs the data-plane role **Storage Blob Data Contributor** on the state storage account — subscription Owner alone is not enough. Grant it, or drop the setting (see `backend.hcl`). |
469
+ | `Error acquiring the state lock` | A previous command died mid-run. `dude iac shell --env <env>`, then `terraform -chdir=iac/terraform force-unlock <id>`. |
470
+ {{#if withPostgres}}| `psql` from your laptop can't connect | By design: the database has no public endpoint and lives inside the VNet. Reach it through a pod, or `dude iac shell`. |
471
+ {{/if}}| `destroy` removes the environment but leaves the shared resource group | The bootstrap's Terraform state is **local and gitignored**, so it exists only where `dude iac bootstrap` ran. A fresh clone or a re-scaffold starts empty and has nothing to destroy. Remove them directly: `az group delete --name <project>-shared-rg --yes`. Keep that state file (or the machine) if you want Terraform to own the teardown. |
472
+ | `exec format error` in a pod | An arm64 image on an x86 node pool. Rebuild without overriding `--platform`. |
@@ -0,0 +1,29 @@
1
+ # Terraform
2
+ **/.terraform/*
3
+ *.tfstate
4
+ *.tfstate.*
5
+ crash.log
6
+ crash.*.log
7
+ *.tfvars.local
8
+ override.tf
9
+ override.tf.json
10
+ *_override.tf
11
+ *_override.tf.json
12
+ .terraformrc
13
+ terraform.rc
14
+ .terraform.lock.hcl
15
+
16
+ # Helm
17
+ *.tgz
18
+ charts/*.tgz
19
+
20
+ # Per-environment Helm values hold real config + secrets (e.g. API keys) and are
21
+ # never committed. The committed `values.yaml` is the documented reference; copy
22
+ # its structure into `values-<env>.yaml` locally. DATABASE_URL is injected at
23
+ # deploy time from Terraform, so it doesn't belong in any committed file.
24
+ **/values-*.yaml
25
+
26
+ # Azure
27
+ # `az ... --file` output and any downloaded kubeconfig — never a committed file.
28
+ kubeconfig
29
+ *.kubeconfig
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+ .git/
3
+ .gitignore
4
+ *.tmp
5
+ *.bak
6
+ *.orig
7
+ .vscode/
@@ -0,0 +1,6 @@
1
+ apiVersion: v2
2
+ name: {{projectName}}
3
+ description: Helm chart for the {{projectName}} application (React + FastAPI on AKS).
4
+ type: application
5
+ version: 0.1.0
6
+ appVersion: "0.1.0"
@@ -0,0 +1,32 @@
1
+ {{ .Chart.Name }} deployed as release "{{ .Release.Name }}" in namespace "{{ .Release.Namespace }}".
2
+
3
+ 1. Open the app:
4
+ {{- if .Values.ingress.host }}
5
+
6
+ {{ if .Values.ingress.tls.enabled }}https{{ else }}http{{ end }}://{{ .Values.ingress.host }}/
7
+
8
+ (API is served under /api.)
9
+ {{- else }}
10
+
11
+ No ingress host is set. `dude iac deploy` normally wires it from the Terraform
12
+ `app_host` output — run `dude iac output --env <env>` to check it is set, or
13
+ reach the ingress controller's IP directly:
14
+
15
+ kubectl get svc -n ingress-nginx ingress-nginx-controller \
16
+ -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
17
+ {{- end }}
18
+ {{- if .Values.database.enabled }}
19
+
20
+ 2. Database: the pre-upgrade migration job runs `alembic upgrade head`.
21
+ The app reads DATABASE_URL from the Secret {{ include "app.fullname" . }}-secret;
22
+ `dude iac ship`/`deploy` wires it in automatically from the Terraform output.
23
+ {{- end }}
24
+ {{- if and .Values.celery.enabled .Values.celery.flower.enabled }}
25
+
26
+ 3. Flower (Celery monitor) is internal. Reach it with:
27
+
28
+ kubectl port-forward svc/{{ include "app.fullname" . }}-flower {{ .Values.celery.flower.port }}:{{ .Values.celery.flower.port }} -n {{ .Release.Namespace }}
29
+ {{- end }}
30
+
31
+ Pods: kubectl get pods -n {{ .Release.Namespace }}
32
+ Status: dude iac status --env <env>
@@ -0,0 +1,44 @@
1
+ apiVersion: apps/v1
2
+ kind: Deployment
3
+ metadata:
4
+ name: {{ include "app.fullname" . }}-backend
5
+ labels:
6
+ {{- include "app.labels" . | nindent 4 }}
7
+ app.kubernetes.io/component: backend
8
+ spec:
9
+ {{- if not .Values.backend.autoscaling.enabled }}
10
+ replicas: {{ .Values.backend.replicas }}
11
+ {{- end }}
12
+ selector:
13
+ matchLabels:
14
+ {{- include "app.selectorLabels" . | nindent 6 }}
15
+ app.kubernetes.io/component: backend
16
+ template:
17
+ metadata:
18
+ labels:
19
+ {{- include "app.selectorLabels" . | nindent 8 }}
20
+ app.kubernetes.io/component: backend
21
+ spec:
22
+ serviceAccountName: {{ include "app.serviceAccountName" . }}
23
+ containers:
24
+ - name: backend
25
+ image: {{ include "app.backendImage" . }}
26
+ imagePullPolicy: {{ .Values.image.pullPolicy }}
27
+ ports:
28
+ - containerPort: {{ .Values.backend.port }}
29
+ envFrom:
30
+ {{- include "app.envFrom" . | nindent 12 }}
31
+ readinessProbe:
32
+ httpGet:
33
+ path: /api/health
34
+ port: {{ .Values.backend.port }}
35
+ initialDelaySeconds: 10
36
+ periodSeconds: 10
37
+ livenessProbe:
38
+ httpGet:
39
+ path: /api/health
40
+ port: {{ .Values.backend.port }}
41
+ initialDelaySeconds: 20
42
+ periodSeconds: 20
43
+ resources:
44
+ {{- toYaml .Values.backend.resources | nindent 12 }}
@@ -0,0 +1,16 @@
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: {{ include "app.fullname" . }}-backend
5
+ labels:
6
+ {{- include "app.labels" . | nindent 4 }}
7
+ app.kubernetes.io/component: backend
8
+ spec:
9
+ type: ClusterIP
10
+ selector:
11
+ {{- include "app.selectorLabels" . | nindent 4 }}
12
+ app.kubernetes.io/component: backend
13
+ ports:
14
+ - port: {{ .Values.backend.port }}
15
+ targetPort: {{ .Values.backend.port }}
16
+ protocol: TCP
@@ -0,0 +1,34 @@
1
+ {{- if .Values.celeryBeat.enabled }}
2
+ apiVersion: apps/v1
3
+ kind: Deployment
4
+ metadata:
5
+ name: {{ include "app.fullname" . }}-celery-beat
6
+ labels:
7
+ {{- include "app.labels" . | nindent 4 }}
8
+ app.kubernetes.io/component: celery-beat
9
+ spec:
10
+ # A single scheduler instance — never scale beat beyond one replica.
11
+ replicas: 1
12
+ strategy:
13
+ type: Recreate
14
+ selector:
15
+ matchLabels:
16
+ {{- include "app.selectorLabels" . | nindent 6 }}
17
+ app.kubernetes.io/component: celery-beat
18
+ template:
19
+ metadata:
20
+ labels:
21
+ {{- include "app.selectorLabels" . | nindent 8 }}
22
+ app.kubernetes.io/component: celery-beat
23
+ spec:
24
+ serviceAccountName: {{ include "app.serviceAccountName" . }}
25
+ containers:
26
+ - name: celery-beat
27
+ image: {{ include "app.backendImage" . }}
28
+ imagePullPolicy: {{ .Values.image.pullPolicy }}
29
+ command: ["uv", "run", "celery", "-A", "app.worker.celery_app", "beat", "--loglevel=info"]
30
+ envFrom:
31
+ {{- include "app.envFrom" . | nindent 12 }}
32
+ resources:
33
+ {{- toYaml .Values.celeryBeat.resources | nindent 12 }}
34
+ {{- end }}
@@ -0,0 +1,31 @@
1
+ {{- if .Values.celery.enabled }}
2
+ apiVersion: apps/v1
3
+ kind: Deployment
4
+ metadata:
5
+ name: {{ include "app.fullname" . }}-celery-worker
6
+ labels:
7
+ {{- include "app.labels" . | nindent 4 }}
8
+ app.kubernetes.io/component: celery-worker
9
+ spec:
10
+ replicas: {{ .Values.celery.worker.replicas }}
11
+ selector:
12
+ matchLabels:
13
+ {{- include "app.selectorLabels" . | nindent 6 }}
14
+ app.kubernetes.io/component: celery-worker
15
+ template:
16
+ metadata:
17
+ labels:
18
+ {{- include "app.selectorLabels" . | nindent 8 }}
19
+ app.kubernetes.io/component: celery-worker
20
+ spec:
21
+ serviceAccountName: {{ include "app.serviceAccountName" . }}
22
+ containers:
23
+ - name: celery-worker
24
+ image: {{ include "app.backendImage" . }}
25
+ imagePullPolicy: {{ .Values.image.pullPolicy }}
26
+ command: ["uv", "run", "celery", "-A", "app.worker.celery_app", "worker", "--loglevel=info"]
27
+ envFrom:
28
+ {{- include "app.envFrom" . | nindent 12 }}
29
+ resources:
30
+ {{- toYaml .Values.celery.worker.resources | nindent 12 }}
31
+ {{- end }}