@cubocicloide/stack-frappe 2.0.4

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 (122) hide show
  1. package/LICENSE +33 -0
  2. package/README.md +37 -0
  3. package/dist/commands/lint/checks/APP/001.d.ts +13 -0
  4. package/dist/commands/lint/checks/APP/001.js +73 -0
  5. package/dist/commands/lint/checks/APP/001.js.map +1 -0
  6. package/dist/commands/lint/checks/APP/002.d.ts +12 -0
  7. package/dist/commands/lint/checks/APP/002.js +94 -0
  8. package/dist/commands/lint/checks/APP/002.js.map +1 -0
  9. package/dist/commands/lint/checks/APP/003.d.ts +12 -0
  10. package/dist/commands/lint/checks/APP/003.js +94 -0
  11. package/dist/commands/lint/checks/APP/003.js.map +1 -0
  12. package/dist/commands/lint/checks/APP/004.d.ts +12 -0
  13. package/dist/commands/lint/checks/APP/004.js +117 -0
  14. package/dist/commands/lint/checks/APP/004.js.map +1 -0
  15. package/dist/commands/lint/checks/DT/001.d.ts +11 -0
  16. package/dist/commands/lint/checks/DT/001.js +57 -0
  17. package/dist/commands/lint/checks/DT/001.js.map +1 -0
  18. package/dist/commands/lint/checks/DT/002.d.ts +12 -0
  19. package/dist/commands/lint/checks/DT/002.js +74 -0
  20. package/dist/commands/lint/checks/DT/002.js.map +1 -0
  21. package/dist/commands/lint/checks/DT/003.d.ts +13 -0
  22. package/dist/commands/lint/checks/DT/003.js +96 -0
  23. package/dist/commands/lint/checks/DT/003.js.map +1 -0
  24. package/dist/commands/lint/checks/DT/004.d.ts +12 -0
  25. package/dist/commands/lint/checks/DT/004.js +101 -0
  26. package/dist/commands/lint/checks/DT/004.js.map +1 -0
  27. package/dist/commands/lint/checks/PY/001.d.ts +12 -0
  28. package/dist/commands/lint/checks/PY/001.js +87 -0
  29. package/dist/commands/lint/checks/PY/001.js.map +1 -0
  30. package/dist/commands/lint/checks/PY/002.d.ts +12 -0
  31. package/dist/commands/lint/checks/PY/002.js +80 -0
  32. package/dist/commands/lint/checks/PY/002.js.map +1 -0
  33. package/dist/commands/lint/checks/PY/003.d.ts +11 -0
  34. package/dist/commands/lint/checks/PY/003.js +56 -0
  35. package/dist/commands/lint/checks/PY/003.js.map +1 -0
  36. package/dist/index.d.ts +5 -0
  37. package/dist/index.js +1987 -0
  38. package/dist/index.js.map +1 -0
  39. package/dude.stack.json +12 -0
  40. package/package.json +41 -0
  41. package/templates/aws-ecs/_dockerignore +11 -0
  42. package/templates/aws-ecs/docker/Dockerfile.prod.hbs +80 -0
  43. package/templates/aws-ecs/docker/nginx-entrypoint.sh +17 -0
  44. package/templates/aws-ecs/docker/nginx-template.conf +95 -0
  45. package/templates/aws-ecs/docs/docs/deploy.md.hbs +53 -0
  46. package/templates/aws-ecs/iac/README.md.hbs +113 -0
  47. package/templates/aws-ecs/iac/_gitignore +14 -0
  48. package/templates/aws-ecs/iac/runner/Dockerfile +35 -0
  49. package/templates/aws-ecs/iac/terraform/bootstrap/main.tf.hbs +93 -0
  50. package/templates/aws-ecs/iac/terraform/bootstrap/outputs.tf +14 -0
  51. package/templates/aws-ecs/iac/terraform/bootstrap/variables.tf.hbs +17 -0
  52. package/templates/aws-ecs/iac/terraform/environments/dev/backend.hcl.hbs +12 -0
  53. package/templates/aws-ecs/iac/terraform/environments/dev/terraform.tfvars.hbs +32 -0
  54. package/templates/aws-ecs/iac/terraform/main.tf.hbs +1205 -0
  55. package/templates/aws-ecs/iac/terraform/outputs.tf.hbs +103 -0
  56. package/templates/aws-ecs/iac/terraform/providers.tf +19 -0
  57. package/templates/aws-ecs/iac/terraform/variables.tf.hbs +139 -0
  58. package/templates/aws-ecs/iac/terraform/versions.tf +19 -0
  59. package/templates/base/.claude/rules/APP/001.md +26 -0
  60. package/templates/base/.claude/rules/APP/002.md +26 -0
  61. package/templates/base/.claude/rules/APP/003.md +25 -0
  62. package/templates/base/.claude/rules/APP/004.md +27 -0
  63. package/templates/base/.claude/rules/DT/001.md +25 -0
  64. package/templates/base/.claude/rules/DT/002.md +25 -0
  65. package/templates/base/.claude/rules/DT/003.md +24 -0
  66. package/templates/base/.claude/rules/DT/004.md +22 -0
  67. package/templates/base/.claude/rules/PY/001.md +30 -0
  68. package/templates/base/.claude/rules/PY/002.md +31 -0
  69. package/templates/base/.claude/rules/PY/003.md +29 -0
  70. package/templates/base/.claude/settings.json +42 -0
  71. package/templates/base/.claude/skills/create-doctype/SKILL.md +99 -0
  72. package/templates/base/.dude/commands/README.md +85 -0
  73. package/templates/base/.dude/commands/hello.ts +34 -0
  74. package/templates/base/.dude/lint/checks/PRJ/001.ts +26 -0
  75. package/templates/base/.dude/lint/checks/README.md +69 -0
  76. package/templates/base/.vscode/tasks.json +44 -0
  77. package/templates/base/CLAUDE.md.hbs +49 -0
  78. package/templates/base/README.md.hbs +68 -0
  79. package/templates/base/_env.example.hbs +5 -0
  80. package/templates/base/_env.hbs +12 -0
  81. package/templates/base/_gitignore +26 -0
  82. package/templates/base/_npmrc +2 -0
  83. package/templates/base/apps/README.md +24 -0
  84. package/templates/base/apps/ticketing/README.md +43 -0
  85. package/templates/base/apps/ticketing/pyproject.toml +34 -0
  86. package/templates/base/apps/ticketing/ticketing/__init__.py +1 -0
  87. package/templates/base/apps/ticketing/ticketing/api.py +35 -0
  88. package/templates/base/apps/ticketing/ticketing/events/__init__.py +0 -0
  89. package/templates/base/apps/ticketing/ticketing/events/hd_ticket.py +32 -0
  90. package/templates/base/apps/ticketing/ticketing/fixtures/workflow.json +55 -0
  91. package/templates/base/apps/ticketing/ticketing/fixtures/workflow_action_master.json +12 -0
  92. package/templates/base/apps/ticketing/ticketing/fixtures/workflow_state.json +20 -0
  93. package/templates/base/apps/ticketing/ticketing/hooks.py +54 -0
  94. package/templates/base/apps/ticketing/ticketing/modules.txt +1 -0
  95. package/templates/base/apps/ticketing/ticketing/patches/__init__.py +0 -0
  96. package/templates/base/apps/ticketing/ticketing/patches/v1_0/__init__.py +0 -0
  97. package/templates/base/apps/ticketing/ticketing/patches/v1_0/set_default_branding.py +26 -0
  98. package/templates/base/apps/ticketing/ticketing/patches.txt +5 -0
  99. package/templates/base/apps/ticketing/ticketing/public/images/favicon.png +0 -0
  100. package/templates/base/apps/ticketing/ticketing/public/images/logo.png +0 -0
  101. package/templates/base/apps/ticketing/ticketing/tasks.py +99 -0
  102. package/templates/base/apps/ticketing/ticketing/templates/__init__.py +0 -0
  103. package/templates/base/apps/ticketing/ticketing/templates/pages/__init__.py +0 -0
  104. package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.html +30 -0
  105. package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.py +14 -0
  106. package/templates/base/apps/ticketing/ticketing/ticketing/__init__.py +0 -0
  107. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/__init__.py +0 -0
  108. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/__init__.py +0 -0
  109. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/test_ticket_escalation_rule.py +32 -0
  110. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.js +23 -0
  111. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.json +99 -0
  112. package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.py +18 -0
  113. package/templates/base/docker/init.sh +114 -0
  114. package/templates/base/docker-compose.yml.hbs +62 -0
  115. package/templates/base/docs/docs/api.md +21 -0
  116. package/templates/base/docs/docs/dude.md.hbs +220 -0
  117. package/templates/base/docs/docs/extending.md +238 -0
  118. package/templates/base/docs/docs/frappe.md.hbs +223 -0
  119. package/templates/base/docs/docs/index.md.hbs +101 -0
  120. package/templates/base/docs/docs/mkdocs.md +235 -0
  121. package/templates/base/docs/mkdocs.yml.hbs +54 -0
  122. package/templates/base/package.json.hbs +11 -0
@@ -0,0 +1,95 @@
1
+ # nginx template for the `frontend` role — rendered by nginx-entrypoint.sh
2
+ # with envsubst. Only ${BACKEND}, ${SOCKETIO}, ${FRAPPE_SITE_NAME_HEADER},
3
+ # ${PROXY_READ_TIMEOUT} and ${CLIENT_MAX_BODY_SIZE} are substituted; every
4
+ # `$other` variable below is a native nginx variable.
5
+ #
6
+ # Runs unprivileged (user frappe): port 8080, pid + temp paths under /tmp,
7
+ # logs to stdout/stderr for CloudWatch.
8
+
9
+ worker_processes auto;
10
+ error_log /dev/stderr info;
11
+ pid /tmp/nginx.pid;
12
+
13
+ events {
14
+ worker_connections 1024;
15
+ }
16
+
17
+ http {
18
+ include /etc/nginx/mime.types;
19
+ default_type application/octet-stream;
20
+
21
+ access_log /dev/stdout;
22
+ sendfile on;
23
+
24
+ client_body_temp_path /tmp/client_body;
25
+ proxy_temp_path /tmp/proxy;
26
+ fastcgi_temp_path /tmp/fastcgi;
27
+ uwsgi_temp_path /tmp/uwsgi;
28
+ scgi_temp_path /tmp/scgi;
29
+
30
+ upstream backend-server {
31
+ server ${BACKEND} fail_timeout=0;
32
+ }
33
+
34
+ upstream socketio-server {
35
+ server ${SOCKETIO} fail_timeout=0;
36
+ }
37
+
38
+ server {
39
+ listen 8080;
40
+ server_name $http_host;
41
+ root /home/frappe/frappe-bench/sites;
42
+
43
+ proxy_buffer_size 128k;
44
+ proxy_buffers 4 256k;
45
+ proxy_busy_buffers_size 256k;
46
+ client_max_body_size ${CLIENT_MAX_BODY_SIZE};
47
+
48
+ add_header X-Frame-Options "SAMEORIGIN";
49
+ add_header Referrer-Policy "same-origin, strict-origin-when-cross-origin";
50
+
51
+ location /assets {
52
+ try_files $uri =404;
53
+ }
54
+
55
+ location ~ ^/protected/(.*) {
56
+ internal;
57
+ try_files /${FRAPPE_SITE_NAME_HEADER}/$1 =404;
58
+ }
59
+
60
+ location /socket.io {
61
+ proxy_http_version 1.1;
62
+ proxy_set_header Upgrade $http_upgrade;
63
+ proxy_set_header Connection "upgrade";
64
+ proxy_set_header X-Frappe-Site-Name ${FRAPPE_SITE_NAME_HEADER};
65
+ proxy_set_header Origin $scheme://$http_host;
66
+ proxy_set_header Host $host;
67
+ proxy_pass http://socketio-server;
68
+ }
69
+
70
+ location / {
71
+ rewrite ^(.+)/$ $1 permanent;
72
+ rewrite ^(.+)/index\.html$ $1 permanent;
73
+ rewrite ^(.+)\.html$ $1 permanent;
74
+
75
+ location ~* ^/files/.*.(htm|html|svg|xml) {
76
+ add_header Content-disposition "attachment";
77
+ try_files /${FRAPPE_SITE_NAME_HEADER}/public/$uri @webserver;
78
+ }
79
+
80
+ try_files /${FRAPPE_SITE_NAME_HEADER}/public/$uri @webserver;
81
+ }
82
+
83
+ location @webserver {
84
+ proxy_http_version 1.1;
85
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
86
+ proxy_set_header X-Forwarded-Proto $scheme;
87
+ proxy_set_header X-Frappe-Site-Name ${FRAPPE_SITE_NAME_HEADER};
88
+ proxy_set_header Host $host;
89
+ proxy_set_header X-Use-X-Accel-Redirect True;
90
+ proxy_read_timeout ${PROXY_READ_TIMEOUT};
91
+ proxy_redirect off;
92
+ proxy_pass http://backend-server;
93
+ }
94
+ }
95
+ }
@@ -0,0 +1,53 @@
1
+ # Deploy to AWS (ECS Fargate)
2
+
3
+ This project ships Terraform + a `dude iac …` command group that deploy the
4
+ ticketing system to AWS ECS Fargate. The full reference lives in
5
+ `iac/README.md` in the repo — this page is the short version.
6
+
7
+ ## What gets provisioned
8
+
9
+ | Piece | Purpose |
10
+ | ----- | ------- |
11
+ | ECS Fargate ×5 | `frontend` (nginx, ALB target), `backend` (gunicorn), `websocket` (socketio), `worker`, `scheduler` — all from ONE image |
12
+ | ALB | Internet-facing entry point; HTTPS when a domain is configured |
13
+ | RDS MariaDB | The frappe database (master creds in Secrets Manager) |
14
+ | ElastiCache Redis | frappe's cache (`/0`) and queue + socketio (`/1`) brokers |
15
+ | EFS | The shared, durable `sites/` volume (site config, files, assets) |
16
+ | S3 + DynamoDB + ECR | Terraform remote state + the shared image registry (created once by `bootstrap`) |
17
+
18
+ One-off Fargate tasks (run by the CLI, never as services): **configurator**
19
+ (writes `common_site_config.json`, refreshes assets), **create-site**
20
+ (`bench new-site`, first deploy only) and **migrate** (`bench --site all migrate`).
21
+
22
+ ## First deploy
23
+
24
+ ```bash
25
+ dude iac login --env dev
26
+ dude iac bootstrap --state-bucket-prefix <your-org> --env dev --yes
27
+ dude iac init --env dev
28
+ dude iac apply --env dev
29
+ dude iac ship --env dev # build + push + deploy the image
30
+ dude iac create-site --env dev # first time only
31
+ dude iac status --env dev
32
+ ```
33
+
34
+ The app URL is in `dude iac output --env dev` (`app_url`). Log in as
35
+ `Administrator` with the password stored in the `…/admin-password` secret.
36
+
37
+ ## Everyday loop
38
+
39
+ ```bash
40
+ dude iac ship --env dev # after code changes
41
+ dude iac migrate --env dev # after DocType/patch/fixture changes
42
+ dude iac logs --env dev --service backend --follow
43
+ ```
44
+
45
+ ## Where things are configured
46
+
47
+ - `iac/terraform/environments/<env>/terraform.tfvars` — region, sizing,
48
+ `image_tag` (written by `deploy`), optional `domain_name` +
49
+ `route53_zone_name` for HTTPS.
50
+ - `docker/Dockerfile.prod` — the production image (frappe{{#if withHelpdesk}} + Helpdesk{{/if}} +
51
+ `apps/ticketing`). Add your own apps with extra `COPY` + `pip install -e`
52
+ lines, mirroring `ticketing`.
53
+ - New environments: `dude iac new-env --env staging`.
@@ -0,0 +1,113 @@
1
+ # iac/ — AWS ECS Fargate deployment (Terraform)
2
+
3
+ Deploys {{projectName}} to AWS: ONE production Frappe image (built by
4
+ `docker/Dockerfile.prod`) run as five ECS Fargate services —
5
+ **frontend** (nginx, the only ALB target), **backend** (gunicorn),
6
+ **websocket** (socketio), **worker** (bench worker) and **scheduler**
7
+ (bench schedule) — plus **RDS MariaDB**, **ElastiCache Redis** and an
8
+ **EFS** file system holding the shared frappe `sites/` volume.
9
+
10
+ Everything is driven through `dude iac …`. Every command is
11
+ **environment-scoped via `--env` (required)**; run any command without
12
+ `--env` to list the environments found under `iac/terraform/environments/`.
13
+
14
+ > **Runner**: terraform runs inside a Docker container built from
15
+ > `iac/runner/Dockerfile` (no local terraform install needed). `aws`,
16
+ > `docker build/push` and `dude iac login` stay on the host. Override with
17
+ > `DUDE_IAC_RUNNER=host` to use native tools.
18
+
19
+ ## First deploy, start to finish
20
+
21
+ ```bash
22
+ # 0. AWS credentials for the env (profile convention: {{projectName}}-dev)
23
+ dude iac login --env dev
24
+
25
+ # 1. One-time shared backend: S3 state bucket + DynamoDB lock + ECR repo
26
+ dude iac bootstrap --state-bucket-prefix <your-org> --env dev --yes
27
+
28
+ # 2. Provision the infrastructure
29
+ dude iac init --env dev
30
+ dude iac plan --env dev
31
+ dude iac apply --env dev
32
+
33
+ # 3. Build + push + deploy the image (tag defaults to the git short SHA)
34
+ dude iac ship --env dev
35
+
36
+ # 4. First time only: configure the bench and create the frappe site
37
+ # (writes common_site_config.json on the EFS volume, then bench new-site
38
+ # against RDS with the admin password from Secrets Manager)
39
+ dude iac create-site --env dev
40
+
41
+ # 5. Check
42
+ dude iac status --env dev
43
+ dude iac output --env dev # app_url, db endpoint, secret ARNs, …
44
+ ```
45
+
46
+ Log in as `Administrator` with the password stored in Secrets Manager
47
+ (`<project>-<env>/admin-password` — see `dude iac output --env dev`).
48
+
49
+ ## Everyday loop
50
+
51
+ ```bash
52
+ dude iac ship --env dev # build + push + deploy
53
+ dude iac migrate --env dev # after any DocType/patch/fixture change
54
+ dude iac logs --env dev --service backend --follow
55
+ dude iac status --env dev --service worker
56
+ dude iac shell --env dev # terraform/aws toolbox scoped to the env
57
+ ```
58
+
59
+ `deploy` records the image tag in `environments/<env>/terraform.tfvars`
60
+ (`image_tag = "…"`) — the file is the source of truth for what the env runs,
61
+ and a plain `apply` never silently changes the deployed version.
62
+
63
+ ## More environments
64
+
65
+ ```bash
66
+ dude iac new-env --env staging # copies dev's tfvars/backend.hcl
67
+ dude iac init --env staging && dude iac apply --env staging
68
+ ```
69
+
70
+ The state bucket, lock table and ECR repository are shared across
71
+ environments (created once by `bootstrap`); each env has its own state `key`.
72
+ Images are promoted between envs by tag: `dude iac deploy --env prod --tag <sha>`.
73
+
74
+ ## Custom domain + HTTPS
75
+
76
+ Set in `environments/<env>/terraform.tfvars`:
77
+
78
+ ```hcl
79
+ domain_name = "helpdesk.example.com"
80
+ route53_zone_name = "example.com"
81
+ ```
82
+
83
+ then `dude iac apply`. An ACM certificate is issued and validated via DNS,
84
+ HTTP redirects to HTTPS, and an alias record points the domain at the ALB.
85
+
86
+ ## Architecture notes
87
+
88
+ - **One image, many roles** — the frappe_docker pattern: only the container
89
+ command differs per service. `docker/Dockerfile.prod` bakes frappe{{#if withHelpdesk}},
90
+ Helpdesk{{/if}} and `apps/ticketing` in.
91
+ - **`sites/` on EFS** — site config, uploaded files and built assets must be
92
+ shared and durable (Fargate storage is ephemeral). The image keeps a baked
93
+ copy of the assets; the `configurator`/`migrate` one-off tasks sync it onto
94
+ the volume.
95
+ - **nginx proxies everything** — the ALB only targets the frontend; frappe's
96
+ nginx config forwards API traffic to `backend.<project>-<env>.internal:8000`
97
+ and `/socket.io` to the websocket service (Cloud Map service discovery).
98
+ - **The site name is not the domain** — nginx pins `FRAPPE_SITE_NAME_HEADER`
99
+ to `site_name` (default: the project name), so the same site answers on the
100
+ ALB DNS name or any custom domain.
101
+ - **Costs (dev defaults)** — single-AZ `db.t4g.micro` RDS, one
102
+ `cache.t4g.micro` Redis node, five small Fargate tasks, no NAT gateway
103
+ (tasks run in public subnets, locked down by security groups).
104
+
105
+ ## Teardown
106
+
107
+ ```bash
108
+ dude iac destroy --env dev
109
+ ```
110
+
111
+ Destroys the environment; the shared bootstrap (state bucket + lock table +
112
+ ECR) is removed only when no other environment still uses it
113
+ (`--keep-backend` to force-keep it).
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,35 @@
1
+ # IaC runner image — the toolchain `dude iac *` runs inside.
2
+ #
3
+ # `dude iac` builds this image on first use and runs terraform inside it, so you
4
+ # don't have to install (or version-match) it on your machine. The image is
5
+ # tagged by a hash of THIS file: edit it (bump a version, add a tool) and the
6
+ # next `dude iac` command rebuilds automatically.
7
+ #
8
+ # Your AWS credentials are NOT baked in — `dude iac` mounts ~/.aws read-only at
9
+ # run time, so named profiles and SSO keep working. `dude iac login` and the
10
+ # aws/docker calls run on the host; terraform runs in here.
11
+ #
12
+ # TARGETARCH is set automatically by Docker BuildKit (amd64 or arm64).
13
+
14
+ FROM debian:bookworm-slim
15
+ ARG TARGETARCH
16
+ ENV DEBIAN_FRONTEND=noninteractive
17
+
18
+ ARG TF_VERSION=1.10.5
19
+
20
+ RUN apt-get update && apt-get install -y --no-install-recommends \
21
+ curl unzip ca-certificates bash less groff git \
22
+ && rm -rf /var/lib/apt/lists/*
23
+
24
+ # terraform
25
+ RUN curl -fsSL --retry 5 --retry-delay 2 --retry-connrefused \
26
+ "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_${TARGETARCH}.zip" -o /tmp/tf.zip \
27
+ && unzip -q /tmp/tf.zip -d /usr/local/bin && rm /tmp/tf.zip
28
+
29
+ # aws cli v2 (arch naming differs: amd64 -> x86_64, arm64 -> aarch64)
30
+ RUN case "${TARGETARCH}" in amd64) A=x86_64;; arm64) A=aarch64;; *) A=${TARGETARCH};; esac \
31
+ && curl -fsSL --retry 5 --retry-delay 2 --retry-connrefused \
32
+ "https://awscli.amazonaws.com/awscli-exe-linux-${A}.zip" -o /tmp/aws.zip \
33
+ && unzip -q /tmp/aws.zip -d /tmp && /tmp/aws/install && rm -rf /tmp/aws*
34
+
35
+ WORKDIR /work
@@ -0,0 +1,93 @@
1
+ # Bootstrap — creates the project-wide shared resources: the S3 bucket +
2
+ # DynamoDB table that hold Terraform remote state for every environment, and
3
+ # the single ECR repository the production Frappe image is pushed to (one
4
+ # image serves every role — frontend/backend/websocket/worker/scheduler).
5
+ # These are SHARED across all environments (one image, promoted dev →
6
+ # staging → prod by tag), so they have a single owner here rather than being
7
+ # recreated by each per-env config — which would otherwise collide
8
+ # (RepositoryAlreadyExistsException) and let one env's `destroy` delete another
9
+ # env's registry. Run ONCE per project, with LOCAL state (this config has no
10
+ # remote backend on purpose), then paste the outputs into each environment's
11
+ # backend.hcl.
12
+ #
13
+ # cd iac/terraform/bootstrap
14
+ # terraform init
15
+ # terraform apply -var project_name={{projectName}} -var region=eu-west-1
16
+
17
+ terraform {
18
+ required_version = ">= 1.6.0"
19
+ required_providers {
20
+ aws = {
21
+ source = "hashicorp/aws"
22
+ version = "~> 5.60"
23
+ }
24
+ }
25
+ }
26
+
27
+ provider "aws" {
28
+ region = var.region
29
+
30
+ # Pin to the standard public endpoints — the AWS provider 5.x enables
31
+ # endpoint discovery by default for DynamoDB, which can return a
32
+ # VPC-endpoint-scoped URL that doesn't resolve from a local machine.
33
+ endpoints {
34
+ dynamodb = "https://dynamodb.${var.region}.amazonaws.com"
35
+ s3 = "https://s3.${var.region}.amazonaws.com"
36
+ }
37
+ }
38
+
39
+ resource "aws_s3_bucket" "state" {
40
+ bucket = "${var.state_bucket_prefix}-${var.project_name}-tfstate"
41
+
42
+ # Allow `dude iac destroy` to remove the bucket even though versioning keeps
43
+ # old object versions around (the command also empties it first).
44
+ force_destroy = true
45
+ }
46
+
47
+ resource "aws_s3_bucket_versioning" "state" {
48
+ bucket = aws_s3_bucket.state.id
49
+ versioning_configuration {
50
+ status = "Enabled"
51
+ }
52
+ }
53
+
54
+ resource "aws_s3_bucket_server_side_encryption_configuration" "state" {
55
+ bucket = aws_s3_bucket.state.id
56
+ rule {
57
+ apply_server_side_encryption_by_default {
58
+ sse_algorithm = "AES256"
59
+ }
60
+ }
61
+ }
62
+
63
+ resource "aws_s3_bucket_public_access_block" "state" {
64
+ bucket = aws_s3_bucket.state.id
65
+ block_public_acls = true
66
+ block_public_policy = true
67
+ ignore_public_acls = true
68
+ restrict_public_buckets = true
69
+ }
70
+
71
+ resource "aws_dynamodb_table" "lock" {
72
+ name = "${var.project_name}-tflock"
73
+ billing_mode = "PAY_PER_REQUEST"
74
+ hash_key = "LockID"
75
+
76
+ attribute {
77
+ name = "LockID"
78
+ type = "S"
79
+ }
80
+ }
81
+
82
+ # Shared ECR repository — the single production Frappe image, used by every
83
+ # environment. Per-env Terraform reads it by name via a data source; it is
84
+ # created/destroyed only here, with the rest of the shared backend.
85
+ resource "aws_ecr_repository" "app" {
86
+ name = "${var.project_name}-app"
87
+ image_tag_mutability = "MUTABLE"
88
+ force_delete = true
89
+
90
+ image_scanning_configuration {
91
+ scan_on_push = true
92
+ }
93
+ }
@@ -0,0 +1,14 @@
1
+ output "state_bucket" {
2
+ description = "Set this as `bucket` in every environment's backend.hcl."
3
+ value = aws_s3_bucket.state.id
4
+ }
5
+
6
+ output "lock_table" {
7
+ description = "Set this as `dynamodb_table` in every environment's backend.hcl."
8
+ value = aws_dynamodb_table.lock.name
9
+ }
10
+
11
+ output "ecr_app_repository_url" {
12
+ description = "Shared ECR repository URL for the production Frappe image."
13
+ value = aws_ecr_repository.app.repository_url
14
+ }
@@ -0,0 +1,17 @@
1
+ variable "project_name" {
2
+ description = "Project slug — used to name the state bucket, lock table and ECR repositories."
3
+ type = string
4
+ default = "{{projectName}}"
5
+ }
6
+
7
+ variable "region" {
8
+ description = "AWS region for the state bucket + lock table + ECR repositories."
9
+ type = string
10
+ default = "eu-west-1"
11
+ }
12
+
13
+ variable "state_bucket_prefix" {
14
+ description = "Prefix to make the S3 bucket name globally unique (e.g. your org slug)."
15
+ type = string
16
+ default = "change-me"
17
+ }
@@ -0,0 +1,12 @@
1
+ # Remote state for the `dev` environment.
2
+ # These resources are created once by `iac/terraform/bootstrap` (see the IaC
3
+ # README). The same backend works locally and from CI/CD.
4
+ #
5
+ # Each environment uses a distinct `key`, so adding `staging`/`prod` is just a
6
+ # new folder with its own backend.hcl + terraform.tfvars.
7
+
8
+ bucket = "CHANGE-ME-{{projectName}}-tfstate"
9
+ key = "{{projectName}}/dev/terraform.tfstate"
10
+ region = "eu-west-1"
11
+ dynamodb_table = "{{projectName}}-tflock"
12
+ encrypt = true
@@ -0,0 +1,32 @@
1
+ # dev environment — {{projectName}}
2
+ #
3
+ # `dude iac deploy` rewrites `image_tag` here on every deploy, so this file is
4
+ # the source of truth for what the environment runs. Everything else is a
5
+ # knob you tune by hand.
6
+
7
+ project_name = "{{projectName}}"
8
+ environment = "dev"
9
+ region = "eu-west-1"
10
+
11
+ # Written by `dude iac deploy --env dev` (defaults to the git short SHA).
12
+ image_tag = "latest"
13
+
14
+ # The frappe site name (default: the project name). Keep it stable — changing
15
+ # it after `dude iac create-site` means creating a new site.
16
+ # site_name = "{{projectName}}"
17
+
18
+ # Serve on a custom domain with HTTPS (both must be set; the zone must already
19
+ # exist in Route53):
20
+ # domain_name = "helpdesk.example.com"
21
+ # route53_zone_name = "example.com"
22
+
23
+ # Restrict who can reach the ALB (default: the whole internet):
24
+ # allowed_cidrs = ["203.0.113.0/24"]
25
+
26
+ # ── Sizing (dev defaults are the cheapest sensible options) ──────────────────
27
+ # db_instance_class = "db.t4g.micro"
28
+ # db_allocated_storage = 20
29
+ # redis_node_type = "cache.t4g.micro"
30
+ # backend_cpu = 512
31
+ # backend_memory = 1024
32
+ # worker_desired_count = 1