@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.
- package/LICENSE +33 -0
- package/README.md +37 -0
- package/dist/commands/lint/checks/APP/001.d.ts +13 -0
- package/dist/commands/lint/checks/APP/001.js +73 -0
- package/dist/commands/lint/checks/APP/001.js.map +1 -0
- package/dist/commands/lint/checks/APP/002.d.ts +12 -0
- package/dist/commands/lint/checks/APP/002.js +94 -0
- package/dist/commands/lint/checks/APP/002.js.map +1 -0
- package/dist/commands/lint/checks/APP/003.d.ts +12 -0
- package/dist/commands/lint/checks/APP/003.js +94 -0
- package/dist/commands/lint/checks/APP/003.js.map +1 -0
- package/dist/commands/lint/checks/APP/004.d.ts +12 -0
- package/dist/commands/lint/checks/APP/004.js +117 -0
- package/dist/commands/lint/checks/APP/004.js.map +1 -0
- package/dist/commands/lint/checks/DT/001.d.ts +11 -0
- package/dist/commands/lint/checks/DT/001.js +57 -0
- package/dist/commands/lint/checks/DT/001.js.map +1 -0
- package/dist/commands/lint/checks/DT/002.d.ts +12 -0
- package/dist/commands/lint/checks/DT/002.js +74 -0
- package/dist/commands/lint/checks/DT/002.js.map +1 -0
- package/dist/commands/lint/checks/DT/003.d.ts +13 -0
- package/dist/commands/lint/checks/DT/003.js +96 -0
- package/dist/commands/lint/checks/DT/003.js.map +1 -0
- package/dist/commands/lint/checks/DT/004.d.ts +12 -0
- package/dist/commands/lint/checks/DT/004.js +101 -0
- package/dist/commands/lint/checks/DT/004.js.map +1 -0
- package/dist/commands/lint/checks/PY/001.d.ts +12 -0
- package/dist/commands/lint/checks/PY/001.js +87 -0
- package/dist/commands/lint/checks/PY/001.js.map +1 -0
- package/dist/commands/lint/checks/PY/002.d.ts +12 -0
- package/dist/commands/lint/checks/PY/002.js +80 -0
- package/dist/commands/lint/checks/PY/002.js.map +1 -0
- package/dist/commands/lint/checks/PY/003.d.ts +11 -0
- package/dist/commands/lint/checks/PY/003.js +56 -0
- package/dist/commands/lint/checks/PY/003.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1987 -0
- package/dist/index.js.map +1 -0
- package/dude.stack.json +12 -0
- package/package.json +41 -0
- package/templates/aws-ecs/_dockerignore +11 -0
- package/templates/aws-ecs/docker/Dockerfile.prod.hbs +80 -0
- package/templates/aws-ecs/docker/nginx-entrypoint.sh +17 -0
- package/templates/aws-ecs/docker/nginx-template.conf +95 -0
- package/templates/aws-ecs/docs/docs/deploy.md.hbs +53 -0
- package/templates/aws-ecs/iac/README.md.hbs +113 -0
- package/templates/aws-ecs/iac/_gitignore +14 -0
- package/templates/aws-ecs/iac/runner/Dockerfile +35 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/main.tf.hbs +93 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/outputs.tf +14 -0
- package/templates/aws-ecs/iac/terraform/bootstrap/variables.tf.hbs +17 -0
- package/templates/aws-ecs/iac/terraform/environments/dev/backend.hcl.hbs +12 -0
- package/templates/aws-ecs/iac/terraform/environments/dev/terraform.tfvars.hbs +32 -0
- package/templates/aws-ecs/iac/terraform/main.tf.hbs +1205 -0
- package/templates/aws-ecs/iac/terraform/outputs.tf.hbs +103 -0
- package/templates/aws-ecs/iac/terraform/providers.tf +19 -0
- package/templates/aws-ecs/iac/terraform/variables.tf.hbs +139 -0
- package/templates/aws-ecs/iac/terraform/versions.tf +19 -0
- package/templates/base/.claude/rules/APP/001.md +26 -0
- package/templates/base/.claude/rules/APP/002.md +26 -0
- package/templates/base/.claude/rules/APP/003.md +25 -0
- package/templates/base/.claude/rules/APP/004.md +27 -0
- package/templates/base/.claude/rules/DT/001.md +25 -0
- package/templates/base/.claude/rules/DT/002.md +25 -0
- package/templates/base/.claude/rules/DT/003.md +24 -0
- package/templates/base/.claude/rules/DT/004.md +22 -0
- package/templates/base/.claude/rules/PY/001.md +30 -0
- package/templates/base/.claude/rules/PY/002.md +31 -0
- package/templates/base/.claude/rules/PY/003.md +29 -0
- package/templates/base/.claude/settings.json +42 -0
- package/templates/base/.claude/skills/create-doctype/SKILL.md +99 -0
- package/templates/base/.dude/commands/README.md +85 -0
- package/templates/base/.dude/commands/hello.ts +34 -0
- package/templates/base/.dude/lint/checks/PRJ/001.ts +26 -0
- package/templates/base/.dude/lint/checks/README.md +69 -0
- package/templates/base/.vscode/tasks.json +44 -0
- package/templates/base/CLAUDE.md.hbs +49 -0
- package/templates/base/README.md.hbs +68 -0
- package/templates/base/_env.example.hbs +5 -0
- package/templates/base/_env.hbs +12 -0
- package/templates/base/_gitignore +26 -0
- package/templates/base/_npmrc +2 -0
- package/templates/base/apps/README.md +24 -0
- package/templates/base/apps/ticketing/README.md +43 -0
- package/templates/base/apps/ticketing/pyproject.toml +34 -0
- package/templates/base/apps/ticketing/ticketing/__init__.py +1 -0
- package/templates/base/apps/ticketing/ticketing/api.py +35 -0
- package/templates/base/apps/ticketing/ticketing/events/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/events/hd_ticket.py +32 -0
- package/templates/base/apps/ticketing/ticketing/fixtures/workflow.json +55 -0
- package/templates/base/apps/ticketing/ticketing/fixtures/workflow_action_master.json +12 -0
- package/templates/base/apps/ticketing/ticketing/fixtures/workflow_state.json +20 -0
- package/templates/base/apps/ticketing/ticketing/hooks.py +54 -0
- package/templates/base/apps/ticketing/ticketing/modules.txt +1 -0
- package/templates/base/apps/ticketing/ticketing/patches/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/patches/v1_0/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/patches/v1_0/set_default_branding.py +26 -0
- package/templates/base/apps/ticketing/ticketing/patches.txt +5 -0
- package/templates/base/apps/ticketing/ticketing/public/images/favicon.png +0 -0
- package/templates/base/apps/ticketing/ticketing/public/images/logo.png +0 -0
- package/templates/base/apps/ticketing/ticketing/tasks.py +99 -0
- package/templates/base/apps/ticketing/ticketing/templates/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/templates/pages/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.html +30 -0
- package/templates/base/apps/ticketing/ticketing/templates/pages/ticket_stats.py +14 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/__init__.py +0 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/test_ticket_escalation_rule.py +32 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.js +23 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.json +99 -0
- package/templates/base/apps/ticketing/ticketing/ticketing/doctype/ticket_escalation_rule/ticket_escalation_rule.py +18 -0
- package/templates/base/docker/init.sh +114 -0
- package/templates/base/docker-compose.yml.hbs +62 -0
- package/templates/base/docs/docs/api.md +21 -0
- package/templates/base/docs/docs/dude.md.hbs +220 -0
- package/templates/base/docs/docs/extending.md +238 -0
- package/templates/base/docs/docs/frappe.md.hbs +223 -0
- package/templates/base/docs/docs/index.md.hbs +101 -0
- package/templates/base/docs/docs/mkdocs.md +235 -0
- package/templates/base/docs/mkdocs.yml.hbs +54 -0
- package/templates/base/package.json.hbs +11 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1987 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import path9 from "pathe";
|
|
3
|
+
import { defineStack, renderTemplateTree } from "@cubocicloide/dude";
|
|
4
|
+
|
|
5
|
+
// src/commands/_docker.ts
|
|
6
|
+
import { spawnSync } from "child_process";
|
|
7
|
+
function dc(args) {
|
|
8
|
+
const result = spawnSync("docker", ["compose", ...args], { stdio: "inherit" });
|
|
9
|
+
process.exit(result.status ?? 0);
|
|
10
|
+
}
|
|
11
|
+
function benchSh(cmd) {
|
|
12
|
+
dc(["exec", "bench", "bash", "-lc", cmd]);
|
|
13
|
+
}
|
|
14
|
+
function shellQuote(s) {
|
|
15
|
+
if (/^[A-Za-z0-9_@%+=:,./-]+$/.test(s)) return s;
|
|
16
|
+
return `'${s.replaceAll("'", `'\\''`)}'`;
|
|
17
|
+
}
|
|
18
|
+
function isDockerRunning() {
|
|
19
|
+
const r = spawnSync("docker", ["info"], { stdio: "ignore" });
|
|
20
|
+
return r.error == null && r.status === 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/commands/app/index.ts
|
|
24
|
+
var IN_BENCH = "cd /home/frappe/frappe-bench";
|
|
25
|
+
var newAppCommand = {
|
|
26
|
+
description: "Scaffold a new custom Frappe app (bench new-app) and move it into this repo under apps/, linked into the bench in editable mode.",
|
|
27
|
+
args: {
|
|
28
|
+
name: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "App name (snake_case python package name).",
|
|
31
|
+
required: true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
async run({ args }) {
|
|
35
|
+
const name = String(args.name);
|
|
36
|
+
if (!/^[a-z][a-z0-9_]*$/.test(name)) {
|
|
37
|
+
process.stderr.write("error: app name must be snake_case (e.g. my_app)\n");
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
const q = shellQuote(name);
|
|
41
|
+
benchSh(
|
|
42
|
+
[
|
|
43
|
+
IN_BENCH,
|
|
44
|
+
`bench new-app ${q}`,
|
|
45
|
+
// Relocate into the repo (mounted at /workspace/apps) and symlink back,
|
|
46
|
+
// exactly like docker/init.sh does for existing apps.
|
|
47
|
+
`rm -rf /workspace/apps/${q}`,
|
|
48
|
+
`mv apps/${q} /workspace/apps/${q}`,
|
|
49
|
+
`ln -s /workspace/apps/${q} apps/${q}`,
|
|
50
|
+
`./env/bin/pip install --quiet -e apps/${q}`,
|
|
51
|
+
`echo "App created in apps/${q}. Install it on the site with: dude app install --name ${q}"`
|
|
52
|
+
].join(" && ")
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var installAppCommand = {
|
|
57
|
+
description: "Install an app from the bench onto the default site (bench install-app).",
|
|
58
|
+
args: {
|
|
59
|
+
name: { type: "string", description: "App name.", required: true }
|
|
60
|
+
},
|
|
61
|
+
async run({ args }) {
|
|
62
|
+
const q = shellQuote(String(args.name));
|
|
63
|
+
benchSh(`${IN_BENCH} && bench --site "$SITE_NAME" install-app ${q}`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/commands/bench/index.ts
|
|
68
|
+
var benchCommand = {
|
|
69
|
+
description: "Raw bench passthrough: everything after `dude bench` runs as `bench \u2026` inside the bench container, e.g. `dude bench --site all migrate`.",
|
|
70
|
+
args: {},
|
|
71
|
+
async run() {
|
|
72
|
+
const idx = process.argv.indexOf("bench");
|
|
73
|
+
const benchArgs = idx === -1 ? [] : process.argv.slice(idx + 1);
|
|
74
|
+
const line = benchArgs.map(shellQuote).join(" ");
|
|
75
|
+
benchSh(`cd /home/frappe/frappe-bench && bench ${line}`);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/commands/docs/index.ts
|
|
80
|
+
import { spawn, spawnSync as spawnSync2 } from "child_process";
|
|
81
|
+
import { existsSync, writeFileSync } from "fs";
|
|
82
|
+
import path from "pathe";
|
|
83
|
+
async function regenerateApiDoc(projectRoot, docsDir) {
|
|
84
|
+
try {
|
|
85
|
+
const dude = await import("@cubocicloide/dude");
|
|
86
|
+
if (typeof dude.generateApiDoc !== "function") return;
|
|
87
|
+
const md = await dude.generateApiDoc(projectRoot, "md");
|
|
88
|
+
writeFileSync(path.join(docsDir, "docs", "api.md"), md);
|
|
89
|
+
process.stdout.write("[docs] Regenerated docs/api.md from the live command catalog.\n");
|
|
90
|
+
} catch (e) {
|
|
91
|
+
process.stderr.write(
|
|
92
|
+
`[docs] Could not regenerate api.md (${e.message}); using the existing file.
|
|
93
|
+
`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function isDockerRunning2() {
|
|
98
|
+
const r = spawnSync2("docker", ["info"], { stdio: "ignore" });
|
|
99
|
+
return r.error == null && r.status === 0;
|
|
100
|
+
}
|
|
101
|
+
function openBrowser(url) {
|
|
102
|
+
if (process.platform === "win32") {
|
|
103
|
+
spawnSync2("cmd", ["/c", "start", "", url], { stdio: "ignore" });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const opener = process.platform === "darwin" ? "open" : "xdg-open";
|
|
107
|
+
spawnSync2(opener, [url], { stdio: "ignore" });
|
|
108
|
+
}
|
|
109
|
+
var docsCommand = {
|
|
110
|
+
description: "Serve the project documentation in dev mode (live-reload) at http://localhost:8001.",
|
|
111
|
+
args: {
|
|
112
|
+
port: {
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "Host port to expose the docs site on (default: 8001).",
|
|
115
|
+
default: "8001"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
async run({ projectRoot, args }) {
|
|
119
|
+
const docsDir = path.join(projectRoot, "docs");
|
|
120
|
+
const port = String(args.port ?? "8001");
|
|
121
|
+
const url = `http://localhost:${port}`;
|
|
122
|
+
if (!existsSync(docsDir)) {
|
|
123
|
+
process.stderr.write(
|
|
124
|
+
"[docs] No docs/ folder found in the project root. Make sure you ran `dude init`.\n"
|
|
125
|
+
);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
await regenerateApiDoc(projectRoot, docsDir);
|
|
129
|
+
if (!isDockerRunning2()) {
|
|
130
|
+
process.stderr.write("[docs] Docker is not running. Start Docker Desktop and retry.\n");
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
process.stdout.write(`[docs] Starting MkDocs at ${url} (Ctrl+C to stop)
|
|
134
|
+
`);
|
|
135
|
+
const child = spawn(
|
|
136
|
+
"docker",
|
|
137
|
+
[
|
|
138
|
+
"run",
|
|
139
|
+
"--rm",
|
|
140
|
+
"-i",
|
|
141
|
+
"-p",
|
|
142
|
+
`${port}:8000`,
|
|
143
|
+
"-v",
|
|
144
|
+
`${docsDir}:/docs`,
|
|
145
|
+
"squidfunk/mkdocs-material",
|
|
146
|
+
"serve",
|
|
147
|
+
"--dev-addr=0.0.0.0:8000"
|
|
148
|
+
],
|
|
149
|
+
{ stdio: ["inherit", "pipe", "pipe"] }
|
|
150
|
+
);
|
|
151
|
+
if (child.pid == null) {
|
|
152
|
+
process.stderr.write("[docs] Failed to start Docker container.\n");
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
let browserOpened = false;
|
|
156
|
+
function watchChunk(chunk) {
|
|
157
|
+
if (!browserOpened && chunk.toString().includes("Serving on")) {
|
|
158
|
+
browserOpened = true;
|
|
159
|
+
process.stdout.write(`[docs] Opening ${url}
|
|
160
|
+
`);
|
|
161
|
+
openBrowser(url);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
child.stdout?.on("data", (chunk) => {
|
|
165
|
+
process.stdout.write(chunk);
|
|
166
|
+
watchChunk(chunk);
|
|
167
|
+
});
|
|
168
|
+
child.stderr?.on("data", (chunk) => {
|
|
169
|
+
process.stderr.write(chunk);
|
|
170
|
+
watchChunk(chunk);
|
|
171
|
+
});
|
|
172
|
+
await new Promise((resolve) => child.on("close", resolve));
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// src/commands/down/index.ts
|
|
177
|
+
var downCommand = {
|
|
178
|
+
description: "Stop and remove all service containers (docker compose down).",
|
|
179
|
+
args: {
|
|
180
|
+
volumes: {
|
|
181
|
+
type: "boolean",
|
|
182
|
+
description: "Also remove volumes \u2014 DESTROYS the bench and the database.",
|
|
183
|
+
default: false
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
async run({ args }) {
|
|
187
|
+
dc(Boolean(args.volumes) ? ["down", "--volumes"] : ["down"]);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/commands/format/index.ts
|
|
192
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
193
|
+
import path2 from "pathe";
|
|
194
|
+
function ruff(projectRoot, ruffArgs) {
|
|
195
|
+
const appsDir = path2.join(projectRoot, "apps");
|
|
196
|
+
const r = spawnSync3(
|
|
197
|
+
"docker",
|
|
198
|
+
["run", "--rm", "-v", `${appsDir}:/apps`, "-w", "/apps", "ghcr.io/astral-sh/ruff:latest", ...ruffArgs],
|
|
199
|
+
{ stdio: "inherit" }
|
|
200
|
+
);
|
|
201
|
+
return r.status ?? 1;
|
|
202
|
+
}
|
|
203
|
+
var formatCommand = {
|
|
204
|
+
description: "Format and autofix Python in apps/ with ruff (Frappe style \u2014 tabs).",
|
|
205
|
+
args: {},
|
|
206
|
+
async run({ projectRoot }) {
|
|
207
|
+
if (!isDockerRunning()) {
|
|
208
|
+
process.stderr.write("[format] Docker is not running. Start Docker Desktop and retry.\n");
|
|
209
|
+
process.exit(1);
|
|
210
|
+
}
|
|
211
|
+
const fmt = ruff(projectRoot, ["format", "."]);
|
|
212
|
+
const fix = ruff(projectRoot, ["check", "--fix", "."]);
|
|
213
|
+
process.exit(fmt || fix ? 1 : 0);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/commands/iac/providers/aws-ecs/lib/terraform.ts
|
|
218
|
+
import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync3 } from "fs";
|
|
219
|
+
import path5 from "pathe";
|
|
220
|
+
|
|
221
|
+
// src/commands/iac/shared.ts
|
|
222
|
+
import { spawnSync as spawnSync4 } from "child_process";
|
|
223
|
+
import { readFileSync } from "fs";
|
|
224
|
+
import path3 from "pathe";
|
|
225
|
+
function shouldUseShell() {
|
|
226
|
+
return process.platform === "win32";
|
|
227
|
+
}
|
|
228
|
+
function childEnv(profile) {
|
|
229
|
+
return profile ? { ...process.env, AWS_PROFILE: profile } : process.env;
|
|
230
|
+
}
|
|
231
|
+
function run(cmd, args, cwd, profile) {
|
|
232
|
+
const r = spawnSync4(cmd, args, {
|
|
233
|
+
cwd,
|
|
234
|
+
stdio: "inherit",
|
|
235
|
+
env: childEnv(profile),
|
|
236
|
+
shell: shouldUseShell()
|
|
237
|
+
});
|
|
238
|
+
if (r.error) {
|
|
239
|
+
const code = r.error.code;
|
|
240
|
+
if (code === "ENOENT") {
|
|
241
|
+
process.stderr.write(`
|
|
242
|
+
\u2717 \`${cmd}\` not found on PATH. Install it and retry.
|
|
243
|
+
|
|
244
|
+
`);
|
|
245
|
+
} else {
|
|
246
|
+
process.stderr.write(`
|
|
247
|
+
\u2717 failed to run ${cmd}: ${r.error.message}
|
|
248
|
+
|
|
249
|
+
`);
|
|
250
|
+
}
|
|
251
|
+
return 1;
|
|
252
|
+
}
|
|
253
|
+
return r.status ?? 1;
|
|
254
|
+
}
|
|
255
|
+
function capture(cmd, args, cwd, profile) {
|
|
256
|
+
const r = spawnSync4(cmd, args, {
|
|
257
|
+
cwd,
|
|
258
|
+
encoding: "utf8",
|
|
259
|
+
env: childEnv(profile),
|
|
260
|
+
shell: shouldUseShell()
|
|
261
|
+
});
|
|
262
|
+
return { status: r.status ?? 1, stdout: r.stdout ?? "" };
|
|
263
|
+
}
|
|
264
|
+
function readAnswers(projectRoot) {
|
|
265
|
+
try {
|
|
266
|
+
const j = JSON.parse(readFileSync(path3.join(projectRoot, "dude.json"), "utf8"));
|
|
267
|
+
return j.answers ?? {};
|
|
268
|
+
} catch {
|
|
269
|
+
return {};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function projectName(projectRoot) {
|
|
273
|
+
const name = readAnswers(projectRoot).projectName;
|
|
274
|
+
return typeof name === "string" && name ? name : "app";
|
|
275
|
+
}
|
|
276
|
+
function hclScalar(text, key) {
|
|
277
|
+
const m = text.match(new RegExp(`^\\s*${key}\\s*=\\s*"([^"]*)"`, "m"));
|
|
278
|
+
return m?.[1] ?? "";
|
|
279
|
+
}
|
|
280
|
+
function sleepMs(ms) {
|
|
281
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/commands/iac/providers/aws-ecs/lib/exec.ts
|
|
285
|
+
import { spawnSync as spawnSync6 } from "child_process";
|
|
286
|
+
|
|
287
|
+
// src/commands/iac/providers/aws-ecs/lib/runner.ts
|
|
288
|
+
import { spawnSync as spawnSync5 } from "child_process";
|
|
289
|
+
import { createHash } from "crypto";
|
|
290
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
291
|
+
import os from "os";
|
|
292
|
+
import path4 from "pathe";
|
|
293
|
+
var RUNNER_DOCKERFILE = path4.join("iac", "runner", "Dockerfile");
|
|
294
|
+
var CONTAINERIZED = /* @__PURE__ */ new Set(["terraform"]);
|
|
295
|
+
function findDockerfile(cwd) {
|
|
296
|
+
let dir = path4.resolve(cwd);
|
|
297
|
+
for (; ; ) {
|
|
298
|
+
const candidate = path4.join(dir, RUNNER_DOCKERFILE);
|
|
299
|
+
if (existsSync2(candidate)) return candidate;
|
|
300
|
+
const parent = path4.dirname(dir);
|
|
301
|
+
if (parent === dir) return "";
|
|
302
|
+
dir = parent;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function imageTag(dockerfile) {
|
|
306
|
+
const hash = createHash("sha256").update(readFileSync2(dockerfile)).digest("hex").slice(0, 12);
|
|
307
|
+
return `dude-iac-runner:${hash}`;
|
|
308
|
+
}
|
|
309
|
+
var dockerChecked;
|
|
310
|
+
var ensured = /* @__PURE__ */ new Set();
|
|
311
|
+
function dockerAvailable() {
|
|
312
|
+
if (dockerChecked !== void 0) return dockerChecked;
|
|
313
|
+
const r = spawnSync5("docker", ["version", "--format", "{{.Server.Version}}"], {
|
|
314
|
+
encoding: "utf8"
|
|
315
|
+
});
|
|
316
|
+
dockerChecked = r.status === 0 && !!r.stdout.trim();
|
|
317
|
+
return dockerChecked;
|
|
318
|
+
}
|
|
319
|
+
function useRunner(cwd) {
|
|
320
|
+
if (process.env.DUDE_IAC_RUNNER === "host") return false;
|
|
321
|
+
return dockerAvailable() && !!findDockerfile(cwd);
|
|
322
|
+
}
|
|
323
|
+
function ensureImage(dockerfile, tag) {
|
|
324
|
+
if (ensured.has(tag)) return;
|
|
325
|
+
const exists = spawnSync5("docker", ["image", "inspect", tag], { stdio: "ignore" }).status === 0;
|
|
326
|
+
if (!exists) {
|
|
327
|
+
process.stderr.write(
|
|
328
|
+
`
|
|
329
|
+
\u2192 Building the IaC runner image (${tag}). First run only \u2014 a minute or two\u2026
|
|
330
|
+
|
|
331
|
+
`
|
|
332
|
+
);
|
|
333
|
+
const build = spawnSync5(
|
|
334
|
+
"docker",
|
|
335
|
+
["build", "-t", tag, "-f", dockerfile, path4.dirname(dockerfile)],
|
|
336
|
+
{ stdio: "inherit" }
|
|
337
|
+
);
|
|
338
|
+
if (build.status !== 0) {
|
|
339
|
+
process.stderr.write("\n \u2717 Failed to build the IaC runner image.\n\n");
|
|
340
|
+
process.exit(build.status ?? 1);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
ensured.add(tag);
|
|
344
|
+
}
|
|
345
|
+
function baseDockerArgs(cwd, profile, tty) {
|
|
346
|
+
const args = ["run", "--rm", tty ? "-it" : "-i"];
|
|
347
|
+
args.push("-v", `${cwd}:/work`, "-w", "/work");
|
|
348
|
+
const home = os.homedir();
|
|
349
|
+
args.push("-v", `${path4.join(home, ".aws")}:/root/.aws:ro`);
|
|
350
|
+
if (profile) args.push("-e", `AWS_PROFILE=${profile}`);
|
|
351
|
+
return args;
|
|
352
|
+
}
|
|
353
|
+
function dockerRunArgs(cmd, toolArgs, cwd, profile, opts = {}) {
|
|
354
|
+
const dockerfile = findDockerfile(cwd);
|
|
355
|
+
const tag = imageTag(dockerfile);
|
|
356
|
+
ensureImage(dockerfile, tag);
|
|
357
|
+
const base = baseDockerArgs(cwd, profile, !!opts.tty);
|
|
358
|
+
return [...base, tag, cmd, ...toolArgs];
|
|
359
|
+
}
|
|
360
|
+
function dockerShellArgs(projectRoot, profile) {
|
|
361
|
+
const dockerfile = findDockerfile(projectRoot);
|
|
362
|
+
const tag = imageTag(dockerfile);
|
|
363
|
+
ensureImage(dockerfile, tag);
|
|
364
|
+
const base = baseDockerArgs(projectRoot, profile, true);
|
|
365
|
+
return [...base, tag, "bash"];
|
|
366
|
+
}
|
|
367
|
+
function hasRunnerDockerfile(cwd) {
|
|
368
|
+
return !!findDockerfile(cwd);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/commands/iac/providers/aws-ecs/lib/exec.ts
|
|
372
|
+
function routed(cmd, cwd) {
|
|
373
|
+
return CONTAINERIZED.has(cmd) && useRunner(cwd);
|
|
374
|
+
}
|
|
375
|
+
function run2(cmd, args, cwd, profile) {
|
|
376
|
+
if (!routed(cmd, cwd)) return run(cmd, args, cwd, profile);
|
|
377
|
+
const dargs = dockerRunArgs(cmd, args, cwd, profile, { tty: !!process.stdin.isTTY });
|
|
378
|
+
const r = spawnSync6("docker", dargs, { stdio: "inherit" });
|
|
379
|
+
if (r.error) {
|
|
380
|
+
process.stderr.write(`
|
|
381
|
+
\u2717 failed to run docker: ${r.error.message}
|
|
382
|
+
|
|
383
|
+
`);
|
|
384
|
+
return 1;
|
|
385
|
+
}
|
|
386
|
+
return r.status ?? 1;
|
|
387
|
+
}
|
|
388
|
+
function capture2(cmd, args, cwd, profile) {
|
|
389
|
+
if (!routed(cmd, cwd)) return capture(cmd, args, cwd, profile);
|
|
390
|
+
const dargs = dockerRunArgs(cmd, args, cwd, profile, { tty: false });
|
|
391
|
+
const r = spawnSync6("docker", dargs, { encoding: "utf8" });
|
|
392
|
+
return { status: r.status ?? 1, stdout: r.stdout ?? "" };
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// src/commands/iac/providers/aws-ecs/lib/terraform.ts
|
|
396
|
+
var TF_DIR = path5.join("iac", "terraform");
|
|
397
|
+
var TF_BOOTSTRAP_DIR = path5.join(TF_DIR, "bootstrap");
|
|
398
|
+
var TF_ENVIRONMENTS_DIR = path5.join(TF_DIR, "environments");
|
|
399
|
+
function hasIac(projectRoot) {
|
|
400
|
+
return existsSync3(path5.join(projectRoot, "iac", "terraform"));
|
|
401
|
+
}
|
|
402
|
+
function requireIac(projectRoot) {
|
|
403
|
+
if (!hasIac(projectRoot)) {
|
|
404
|
+
process.stderr.write(
|
|
405
|
+
"\n \u2717 No IaC configuration found (iac/terraform).\n This project was not initialised with an IaC target.\n Re-scaffold with `--iac aws-ecs` to enable it.\n\n"
|
|
406
|
+
);
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
function tf(projectRoot, args, profile) {
|
|
412
|
+
return run2("terraform", [`-chdir=${TF_DIR}`, ...args], projectRoot, profile);
|
|
413
|
+
}
|
|
414
|
+
function tfOutputRaw(projectRoot, name, profile) {
|
|
415
|
+
const r = capture2("terraform", [`-chdir=${TF_DIR}`, "output", "-raw", name], projectRoot, profile);
|
|
416
|
+
const value = r.stdout.trim();
|
|
417
|
+
return r.status === 0 && value && !/\s/.test(value) ? value : "";
|
|
418
|
+
}
|
|
419
|
+
function backendConfig(env) {
|
|
420
|
+
return `-backend-config=environments/${env}/backend.hcl`;
|
|
421
|
+
}
|
|
422
|
+
function varFile(env) {
|
|
423
|
+
return `-var-file=environments/${env}/terraform.tfvars`;
|
|
424
|
+
}
|
|
425
|
+
function tfBoot(projectRoot, args, profile) {
|
|
426
|
+
return run2("terraform", args, path5.join(projectRoot, TF_BOOTSTRAP_DIR), profile);
|
|
427
|
+
}
|
|
428
|
+
function captureBootstrap(projectRoot, args, profile) {
|
|
429
|
+
return capture2("terraform", args, path5.join(projectRoot, TF_BOOTSTRAP_DIR), profile);
|
|
430
|
+
}
|
|
431
|
+
function resolveProfile(projectRoot, args, env) {
|
|
432
|
+
if (args.profile) return String(args.profile);
|
|
433
|
+
if (process.env.AWS_PROFILE) return process.env.AWS_PROFILE;
|
|
434
|
+
return `${projectName(projectRoot)}-${env}`;
|
|
435
|
+
}
|
|
436
|
+
function tfvarsValue(projectRoot, env, key) {
|
|
437
|
+
try {
|
|
438
|
+
return hclScalar(
|
|
439
|
+
readFileSync3(path5.join(projectRoot, TF_DIR, "environments", env, "terraform.tfvars"), "utf8"),
|
|
440
|
+
key
|
|
441
|
+
);
|
|
442
|
+
} catch {
|
|
443
|
+
return "";
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function readBackend(projectRoot, env) {
|
|
447
|
+
try {
|
|
448
|
+
const txt = readFileSync3(
|
|
449
|
+
path5.join(projectRoot, TF_DIR, "environments", env, "backend.hcl"),
|
|
450
|
+
"utf8"
|
|
451
|
+
);
|
|
452
|
+
return {
|
|
453
|
+
bucket: hclScalar(txt, "bucket"),
|
|
454
|
+
key: hclScalar(txt, "key"),
|
|
455
|
+
table: hclScalar(txt, "dynamodb_table"),
|
|
456
|
+
region: hclScalar(txt, "region")
|
|
457
|
+
};
|
|
458
|
+
} catch {
|
|
459
|
+
return { bucket: "", key: "", table: "", region: "" };
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
var envArg = {
|
|
463
|
+
env: {
|
|
464
|
+
type: "string",
|
|
465
|
+
description: "Target environment (required) \u2014 one of iac/terraform/environments/*."
|
|
466
|
+
},
|
|
467
|
+
profile: {
|
|
468
|
+
type: "string",
|
|
469
|
+
description: "AWS profile to use (default: <project>-<env>, or $AWS_PROFILE)."
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
function listEnvironments(projectRoot) {
|
|
473
|
+
const base = path5.join(projectRoot, TF_ENVIRONMENTS_DIR);
|
|
474
|
+
try {
|
|
475
|
+
return readdirSync(base, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).filter(
|
|
476
|
+
(name) => existsSync3(path5.join(base, name, "backend.hcl")) && existsSync3(path5.join(base, name, "terraform.tfvars"))
|
|
477
|
+
).sort();
|
|
478
|
+
} catch {
|
|
479
|
+
return [];
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function requireEnv(projectRoot, args) {
|
|
483
|
+
const envs = listEnvironments(projectRoot);
|
|
484
|
+
const available = envs.length ? envs.join(", ") : "(none \u2014 create one first)";
|
|
485
|
+
const raw = args.env == null ? "" : String(args.env);
|
|
486
|
+
if (!raw) {
|
|
487
|
+
process.stderr.write(
|
|
488
|
+
`
|
|
489
|
+
\u2717 --env is required.
|
|
490
|
+
Available environments: ${available}
|
|
491
|
+
Create a new one with: dude iac new-env --env <name>
|
|
492
|
+
|
|
493
|
+
`
|
|
494
|
+
);
|
|
495
|
+
process.exit(1);
|
|
496
|
+
}
|
|
497
|
+
if (!/^[a-z][a-z0-9-]*$/.test(raw)) {
|
|
498
|
+
process.stderr.write(`
|
|
499
|
+
\u2717 invalid --env "${raw}" (expected lowercase kebab-case).
|
|
500
|
+
|
|
501
|
+
`);
|
|
502
|
+
process.exit(1);
|
|
503
|
+
}
|
|
504
|
+
if (!envs.includes(raw)) {
|
|
505
|
+
process.stderr.write(
|
|
506
|
+
`
|
|
507
|
+
\u2717 environment "${raw}" does not exist.
|
|
508
|
+
An environment is a folder iac/terraform/environments/<name>/ with a
|
|
509
|
+
backend.hcl and a terraform.tfvars. Available: ${available}
|
|
510
|
+
Create it with: dude iac new-env --env ${raw}
|
|
511
|
+
|
|
512
|
+
`
|
|
513
|
+
);
|
|
514
|
+
process.exit(1);
|
|
515
|
+
}
|
|
516
|
+
return raw;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// src/commands/iac/providers/aws-ecs/commands/apply/index.ts
|
|
520
|
+
var iacApplyCommand = {
|
|
521
|
+
available: hasIac,
|
|
522
|
+
description: "Provision/update the infrastructure for an environment.",
|
|
523
|
+
args: {
|
|
524
|
+
...envArg,
|
|
525
|
+
yes: { type: "boolean", description: "Skip the interactive approval (-auto-approve)." }
|
|
526
|
+
},
|
|
527
|
+
async run({ projectRoot, args }) {
|
|
528
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
529
|
+
const env = requireEnv(projectRoot, args);
|
|
530
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
531
|
+
const extra = args.yes ? ["-auto-approve"] : [];
|
|
532
|
+
process.exit(tf(projectRoot, ["apply", varFile(env), ...extra], profile));
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
// src/commands/iac/providers/aws-ecs/commands/bootstrap/index.ts
|
|
537
|
+
import { readFileSync as readFileSync4, writeFileSync as writeFileSync2 } from "fs";
|
|
538
|
+
import path6 from "pathe";
|
|
539
|
+
var iacBootstrapCommand = {
|
|
540
|
+
available: hasIac,
|
|
541
|
+
description: "One-time: create the S3 state bucket + DynamoDB lock table + shared ECR repository, then write the values into backend.hcl.",
|
|
542
|
+
args: {
|
|
543
|
+
region: {
|
|
544
|
+
type: "string",
|
|
545
|
+
description: "AWS region for the state resources.",
|
|
546
|
+
default: "eu-west-1"
|
|
547
|
+
},
|
|
548
|
+
"state-bucket-prefix": {
|
|
549
|
+
type: "string",
|
|
550
|
+
description: "Prefix for the S3 bucket name \u2014 must be globally unique (e.g. your org slug).",
|
|
551
|
+
required: true
|
|
552
|
+
},
|
|
553
|
+
env: { type: "string", description: "Environment whose backend.hcl to update (required)." },
|
|
554
|
+
profile: {
|
|
555
|
+
type: "string",
|
|
556
|
+
description: "AWS profile to use (default: <project>-<env>, or $AWS_PROFILE)."
|
|
557
|
+
},
|
|
558
|
+
yes: { type: "boolean", description: "Skip the interactive approval (-auto-approve)." }
|
|
559
|
+
},
|
|
560
|
+
async run({ projectRoot, args }) {
|
|
561
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
562
|
+
const env = requireEnv(projectRoot, args);
|
|
563
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
564
|
+
const prefix = String(args["state-bucket-prefix"] ?? "");
|
|
565
|
+
if (!prefix) {
|
|
566
|
+
process.stderr.write(
|
|
567
|
+
"\n \u2717 --state-bucket-prefix is required (e.g. your org slug, must be globally unique).\n\n"
|
|
568
|
+
);
|
|
569
|
+
process.exit(1);
|
|
570
|
+
}
|
|
571
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(prefix)) {
|
|
572
|
+
process.stderr.write(
|
|
573
|
+
`
|
|
574
|
+
\u2717 invalid --state-bucket-prefix "${prefix}" (expected lowercase alphanumeric / hyphens).
|
|
575
|
+
|
|
576
|
+
`
|
|
577
|
+
);
|
|
578
|
+
process.exit(1);
|
|
579
|
+
}
|
|
580
|
+
const region = String(args.region ?? "eu-west-1");
|
|
581
|
+
if (!/^[a-z]{2}-[a-z]+-\d$/.test(region)) {
|
|
582
|
+
process.stderr.write(`
|
|
583
|
+
\u2717 invalid --region "${region}" (expected e.g. eu-west-1).
|
|
584
|
+
|
|
585
|
+
`);
|
|
586
|
+
process.exit(1);
|
|
587
|
+
}
|
|
588
|
+
const name = projectName(projectRoot);
|
|
589
|
+
let status = tfBoot(projectRoot, ["init", "-reconfigure"], profile);
|
|
590
|
+
if (status !== 0) process.exit(status);
|
|
591
|
+
const extra = args.yes ? ["-auto-approve"] : [];
|
|
592
|
+
status = tfBoot(
|
|
593
|
+
projectRoot,
|
|
594
|
+
[
|
|
595
|
+
"apply",
|
|
596
|
+
`-var=project_name=${name}`,
|
|
597
|
+
`-var=region=${region}`,
|
|
598
|
+
`-var=state_bucket_prefix=${prefix}`,
|
|
599
|
+
...extra
|
|
600
|
+
],
|
|
601
|
+
profile
|
|
602
|
+
);
|
|
603
|
+
if (status !== 0) process.exit(status);
|
|
604
|
+
const out = captureBootstrap(projectRoot, ["output", "-json"], profile);
|
|
605
|
+
if (out.status !== 0) {
|
|
606
|
+
process.stderr.write("\n \u2717 Could not read bootstrap outputs.\n\n");
|
|
607
|
+
process.exit(1);
|
|
608
|
+
}
|
|
609
|
+
let stateBucket = "";
|
|
610
|
+
let lockTable = "";
|
|
611
|
+
try {
|
|
612
|
+
const o = JSON.parse(out.stdout);
|
|
613
|
+
stateBucket = o.state_bucket?.value ?? "";
|
|
614
|
+
lockTable = o.lock_table?.value ?? "";
|
|
615
|
+
} catch {
|
|
616
|
+
}
|
|
617
|
+
if (!stateBucket || !lockTable) {
|
|
618
|
+
process.stderr.write("\n \u2717 Bootstrap outputs `state_bucket` / `lock_table` not found.\n\n");
|
|
619
|
+
process.exit(1);
|
|
620
|
+
}
|
|
621
|
+
const backendHclPath = path6.join(projectRoot, TF_DIR, "environments", env, "backend.hcl");
|
|
622
|
+
try {
|
|
623
|
+
let hcl = readFileSync4(backendHclPath, "utf8");
|
|
624
|
+
hcl = hcl.replace(/^bucket\s*=\s*".*"$/m, `bucket = "${stateBucket}"`);
|
|
625
|
+
hcl = hcl.replace(/^dynamodb_table\s*=\s*".*"$/m, `dynamodb_table = "${lockTable}"`);
|
|
626
|
+
writeFileSync2(backendHclPath, hcl);
|
|
627
|
+
} catch {
|
|
628
|
+
process.stderr.write(`
|
|
629
|
+
\u2717 Could not update ${backendHclPath}.
|
|
630
|
+
|
|
631
|
+
`);
|
|
632
|
+
process.exit(1);
|
|
633
|
+
}
|
|
634
|
+
process.stdout.write(
|
|
635
|
+
`
|
|
636
|
+
\u2713 Bootstrap complete.
|
|
637
|
+
state_bucket: ${stateBucket}
|
|
638
|
+
lock_table: ${lockTable}
|
|
639
|
+
Updated: iac/terraform/environments/${env}/backend.hcl
|
|
640
|
+
|
|
641
|
+
Next: dude iac init --env ${env}
|
|
642
|
+
|
|
643
|
+
`
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
// src/commands/iac/providers/aws-ecs/lib/images.ts
|
|
649
|
+
import { spawnSync as spawnSync7 } from "child_process";
|
|
650
|
+
import { readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
651
|
+
import path7 from "pathe";
|
|
652
|
+
var tagArg = {
|
|
653
|
+
tag: {
|
|
654
|
+
type: "string",
|
|
655
|
+
description: "Image tag (default: git short SHA, with -dirty if uncommitted changes)."
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
var platformArg = {
|
|
659
|
+
platform: {
|
|
660
|
+
type: "string",
|
|
661
|
+
description: "Docker build platform (default linux/amd64, to match Fargate x86)."
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
function readEcsTarget(projectRoot, profile) {
|
|
665
|
+
const out = capture2("terraform", [`-chdir=${TF_DIR}`, "output", "-json"], projectRoot, profile);
|
|
666
|
+
if (out.status !== 0) return null;
|
|
667
|
+
try {
|
|
668
|
+
const o = JSON.parse(out.stdout);
|
|
669
|
+
const appRepo = o.ecr_app_repository_url?.value ?? "";
|
|
670
|
+
const region = o.region?.value ?? "";
|
|
671
|
+
const cluster = o.cluster_name?.value ?? "";
|
|
672
|
+
const frontendService = o.frontend_service_name?.value ?? "";
|
|
673
|
+
const backendService = o.backend_service_name?.value ?? "";
|
|
674
|
+
const websocketService = o.websocket_service_name?.value ?? "";
|
|
675
|
+
if (!appRepo || !region || !cluster || !backendService) return null;
|
|
676
|
+
return {
|
|
677
|
+
image: {
|
|
678
|
+
name: "app",
|
|
679
|
+
repository: appRepo,
|
|
680
|
+
// Single production image, built from the project root (the Dockerfile
|
|
681
|
+
// COPYs apps/ into the bench).
|
|
682
|
+
dockerfile: "docker/Dockerfile.prod",
|
|
683
|
+
context: "."
|
|
684
|
+
},
|
|
685
|
+
registryHost: appRepo.split("/")[0] ?? appRepo,
|
|
686
|
+
region,
|
|
687
|
+
cluster,
|
|
688
|
+
frontendService,
|
|
689
|
+
backendService,
|
|
690
|
+
websocketService,
|
|
691
|
+
appUrl: o.app_url?.value || void 0
|
|
692
|
+
};
|
|
693
|
+
} catch {
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
function requireEcsTarget(projectRoot, profile) {
|
|
698
|
+
const target = readEcsTarget(projectRoot, profile);
|
|
699
|
+
if (!target) {
|
|
700
|
+
process.stderr.write(
|
|
701
|
+
"error: could not read Terraform outputs (ecr_app_repository_url, cluster_name, \u2026) \u2014 run `dude iac apply` first.\n"
|
|
702
|
+
);
|
|
703
|
+
process.exit(1);
|
|
704
|
+
}
|
|
705
|
+
return target;
|
|
706
|
+
}
|
|
707
|
+
function resolveTag(projectRoot, args) {
|
|
708
|
+
if (args.tag) {
|
|
709
|
+
const t = String(args.tag);
|
|
710
|
+
if (!/^[\w][\w.-]{0,127}$/.test(t)) {
|
|
711
|
+
process.stderr.write(`
|
|
712
|
+
\u2717 invalid --tag "${t}" (not a valid Docker tag).
|
|
713
|
+
|
|
714
|
+
`);
|
|
715
|
+
return null;
|
|
716
|
+
}
|
|
717
|
+
return t;
|
|
718
|
+
}
|
|
719
|
+
const sha = capture2("git", ["rev-parse", "--short=12", "HEAD"], projectRoot);
|
|
720
|
+
if (sha.status !== 0 || !sha.stdout.trim()) {
|
|
721
|
+
process.stderr.write(
|
|
722
|
+
"\n \u2717 Could not derive a git SHA for the image tag.\n Pass --tag <tag>, or run inside a git repo with at least one commit.\n\n"
|
|
723
|
+
);
|
|
724
|
+
return null;
|
|
725
|
+
}
|
|
726
|
+
let tag = sha.stdout.trim();
|
|
727
|
+
const status = capture2("git", ["status", "--porcelain"], projectRoot);
|
|
728
|
+
if (status.status === 0 && status.stdout.trim() !== "") tag += "-dirty";
|
|
729
|
+
return tag;
|
|
730
|
+
}
|
|
731
|
+
function dockerLogin(host, region, projectRoot, profile) {
|
|
732
|
+
const pw = capture2("aws", ["ecr", "get-login-password", "--region", region], projectRoot, profile);
|
|
733
|
+
if (pw.status !== 0 || !pw.stdout.trim()) {
|
|
734
|
+
process.stderr.write("\n \u2717 Could not obtain an ECR login password (check your AWS auth).\n\n");
|
|
735
|
+
return 1;
|
|
736
|
+
}
|
|
737
|
+
const r = spawnSync7("docker", ["login", "--username", "AWS", "--password-stdin", host], {
|
|
738
|
+
cwd: projectRoot,
|
|
739
|
+
input: pw.stdout.trim(),
|
|
740
|
+
stdio: ["pipe", "inherit", "inherit"],
|
|
741
|
+
env: childEnv(profile)
|
|
742
|
+
});
|
|
743
|
+
if (r.error) {
|
|
744
|
+
const code = r.error.code;
|
|
745
|
+
process.stderr.write(
|
|
746
|
+
code === "ENOENT" ? "\n \u2717 `docker` not found on PATH. Install it and retry.\n\n" : `
|
|
747
|
+
\u2717 failed to run docker: ${r.error.message}
|
|
748
|
+
|
|
749
|
+
`
|
|
750
|
+
);
|
|
751
|
+
return 1;
|
|
752
|
+
}
|
|
753
|
+
return r.status ?? 1;
|
|
754
|
+
}
|
|
755
|
+
function doBuild(projectRoot, profile, tag, target, platform) {
|
|
756
|
+
const image = target.image;
|
|
757
|
+
process.stdout.write(`
|
|
758
|
+
\u2192 building ${image.name} ${image.repository}:${tag} (${platform})
|
|
759
|
+
`);
|
|
760
|
+
return run2(
|
|
761
|
+
"docker",
|
|
762
|
+
[
|
|
763
|
+
"build",
|
|
764
|
+
"--platform",
|
|
765
|
+
platform,
|
|
766
|
+
"-f",
|
|
767
|
+
image.dockerfile,
|
|
768
|
+
"-t",
|
|
769
|
+
`${image.repository}:${tag}`,
|
|
770
|
+
image.context
|
|
771
|
+
],
|
|
772
|
+
projectRoot,
|
|
773
|
+
profile
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
function doPush(projectRoot, profile, tag, target) {
|
|
777
|
+
const code = dockerLogin(target.registryHost, target.region, projectRoot, profile);
|
|
778
|
+
if (code !== 0) return code;
|
|
779
|
+
process.stdout.write(`
|
|
780
|
+
\u2192 pushing ${target.image.repository}:${tag}
|
|
781
|
+
`);
|
|
782
|
+
return run2("docker", ["push", `${target.image.repository}:${tag}`], projectRoot, profile);
|
|
783
|
+
}
|
|
784
|
+
function doDeploy(projectRoot, profile, env, tag, target) {
|
|
785
|
+
const tfvarsPath = path7.join(projectRoot, TF_DIR, "environments", env, "terraform.tfvars");
|
|
786
|
+
try {
|
|
787
|
+
let tfvars = readFileSync5(tfvarsPath, "utf8");
|
|
788
|
+
if (/^\s*image_tag\s*=/m.test(tfvars)) {
|
|
789
|
+
tfvars = tfvars.replace(/^(\s*image_tag\s*=\s*).*$/m, `$1"${tag}"`);
|
|
790
|
+
} else {
|
|
791
|
+
tfvars += `
|
|
792
|
+
image_tag = "${tag}"
|
|
793
|
+
`;
|
|
794
|
+
}
|
|
795
|
+
writeFileSync3(tfvarsPath, tfvars);
|
|
796
|
+
} catch {
|
|
797
|
+
process.stderr.write(`
|
|
798
|
+
\u2717 Could not update ${tfvarsPath}.
|
|
799
|
+
|
|
800
|
+
`);
|
|
801
|
+
return 1;
|
|
802
|
+
}
|
|
803
|
+
process.stdout.write(`
|
|
804
|
+
\u2192 deploying :${tag} to "${env}"\u2026
|
|
805
|
+
`);
|
|
806
|
+
const code = tf(projectRoot, ["apply", varFile(env), "-auto-approve"], profile);
|
|
807
|
+
if (code === 0) {
|
|
808
|
+
process.stdout.write(
|
|
809
|
+
`
|
|
810
|
+
\u2713 Task definitions updated to :${tag} \u2014 ECS is rolling the services now
|
|
811
|
+
(auto-rollback on failure). Watch them with: dude iac status --env ${env}
|
|
812
|
+
First deploy? Create the site once: dude iac create-site --env ${env}
|
|
813
|
+
Then apply pending schema changes: dude iac migrate --env ${env}
|
|
814
|
+
` + (target.appUrl ? ` App URL: ${target.appUrl}
|
|
815
|
+
` : "")
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
return code;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// src/commands/iac/providers/aws-ecs/commands/build/index.ts
|
|
822
|
+
var iacBuildCommand = {
|
|
823
|
+
available: hasIac,
|
|
824
|
+
description: "Build the production Frappe image (docker/Dockerfile.prod \u2014 one image for all service roles), tagged for the shared ECR repo.",
|
|
825
|
+
args: { ...envArg, ...tagArg, ...platformArg },
|
|
826
|
+
async run({ projectRoot, args }) {
|
|
827
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
828
|
+
const env = requireEnv(projectRoot, args);
|
|
829
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
830
|
+
const tag = resolveTag(projectRoot, args);
|
|
831
|
+
if (!tag) process.exit(1);
|
|
832
|
+
const target = requireEcsTarget(projectRoot, profile);
|
|
833
|
+
const platform = String(args.platform ?? "linux/amd64");
|
|
834
|
+
process.exit(doBuild(projectRoot, profile, tag, target, platform));
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
// src/commands/iac/providers/aws-ecs/lib/tasks.ts
|
|
839
|
+
function readOneOffTarget(projectRoot, profile, taskDefinitionOutputs) {
|
|
840
|
+
const out = capture2("terraform", [`-chdir=${TF_DIR}`, "output", "-json"], projectRoot, profile);
|
|
841
|
+
if (out.status !== 0) return null;
|
|
842
|
+
try {
|
|
843
|
+
const o = JSON.parse(out.stdout);
|
|
844
|
+
const cluster = String(o.cluster_name?.value ?? "");
|
|
845
|
+
const subnets = Array.isArray(o.public_subnet_ids?.value) ? o.public_subnet_ids.value : [];
|
|
846
|
+
const securityGroup = String(o.app_security_group_id?.value ?? "");
|
|
847
|
+
const region = String(o.region?.value ?? "");
|
|
848
|
+
if (!cluster || !subnets.length || !securityGroup || !region) return null;
|
|
849
|
+
const taskDefinitions = {};
|
|
850
|
+
for (const name of taskDefinitionOutputs) {
|
|
851
|
+
const arn = String(o[name]?.value ?? "");
|
|
852
|
+
if (!arn) return null;
|
|
853
|
+
taskDefinitions[name] = arn;
|
|
854
|
+
}
|
|
855
|
+
return { target: { cluster, subnets, securityGroup, region }, taskDefinitions };
|
|
856
|
+
} catch {
|
|
857
|
+
return null;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
function runOneOffTask(projectRoot, profile, target, taskDefinition, label) {
|
|
861
|
+
process.stdout.write(`
|
|
862
|
+
\u2192 running ${label} (${taskDefinition.split("/").pop()})\u2026
|
|
863
|
+
`);
|
|
864
|
+
const netConf = `awsvpcConfiguration={subnets=[${target.subnets.join(",")}],securityGroups=[${target.securityGroup}],assignPublicIp=ENABLED}`;
|
|
865
|
+
const started = capture(
|
|
866
|
+
"aws",
|
|
867
|
+
[
|
|
868
|
+
"ecs",
|
|
869
|
+
"run-task",
|
|
870
|
+
"--cluster",
|
|
871
|
+
target.cluster,
|
|
872
|
+
"--task-definition",
|
|
873
|
+
taskDefinition,
|
|
874
|
+
"--launch-type",
|
|
875
|
+
"FARGATE",
|
|
876
|
+
"--count",
|
|
877
|
+
"1",
|
|
878
|
+
"--network-configuration",
|
|
879
|
+
netConf,
|
|
880
|
+
"--region",
|
|
881
|
+
target.region,
|
|
882
|
+
"--output",
|
|
883
|
+
"json"
|
|
884
|
+
],
|
|
885
|
+
projectRoot,
|
|
886
|
+
profile
|
|
887
|
+
);
|
|
888
|
+
if (started.status !== 0) {
|
|
889
|
+
process.stderr.write("\n \u2717 aws ecs run-task failed.\n\n");
|
|
890
|
+
return 1;
|
|
891
|
+
}
|
|
892
|
+
let taskArn = "";
|
|
893
|
+
try {
|
|
894
|
+
const parsed = JSON.parse(started.stdout);
|
|
895
|
+
taskArn = parsed.tasks?.[0]?.taskArn ?? "";
|
|
896
|
+
if (!taskArn) {
|
|
897
|
+
const reason = parsed.failures?.[0]?.reason ?? "unknown";
|
|
898
|
+
process.stderr.write(`
|
|
899
|
+
\u2717 Task did not start (${reason}).
|
|
900
|
+
|
|
901
|
+
`);
|
|
902
|
+
return 1;
|
|
903
|
+
}
|
|
904
|
+
} catch {
|
|
905
|
+
process.stderr.write("\n \u2717 Could not parse the run-task response.\n\n");
|
|
906
|
+
return 1;
|
|
907
|
+
}
|
|
908
|
+
process.stdout.write(` task ${taskArn.split("/").pop()} started \u2014 waiting\u2026
|
|
909
|
+
`);
|
|
910
|
+
for (; ; ) {
|
|
911
|
+
sleepMs(5e3);
|
|
912
|
+
const described = capture(
|
|
913
|
+
"aws",
|
|
914
|
+
[
|
|
915
|
+
"ecs",
|
|
916
|
+
"describe-tasks",
|
|
917
|
+
"--cluster",
|
|
918
|
+
target.cluster,
|
|
919
|
+
"--tasks",
|
|
920
|
+
taskArn,
|
|
921
|
+
"--region",
|
|
922
|
+
target.region,
|
|
923
|
+
"--output",
|
|
924
|
+
"json"
|
|
925
|
+
],
|
|
926
|
+
projectRoot,
|
|
927
|
+
profile
|
|
928
|
+
);
|
|
929
|
+
if (described.status !== 0) continue;
|
|
930
|
+
let task;
|
|
931
|
+
try {
|
|
932
|
+
task = JSON.parse(described.stdout).tasks?.[0];
|
|
933
|
+
} catch {
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
if (!task) continue;
|
|
937
|
+
if (task.lastStatus !== "STOPPED") {
|
|
938
|
+
process.stdout.write(` ${task.lastStatus ?? "\u2026"}
|
|
939
|
+
`);
|
|
940
|
+
continue;
|
|
941
|
+
}
|
|
942
|
+
const exitCode = task.containers?.[0]?.exitCode;
|
|
943
|
+
if (exitCode === 0) return 0;
|
|
944
|
+
process.stderr.write(
|
|
945
|
+
`
|
|
946
|
+
\u2717 ${label} task failed (exit ${exitCode ?? "?"}) \u2014 ${task.stoppedReason ?? task.containers?.[0]?.reason ?? "no reason reported"}.
|
|
947
|
+
`
|
|
948
|
+
);
|
|
949
|
+
return typeof exitCode === "number" && exitCode > 0 ? exitCode : 1;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// src/commands/iac/providers/aws-ecs/commands/create-site/index.ts
|
|
954
|
+
var iacCreateSiteCommand = {
|
|
955
|
+
available: hasIac,
|
|
956
|
+
description: "First-deploy step: configure the bench (common_site_config) and create the frappe site (bench new-site) as one-off ECS Fargate tasks.",
|
|
957
|
+
args: { ...envArg },
|
|
958
|
+
async run({ projectRoot, args }) {
|
|
959
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
960
|
+
const env = requireEnv(projectRoot, args);
|
|
961
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
962
|
+
const read = readOneOffTarget(projectRoot, profile, [
|
|
963
|
+
"configurator_task_definition",
|
|
964
|
+
"create_site_task_definition"
|
|
965
|
+
]);
|
|
966
|
+
if (!read) {
|
|
967
|
+
process.stderr.write(
|
|
968
|
+
"error: could not read Terraform outputs (create_site_task_definition, cluster_name, \u2026) \u2014 run `dude iac apply` first.\n"
|
|
969
|
+
);
|
|
970
|
+
process.exit(1);
|
|
971
|
+
}
|
|
972
|
+
let code = runOneOffTask(
|
|
973
|
+
projectRoot,
|
|
974
|
+
profile,
|
|
975
|
+
read.target,
|
|
976
|
+
read.taskDefinitions.configurator_task_definition,
|
|
977
|
+
`configurator on "${env}"`
|
|
978
|
+
);
|
|
979
|
+
if (code !== 0) {
|
|
980
|
+
process.stderr.write(
|
|
981
|
+
` Inspect the logs with: dude iac logs --env ${env} --service backend
|
|
982
|
+
|
|
983
|
+
`
|
|
984
|
+
);
|
|
985
|
+
process.exit(code);
|
|
986
|
+
}
|
|
987
|
+
process.stdout.write(" \u2713 Bench configured (common_site_config.json).\n");
|
|
988
|
+
code = runOneOffTask(
|
|
989
|
+
projectRoot,
|
|
990
|
+
profile,
|
|
991
|
+
read.target,
|
|
992
|
+
read.taskDefinitions.create_site_task_definition,
|
|
993
|
+
`site creation on "${env}"`
|
|
994
|
+
);
|
|
995
|
+
if (code === 0) {
|
|
996
|
+
process.stdout.write(
|
|
997
|
+
"\n \u2713 Site ready. The frontend/backend services become healthy on their\n next health check. Log in as Administrator with the admin password\n stored in Secrets Manager (see `dude iac output --env " + env + "`).\n\n"
|
|
998
|
+
);
|
|
999
|
+
process.exit(0);
|
|
1000
|
+
}
|
|
1001
|
+
process.stderr.write(
|
|
1002
|
+
` Inspect the logs with: dude iac logs --env ${env} --service backend
|
|
1003
|
+
|
|
1004
|
+
`
|
|
1005
|
+
);
|
|
1006
|
+
process.exit(code);
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
// src/commands/iac/providers/aws-ecs/commands/deploy/index.ts
|
|
1011
|
+
var iacDeployCommand = {
|
|
1012
|
+
available: hasIac,
|
|
1013
|
+
description: "Deploy: record the image tag in terraform.tfvars and roll all ECS services (frontend/backend/websocket/worker/scheduler) onto it (terraform apply).",
|
|
1014
|
+
args: { ...envArg, ...tagArg },
|
|
1015
|
+
async run({ projectRoot, args }) {
|
|
1016
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1017
|
+
const env = requireEnv(projectRoot, args);
|
|
1018
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1019
|
+
const tag = resolveTag(projectRoot, args);
|
|
1020
|
+
if (!tag) process.exit(1);
|
|
1021
|
+
const target = requireEcsTarget(projectRoot, profile);
|
|
1022
|
+
process.exit(doDeploy(projectRoot, profile, env, tag, target));
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1025
|
+
|
|
1026
|
+
// src/commands/iac/providers/aws-ecs/lib/aws.ts
|
|
1027
|
+
function emptyVersionedBucket(bucket, region, projectRoot, profile) {
|
|
1028
|
+
const regionFlag = region ? ["--region", region] : [];
|
|
1029
|
+
for (let i = 0; i < 100; i++) {
|
|
1030
|
+
const list = capture(
|
|
1031
|
+
"aws",
|
|
1032
|
+
[
|
|
1033
|
+
"s3api",
|
|
1034
|
+
"list-object-versions",
|
|
1035
|
+
"--bucket",
|
|
1036
|
+
bucket,
|
|
1037
|
+
"--max-items",
|
|
1038
|
+
"1000",
|
|
1039
|
+
"--query",
|
|
1040
|
+
"[Versions[].{Key:Key,VersionId:VersionId}, DeleteMarkers[].{Key:Key,VersionId:VersionId}][]",
|
|
1041
|
+
"--output",
|
|
1042
|
+
"json",
|
|
1043
|
+
...regionFlag
|
|
1044
|
+
],
|
|
1045
|
+
projectRoot,
|
|
1046
|
+
profile
|
|
1047
|
+
);
|
|
1048
|
+
if (list.status !== 0) return;
|
|
1049
|
+
let objects = [];
|
|
1050
|
+
try {
|
|
1051
|
+
objects = JSON.parse(list.stdout) ?? [];
|
|
1052
|
+
} catch {
|
|
1053
|
+
return;
|
|
1054
|
+
}
|
|
1055
|
+
if (!objects.length) return;
|
|
1056
|
+
capture(
|
|
1057
|
+
"aws",
|
|
1058
|
+
[
|
|
1059
|
+
"s3api",
|
|
1060
|
+
"delete-objects",
|
|
1061
|
+
"--bucket",
|
|
1062
|
+
bucket,
|
|
1063
|
+
"--delete",
|
|
1064
|
+
JSON.stringify({ Objects: objects.slice(0, 1e3), Quiet: true }),
|
|
1065
|
+
...regionFlag
|
|
1066
|
+
],
|
|
1067
|
+
projectRoot,
|
|
1068
|
+
profile
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
function envStateLiveness(bucket, key, region, projectRoot, profile) {
|
|
1073
|
+
if (!bucket || !key) return { live: false, reason: "no remote state configured" };
|
|
1074
|
+
const regionFlag = region ? ["--region", region] : [];
|
|
1075
|
+
const r = capture("aws", ["s3", "cp", `s3://${bucket}/${key}`, "-", ...regionFlag], projectRoot, profile);
|
|
1076
|
+
if (r.status !== 0) {
|
|
1077
|
+
return { live: false, reason: "no state object (never applied, or already removed)" };
|
|
1078
|
+
}
|
|
1079
|
+
try {
|
|
1080
|
+
const state = JSON.parse(r.stdout);
|
|
1081
|
+
const n = Array.isArray(state.resources) ? state.resources.length : 0;
|
|
1082
|
+
return n > 0 ? { live: true, reason: `${n} resource(s) still in state` } : { live: false, reason: "state is empty (already destroyed)" };
|
|
1083
|
+
} catch {
|
|
1084
|
+
return { live: true, reason: "state present but unreadable \u2014 keeping to be safe" };
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// src/commands/iac/providers/aws-ecs/commands/destroy/index.ts
|
|
1089
|
+
var iacDestroyCommand = {
|
|
1090
|
+
available: hasIac,
|
|
1091
|
+
description: "Tear down everything for an environment: destroy the Terraform infrastructure, then empty + destroy the state backend (S3 bucket + DynamoDB table) and the shared ECR repository. Use --keep-backend to preserve the shared bootstrap.",
|
|
1092
|
+
args: {
|
|
1093
|
+
...envArg,
|
|
1094
|
+
yes: { type: "boolean", description: "Skip the interactive approval (-auto-approve)." },
|
|
1095
|
+
"keep-backend": {
|
|
1096
|
+
type: "boolean",
|
|
1097
|
+
description: "Keep the shared bootstrap (S3 state bucket + DynamoDB lock table + ECR repository). It is kept automatically while any other environment still uses the same bucket; pass this to force-keep it even when destroying the last environment."
|
|
1098
|
+
},
|
|
1099
|
+
"skip-tf": {
|
|
1100
|
+
type: "boolean",
|
|
1101
|
+
description: "Skip the Terraform destroy of the environment \u2014 only run the backend teardown (unless --keep-backend)."
|
|
1102
|
+
}
|
|
1103
|
+
},
|
|
1104
|
+
async run({ projectRoot, args }) {
|
|
1105
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1106
|
+
const env = requireEnv(projectRoot, args);
|
|
1107
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1108
|
+
const extra = args.yes ? ["-auto-approve"] : [];
|
|
1109
|
+
const region = tfOutputRaw(projectRoot, "region", profile) || tfvarsValue(projectRoot, env, "region");
|
|
1110
|
+
if (!args["skip-tf"]) {
|
|
1111
|
+
const code = tf(projectRoot, ["destroy", varFile(env), ...extra], profile);
|
|
1112
|
+
if (code !== 0) process.exit(code);
|
|
1113
|
+
}
|
|
1114
|
+
if (args["keep-backend"]) {
|
|
1115
|
+
process.stdout.write(" \u21B7 Keeping the Terraform state backend (--keep-backend). Done.\n\n");
|
|
1116
|
+
process.exit(0);
|
|
1117
|
+
}
|
|
1118
|
+
const backend = readBackend(projectRoot, env);
|
|
1119
|
+
const stateBucket = backend.bucket;
|
|
1120
|
+
const lockTable = backend.table;
|
|
1121
|
+
const backendRegion = backend.region || region;
|
|
1122
|
+
if (!stateBucket && !lockTable) {
|
|
1123
|
+
process.stdout.write(" \u21B7 No state backend configured to tear down. Done.\n\n");
|
|
1124
|
+
process.exit(0);
|
|
1125
|
+
}
|
|
1126
|
+
if (stateBucket) {
|
|
1127
|
+
const siblings = listEnvironments(projectRoot).filter(
|
|
1128
|
+
(e) => e !== env && readBackend(projectRoot, e).bucket === stateBucket
|
|
1129
|
+
);
|
|
1130
|
+
const live = [];
|
|
1131
|
+
if (siblings.length) {
|
|
1132
|
+
process.stdout.write(` \u2192 checking sibling environments on this backend\u2026
|
|
1133
|
+
`);
|
|
1134
|
+
for (const e of siblings) {
|
|
1135
|
+
const b = readBackend(projectRoot, e);
|
|
1136
|
+
const { live: isLive, reason } = envStateLiveness(
|
|
1137
|
+
b.bucket,
|
|
1138
|
+
b.key,
|
|
1139
|
+
b.region || region,
|
|
1140
|
+
projectRoot,
|
|
1141
|
+
profile
|
|
1142
|
+
);
|
|
1143
|
+
process.stdout.write(` \u2022 ${e}: ${isLive ? "still live" : "not live"} \u2014 ${reason}
|
|
1144
|
+
`);
|
|
1145
|
+
if (isLive) live.push(e);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (live.length) {
|
|
1149
|
+
process.stdout.write(
|
|
1150
|
+
`
|
|
1151
|
+
\u21B7 Keeping the shared backend + ECR \u2014 still used by: ${live.join(", ")}.
|
|
1152
|
+
Destroying it would wipe their state and registry. Destroy those
|
|
1153
|
+
environments first, or pass --keep-backend. Done.
|
|
1154
|
+
|
|
1155
|
+
`
|
|
1156
|
+
);
|
|
1157
|
+
process.exit(0);
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
process.stdout.write(
|
|
1161
|
+
`
|
|
1162
|
+
\u2192 tearing down the shared bootstrap (S3 + DynamoDB + ECR)\u2026
|
|
1163
|
+
bucket: ${stateBucket || "(none)"} lock table: ${lockTable || "(none)"}
|
|
1164
|
+
`
|
|
1165
|
+
);
|
|
1166
|
+
if (stateBucket) {
|
|
1167
|
+
process.stdout.write(` \u2192 emptying state bucket ${stateBucket}\u2026
|
|
1168
|
+
`);
|
|
1169
|
+
emptyVersionedBucket(stateBucket, backendRegion, projectRoot, profile);
|
|
1170
|
+
}
|
|
1171
|
+
tfBoot(projectRoot, ["init", "-input=false"], profile);
|
|
1172
|
+
const bootCode = tfBoot(projectRoot, ["destroy", ...extra], profile);
|
|
1173
|
+
const regionFlag = backendRegion ? ["--region", backendRegion] : [];
|
|
1174
|
+
if (stateBucket) {
|
|
1175
|
+
emptyVersionedBucket(stateBucket, backendRegion, projectRoot, profile);
|
|
1176
|
+
capture("aws", ["s3api", "delete-bucket", "--bucket", stateBucket, ...regionFlag], projectRoot, profile);
|
|
1177
|
+
}
|
|
1178
|
+
if (lockTable) {
|
|
1179
|
+
capture("aws", ["dynamodb", "delete-table", "--table-name", lockTable, ...regionFlag], projectRoot, profile);
|
|
1180
|
+
}
|
|
1181
|
+
const bucketGone = !stateBucket || capture("aws", ["s3api", "head-bucket", "--bucket", stateBucket, ...regionFlag], projectRoot, profile).status !== 0;
|
|
1182
|
+
const tableGone = !lockTable || capture("aws", ["dynamodb", "describe-table", "--table-name", lockTable, ...regionFlag], projectRoot, profile).status !== 0;
|
|
1183
|
+
if (bucketGone && tableGone) {
|
|
1184
|
+
process.stdout.write(" \u2713 State backend removed.\n\n");
|
|
1185
|
+
process.exit(0);
|
|
1186
|
+
}
|
|
1187
|
+
process.stderr.write(
|
|
1188
|
+
" \u2717 Some state-backend resources could not be removed. Check the AWS console:\n" + (bucketGone ? "" : ` S3 bucket: ${stateBucket}
|
|
1189
|
+
`) + (tableGone ? "" : ` DynamoDB table: ${lockTable}
|
|
1190
|
+
|
|
1191
|
+
`)
|
|
1192
|
+
);
|
|
1193
|
+
process.exit(bootCode || 1);
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
|
|
1197
|
+
// src/commands/iac/providers/aws-ecs/commands/fmt/index.ts
|
|
1198
|
+
var iacFmtCommand = {
|
|
1199
|
+
available: hasIac,
|
|
1200
|
+
description: "Format all Terraform files (terraform fmt -recursive).",
|
|
1201
|
+
async run({ projectRoot }) {
|
|
1202
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1203
|
+
process.exit(tf(projectRoot, ["fmt", "-recursive"]));
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
|
+
// src/commands/iac/providers/aws-ecs/commands/init/index.ts
|
|
1208
|
+
var iacInitCommand = {
|
|
1209
|
+
available: hasIac,
|
|
1210
|
+
description: "Initialise Terraform for an environment (configures the S3 remote backend).",
|
|
1211
|
+
args: { ...envArg },
|
|
1212
|
+
async run({ projectRoot, args }) {
|
|
1213
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1214
|
+
const env = requireEnv(projectRoot, args);
|
|
1215
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1216
|
+
process.exit(tf(projectRoot, ["init", "-reconfigure", backendConfig(env)], profile));
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
|
|
1220
|
+
// src/commands/iac/providers/aws-ecs/commands/login/index.ts
|
|
1221
|
+
var iacLoginCommand = {
|
|
1222
|
+
available: hasIac,
|
|
1223
|
+
description: "Configure/verify AWS credentials for an environment (maps --env to an AWS profile).",
|
|
1224
|
+
args: { ...envArg },
|
|
1225
|
+
async run({ projectRoot, args }) {
|
|
1226
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1227
|
+
const env = requireEnv(projectRoot, args);
|
|
1228
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1229
|
+
const list = capture("aws", ["configure", "list-profiles"], projectRoot);
|
|
1230
|
+
const known = list.stdout.split("\n").map((s) => s.trim()).filter(Boolean);
|
|
1231
|
+
const exists = list.status === 0 && known.includes(profile);
|
|
1232
|
+
const ssoStart = exists ? capture("aws", ["configure", "get", "sso_start_url", "--profile", profile], projectRoot) : { status: 1, stdout: "" };
|
|
1233
|
+
const ssoSession = exists ? capture("aws", ["configure", "get", "sso_session", "--profile", profile], projectRoot) : { status: 1, stdout: "" };
|
|
1234
|
+
const isSso = ssoStart.stdout.trim() !== "" || ssoSession.stdout.trim() !== "";
|
|
1235
|
+
if (!exists) {
|
|
1236
|
+
process.stdout.write(
|
|
1237
|
+
`
|
|
1238
|
+
Profile "${profile}" is not configured yet. Setting it up interactively.
|
|
1239
|
+
(For SSO instead, cancel and run: aws configure sso --profile ${profile})
|
|
1240
|
+
|
|
1241
|
+
`
|
|
1242
|
+
);
|
|
1243
|
+
const code = run("aws", ["configure", "--profile", profile], projectRoot);
|
|
1244
|
+
if (code !== 0) process.exit(code);
|
|
1245
|
+
} else if (isSso) {
|
|
1246
|
+
const code = run("aws", ["sso", "login", "--profile", profile], projectRoot);
|
|
1247
|
+
if (code !== 0) process.exit(code);
|
|
1248
|
+
}
|
|
1249
|
+
const who = capture(
|
|
1250
|
+
"aws",
|
|
1251
|
+
["sts", "get-caller-identity", "--profile", profile, "--output", "json"],
|
|
1252
|
+
projectRoot
|
|
1253
|
+
);
|
|
1254
|
+
if (who.status !== 0) {
|
|
1255
|
+
process.stderr.write(
|
|
1256
|
+
`
|
|
1257
|
+
\u2717 Credentials for profile "${profile}" are not valid.
|
|
1258
|
+
` + (isSso ? ` Try: aws sso login --profile ${profile}
|
|
1259
|
+
|
|
1260
|
+
` : ` Try: aws configure --profile ${profile}
|
|
1261
|
+
|
|
1262
|
+
`)
|
|
1263
|
+
);
|
|
1264
|
+
process.exit(1);
|
|
1265
|
+
}
|
|
1266
|
+
let account = "";
|
|
1267
|
+
let arn = "";
|
|
1268
|
+
try {
|
|
1269
|
+
const o = JSON.parse(who.stdout);
|
|
1270
|
+
account = o.Account ?? "";
|
|
1271
|
+
arn = o.Arn ?? "";
|
|
1272
|
+
} catch {
|
|
1273
|
+
}
|
|
1274
|
+
process.stdout.write(
|
|
1275
|
+
`
|
|
1276
|
+
\u2713 Authenticated for env "${env}".
|
|
1277
|
+
profile: ${profile}
|
|
1278
|
+
account: ${account}
|
|
1279
|
+
arn: ${arn}
|
|
1280
|
+
|
|
1281
|
+
Now: dude iac plan --env ${env}
|
|
1282
|
+
|
|
1283
|
+
`
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
|
|
1288
|
+
// src/commands/iac/providers/aws-ecs/commands/logs/index.ts
|
|
1289
|
+
import { spawnSync as spawnSync8 } from "child_process";
|
|
1290
|
+
var SERVICES = ["backend", "frontend", "websocket", "worker", "scheduler"];
|
|
1291
|
+
function awsCliMajorVersion() {
|
|
1292
|
+
const r = spawnSync8("aws", ["--version"], { encoding: "utf8" });
|
|
1293
|
+
const m = /aws-cli\/(\d+)\./.exec(`${r.stdout ?? ""}${r.stderr ?? ""}`);
|
|
1294
|
+
return m ? Number(m[1]) : void 0;
|
|
1295
|
+
}
|
|
1296
|
+
var iacLogsCommand = {
|
|
1297
|
+
available: hasIac,
|
|
1298
|
+
description: "Tail a service's CloudWatch logs (aws logs tail).",
|
|
1299
|
+
args: {
|
|
1300
|
+
...envArg,
|
|
1301
|
+
service: {
|
|
1302
|
+
type: "string",
|
|
1303
|
+
description: "Which service to tail: backend (default), frontend, websocket, worker, scheduler."
|
|
1304
|
+
},
|
|
1305
|
+
since: {
|
|
1306
|
+
type: "string",
|
|
1307
|
+
description: "How far back to start (e.g. 15m, 2h, 1d). Default: 15m."
|
|
1308
|
+
},
|
|
1309
|
+
follow: { type: "boolean", description: "Keep streaming new log events (like tail -f)." }
|
|
1310
|
+
},
|
|
1311
|
+
async run({ projectRoot, args }) {
|
|
1312
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1313
|
+
const env = requireEnv(projectRoot, args);
|
|
1314
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1315
|
+
const which = String(args.service ?? "backend");
|
|
1316
|
+
if (!SERVICES.includes(which)) {
|
|
1317
|
+
process.stderr.write(`
|
|
1318
|
+
\u2717 Unknown --service "${which}" (use: ${SERVICES.join(", ")}).
|
|
1319
|
+
|
|
1320
|
+
`);
|
|
1321
|
+
process.exit(1);
|
|
1322
|
+
}
|
|
1323
|
+
const awsMajor = awsCliMajorVersion();
|
|
1324
|
+
if (awsMajor !== void 0 && awsMajor < 2) {
|
|
1325
|
+
process.stderr.write(
|
|
1326
|
+
`
|
|
1327
|
+
\u2717 \`aws logs tail\` requires AWS CLI v2 \u2014 this machine has v${awsMajor}.
|
|
1328
|
+
Upgrade: https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
|
|
1329
|
+
Or tail logs directly: aws logs filter-log-events --log-group-name /ecs/${projectName(projectRoot)}-${env}-${which}
|
|
1330
|
+
|
|
1331
|
+
`
|
|
1332
|
+
);
|
|
1333
|
+
process.exit(1);
|
|
1334
|
+
}
|
|
1335
|
+
const group = `/ecs/${projectName(projectRoot)}-${env}-${which}`;
|
|
1336
|
+
const region = tfOutputRaw(projectRoot, "region", profile) || tfvarsValue(projectRoot, env, "region");
|
|
1337
|
+
const cliArgs = ["logs", "tail", group, "--since", String(args.since ?? "15m")];
|
|
1338
|
+
if (args.follow) cliArgs.push("--follow");
|
|
1339
|
+
if (region) cliArgs.push("--region", region);
|
|
1340
|
+
process.exit(run("aws", cliArgs, projectRoot, profile));
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
|
|
1344
|
+
// src/commands/iac/providers/aws-ecs/commands/migrate/index.ts
|
|
1345
|
+
var iacMigrateCommand = {
|
|
1346
|
+
available: hasIac,
|
|
1347
|
+
description: "Run frappe migrations (bench --site all migrate) as a one-off ECS Fargate task. Run it after every deploy that changes DocTypes/patches.",
|
|
1348
|
+
args: { ...envArg },
|
|
1349
|
+
async run({ projectRoot, args }) {
|
|
1350
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1351
|
+
const env = requireEnv(projectRoot, args);
|
|
1352
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1353
|
+
const read = readOneOffTarget(projectRoot, profile, ["migrate_task_definition"]);
|
|
1354
|
+
if (!read) {
|
|
1355
|
+
process.stderr.write(
|
|
1356
|
+
"error: could not read Terraform outputs (migrate_task_definition, cluster_name, \u2026) \u2014 run `dude iac apply` first.\n"
|
|
1357
|
+
);
|
|
1358
|
+
process.exit(1);
|
|
1359
|
+
}
|
|
1360
|
+
const code = runOneOffTask(
|
|
1361
|
+
projectRoot,
|
|
1362
|
+
profile,
|
|
1363
|
+
read.target,
|
|
1364
|
+
read.taskDefinitions.migrate_task_definition,
|
|
1365
|
+
`migrations on "${env}"`
|
|
1366
|
+
);
|
|
1367
|
+
if (code === 0) {
|
|
1368
|
+
process.stdout.write("\n \u2713 Migrations applied.\n\n");
|
|
1369
|
+
process.exit(0);
|
|
1370
|
+
}
|
|
1371
|
+
process.stderr.write(
|
|
1372
|
+
` Inspect the logs with: dude iac logs --env ${env} --service backend
|
|
1373
|
+
|
|
1374
|
+
`
|
|
1375
|
+
);
|
|
1376
|
+
process.exit(code);
|
|
1377
|
+
}
|
|
1378
|
+
};
|
|
1379
|
+
|
|
1380
|
+
// src/commands/iac/providers/aws-ecs/commands/new-env/index.ts
|
|
1381
|
+
import { cpSync, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
1382
|
+
import path8 from "pathe";
|
|
1383
|
+
var iacNewEnvCommand = {
|
|
1384
|
+
available: hasIac,
|
|
1385
|
+
description: "Scaffold a new environment (iac/terraform/environments/<name>) by copying an existing one.",
|
|
1386
|
+
args: {
|
|
1387
|
+
env: {
|
|
1388
|
+
type: "string",
|
|
1389
|
+
description: "Name of the new environment to create (lowercase kebab-case).",
|
|
1390
|
+
required: true
|
|
1391
|
+
},
|
|
1392
|
+
from: {
|
|
1393
|
+
type: "string",
|
|
1394
|
+
description: "Existing environment to copy as a starting point (default: dev)."
|
|
1395
|
+
}
|
|
1396
|
+
},
|
|
1397
|
+
async run({ projectRoot, args }) {
|
|
1398
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1399
|
+
const name = args.env == null ? "" : String(args.env);
|
|
1400
|
+
if (!name) {
|
|
1401
|
+
process.stderr.write("\n \u2717 --env is required (the name of the environment to create).\n\n");
|
|
1402
|
+
process.exit(1);
|
|
1403
|
+
}
|
|
1404
|
+
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
1405
|
+
process.stderr.write(`
|
|
1406
|
+
\u2717 invalid --env "${name}" (expected lowercase kebab-case).
|
|
1407
|
+
|
|
1408
|
+
`);
|
|
1409
|
+
process.exit(1);
|
|
1410
|
+
}
|
|
1411
|
+
const envs = listEnvironments(projectRoot);
|
|
1412
|
+
if (envs.includes(name)) {
|
|
1413
|
+
process.stderr.write(`
|
|
1414
|
+
\u2717 environment "${name}" already exists.
|
|
1415
|
+
|
|
1416
|
+
`);
|
|
1417
|
+
process.exit(1);
|
|
1418
|
+
}
|
|
1419
|
+
if (!envs.length) {
|
|
1420
|
+
process.stderr.write(
|
|
1421
|
+
"\n \u2717 no existing environment to copy from (expected at least iac/terraform/environments/dev).\n\n"
|
|
1422
|
+
);
|
|
1423
|
+
process.exit(1);
|
|
1424
|
+
}
|
|
1425
|
+
const from = args.from == null ? "dev" : String(args.from);
|
|
1426
|
+
if (!envs.includes(from)) {
|
|
1427
|
+
process.stderr.write(`
|
|
1428
|
+
\u2717 --from "${from}" does not exist. Available: ${envs.join(", ")}
|
|
1429
|
+
|
|
1430
|
+
`);
|
|
1431
|
+
process.exit(1);
|
|
1432
|
+
}
|
|
1433
|
+
const base = path8.join(projectRoot, TF_ENVIRONMENTS_DIR);
|
|
1434
|
+
const dst = path8.join(base, name);
|
|
1435
|
+
cpSync(path8.join(base, from), dst, { recursive: true });
|
|
1436
|
+
const tfvarsPath = path8.join(dst, "terraform.tfvars");
|
|
1437
|
+
writeFileSync4(
|
|
1438
|
+
tfvarsPath,
|
|
1439
|
+
readFileSync6(tfvarsPath, "utf8").replace(/^(\s*environment\s*=\s*).*$/m, `$1"${name}"`)
|
|
1440
|
+
);
|
|
1441
|
+
const backendPath = path8.join(dst, "backend.hcl");
|
|
1442
|
+
writeFileSync4(
|
|
1443
|
+
backendPath,
|
|
1444
|
+
readFileSync6(backendPath, "utf8").replace(
|
|
1445
|
+
/^(\s*key\s*=\s*).*$/m,
|
|
1446
|
+
`$1"${projectName(projectRoot)}/${name}/terraform.tfstate"`
|
|
1447
|
+
)
|
|
1448
|
+
);
|
|
1449
|
+
process.stdout.write(
|
|
1450
|
+
`
|
|
1451
|
+
\u2713 Created environment "${name}" (copied from "${from}").
|
|
1452
|
+
iac/terraform/environments/${name}/{backend.hcl,terraform.tfvars}
|
|
1453
|
+
|
|
1454
|
+
Next:
|
|
1455
|
+
1. Review iac/terraform/environments/${name}/terraform.tfvars (sizing, domain, allowed_cidrs, \u2026).
|
|
1456
|
+
2. First env on a brand-new state backend? Run:
|
|
1457
|
+
dude iac bootstrap --env ${name} --state-bucket-prefix <prefix>
|
|
1458
|
+
Otherwise it reuses the existing bucket \u2014 skip bootstrap.
|
|
1459
|
+
3. dude iac init --env ${name} && dude iac apply --env ${name}
|
|
1460
|
+
|
|
1461
|
+
`
|
|
1462
|
+
);
|
|
1463
|
+
}
|
|
1464
|
+
};
|
|
1465
|
+
|
|
1466
|
+
// src/commands/iac/providers/aws-ecs/commands/output/index.ts
|
|
1467
|
+
var iacOutputCommand = {
|
|
1468
|
+
available: hasIac,
|
|
1469
|
+
description: "Print Terraform outputs for an environment (app URL, ECR URLs, cluster/services\u2026).",
|
|
1470
|
+
args: {
|
|
1471
|
+
...envArg,
|
|
1472
|
+
json: { type: "boolean", description: "Emit machine-readable JSON." }
|
|
1473
|
+
},
|
|
1474
|
+
async run({ projectRoot, args }) {
|
|
1475
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1476
|
+
const env = requireEnv(projectRoot, args);
|
|
1477
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1478
|
+
const extra = args.json ? ["-json"] : [];
|
|
1479
|
+
process.exit(tf(projectRoot, ["output", ...extra], profile));
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
|
|
1483
|
+
// src/commands/iac/providers/aws-ecs/commands/plan/index.ts
|
|
1484
|
+
var iacPlanCommand = {
|
|
1485
|
+
available: hasIac,
|
|
1486
|
+
description: "Show the infrastructure changes Terraform would apply for an environment.",
|
|
1487
|
+
args: { ...envArg },
|
|
1488
|
+
async run({ projectRoot, args }) {
|
|
1489
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1490
|
+
const env = requireEnv(projectRoot, args);
|
|
1491
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1492
|
+
process.exit(tf(projectRoot, ["plan", varFile(env)], profile));
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
|
|
1496
|
+
// src/commands/iac/providers/aws-ecs/commands/push/index.ts
|
|
1497
|
+
var iacPushCommand = {
|
|
1498
|
+
available: hasIac,
|
|
1499
|
+
description: "Log in to ECR and push the production Frappe image (build it first).",
|
|
1500
|
+
args: { ...envArg, ...tagArg },
|
|
1501
|
+
async run({ projectRoot, args }) {
|
|
1502
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1503
|
+
const env = requireEnv(projectRoot, args);
|
|
1504
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1505
|
+
const tag = resolveTag(projectRoot, args);
|
|
1506
|
+
if (!tag) process.exit(1);
|
|
1507
|
+
const target = requireEcsTarget(projectRoot, profile);
|
|
1508
|
+
process.exit(doPush(projectRoot, profile, tag, target));
|
|
1509
|
+
}
|
|
1510
|
+
};
|
|
1511
|
+
|
|
1512
|
+
// src/commands/iac/providers/aws-ecs/commands/shell/index.ts
|
|
1513
|
+
import { spawnSync as spawnSync9 } from "child_process";
|
|
1514
|
+
var iacShellCommand = {
|
|
1515
|
+
available: hasIac,
|
|
1516
|
+
description: "Open an interactive shell in the IaC runner container (terraform, aws) scoped to an environment.",
|
|
1517
|
+
args: { ...envArg },
|
|
1518
|
+
async run({ projectRoot, args }) {
|
|
1519
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1520
|
+
if (!dockerAvailable()) {
|
|
1521
|
+
process.stderr.write(
|
|
1522
|
+
"\n \u2717 Docker is required for `dude iac shell` (it runs the IaC toolchain in a container).\n Start Docker and retry.\n\n"
|
|
1523
|
+
);
|
|
1524
|
+
process.exit(1);
|
|
1525
|
+
}
|
|
1526
|
+
if (!hasRunnerDockerfile(projectRoot)) {
|
|
1527
|
+
process.stderr.write(
|
|
1528
|
+
`
|
|
1529
|
+
\u2717 No runner Dockerfile found (iac/runner/Dockerfile).
|
|
1530
|
+
Re-scaffold with \`--iac aws-ecs\` or add it to enable the runner.
|
|
1531
|
+
|
|
1532
|
+
`
|
|
1533
|
+
);
|
|
1534
|
+
process.exit(1);
|
|
1535
|
+
}
|
|
1536
|
+
const env = requireEnv(projectRoot, args);
|
|
1537
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1538
|
+
process.stdout.write(
|
|
1539
|
+
`
|
|
1540
|
+
\u2192 Entering the IaC runner for env "${env}" (profile "${profile}").
|
|
1541
|
+
The project is mounted at /work. Type "exit" to leave.
|
|
1542
|
+
|
|
1543
|
+
`
|
|
1544
|
+
);
|
|
1545
|
+
const r = spawnSync9("docker", dockerShellArgs(projectRoot, profile), {
|
|
1546
|
+
stdio: "inherit",
|
|
1547
|
+
cwd: projectRoot
|
|
1548
|
+
});
|
|
1549
|
+
process.exit(r.status ?? 1);
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
|
|
1553
|
+
// src/commands/iac/providers/aws-ecs/commands/ship/index.ts
|
|
1554
|
+
var iacShipCommand = {
|
|
1555
|
+
available: hasIac,
|
|
1556
|
+
description: "Build, push, and deploy in one step (the local inner loop).",
|
|
1557
|
+
args: { ...envArg, ...tagArg, ...platformArg },
|
|
1558
|
+
async run({ projectRoot, args }) {
|
|
1559
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1560
|
+
const env = requireEnv(projectRoot, args);
|
|
1561
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1562
|
+
const tag = resolveTag(projectRoot, args);
|
|
1563
|
+
if (!tag) process.exit(1);
|
|
1564
|
+
const target = requireEcsTarget(projectRoot, profile);
|
|
1565
|
+
const platform = String(args.platform ?? "linux/amd64");
|
|
1566
|
+
const project = projectName(projectRoot);
|
|
1567
|
+
let code = doBuild(projectRoot, profile, tag, target, platform);
|
|
1568
|
+
if (code !== 0) process.exit(code);
|
|
1569
|
+
code = doPush(projectRoot, profile, tag, target);
|
|
1570
|
+
if (code !== 0) process.exit(code);
|
|
1571
|
+
code = doDeploy(projectRoot, profile, env, tag, target);
|
|
1572
|
+
if (code === 0) {
|
|
1573
|
+
process.stdout.write(`
|
|
1574
|
+
\u2713 Shipped ${project}:${tag} to "${env}".
|
|
1575
|
+
|
|
1576
|
+
`);
|
|
1577
|
+
}
|
|
1578
|
+
process.exit(code);
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
|
|
1582
|
+
// src/commands/iac/providers/aws-ecs/commands/status/index.ts
|
|
1583
|
+
var SERVICES2 = ["backend", "frontend", "websocket", "worker", "scheduler"];
|
|
1584
|
+
var iacStatusCommand = {
|
|
1585
|
+
available: hasIac,
|
|
1586
|
+
description: "Show an ECS service state, running tasks and recent deployment events.",
|
|
1587
|
+
args: {
|
|
1588
|
+
...envArg,
|
|
1589
|
+
service: {
|
|
1590
|
+
type: "string",
|
|
1591
|
+
description: "Which service to inspect: backend (default), frontend, websocket, worker, scheduler."
|
|
1592
|
+
}
|
|
1593
|
+
},
|
|
1594
|
+
async run({ projectRoot, args }) {
|
|
1595
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1596
|
+
const env = requireEnv(projectRoot, args);
|
|
1597
|
+
const profile = resolveProfile(projectRoot, args, env);
|
|
1598
|
+
const which = String(args.service ?? "backend");
|
|
1599
|
+
if (!SERVICES2.includes(which)) {
|
|
1600
|
+
process.stderr.write(`
|
|
1601
|
+
\u2717 Unknown --service "${which}" (use: ${SERVICES2.join(", ")}).
|
|
1602
|
+
|
|
1603
|
+
`);
|
|
1604
|
+
process.exit(1);
|
|
1605
|
+
}
|
|
1606
|
+
const conventional = `${projectName(projectRoot)}-${env}-${which}`;
|
|
1607
|
+
const cluster = tfOutputRaw(projectRoot, "cluster_name", profile) || `${projectName(projectRoot)}-${env}`;
|
|
1608
|
+
const service = tfOutputRaw(projectRoot, `${which}_service_name`, profile) || conventional;
|
|
1609
|
+
const region = tfOutputRaw(projectRoot, "region", profile) || tfvarsValue(projectRoot, env, "region");
|
|
1610
|
+
const regionFlag = region ? ["--region", region] : [];
|
|
1611
|
+
const r = capture(
|
|
1612
|
+
"aws",
|
|
1613
|
+
[
|
|
1614
|
+
"ecs",
|
|
1615
|
+
"describe-services",
|
|
1616
|
+
"--cluster",
|
|
1617
|
+
cluster,
|
|
1618
|
+
"--services",
|
|
1619
|
+
service,
|
|
1620
|
+
"--output",
|
|
1621
|
+
"json",
|
|
1622
|
+
...regionFlag
|
|
1623
|
+
],
|
|
1624
|
+
projectRoot,
|
|
1625
|
+
profile
|
|
1626
|
+
);
|
|
1627
|
+
if (r.status !== 0) {
|
|
1628
|
+
process.stderr.write(
|
|
1629
|
+
`
|
|
1630
|
+
\u2717 Could not describe service "${service}" on cluster "${cluster}".
|
|
1631
|
+
Is the environment provisioned? Try: dude iac apply --env ${env}
|
|
1632
|
+
|
|
1633
|
+
`
|
|
1634
|
+
);
|
|
1635
|
+
process.exit(1);
|
|
1636
|
+
}
|
|
1637
|
+
let svc;
|
|
1638
|
+
try {
|
|
1639
|
+
svc = JSON.parse(r.stdout).services?.[0];
|
|
1640
|
+
} catch {
|
|
1641
|
+
}
|
|
1642
|
+
if (!svc) {
|
|
1643
|
+
process.stderr.write(`
|
|
1644
|
+
\u2717 Service "${service}" not found on cluster "${cluster}".
|
|
1645
|
+
|
|
1646
|
+
`);
|
|
1647
|
+
process.exit(1);
|
|
1648
|
+
}
|
|
1649
|
+
process.stdout.write(
|
|
1650
|
+
`
|
|
1651
|
+
Service ${service} (cluster ${cluster})
|
|
1652
|
+
status: ${svc.status ?? "UNKNOWN"}
|
|
1653
|
+
tasks: ${svc.runningCount ?? 0} running / ${svc.pendingCount ?? 0} pending / ${svc.desiredCount ?? 0} desired
|
|
1654
|
+
`
|
|
1655
|
+
);
|
|
1656
|
+
for (const d of svc.deployments ?? []) {
|
|
1657
|
+
const taskDef = d.taskDefinition?.split("/").pop() ?? "";
|
|
1658
|
+
process.stdout.write(
|
|
1659
|
+
` deploy: ${d.status ?? ""} ${d.rolloutState ?? ""} ${taskDef} (${d.runningCount ?? 0}/${d.desiredCount ?? 0})
|
|
1660
|
+
`
|
|
1661
|
+
);
|
|
1662
|
+
}
|
|
1663
|
+
const events = (svc.events ?? []).slice(0, 5);
|
|
1664
|
+
if (events.length) {
|
|
1665
|
+
process.stdout.write(`
|
|
1666
|
+
Recent events:
|
|
1667
|
+
`);
|
|
1668
|
+
for (const e of events) {
|
|
1669
|
+
process.stdout.write(` ${e.createdAt ?? ""} ${e.message ?? ""}
|
|
1670
|
+
`);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
const appUrl = tfOutputRaw(projectRoot, "app_url", profile);
|
|
1674
|
+
if (appUrl) process.stdout.write(`
|
|
1675
|
+
App URL: ${appUrl}
|
|
1676
|
+
`);
|
|
1677
|
+
process.stdout.write("\n");
|
|
1678
|
+
}
|
|
1679
|
+
};
|
|
1680
|
+
|
|
1681
|
+
// src/commands/iac/providers/aws-ecs/commands/validate/index.ts
|
|
1682
|
+
var iacValidateCommand = {
|
|
1683
|
+
available: hasIac,
|
|
1684
|
+
description: "Validate the Terraform configuration.",
|
|
1685
|
+
async run({ projectRoot }) {
|
|
1686
|
+
if (!requireIac(projectRoot)) process.exit(1);
|
|
1687
|
+
process.exit(tf(projectRoot, ["validate"]));
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1690
|
+
|
|
1691
|
+
// src/commands/iac/providers/aws-ecs/index.ts
|
|
1692
|
+
var awsEcsProvider = {
|
|
1693
|
+
id: "aws-ecs",
|
|
1694
|
+
label: "AWS ECS Fargate (Terraform)",
|
|
1695
|
+
detect: hasIac,
|
|
1696
|
+
commands: {
|
|
1697
|
+
login: iacLoginCommand,
|
|
1698
|
+
"new-env": iacNewEnvCommand,
|
|
1699
|
+
bootstrap: iacBootstrapCommand,
|
|
1700
|
+
init: iacInitCommand,
|
|
1701
|
+
plan: iacPlanCommand,
|
|
1702
|
+
apply: iacApplyCommand,
|
|
1703
|
+
destroy: iacDestroyCommand,
|
|
1704
|
+
output: iacOutputCommand,
|
|
1705
|
+
fmt: iacFmtCommand,
|
|
1706
|
+
validate: iacValidateCommand,
|
|
1707
|
+
build: iacBuildCommand,
|
|
1708
|
+
push: iacPushCommand,
|
|
1709
|
+
deploy: iacDeployCommand,
|
|
1710
|
+
ship: iacShipCommand,
|
|
1711
|
+
"create-site": iacCreateSiteCommand,
|
|
1712
|
+
migrate: iacMigrateCommand,
|
|
1713
|
+
status: iacStatusCommand,
|
|
1714
|
+
logs: iacLogsCommand,
|
|
1715
|
+
shell: iacShellCommand
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
|
|
1719
|
+
// src/commands/iac/index.ts
|
|
1720
|
+
var iacProviders = [awsEcsProvider];
|
|
1721
|
+
function activeIacProvider(projectRoot = process.cwd()) {
|
|
1722
|
+
return iacProviders.find((p) => p.detect(projectRoot));
|
|
1723
|
+
}
|
|
1724
|
+
var provider = activeIacProvider() ?? iacProviders[0];
|
|
1725
|
+
var iacCommands = provider?.commands ?? {};
|
|
1726
|
+
|
|
1727
|
+
// src/commands/lint/index.ts
|
|
1728
|
+
import { defineLintCommand } from "@cubocicloide/dude";
|
|
1729
|
+
var lintCommand = defineLintCommand({
|
|
1730
|
+
description: "Check Frappe project conventions using the stack's own rules (APP/DT/PY)."
|
|
1731
|
+
});
|
|
1732
|
+
|
|
1733
|
+
// src/commands/logs/index.ts
|
|
1734
|
+
var logsCommand = {
|
|
1735
|
+
description: "Follow service logs (docker compose logs -f [--service <name>]).",
|
|
1736
|
+
args: {
|
|
1737
|
+
service: {
|
|
1738
|
+
type: "string",
|
|
1739
|
+
description: "Service name (bench, mariadb, redis-cache, redis-queue); omit for all.",
|
|
1740
|
+
required: false
|
|
1741
|
+
}
|
|
1742
|
+
},
|
|
1743
|
+
async run({ args }) {
|
|
1744
|
+
const svc = typeof args.service === "string" && args.service ? args.service : null;
|
|
1745
|
+
dc(svc ? ["logs", "-f", svc] : ["logs", "-f"]);
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
|
|
1749
|
+
// src/commands/review/index.ts
|
|
1750
|
+
import { runLint, formatDiagnostic } from "@cubocicloide/dude";
|
|
1751
|
+
var reviewCommand = {
|
|
1752
|
+
description: "One-pass review: stack lint rules + ruff check (no autofix).",
|
|
1753
|
+
args: {},
|
|
1754
|
+
async run({ projectRoot, stackRoot }) {
|
|
1755
|
+
let failed = false;
|
|
1756
|
+
process.stdout.write("\u2500\u2500 dude lint \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n");
|
|
1757
|
+
const { diagnostics, errorCount } = await runLint(projectRoot, stackRoot);
|
|
1758
|
+
for (const d of diagnostics) process.stdout.write(formatDiagnostic(d) + "\n");
|
|
1759
|
+
if (errorCount > 0) failed = true;
|
|
1760
|
+
if (diagnostics.length === 0) process.stdout.write("No issues found.\n");
|
|
1761
|
+
process.stdout.write("\n\u2500\u2500 ruff check \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n");
|
|
1762
|
+
if (!isDockerRunning()) {
|
|
1763
|
+
process.stderr.write("[review] Docker is not running \u2014 skipping ruff check.\n");
|
|
1764
|
+
} else if (ruff(projectRoot, ["check", "."]) !== 0) {
|
|
1765
|
+
failed = true;
|
|
1766
|
+
}
|
|
1767
|
+
process.exit(failed ? 1 : 0);
|
|
1768
|
+
}
|
|
1769
|
+
};
|
|
1770
|
+
|
|
1771
|
+
// src/commands/shell/index.ts
|
|
1772
|
+
import { spawnSync as spawnSync10 } from "child_process";
|
|
1773
|
+
var shellCommand = {
|
|
1774
|
+
description: "Open an interactive shell in a service container (default: bench, inside the frappe-bench directory).",
|
|
1775
|
+
args: {
|
|
1776
|
+
service: {
|
|
1777
|
+
type: "string",
|
|
1778
|
+
description: "Service name (default: bench).",
|
|
1779
|
+
required: false
|
|
1780
|
+
}
|
|
1781
|
+
},
|
|
1782
|
+
async run({ args }) {
|
|
1783
|
+
const svc = typeof args.service === "string" && args.service ? args.service : "bench";
|
|
1784
|
+
if (svc === "bench") {
|
|
1785
|
+
dc(["exec", "-w", "/home/frappe/frappe-bench", "bench", "/bin/bash"]);
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
const bash = spawnSync10("docker", ["compose", "exec", svc, "/bin/bash"], { stdio: "inherit" });
|
|
1789
|
+
if (bash.status !== 0) {
|
|
1790
|
+
dc(["exec", svc, "/bin/sh"]);
|
|
1791
|
+
} else {
|
|
1792
|
+
process.exit(bash.status ?? 0);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
};
|
|
1796
|
+
|
|
1797
|
+
// src/commands/site/index.ts
|
|
1798
|
+
var IN_BENCH2 = "cd /home/frappe/frappe-bench";
|
|
1799
|
+
var migrateCommand = {
|
|
1800
|
+
description: "Apply pending schema changes, patches and fixtures (bench migrate).",
|
|
1801
|
+
args: {},
|
|
1802
|
+
async run() {
|
|
1803
|
+
benchSh(`${IN_BENCH2} && bench --site "$SITE_NAME" migrate`);
|
|
1804
|
+
}
|
|
1805
|
+
};
|
|
1806
|
+
var consoleCommand = {
|
|
1807
|
+
description: "Open an IPython console with the site loaded (bench console).",
|
|
1808
|
+
args: {},
|
|
1809
|
+
async run() {
|
|
1810
|
+
benchSh(`${IN_BENCH2} && bench --site "$SITE_NAME" console`);
|
|
1811
|
+
}
|
|
1812
|
+
};
|
|
1813
|
+
var backupCommand = {
|
|
1814
|
+
description: "Backup the site database (and optionally files) into the bench; copies land in sites/$SITE_NAME/private/backups.",
|
|
1815
|
+
args: {
|
|
1816
|
+
files: {
|
|
1817
|
+
type: "boolean",
|
|
1818
|
+
description: "Include public/private files in the backup.",
|
|
1819
|
+
default: false
|
|
1820
|
+
}
|
|
1821
|
+
},
|
|
1822
|
+
async run({ args }) {
|
|
1823
|
+
const withFiles = Boolean(args.files) ? " --with-files" : "";
|
|
1824
|
+
benchSh(`${IN_BENCH2} && bench --site "$SITE_NAME" backup${withFiles}`);
|
|
1825
|
+
}
|
|
1826
|
+
};
|
|
1827
|
+
var clearCacheCommand = {
|
|
1828
|
+
description: "Clear the site cache and website cache (bench clear-cache).",
|
|
1829
|
+
args: {},
|
|
1830
|
+
async run() {
|
|
1831
|
+
benchSh(`${IN_BENCH2} && bench --site "$SITE_NAME" clear-cache`);
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
var mariadbCommand = {
|
|
1835
|
+
description: "Open a MariaDB client connected to the site's database (bench mariadb).",
|
|
1836
|
+
args: {},
|
|
1837
|
+
async run() {
|
|
1838
|
+
benchSh(`${IN_BENCH2} && bench --site "$SITE_NAME" mariadb`);
|
|
1839
|
+
}
|
|
1840
|
+
};
|
|
1841
|
+
|
|
1842
|
+
// src/commands/test/index.ts
|
|
1843
|
+
var testCommand = {
|
|
1844
|
+
description: "Run a custom app's test suite on the default site (bench run-tests).",
|
|
1845
|
+
args: {
|
|
1846
|
+
app: {
|
|
1847
|
+
type: "string",
|
|
1848
|
+
description: "App to test (default: ticketing).",
|
|
1849
|
+
default: "ticketing"
|
|
1850
|
+
},
|
|
1851
|
+
module: {
|
|
1852
|
+
type: "string",
|
|
1853
|
+
description: "Run a single test module (dotted path) instead of the whole app.",
|
|
1854
|
+
required: false
|
|
1855
|
+
}
|
|
1856
|
+
},
|
|
1857
|
+
async run({ args }) {
|
|
1858
|
+
const app = shellQuote(String(args.app ?? "ticketing"));
|
|
1859
|
+
const module = typeof args.module === "string" && args.module ? args.module : null;
|
|
1860
|
+
const target = module ? `--module ${shellQuote(module)}` : `--app ${app}`;
|
|
1861
|
+
benchSh(`cd /home/frappe/frappe-bench && bench --site "$SITE_NAME" run-tests ${target}`);
|
|
1862
|
+
}
|
|
1863
|
+
};
|
|
1864
|
+
|
|
1865
|
+
// src/commands/up/index.ts
|
|
1866
|
+
var upCommand = {
|
|
1867
|
+
description: "Start all services (docker compose up -d). First boot provisions the bench + site \u2014 follow with `dude logs --service bench`.",
|
|
1868
|
+
args: {
|
|
1869
|
+
build: { type: "boolean", description: "Rebuild images before starting.", default: false }
|
|
1870
|
+
},
|
|
1871
|
+
async run({ args }) {
|
|
1872
|
+
dc(Boolean(args.build) ? ["up", "-d", "--build"] : ["up", "-d"]);
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
|
|
1876
|
+
// src/index.ts
|
|
1877
|
+
var src_default = defineStack({
|
|
1878
|
+
name: "frappe",
|
|
1879
|
+
version: "0.1.0",
|
|
1880
|
+
minDudeVersion: "0.1.0",
|
|
1881
|
+
description: "Frappe Framework ticketing system (Frappe Helpdesk) with a worked-example custom app.",
|
|
1882
|
+
variables: [
|
|
1883
|
+
{
|
|
1884
|
+
name: "projectName",
|
|
1885
|
+
type: "string",
|
|
1886
|
+
prompt: "Project name",
|
|
1887
|
+
pattern: "^[a-z][a-z0-9-]*$",
|
|
1888
|
+
default: "my-helpdesk"
|
|
1889
|
+
},
|
|
1890
|
+
{
|
|
1891
|
+
name: "helpdesk",
|
|
1892
|
+
type: "boolean",
|
|
1893
|
+
prompt: "Install Frappe Helpdesk (the ticketing UI)?",
|
|
1894
|
+
default: true
|
|
1895
|
+
},
|
|
1896
|
+
{
|
|
1897
|
+
name: "iac",
|
|
1898
|
+
type: "select",
|
|
1899
|
+
prompt: "Infrastructure-as-Code (Terraform, AWS ECS Fargate)",
|
|
1900
|
+
choices: ["none", "aws-ecs"],
|
|
1901
|
+
default: "none"
|
|
1902
|
+
}
|
|
1903
|
+
],
|
|
1904
|
+
async scaffold(ctx) {
|
|
1905
|
+
const { answers, dest, stackRoot, dudeVersion, stackVersion } = ctx;
|
|
1906
|
+
const withHelpdesk = answers.helpdesk !== false;
|
|
1907
|
+
const withIac = answers.iac === "aws-ecs";
|
|
1908
|
+
const data = {
|
|
1909
|
+
...answers,
|
|
1910
|
+
withHelpdesk,
|
|
1911
|
+
withIac,
|
|
1912
|
+
dudeVersion,
|
|
1913
|
+
stackVersion
|
|
1914
|
+
};
|
|
1915
|
+
const templates = path9.join(stackRoot, "templates");
|
|
1916
|
+
await renderTemplateTree({ src: path9.join(templates, "base"), dest, data });
|
|
1917
|
+
if (withIac) {
|
|
1918
|
+
await renderTemplateTree({ src: path9.join(templates, "aws-ecs"), dest, data });
|
|
1919
|
+
}
|
|
1920
|
+
},
|
|
1921
|
+
hooks: {
|
|
1922
|
+
async postInit(ctx) {
|
|
1923
|
+
const name = String(ctx.answers.projectName ?? "your-project");
|
|
1924
|
+
const withHelpdesk = ctx.answers.helpdesk !== false;
|
|
1925
|
+
const withIac = ctx.answers.iac === "aws-ecs";
|
|
1926
|
+
ctx.logger.info("Project scaffolded. Next steps:");
|
|
1927
|
+
ctx.logger.info("");
|
|
1928
|
+
ctx.logger.info(" 1. Install the dude launcher once (globally), then provision the project:");
|
|
1929
|
+
ctx.logger.info(" npm install -g @cubocicloide/dude-launcher");
|
|
1930
|
+
ctx.logger.info(` cd ${name} && pnpm install`);
|
|
1931
|
+
ctx.logger.info(" From now on `dude <cmd>` runs this project\u2019s pinned CLI + stack.");
|
|
1932
|
+
ctx.logger.info("");
|
|
1933
|
+
ctx.logger.info(" 2. Start the stack \u2014 the FIRST boot creates the bench, the site and");
|
|
1934
|
+
ctx.logger.info(" installs the apps, which takes several minutes:");
|
|
1935
|
+
ctx.logger.info(" dude up");
|
|
1936
|
+
ctx.logger.info(" dude logs --service bench # watch the provisioning");
|
|
1937
|
+
ctx.logger.info("");
|
|
1938
|
+
ctx.logger.info(" Endpoints (once `bench start` is running):");
|
|
1939
|
+
ctx.logger.info(` Desk (admin): http://${name}.localhost:8000/app (Administrator / admin)`);
|
|
1940
|
+
if (withHelpdesk) {
|
|
1941
|
+
ctx.logger.info(` Helpdesk: http://${name}.localhost:8000/helpdesk`);
|
|
1942
|
+
}
|
|
1943
|
+
ctx.logger.info(` Portal example: http://${name}.localhost:8000/ticket_stats`);
|
|
1944
|
+
ctx.logger.info(` API example: http://${name}.localhost:8000/api/method/ticketing.api.ticket_stats`);
|
|
1945
|
+
ctx.logger.info("");
|
|
1946
|
+
ctx.logger.info(" Learn Frappe with this repo: apps/ticketing/README.md maps every core");
|
|
1947
|
+
ctx.logger.info(" concept (DocType, hooks, tasks, workflow, portal page) to a file.");
|
|
1948
|
+
if (withIac) {
|
|
1949
|
+
ctx.logger.info("");
|
|
1950
|
+
ctx.logger.info(" Deploy to AWS ECS Fargate (Terraform) \u2014 see iac/README.md:");
|
|
1951
|
+
ctx.logger.info(" dude iac login --env dev");
|
|
1952
|
+
ctx.logger.info(" dude iac bootstrap --state-bucket-prefix <your-org> --env dev --yes");
|
|
1953
|
+
ctx.logger.info(" dude iac init --env dev && dude iac apply --env dev");
|
|
1954
|
+
ctx.logger.info(" dude iac ship --env dev");
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
},
|
|
1958
|
+
rules: [],
|
|
1959
|
+
commands: {
|
|
1960
|
+
up: upCommand,
|
|
1961
|
+
down: downCommand,
|
|
1962
|
+
logs: logsCommand,
|
|
1963
|
+
shell: shellCommand,
|
|
1964
|
+
bench: benchCommand,
|
|
1965
|
+
lint: lintCommand,
|
|
1966
|
+
format: formatCommand,
|
|
1967
|
+
review: reviewCommand,
|
|
1968
|
+
test: testCommand,
|
|
1969
|
+
docs: docsCommand,
|
|
1970
|
+
site: {
|
|
1971
|
+
migrate: migrateCommand,
|
|
1972
|
+
console: consoleCommand,
|
|
1973
|
+
backup: backupCommand,
|
|
1974
|
+
"clear-cache": clearCacheCommand,
|
|
1975
|
+
mariadb: mariadbCommand
|
|
1976
|
+
},
|
|
1977
|
+
app: {
|
|
1978
|
+
new: newAppCommand,
|
|
1979
|
+
install: installAppCommand
|
|
1980
|
+
},
|
|
1981
|
+
iac: iacCommands
|
|
1982
|
+
}
|
|
1983
|
+
});
|
|
1984
|
+
export {
|
|
1985
|
+
src_default as default
|
|
1986
|
+
};
|
|
1987
|
+
//# sourceMappingURL=index.js.map
|