@cubocicloide/stack-react-fastapi 13.4.2 → 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,200 @@
1
+ # ── Identity ──────────────────────────────────────────────────────────────────
2
+ variable "project_name" {
3
+ description = "Project slug, used to name and tag every resource."
4
+ type = string
5
+ default = "{{projectName}}"
6
+ }
7
+
8
+ variable "environment" {
9
+ description = "Environment name (dev, staging, prod, …). Drives naming + state key."
10
+ type = string
11
+ }
12
+
13
+ variable "location" {
14
+ description = "Azure region to deploy into. North Europe is the default because several popular regions — West Europe among them — are capacity-closed to new subscriptions and reject resource creation with RequestDisallowedByAzure."
15
+ type = string
16
+ default = "northeurope"
17
+ }
18
+
19
+ variable "subscription_id" {
20
+ description = "Azure subscription this environment lives in. Empty = whatever ARM_SUBSCRIPTION_ID / your az default resolves to."
21
+ type = string
22
+ default = ""
23
+ }
24
+
25
+ # ── Shared registry (created by the bootstrap; written here by `dude iac bootstrap`) ──
26
+ variable "acr_name" {
27
+ description = "Name of the shared container registry created by the bootstrap."
28
+ type = string
29
+ }
30
+
31
+ variable "acr_resource_group" {
32
+ description = "Resource group holding the shared container registry (the bootstrap's group)."
33
+ type = string
34
+ }
35
+
36
+ variable "image_tag" {
37
+ description = "Image tag every container app runs. `dude iac deploy`/`ship` rewrites this, so it is the committed record of what is deployed."
38
+ type = string
39
+ default = "latest"
40
+ }
41
+
42
+ # ── Network ───────────────────────────────────────────────────────────────────
43
+ variable "vnet_cidr" {
44
+ description = "Address space for the virtual network."
45
+ type = string
46
+ default = "10.0.0.0/16"
47
+ }
48
+
49
+ variable "aca_subnet_cidr" {
50
+ description = "Subnet delegated to the Container Apps environment. Must be at least a /23 — the platform refuses anything smaller."
51
+ type = string
52
+ default = "10.0.0.0/23"
53
+ }
54
+ {{#if withPostgres}}
55
+
56
+ variable "db_subnet_cidr" {
57
+ description = "Subnet delegated to the PostgreSQL Flexible Server (must not overlap the Container Apps subnet)."
58
+ type = string
59
+ default = "10.0.4.0/24"
60
+ }
61
+ {{/if}}
62
+
63
+ # ── Application sizing ────────────────────────────────────────────────────────
64
+ # Container Apps bills per vCPU-second and per GiB-second of *running* replicas,
65
+ # and the allowed cpu/memory pairs are fixed (0.25/0.5Gi, 0.5/1Gi, 0.75/1.5Gi,
66
+ # 1/2Gi, …). Scaling a service to zero makes it free when idle, at the cost of a
67
+ # cold start on the next request.
68
+
69
+ variable "frontend_cpu" {
70
+ description = "vCPU per frontend replica."
71
+ type = number
72
+ default = 0.25
73
+ }
74
+
75
+ variable "frontend_memory" {
76
+ description = "Memory per frontend replica (must pair with the CPU value)."
77
+ type = string
78
+ default = "0.5Gi"
79
+ }
80
+
81
+ variable "frontend_min_replicas" {
82
+ description = "Minimum frontend replicas. 1 keeps the public URL warm; 0 is free when idle but adds a cold start."
83
+ type = number
84
+ default = 1
85
+ }
86
+
87
+ variable "frontend_max_replicas" {
88
+ description = "Maximum frontend replicas."
89
+ type = number
90
+ default = 3
91
+ }
92
+
93
+ variable "backend_cpu" {
94
+ description = "vCPU per backend replica."
95
+ type = number
96
+ default = 0.5
97
+ }
98
+
99
+ variable "backend_memory" {
100
+ description = "Memory per backend replica (must pair with the CPU value)."
101
+ type = string
102
+ default = "1Gi"
103
+ }
104
+
105
+ variable "backend_min_replicas" {
106
+ description = "Minimum backend replicas."
107
+ type = number
108
+ default = 1
109
+ }
110
+
111
+ variable "backend_max_replicas" {
112
+ description = "Maximum backend replicas."
113
+ type = number
114
+ default = 3
115
+ }
116
+ {{#if withCelery}}
117
+
118
+ variable "worker_cpu" {
119
+ description = "vCPU per Celery worker replica."
120
+ type = number
121
+ default = 0.5
122
+ }
123
+
124
+ variable "worker_memory" {
125
+ description = "Memory per Celery worker replica."
126
+ type = string
127
+ default = "1Gi"
128
+ }
129
+
130
+ variable "worker_replicas" {
131
+ description = "Celery worker replicas. Kept fixed rather than autoscaled: scaling on queue depth needs a KEDA scale rule tuned to your workload."
132
+ type = number
133
+ default = 1
134
+ }
135
+ {{/if}}
136
+ {{#if withRedis}}
137
+
138
+ variable "redis_image" {
139
+ description = "Redis image used as the Celery broker and result backend."
140
+ type = string
141
+ default = "docker.io/library/redis:7-alpine"
142
+ }
143
+ {{/if}}
144
+
145
+ variable "log_retention_days" {
146
+ description = "Days of container logs to retain in Log Analytics."
147
+ type = number
148
+ default = 30
149
+ }
150
+
151
+ variable "debug" {
152
+ description = "Value of the backend DEBUG setting."
153
+ type = string
154
+ default = "false"
155
+ }
156
+ {{#if withPostgres}}
157
+
158
+ # ── Azure Database for PostgreSQL (Flexible Server) ───────────────────────────
159
+ variable "db_version" {
160
+ description = "PostgreSQL major version."
161
+ type = string
162
+ default = "16"
163
+ }
164
+
165
+ variable "db_sku_name" {
166
+ description = "Flexible Server SKU (e.g. B_Standard_B1ms for dev, GP_Standard_D2ds_v4 for prod)."
167
+ type = string
168
+ default = "B_Standard_B1ms"
169
+ }
170
+
171
+ variable "db_storage_mb" {
172
+ description = "Allocated storage in MB (minimum 32768)."
173
+ type = number
174
+ default = 32768
175
+ }
176
+
177
+ variable "db_name" {
178
+ description = "Initial database name."
179
+ type = string
180
+ default = "app"
181
+ }
182
+
183
+ variable "db_username" {
184
+ description = "Administrator username. The password is generated by Terraform and surfaced through the sensitive `database_url` output."
185
+ type = string
186
+ default = "appadmin"
187
+ }
188
+
189
+ variable "db_backup_retention_days" {
190
+ description = "Days of automated backups to retain (7–35)."
191
+ type = number
192
+ default = 7
193
+ }
194
+
195
+ variable "db_high_availability" {
196
+ description = "Run the database zone-redundant (recommended for prod; not available on Burstable SKUs)."
197
+ type = bool
198
+ default = false
199
+ }
200
+ {{/if}}
@@ -0,0 +1,21 @@
1
+ terraform {
2
+ required_version = ">= 1.6.0"
3
+
4
+ required_providers {
5
+ azurerm = {
6
+ source = "hashicorp/azurerm"
7
+ version = "~> 4.14"
8
+ }
9
+ random = {
10
+ source = "hashicorp/random"
11
+ version = "~> 3.6"
12
+ }
13
+ }
14
+
15
+ # Partial backend: the concrete resource group / storage account / container are
16
+ # supplied per environment via `-backend-config=environments/<env>/backend.hcl`
17
+ # at `terraform init`. This keeps a single root usable both locally and from
18
+ # CI/CD. State locking is a blob lease — no separate lock table exists or is
19
+ # needed.
20
+ backend "azurerm" {}
21
+ }
@@ -0,0 +1,29 @@
1
+ # Production image for the backend: no --reload, no dev dependencies, app code
2
+ # baked in (no bind mounts in Kubernetes). Migrations run as a Helm pre-upgrade
3
+ # Job (`alembic upgrade head`), not on container start.
4
+ #
5
+ # docker build -f Dockerfile.prod -t <ecr>/<proj>-backend:<tag> .
6
+
7
+ FROM python:3.13-slim
8
+ WORKDIR /app
9
+
10
+ RUN pip install --no-cache-dir uv
11
+
12
+ # Run as an unprivileged user (trivy DS002). The user is created *before* the
13
+ # virtualenv is built so every layer is written with the right ownership — a
14
+ # trailing `chown -R /app` would instead duplicate the whole .venv into an
15
+ # extra layer.
16
+ RUN useradd -m -u 1000 appuser && chown appuser:appuser /app
17
+ USER appuser
18
+
19
+ COPY --chown=appuser:appuser pyproject.toml .
20
+ RUN uv sync --no-cache --no-dev
21
+
22
+ COPY --chown=appuser:appuser app ./app
23
+ {{#if withPostgres}}
24
+ COPY --chown=appuser:appuser alembic ./alembic
25
+ COPY --chown=appuser:appuser alembic.ini ./alembic.ini
26
+ {{/if}}
27
+
28
+ EXPOSE 8000
29
+ CMD ["uv", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
@@ -0,0 +1,273 @@
1
+ # Deploy — Azure AKS (Terraform + Helm)
2
+
3
+ This project was scaffolded with the **Azure AKS** IaC target. Infrastructure is
4
+ described with Terraform and the application is released with Helm. Every command
5
+ is scoped per environment via `--env`, which is **required** (no default) — run a
6
+ command without it to list the environments discovered under
7
+ `iac/terraform/environments/`. Add a new one with `dude iac new-env --env <name>`.
8
+ State lives in an Azure Storage blob container, so the same commands run locally
9
+ and in CI.
10
+
11
+ !!! info "The IaC runner (Docker)"
12
+ `dude iac *` runs terraform / kubectl / helm / k9s inside a pinned container
13
+ built from `iac/runner/Dockerfile` (yours to edit) — so you only need
14
+ **Docker** and the `az` CLI installed, not the whole toolchain. Your
15
+ `~/.azure` and `~/.kube` are mounted in, so your Azure login and the cluster
16
+ context keep working. `dude iac login` stays on the host (it needs a browser).
17
+ Set `DUDE_IAC_RUNNER=host` to use your local tools instead.
18
+
19
+ ## What gets provisioned
20
+
21
+ | Layer | Resource | Notes |
22
+ |-------|----------|-------|
23
+ | Resource group | `{{projectName}}-<env>-rg` | everything for one environment lives in it, so teardown is total |
24
+ | Network | Virtual network + AKS subnet{{#if withPostgres}} + delegated database subnet{{/if}} | Azure CNI **overlay**, so pod IPs don't consume the subnet |
25
+ | Cluster | AKS control plane + autoscaling node pool | `Standard_D2s_v3` nodes, 2–4, Free control-plane tier — see "Node sizing and quota" below |
26
+ | Registry | Azure Container Registry | `{{projectName}}-backend`, `{{projectName}}-frontend` — **shared** across envs, created once by `dude iac bootstrap` |
27
+ | Ingress | ingress-nginx + an Azure public IP with a DNS label | gives the app a real hostname with no domain of your own — see below |
28
+ | TLS *(optional)* | cert-manager + Let's Encrypt | needs a domain **you own**; see "HTTPS" below for why Azure's hostname can't have one |
29
+ {{#if withPostgres}}| Database | Azure Database for PostgreSQL Flexible Server | private (VNet-integrated, no public endpoint); password generated by Terraform, `DATABASE_URL` wired into Helm automatically by `dude iac ship` |
30
+ {{/if}}{{#if withRedis}}| Cache/broker | Redis (in-cluster) | broker/result backend for Celery |
31
+ {{/if}}| Release | Helm chart `iac/helm/app` | backend + frontend{{#if withCelery}} + Celery worker{{/if}}{{#if withCeleryBeat}} + Celery Beat{{/if}} |
32
+ | State backend | Storage account + `tfstate` blob container | created once by `dude iac bootstrap`; the blob lease **is** the state lock, so there is no lock table |
33
+
34
+ ## Before you start
35
+
36
+ You need, on your machine:
37
+
38
+ - **Docker**, running.
39
+ - The **Azure CLI** (`az`) — `brew install azure-cli`, or see
40
+ [Microsoft's install guide](https://learn.microsoft.com/cli/azure/install-azure-cli).
41
+ - An Azure subscription where your account can **create resource groups** and
42
+ **assign roles** (the Contributor + User Access Administrator pair, or Owner).
43
+ The role assignment is what lets the cluster pull from the registry; without it
44
+ `dude iac apply` fails at `azurerm_role_assignment.acr_pull`.
45
+
46
+ ## Node sizing and quota
47
+
48
+ A new Azure subscription grants vCPU quota **per VM family**, and several of the
49
+ newer families start at a limit of **zero** — you can see a size in the price
50
+ list and still be unable to create it. The default node pool is
51
+ `Standard_D2s_v3` for that reason: the Dsv3 and BS families are the ones a fresh
52
+ subscription reliably gets.
53
+
54
+ Check before the first apply — this fails several minutes in, not at plan time:
55
+
56
+ ```bash
57
+ az vm list-usage --location northeurope -o table | grep -E "Total Regional|Dsv3|BS Family"
58
+ ```
59
+
60
+ You need `node_max_count × (vCPUs per node)` available in both the family row and
61
+ `Total Regional vCPUs` — 8 vCPUs for the defaults. If a row you want reads
62
+ `Limit 0`, either pick a family that has quota or request an increase from
63
+ *Subscription → Usage + quotas* in the portal.
64
+
65
+ !!! warning "Some regions are closed to new subscriptions"
66
+ Azure caps capacity per region, and a new subscription is often refused
67
+ outright — West Europe is the common case, failing with
68
+ `RequestDisallowedByAzure: the selected region is currently not accepting new
69
+ customers`. The scaffold defaults to **North Europe**, which is reliably open.
70
+ If you change `location`, verify the region accepts your subscription before
71
+ planning a deploy around it.
72
+
73
+ ## Deploy, in order
74
+
75
+ ```bash
76
+ # 1. Sign in to Azure and confirm which subscription this environment uses
77
+ dude iac login --env dev
78
+
79
+ # 2. One-time per project: create the shared resource group, the Terraform state
80
+ # storage account and the container registry, then wire them into the env
81
+ # config. The prefix makes those names globally unique across Azure — use your
82
+ # org slug, lowercase letters/digits only. You do NOT repeat this for more envs.
83
+ dude iac bootstrap --state-prefix <yourorg> --env dev --yes
84
+
85
+ # 3. Initialise Terraform against the remote backend
86
+ dude iac init --env dev
87
+
88
+ # 4. Provision the infrastructure (resource group, VNet, AKS, ingress-nginx{{#if withPostgres}}, database{{/if}})
89
+ # Expect ~10 minutes: the cluster and the load balancer both take a while.
90
+ dude iac apply --env dev
91
+
92
+ # 5. Point kubectl at the new cluster
93
+ dude iac kubeconfig --env dev
94
+
95
+ # 6. Build, push and deploy the app in one step (build + push + helm upgrade --install).
96
+ # The registry, image tag and public hostname are wired automatically — no need
97
+ # to hand-edit values files.
98
+ dude iac ship --env dev
99
+ ```
100
+
101
+ Then open the URL `dude iac output --env dev` prints as `app_url`:
102
+
103
+ ```
104
+ http://{{projectName}}-dev.northeurope.cloudapp.azure.com/
105
+ ```
106
+
107
+ Check what's running:
108
+
109
+ ```bash
110
+ dude iac status --env dev # helm release + pods
111
+ dude iac output --env dev # cluster name, registry URLs, app URL…
112
+ ```
113
+
114
+ ## The public hostname
115
+
116
+ You do not need to own a domain. The ingress controller asks Azure for a public
117
+ IP **with a DNS label**, and Azure serves it at:
118
+
119
+ ```
120
+ <dns_label>.<location>.cloudapp.azure.com
121
+ ```
122
+
123
+ `dns_label` defaults to `{{projectName}}-<env>` and lives in the environment's
124
+ `terraform.tfvars`. It must be unique **within the region** — if `dude iac apply`
125
+ reports the name is taken, change it there and re-apply.
126
+
127
+ `dude iac deploy`/`ship` reads the resulting hostname from the Terraform
128
+ `app_host` output and sets it on the Ingress, so the chart's `ingress.host` is
129
+ left empty on purpose: it is a deploy-time fact, not a committed one.
130
+
131
+ ## HTTPS
132
+
133
+ **The Azure-provided hostname is served over plain HTTP, and that is not a
134
+ configuration you can flip.** `cloudapp.azure.com` is not on the
135
+ [Public Suffix List](https://publicsuffix.org/), so Let's Encrypt treats every
136
+ certificate for it as a certificate for `azure.com` — one rate limit shared by
137
+ every Azure customer on earth, which is permanently exhausted. No free, trusted
138
+ certificate is obtainable for that name.
139
+
140
+ Two ways to get HTTPS:
141
+
142
+ 1. **Point a domain you own at the ingress** (the supported path). Create a CNAME
143
+ from your hostname to `<dns_label>.<location>.cloudapp.azure.com`, then set in
144
+ `iac/terraform/environments/dev/terraform.tfvars`:
145
+
146
+ ```hcl
147
+ letsencrypt_email = "ops@example.com"
148
+ ```
149
+
150
+ `dude iac apply` installs cert-manager and a `letsencrypt-prod` ClusterIssuer.
151
+ Then set the host and turn TLS on in `iac/helm/app/values-dev.yaml`:
152
+
153
+ ```yaml
154
+ ingress:
155
+ host: app.example.com
156
+ tls:
157
+ enabled: true
158
+ clusterIssuer: letsencrypt-prod
159
+ ```
160
+
161
+ and `dude iac deploy --env dev`. The certificate is issued over HTTP-01
162
+ through the same ingress, so nothing else needs opening.
163
+
164
+ 2. **Put a fronting service with its own managed certificate in front** — Azure
165
+ Front Door Standard serves `*.azurefd.net` with a Microsoft-issued
166
+ certificate and needs no domain. It is not provisioned by this scaffold and
167
+ carries a monthly base cost.
168
+
169
+ Until then, treat the HTTP URL as what it is: fine for a demo or an internal
170
+ review, not for anything handling real credentials.
171
+
172
+ ## Add another environment (staging, prod, …)
173
+
174
+ Environments are independent infrastructure (their own resource group, cluster{{#if withPostgres}},
175
+ database{{/if}}) that **share one state backend and one container registry** — they
176
+ differ only by their Terraform state `key`. So adding `staging` does **not**
177
+ require another `bootstrap`.
178
+
179
+ ```bash
180
+ # 1. Scaffold environments/staging/ by copying an existing env (default: dev).
181
+ # Rewrites `environment` and `dns_label` for the new env, and copies its
182
+ # gitignored helm/app/values-<from>.yaml → values-staging.yaml.
183
+ dude iac new-env --env staging # or --from prod to copy a different one
184
+
185
+ # 2. Review the new env's settings in
186
+ # iac/terraform/environments/staging/terraform.tfvars:
187
+ # dns_label = "{{projectName}}-staging" # its own hostname
188
+ # node_vm_size / node_max_count / db_sku_name / … to taste
189
+ # …and iac/helm/app/values-staging.yaml (replicas, autoscaling, secrets, …).
190
+
191
+ # 3. Initialise and provision — same flow as the first env, minus bootstrap
192
+ # (the state backend + registry already exist).
193
+ dude iac login --env staging
194
+ dude iac init --env staging
195
+ dude iac apply --env staging
196
+ dude iac kubeconfig --env staging
197
+ dude iac ship --env staging
198
+ ```
199
+
200
+ > **Promoting an image.** Because the registry is shared, you can deploy the exact
201
+ > image already built for one env to another instead of rebuilding:
202
+ > `dude iac deploy --env staging --tag <sha>` (use the tag from
203
+ > `dude iac status --env dev`).
204
+
205
+ ## Image tags
206
+
207
+ `dude iac build/push/ship` derive the tag from your git state:
208
+
209
+ | Working tree | Tag |
210
+ |--------------|-----|
211
+ | clean | `<git-short-sha>` |
212
+ | uncommitted changes | `<git-short-sha>-dirty-<hash-of-the-diff>` |
213
+
214
+ The `-dirty-<hash>` part is what makes iterating on a branch work: every edit
215
+ changes the digest, so every `dude iac ship` publishes a distinguishable image.
216
+
217
+ Pushing a tag that already exists **overwrites** it — Azure Container Registry on
218
+ the Basic tier does not enforce tag immutability — so `dude iac push`/`ship` warn
219
+ before doing it. If you are promoting a build rather than making a new one, use
220
+ `dude iac deploy --env <env> --tag <tag>`: the image is already in the registry
221
+ and there is nothing to rebuild.
222
+
223
+ ## Ad-hoc work with `dude iac shell`
224
+
225
+ When you need to run commands directly against an environment — inspect state,
226
+ force-unlock a Terraform lock, debug a failing pod, or run a one-off Helm
227
+ operation — drop into the runner:
228
+
229
+ ```bash
230
+ dude iac shell --env dev
231
+ ```
232
+
233
+ This opens an interactive shell inside the Docker runner with the project mounted
234
+ at `/work`, the env's subscription exported, and `kubectl`/`helm`/`k9s` **already
235
+ pointed at this env's cluster and namespace** — so you don't inherit whatever
236
+ context your host's `kubectl` happened to be on. (If the cluster isn't reachable
237
+ yet, it falls back to your mounted `~/.kube`.) The full toolchain is available:
238
+
239
+ | Tool | Example |
240
+ |------|---------|
241
+ | `terraform` | `terraform state list` · `terraform force-unlock <id>` |
242
+ | `kubectl` | `kubectl get pods -n dev` · `kubectl logs <pod> -n dev -f` · `kubectl describe ingress -n dev` |
243
+ | `helm` | `helm get values {{projectName}} -n dev` · `helm history {{projectName}} -n dev` |
244
+ | `k9s` | `k9s` — full interactive cluster UI |
245
+ | `az` | `az aks list -o table` · `az acr repository list -n <registry>` |
246
+
247
+ The project root is `/work` — relative paths in Terraform and Helm configs
248
+ resolve correctly from there. Type `exit` (or Ctrl-D) to leave the runner.
249
+
250
+ ## Tear down
251
+
252
+ ```bash
253
+ dude iac destroy --env staging # destroy non-last envs first
254
+ dude iac destroy --env dev # the last env also removes the shared backend + registry
255
+ ```
256
+
257
+ For each environment, `destroy` uninstalls the Helm release (so the ingress
258
+ controller releases the public IP cleanly), then runs `terraform destroy`, which
259
+ removes the environment's whole resource group. It then re-checks that the group
260
+ is really gone, because Azure reporting a successful delete while the group
261
+ lingers — a deletion still in flight, or a resource lock — is the case that keeps
262
+ costing money quietly.
263
+
264
+ The **shared bootstrap** — the state storage account and the container registry —
265
+ is torn down **only when no other environment is still provisioned** (i.e. when
266
+ you destroy the last one). "Still provisioned" is judged from each sibling's
267
+ remote Terraform state, not its folder on disk — so a leftover `staging/` folder
268
+ whose infrastructure you already destroyed won't keep the backend alive.
269
+ Destroying a non-last environment never touches another env's state or the shared
270
+ registry. Pass `--keep-backend` to keep the bootstrap even when destroying the
271
+ last environment.
272
+
273
+ See `iac/README.md` for the full command reference and flags.
@@ -0,0 +1,32 @@
1
+ # Production image for the frontend: build the Vite app, serve the static
2
+ # bundle with nginx. Used by the Helm deployment (port 8080). The dev Dockerfile
3
+ # (Vite dev server) is kept for `dude up`.
4
+ #
5
+ # VITE_* values are baked in at build time — pass them as build args:
6
+ # docker build -f Dockerfile.prod --build-arg VITE_APP_TITLE="My App" -t <ecr>/<proj>-frontend:<tag> .
7
+
8
+ FROM node:22-alpine AS build
9
+ WORKDIR /app
10
+
11
+ RUN npm install -g pnpm@9
12
+
13
+ COPY package.json pnpm-lock.yaml* ./
14
+ RUN pnpm install --frozen-lockfile || pnpm install
15
+
16
+ ARG VITE_APP_TITLE=app
17
+ ARG VITE_REACT_QUERY_DEVTOOLS=false
18
+ ENV VITE_APP_TITLE=$VITE_APP_TITLE
19
+ ENV VITE_REACT_QUERY_DEVTOOLS=$VITE_REACT_QUERY_DEVTOOLS
20
+
21
+ COPY . .
22
+ RUN pnpm build
23
+
24
+ # nginx-unprivileged is the stock nginx image rebuilt to run as UID 101 with no
25
+ # root master process (trivy DS002). Because it cannot bind a privileged port,
26
+ # it listens on 8080 — see nginx.conf and `frontend.port` in the Helm values.
27
+ FROM nginxinc/nginx-unprivileged:1.27-alpine
28
+ COPY --from=build /app/dist /usr/share/nginx/html
29
+ COPY nginx.conf /etc/nginx/conf.d/default.conf
30
+ USER nginx
31
+ EXPOSE 8080
32
+ CMD ["nginx", "-g", "daemon off;"]
@@ -0,0 +1,20 @@
1
+ # SPA routing. The /api traffic is routed to the backend by the ALB Ingress
2
+ # (path-based), so nginx only needs to serve the static bundle and fall back to
3
+ # index.html for client-side routes.
4
+ server {
5
+ # 8080, not 80: the image runs unprivileged and cannot bind a port < 1024.
6
+ listen 8080;
7
+ server_name _;
8
+ root /usr/share/nginx/html;
9
+ index index.html;
10
+
11
+ location / {
12
+ try_files $uri $uri/ /index.html;
13
+ }
14
+
15
+ # Long-cache hashed assets.
16
+ location /assets/ {
17
+ expires 1y;
18
+ add_header Cache-Control "public, immutable";
19
+ }
20
+ }