@cubocicloide/stack-react-fastapi 13.4.2 → 13.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2654 -329
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/templates/azure-aca/backend/Dockerfile.prod.hbs +29 -0
- package/templates/azure-aca/docs/docs/deploy.md.hbs +127 -0
- package/templates/azure-aca/frontend/Dockerfile.prod +36 -0
- package/templates/azure-aca/frontend/nginx.conf.template +47 -0
- package/templates/azure-aca/iac/README.md.hbs +286 -0
- package/templates/azure-aca/iac/_gitignore +19 -0
- package/templates/azure-aca/iac/runner/Dockerfile +51 -0
- package/templates/azure-aca/iac/terraform/bootstrap/main.tf.hbs +123 -0
- package/templates/azure-aca/iac/terraform/bootstrap/outputs.tf +24 -0
- package/templates/azure-aca/iac/terraform/bootstrap/variables.tf.hbs +23 -0
- package/templates/azure-aca/iac/terraform/environments/dev/backend.hcl.hbs +25 -0
- package/templates/azure-aca/iac/terraform/environments/dev/terraform.tfvars.hbs +69 -0
- package/templates/azure-aca/iac/terraform/main.tf.hbs +593 -0
- package/templates/azure-aca/iac/terraform/outputs.tf.hbs +72 -0
- package/templates/azure-aca/iac/terraform/providers.tf +16 -0
- package/templates/azure-aca/iac/terraform/variables.tf.hbs +200 -0
- package/templates/azure-aca/iac/terraform/versions.tf +21 -0
- package/templates/azure-aks/backend/Dockerfile.prod.hbs +29 -0
- package/templates/azure-aks/docs/docs/deploy.md.hbs +273 -0
- package/templates/azure-aks/frontend/Dockerfile.prod +32 -0
- package/templates/azure-aks/frontend/nginx.conf +20 -0
- package/templates/azure-aks/iac/README.md.hbs +472 -0
- package/templates/azure-aks/iac/_gitignore +29 -0
- package/templates/azure-aks/iac/helm/app/.helmignore +7 -0
- package/templates/azure-aks/iac/helm/app/Chart.yaml.hbs +6 -0
- package/templates/azure-aks/iac/helm/app/templates/NOTES.txt +32 -0
- package/templates/azure-aks/iac/helm/app/templates/backend-deployment.yaml +44 -0
- package/templates/azure-aks/iac/helm/app/templates/backend-service.yaml +16 -0
- package/templates/azure-aks/iac/helm/app/templates/celery-beat-deployment.yaml +34 -0
- package/templates/azure-aks/iac/helm/app/templates/celery-worker-deployment.yaml +31 -0
- package/templates/azure-aks/iac/helm/app/templates/configmap.yaml +15 -0
- package/templates/azure-aks/iac/helm/app/templates/flower-deployment.yaml +28 -0
- package/templates/azure-aks/iac/helm/app/templates/flower-service.yaml +19 -0
- package/templates/azure-aks/iac/helm/app/templates/frontend-deployment.yaml +34 -0
- package/templates/azure-aks/iac/helm/app/templates/frontend-service.yaml +16 -0
- package/templates/azure-aks/iac/helm/app/templates/helpers.tpl +90 -0
- package/templates/azure-aks/iac/helm/app/templates/hpa.yaml +23 -0
- package/templates/azure-aks/iac/helm/app/templates/ingress.yaml +35 -0
- package/templates/azure-aks/iac/helm/app/templates/migration-job.yaml +38 -0
- package/templates/azure-aks/iac/helm/app/templates/redis-deployment.yaml +33 -0
- package/templates/azure-aks/iac/helm/app/templates/redis-service.yaml +18 -0
- package/templates/azure-aks/iac/helm/app/templates/secret.yaml +17 -0
- package/templates/azure-aks/iac/helm/app/templates/serviceaccount.yaml +12 -0
- package/templates/azure-aks/iac/helm/app/values-dev.yaml.hbs +36 -0
- package/templates/azure-aks/iac/helm/app/values.yaml.hbs +147 -0
- package/templates/azure-aks/iac/runner/Dockerfile +61 -0
- package/templates/azure-aks/iac/terraform/bootstrap/main.tf.hbs +123 -0
- package/templates/azure-aks/iac/terraform/bootstrap/outputs.tf +24 -0
- package/templates/azure-aks/iac/terraform/bootstrap/variables.tf.hbs +23 -0
- package/templates/azure-aks/iac/terraform/environments/dev/backend.hcl.hbs +25 -0
- package/templates/azure-aks/iac/terraform/environments/dev/terraform.tfvars.hbs +65 -0
- package/templates/azure-aks/iac/terraform/main.tf.hbs +307 -0
- package/templates/azure-aks/iac/terraform/outputs.tf.hbs +57 -0
- package/templates/azure-aks/iac/terraform/providers.tf +35 -0
- package/templates/azure-aks/iac/terraform/variables.tf.hbs +157 -0
- package/templates/azure-aks/iac/terraform/versions.tf +29 -0
- package/templates/base/CLAUDE.md.hbs +7 -7
- package/templates/base/docs/docs/dude.md.hbs +1 -1
- package/templates/base/docs/docs/index.md.hbs +1 -1
- package/templates/base/docs/mkdocs.yml.hbs +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { existsSync as
|
|
3
|
-
import
|
|
2
|
+
import { existsSync as existsSync20, readFileSync as readFileSync14 } from "fs";
|
|
3
|
+
import path23 from "pathe";
|
|
4
4
|
import yaml2 from "yaml";
|
|
5
5
|
import {
|
|
6
6
|
defineStack,
|
|
@@ -412,12 +412,12 @@ var rollbackCommand = {
|
|
|
412
412
|
};
|
|
413
413
|
|
|
414
414
|
// src/commands/iac/providers/aws-eks/lib/terraform.ts
|
|
415
|
-
import { existsSync as
|
|
415
|
+
import { existsSync as existsSync5, readdirSync as readdirSync2, readFileSync as readFileSync4 } from "fs";
|
|
416
416
|
import path5 from "pathe";
|
|
417
417
|
|
|
418
418
|
// src/commands/iac/shared.ts
|
|
419
419
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
420
|
-
import { readFileSync as readFileSync2 } from "fs";
|
|
420
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
|
|
421
421
|
import path3 from "pathe";
|
|
422
422
|
function shouldUseShell() {
|
|
423
423
|
return process.platform === "win32";
|
|
@@ -426,10 +426,13 @@ function childEnv(profile) {
|
|
|
426
426
|
return profile ? { ...process.env, AWS_PROFILE: profile } : process.env;
|
|
427
427
|
}
|
|
428
428
|
function run(cmd, args, cwd, profile) {
|
|
429
|
+
return runWith(cmd, args, cwd, childEnv(profile));
|
|
430
|
+
}
|
|
431
|
+
function runWith(cmd, args, cwd, env) {
|
|
429
432
|
const r = spawnSync2(cmd, args, {
|
|
430
433
|
cwd,
|
|
431
434
|
stdio: "inherit",
|
|
432
|
-
env
|
|
435
|
+
env,
|
|
433
436
|
shell: shouldUseShell()
|
|
434
437
|
});
|
|
435
438
|
if (r.error) {
|
|
@@ -450,10 +453,13 @@ function run(cmd, args, cwd, profile) {
|
|
|
450
453
|
return r.status ?? 1;
|
|
451
454
|
}
|
|
452
455
|
function capture(cmd, args, cwd, profile) {
|
|
456
|
+
return captureWith(cmd, args, cwd, childEnv(profile));
|
|
457
|
+
}
|
|
458
|
+
function captureWith(cmd, args, cwd, env) {
|
|
453
459
|
const r = spawnSync2(cmd, args, {
|
|
454
460
|
cwd,
|
|
455
461
|
encoding: "utf8",
|
|
456
|
-
env
|
|
462
|
+
env,
|
|
457
463
|
shell: shouldUseShell()
|
|
458
464
|
});
|
|
459
465
|
return { status: r.status ?? 1, stdout: r.stdout ?? "" };
|
|
@@ -472,6 +478,11 @@ function readAnswers(projectRoot) {
|
|
|
472
478
|
return {};
|
|
473
479
|
}
|
|
474
480
|
}
|
|
481
|
+
function iacTarget(projectRoot) {
|
|
482
|
+
const answer = readAnswers(projectRoot).iac;
|
|
483
|
+
if (typeof answer === "string" && answer && answer !== "none") return answer;
|
|
484
|
+
return existsSync3(path3.join(projectRoot, "iac", "terraform")) ? "aws-eks" : "";
|
|
485
|
+
}
|
|
475
486
|
function projectName(projectRoot) {
|
|
476
487
|
const name = readAnswers(projectRoot).projectName;
|
|
477
488
|
return typeof name === "string" && name ? name : "app";
|
|
@@ -487,7 +498,7 @@ import { spawnSync as spawnSync4 } from "child_process";
|
|
|
487
498
|
// src/commands/iac/providers/aws-eks/lib/runner.ts
|
|
488
499
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
489
500
|
import { createHash } from "crypto";
|
|
490
|
-
import { existsSync as
|
|
501
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
|
|
491
502
|
import os from "os";
|
|
492
503
|
import path4 from "pathe";
|
|
493
504
|
var RUNNER_DOCKERFILE = path4.join("iac", "runner", "Dockerfile");
|
|
@@ -496,7 +507,7 @@ function findDockerfile(cwd) {
|
|
|
496
507
|
let dir = path4.resolve(cwd);
|
|
497
508
|
for (; ; ) {
|
|
498
509
|
const candidate = path4.join(dir, RUNNER_DOCKERFILE);
|
|
499
|
-
if (
|
|
510
|
+
if (existsSync4(candidate)) return candidate;
|
|
500
511
|
const parent = path4.dirname(dir);
|
|
501
512
|
if (parent === dir) return "";
|
|
502
513
|
dir = parent;
|
|
@@ -548,7 +559,7 @@ function baseDockerArgs(cwd, profile, tty) {
|
|
|
548
559
|
const home = os.homedir();
|
|
549
560
|
args.push("-v", `${path4.join(home, ".aws")}:/root/.aws:ro`);
|
|
550
561
|
const kube = path4.join(home, ".kube");
|
|
551
|
-
if (
|
|
562
|
+
if (existsSync4(kube)) args.push("-v", `${kube}:/root/.kube:ro`);
|
|
552
563
|
if (profile) args.push("-e", `AWS_PROFILE=${profile}`);
|
|
553
564
|
return args;
|
|
554
565
|
}
|
|
@@ -624,8 +635,9 @@ var TF_DIR = path5.join("iac", "terraform");
|
|
|
624
635
|
var TF_BOOTSTRAP_DIR = path5.join(TF_DIR, "bootstrap");
|
|
625
636
|
var TF_ENVIRONMENTS_DIR = path5.join(TF_DIR, "environments");
|
|
626
637
|
var HELM_CHART = path5.join("iac", "helm", "app");
|
|
638
|
+
var PROVIDER_ID = "aws-eks";
|
|
627
639
|
function hasIac(projectRoot) {
|
|
628
|
-
return
|
|
640
|
+
return iacTarget(projectRoot) === PROVIDER_ID && existsSync5(path5.join(projectRoot, "iac", "terraform"));
|
|
629
641
|
}
|
|
630
642
|
function requireIac(projectRoot) {
|
|
631
643
|
if (!hasIac(projectRoot)) {
|
|
@@ -708,7 +720,7 @@ function listEnvironments(projectRoot) {
|
|
|
708
720
|
const base = path5.join(projectRoot, TF_ENVIRONMENTS_DIR);
|
|
709
721
|
try {
|
|
710
722
|
return readdirSync2(base, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).filter(
|
|
711
|
-
(name) =>
|
|
723
|
+
(name) => existsSync5(path5.join(base, name, "backend.hcl")) && existsSync5(path5.join(base, name, "terraform.tfvars"))
|
|
712
724
|
).sort();
|
|
713
725
|
} catch {
|
|
714
726
|
return [];
|
|
@@ -883,7 +895,7 @@ var iacBootstrapCommand = {
|
|
|
883
895
|
// src/commands/iac/providers/aws-eks/lib/images.ts
|
|
884
896
|
import { spawnSync as spawnSync5 } from "child_process";
|
|
885
897
|
import { createHash as createHash2 } from "crypto";
|
|
886
|
-
import { existsSync as
|
|
898
|
+
import { existsSync as existsSync6 } from "fs";
|
|
887
899
|
import path7 from "pathe";
|
|
888
900
|
var tagArg = {
|
|
889
901
|
tag: {
|
|
@@ -1083,7 +1095,7 @@ function doDeploy(projectRoot, profile, env, ns, tag, repos) {
|
|
|
1083
1095
|
"--create-namespace"
|
|
1084
1096
|
];
|
|
1085
1097
|
const valuesFile = path7.join(HELM_CHART, `values-${env}.yaml`);
|
|
1086
|
-
if (
|
|
1098
|
+
if (existsSync6(path7.join(projectRoot, valuesFile))) helmArgs.push("--values", valuesFile);
|
|
1087
1099
|
helmArgs.push(
|
|
1088
1100
|
"--set",
|
|
1089
1101
|
`image.registry=${repos.registryHost}`,
|
|
@@ -1719,7 +1731,7 @@ var iacLoginCommand = {
|
|
|
1719
1731
|
};
|
|
1720
1732
|
|
|
1721
1733
|
// src/commands/iac/providers/aws-eks/commands/new-env/index.ts
|
|
1722
|
-
import { cpSync, existsSync as
|
|
1734
|
+
import { cpSync, existsSync as existsSync7, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "fs";
|
|
1723
1735
|
import path8 from "pathe";
|
|
1724
1736
|
var iacNewEnvCommand = {
|
|
1725
1737
|
available: hasIac,
|
|
@@ -1788,7 +1800,7 @@ var iacNewEnvCommand = {
|
|
|
1788
1800
|
)
|
|
1789
1801
|
);
|
|
1790
1802
|
const fromValues = path8.join(projectRoot, HELM_CHART, `values-${from}.yaml`);
|
|
1791
|
-
const copiedValues =
|
|
1803
|
+
const copiedValues = existsSync7(fromValues);
|
|
1792
1804
|
if (copiedValues) {
|
|
1793
1805
|
cpSync(fromValues, path8.join(projectRoot, HELM_CHART, `values-${name}.yaml`));
|
|
1794
1806
|
}
|
|
@@ -1998,262 +2010,2523 @@ var awsEksProvider = {
|
|
|
1998
2010
|
}
|
|
1999
2011
|
};
|
|
2000
2012
|
|
|
2001
|
-
// src/commands/iac/
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
return iacProviders.find((p) => p.detect(projectRoot));
|
|
2005
|
-
}
|
|
2006
|
-
var provider = activeIacProvider() ?? iacProviders[0];
|
|
2007
|
-
var iacCommands = provider?.commands ?? {};
|
|
2013
|
+
// src/commands/iac/providers/azure-aca/lib/images.ts
|
|
2014
|
+
import { readFileSync as readFileSync9, writeFileSync as writeFileSync4 } from "fs";
|
|
2015
|
+
import path12 from "pathe";
|
|
2008
2016
|
|
|
2009
|
-
// src/commands/
|
|
2010
|
-
import {
|
|
2011
|
-
|
|
2012
|
-
const result = spawnSync7("docker", ["compose", ...args], { stdio: "inherit" });
|
|
2013
|
-
process.exit(result.status ?? 0);
|
|
2014
|
-
}
|
|
2017
|
+
// src/commands/iac/providers/azure-aca/lib/terraform.ts
|
|
2018
|
+
import { existsSync as existsSync10 } from "fs";
|
|
2019
|
+
import path11 from "pathe";
|
|
2015
2020
|
|
|
2016
|
-
// src/commands/
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
args: {},
|
|
2020
|
-
async run() {
|
|
2021
|
-
dc(["down"]);
|
|
2022
|
-
}
|
|
2023
|
-
};
|
|
2021
|
+
// src/commands/iac/azure/terraform.ts
|
|
2022
|
+
import { existsSync as existsSync9, readdirSync as readdirSync3, readFileSync as readFileSync8 } from "fs";
|
|
2023
|
+
import path10 from "pathe";
|
|
2024
2024
|
|
|
2025
|
-
// src/commands/
|
|
2025
|
+
// src/commands/iac/azure/exec.ts
|
|
2026
2026
|
import { spawnSync as spawnSync8 } from "child_process";
|
|
2027
|
-
|
|
2027
|
+
|
|
2028
|
+
// src/commands/iac/azure/runner.ts
|
|
2029
|
+
import { spawnSync as spawnSync7 } from "child_process";
|
|
2030
|
+
import { createHash as createHash3 } from "crypto";
|
|
2031
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7 } from "fs";
|
|
2032
|
+
import os2 from "os";
|
|
2028
2033
|
import path9 from "pathe";
|
|
2029
|
-
|
|
2030
|
-
|
|
2034
|
+
var RUNNER_DOCKERFILE2 = path9.join("iac", "runner", "Dockerfile");
|
|
2035
|
+
var CONTAINERIZED2 = /* @__PURE__ */ new Set(["terraform", "kubectl", "helm", "k9s"]);
|
|
2036
|
+
function findDockerfile2(cwd) {
|
|
2037
|
+
let dir = path9.resolve(cwd);
|
|
2038
|
+
for (; ; ) {
|
|
2039
|
+
const candidate = path9.join(dir, RUNNER_DOCKERFILE2);
|
|
2040
|
+
if (existsSync8(candidate)) return candidate;
|
|
2041
|
+
const parent = path9.dirname(dir);
|
|
2042
|
+
if (parent === dir) return "";
|
|
2043
|
+
dir = parent;
|
|
2044
|
+
}
|
|
2031
2045
|
}
|
|
2032
|
-
function
|
|
2033
|
-
const
|
|
2034
|
-
return
|
|
2046
|
+
function imageTag2(dockerfile) {
|
|
2047
|
+
const hash = createHash3("sha256").update(readFileSync7(dockerfile)).digest("hex").slice(0, 12);
|
|
2048
|
+
return `dude-iac-runner-azure:${hash}`;
|
|
2035
2049
|
}
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
}
|
|
2043
|
-
|
|
2050
|
+
var dockerChecked2;
|
|
2051
|
+
var ensured2 = /* @__PURE__ */ new Set();
|
|
2052
|
+
function dockerAvailable2() {
|
|
2053
|
+
if (dockerChecked2 !== void 0) return dockerChecked2;
|
|
2054
|
+
const r = spawnSync7("docker", ["version", "--format", "{{.Server.Version}}"], {
|
|
2055
|
+
encoding: "utf8"
|
|
2056
|
+
});
|
|
2057
|
+
dockerChecked2 = r.status === 0 && !!r.stdout.trim();
|
|
2058
|
+
return dockerChecked2;
|
|
2044
2059
|
}
|
|
2045
|
-
function
|
|
2046
|
-
|
|
2047
|
-
return
|
|
2060
|
+
function useRunner2(cwd) {
|
|
2061
|
+
if (process.env.DUDE_IAC_RUNNER === "host") return false;
|
|
2062
|
+
return dockerAvailable2() && !!findDockerfile2(cwd);
|
|
2048
2063
|
}
|
|
2049
|
-
function
|
|
2050
|
-
|
|
2051
|
-
const
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2064
|
+
function ensureImage2(dockerfile, tag) {
|
|
2065
|
+
if (ensured2.has(tag)) return;
|
|
2066
|
+
const exists = spawnSync7("docker", ["image", "inspect", tag], { stdio: "ignore" }).status === 0;
|
|
2067
|
+
if (!exists) {
|
|
2068
|
+
process.stderr.write(
|
|
2069
|
+
`
|
|
2070
|
+
\u2192 Building the IaC runner image (${tag}). First run only \u2014 a minute or two\u2026
|
|
2071
|
+
|
|
2072
|
+
`
|
|
2073
|
+
);
|
|
2074
|
+
const build = spawnSync7(
|
|
2075
|
+
"docker",
|
|
2076
|
+
["build", "-t", tag, "-f", dockerfile, path9.dirname(dockerfile)],
|
|
2077
|
+
{ stdio: "inherit" }
|
|
2078
|
+
);
|
|
2079
|
+
if (build.status !== 0) {
|
|
2080
|
+
process.stderr.write("\n \u2717 Failed to build the IaC runner image.\n\n");
|
|
2081
|
+
process.exit(build.status ?? 1);
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
ensured2.add(tag);
|
|
2059
2085
|
}
|
|
2060
|
-
function
|
|
2061
|
-
const
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2086
|
+
function baseDockerArgs2(cwd, subscription, tty) {
|
|
2087
|
+
const args = ["run", "--rm", tty ? "-it" : "-i"];
|
|
2088
|
+
args.push("-v", `${cwd}:/work`, "-w", "/work");
|
|
2089
|
+
const home = os2.homedir();
|
|
2090
|
+
const azure = path9.join(home, ".azure");
|
|
2091
|
+
if (existsSync8(azure)) args.push("-v", `${azure}:/root/.azure`);
|
|
2092
|
+
const kube = path9.join(home, ".kube");
|
|
2093
|
+
if (existsSync8(kube)) args.push("-v", `${kube}:/root/.kube:ro`);
|
|
2094
|
+
if (subscription) {
|
|
2095
|
+
args.push("-e", `ARM_SUBSCRIPTION_ID=${subscription}`);
|
|
2096
|
+
args.push("-e", `AZURE_SUBSCRIPTION_ID=${subscription}`);
|
|
2097
|
+
}
|
|
2098
|
+
return args;
|
|
2065
2099
|
}
|
|
2066
|
-
function
|
|
2067
|
-
|
|
2068
|
-
stdio: "pipe",
|
|
2069
|
-
cwd
|
|
2070
|
-
});
|
|
2071
|
-
return r.status === 0 && r.stdout != null && r.stdout.toString().trim().length > 0;
|
|
2100
|
+
function shq2(value) {
|
|
2101
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
2072
2102
|
}
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
},
|
|
2082
|
-
async run({ projectRoot, args }) {
|
|
2083
|
-
const check = Boolean(args.check);
|
|
2084
|
-
const backendDir = path9.join(projectRoot, "backend");
|
|
2085
|
-
const frontendDir = path9.join(projectRoot, "frontend");
|
|
2086
|
-
const e2eDir = path9.join(projectRoot, "e2e");
|
|
2087
|
-
const backendExists = existsSync7(backendDir);
|
|
2088
|
-
const backendContainerUp = backendExists && isDockerServiceRunning("backend", projectRoot);
|
|
2089
|
-
const missing = [];
|
|
2090
|
-
if (backendExists && !backendContainerUp && !isAvailable("uv"))
|
|
2091
|
-
missing.push("uv \u2192 https://docs.astral.sh/uv/getting-started/installation/");
|
|
2092
|
-
if ((existsSync7(frontendDir) || existsSync7(e2eDir)) && !isAvailable("pnpm"))
|
|
2093
|
-
missing.push("pnpm \u2192 https://pnpm.io/installation");
|
|
2094
|
-
if (missing.length > 0) {
|
|
2095
|
-
process.stderr.write(
|
|
2096
|
-
"error: the following tools are required but were not found on your PATH:\n\n"
|
|
2097
|
-
);
|
|
2098
|
-
for (const m of missing) process.stderr.write(` \u2022 ${m}
|
|
2099
|
-
`);
|
|
2100
|
-
process.stderr.write("\n");
|
|
2101
|
-
process.exit(1);
|
|
2102
|
-
}
|
|
2103
|
-
let ok = true;
|
|
2104
|
-
if (backendExists) {
|
|
2105
|
-
process.stdout.write(check ? "Checking backend formatting\u2026\n" : "Formatting backend\u2026\n");
|
|
2106
|
-
if (backendContainerUp) {
|
|
2107
|
-
ok = exec(
|
|
2108
|
-
"docker",
|
|
2109
|
-
[
|
|
2110
|
-
"compose",
|
|
2111
|
-
"exec",
|
|
2112
|
-
"backend",
|
|
2113
|
-
"uv",
|
|
2114
|
-
"run",
|
|
2115
|
-
"ruff",
|
|
2116
|
-
"format",
|
|
2117
|
-
...check ? ["--check"] : [],
|
|
2118
|
-
"app/"
|
|
2119
|
-
],
|
|
2120
|
-
projectRoot
|
|
2121
|
-
) && ok;
|
|
2122
|
-
ok = exec(
|
|
2123
|
-
"docker",
|
|
2124
|
-
[
|
|
2125
|
-
"compose",
|
|
2126
|
-
"exec",
|
|
2127
|
-
"backend",
|
|
2128
|
-
"uv",
|
|
2129
|
-
"run",
|
|
2130
|
-
"ruff",
|
|
2131
|
-
"check",
|
|
2132
|
-
"--select",
|
|
2133
|
-
"I",
|
|
2134
|
-
...check ? [] : ["--fix"],
|
|
2135
|
-
"app/"
|
|
2136
|
-
],
|
|
2137
|
-
projectRoot
|
|
2138
|
-
) && ok;
|
|
2139
|
-
} else {
|
|
2140
|
-
const venvReady = ensureVenv(backendDir);
|
|
2141
|
-
if (!venvReady) {
|
|
2142
|
-
process.stderr.write("error: uv sync failed in backend/\n");
|
|
2143
|
-
ok = false;
|
|
2144
|
-
}
|
|
2145
|
-
if (venvReady) {
|
|
2146
|
-
ok = exec("uv", ["run", "ruff", "format", ...check ? ["--check"] : [], "."], backendDir) && ok;
|
|
2147
|
-
ok = exec(
|
|
2148
|
-
"uv",
|
|
2149
|
-
["run", "ruff", "check", "--select", "I", ...check ? [] : ["--fix"], "."],
|
|
2150
|
-
backendDir
|
|
2151
|
-
) && ok;
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
if (existsSync7(frontendDir)) {
|
|
2156
|
-
process.stdout.write(check ? "Checking frontend formatting\u2026\n" : "Formatting frontend\u2026\n");
|
|
2157
|
-
const prettierBin = path9.join(frontendDir, "node_modules", ".bin", "prettier");
|
|
2158
|
-
if (!existsSync7(prettierBin)) {
|
|
2159
|
-
ensureNodeModules(frontendDir, "prettier");
|
|
2160
|
-
}
|
|
2161
|
-
if (!existsSync7(prettierBin)) {
|
|
2162
|
-
process.stderr.write(" prettier not found \u2014 run: cd frontend && npm install\n");
|
|
2163
|
-
ok = false;
|
|
2164
|
-
} else {
|
|
2165
|
-
ok = exec(prettierBin, [...check ? ["--check"] : ["--write"], "src/"], frontendDir) && ok;
|
|
2166
|
-
}
|
|
2167
|
-
}
|
|
2168
|
-
if (existsSync7(e2eDir)) {
|
|
2169
|
-
process.stdout.write(check ? "Checking e2e formatting\u2026\n" : "Formatting e2e\u2026\n");
|
|
2170
|
-
const prettierBin = path9.join(e2eDir, "node_modules", ".bin", "prettier");
|
|
2171
|
-
if (!existsSync7(prettierBin)) {
|
|
2172
|
-
ensureNodeModules(e2eDir, "prettier");
|
|
2173
|
-
}
|
|
2174
|
-
if (!existsSync7(prettierBin)) {
|
|
2175
|
-
process.stderr.write(" prettier not found \u2014 run: cd e2e && npm install\n");
|
|
2176
|
-
ok = false;
|
|
2177
|
-
} else {
|
|
2178
|
-
ok = exec(
|
|
2179
|
-
prettierBin,
|
|
2180
|
-
[
|
|
2181
|
-
...check ? ["--check"] : ["--write"],
|
|
2182
|
-
"**/*.{ts,json}",
|
|
2183
|
-
"--ignore-path",
|
|
2184
|
-
".prettierignore"
|
|
2185
|
-
],
|
|
2186
|
-
e2eDir
|
|
2187
|
-
) && ok;
|
|
2188
|
-
}
|
|
2189
|
-
}
|
|
2190
|
-
if (!ok) process.exit(1);
|
|
2103
|
+
function dockerRunArgs2(cmd, toolArgs, cwd, subscription, opts = {}) {
|
|
2104
|
+
const dockerfile = findDockerfile2(cwd);
|
|
2105
|
+
const tag = imageTag2(dockerfile);
|
|
2106
|
+
ensureImage2(dockerfile, tag);
|
|
2107
|
+
const base = baseDockerArgs2(cwd, subscription, !!opts.tty);
|
|
2108
|
+
if (opts.prelude?.length) {
|
|
2109
|
+
const script = [...opts.prelude, `exec ${cmd} "$@"`].join("\n");
|
|
2110
|
+
return [...base, tag, "bash", "-c", script, "bash", ...toolArgs];
|
|
2191
2111
|
}
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
args: {
|
|
2202
|
-
service: {
|
|
2203
|
-
type: "string",
|
|
2204
|
-
description: "Service name (omit to follow all services).",
|
|
2205
|
-
required: false
|
|
2206
|
-
}
|
|
2207
|
-
},
|
|
2208
|
-
async run({ args }) {
|
|
2209
|
-
const svc = typeof args.service === "string" && args.service ? args.service : null;
|
|
2210
|
-
dc(svc ? ["logs", "-f", svc] : ["logs", "-f"]);
|
|
2112
|
+
return [...base, tag, cmd, ...toolArgs];
|
|
2113
|
+
}
|
|
2114
|
+
function dockerShellArgs2(projectRoot, subscription, prelude) {
|
|
2115
|
+
const dockerfile = findDockerfile2(projectRoot);
|
|
2116
|
+
const tag = imageTag2(dockerfile);
|
|
2117
|
+
ensureImage2(dockerfile, tag);
|
|
2118
|
+
const base = baseDockerArgs2(projectRoot, subscription, true);
|
|
2119
|
+
if (prelude?.length) {
|
|
2120
|
+
return [...base, tag, "bash", "-c", [...prelude, "exec bash"].join("\n")];
|
|
2211
2121
|
}
|
|
2212
|
-
|
|
2122
|
+
return [...base, tag, "bash"];
|
|
2123
|
+
}
|
|
2124
|
+
function hasRunnerDockerfile2(cwd) {
|
|
2125
|
+
return !!findDockerfile2(cwd);
|
|
2126
|
+
}
|
|
2213
2127
|
|
|
2214
|
-
// src/commands/
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2128
|
+
// src/commands/iac/azure/exec.ts
|
|
2129
|
+
function azureEnv(subscription) {
|
|
2130
|
+
if (!subscription) return process.env;
|
|
2131
|
+
return {
|
|
2132
|
+
...process.env,
|
|
2133
|
+
ARM_SUBSCRIPTION_ID: subscription,
|
|
2134
|
+
AZURE_SUBSCRIPTION_ID: subscription
|
|
2135
|
+
};
|
|
2221
2136
|
}
|
|
2222
|
-
function
|
|
2223
|
-
|
|
2224
|
-
return r.error == null;
|
|
2137
|
+
function routed2(cmd, cwd) {
|
|
2138
|
+
return CONTAINERIZED2.has(cmd) && useRunner2(cwd);
|
|
2225
2139
|
}
|
|
2226
|
-
function
|
|
2227
|
-
|
|
2140
|
+
function run3(cmd, args, cwd, subscription, prelude) {
|
|
2141
|
+
if (!routed2(cmd, cwd)) return runWith(cmd, args, cwd, azureEnv(subscription));
|
|
2142
|
+
const dargs = dockerRunArgs2(cmd, args, cwd, subscription, {
|
|
2143
|
+
tty: !!process.stdin.isTTY,
|
|
2144
|
+
prelude
|
|
2145
|
+
});
|
|
2146
|
+
const r = spawnSync8("docker", dargs, { stdio: "inherit" });
|
|
2228
2147
|
if (r.error) {
|
|
2229
|
-
process.stderr.write(`
|
|
2148
|
+
process.stderr.write(`
|
|
2149
|
+
\u2717 failed to run docker: ${r.error.message}
|
|
2150
|
+
|
|
2230
2151
|
`);
|
|
2231
|
-
return
|
|
2152
|
+
return 1;
|
|
2232
2153
|
}
|
|
2233
|
-
return r.status
|
|
2154
|
+
return r.status ?? 1;
|
|
2234
2155
|
}
|
|
2235
|
-
function
|
|
2236
|
-
|
|
2237
|
-
const
|
|
2238
|
-
const
|
|
2239
|
-
|
|
2240
|
-
\x1B[1m${header}\x1B[0m
|
|
2241
|
-
` : `
|
|
2242
|
-
${header}
|
|
2243
|
-
`);
|
|
2156
|
+
function capture3(cmd, args, cwd, subscription, prelude) {
|
|
2157
|
+
if (!routed2(cmd, cwd)) return captureWith(cmd, args, cwd, azureEnv(subscription));
|
|
2158
|
+
const dargs = dockerRunArgs2(cmd, args, cwd, subscription, { tty: false, prelude });
|
|
2159
|
+
const r = spawnSync8("docker", dargs, { encoding: "utf8" });
|
|
2160
|
+
return { status: r.status ?? 1, stdout: r.stdout ?? "" };
|
|
2244
2161
|
}
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2162
|
+
|
|
2163
|
+
// src/commands/iac/azure/terraform.ts
|
|
2164
|
+
var TF_DIR2 = path10.join("iac", "terraform");
|
|
2165
|
+
var TF_BOOTSTRAP_DIR2 = path10.join(TF_DIR2, "bootstrap");
|
|
2166
|
+
var TF_ENVIRONMENTS_DIR2 = path10.join(TF_DIR2, "environments");
|
|
2167
|
+
function tf2(projectRoot, args, subscription) {
|
|
2168
|
+
return run3("terraform", [`-chdir=${TF_DIR2}`, ...args], projectRoot, subscription);
|
|
2169
|
+
}
|
|
2170
|
+
function tfOutputRaw2(projectRoot, name, subscription) {
|
|
2171
|
+
const r = capture3(
|
|
2172
|
+
"terraform",
|
|
2173
|
+
[`-chdir=${TF_DIR2}`, "output", "-raw", name],
|
|
2174
|
+
projectRoot,
|
|
2175
|
+
subscription
|
|
2176
|
+
);
|
|
2177
|
+
const value = r.stdout.trim();
|
|
2178
|
+
return r.status === 0 && value && !/\s/.test(value) ? value : "";
|
|
2179
|
+
}
|
|
2180
|
+
function tfOutputs(projectRoot, subscription) {
|
|
2181
|
+
const out = capture3(
|
|
2182
|
+
"terraform",
|
|
2183
|
+
[`-chdir=${TF_DIR2}`, "output", "-json"],
|
|
2184
|
+
projectRoot,
|
|
2185
|
+
subscription
|
|
2186
|
+
);
|
|
2187
|
+
if (out.status !== 0) return null;
|
|
2188
|
+
try {
|
|
2189
|
+
return JSON.parse(out.stdout);
|
|
2190
|
+
} catch {
|
|
2191
|
+
return null;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
function backendConfig2(env) {
|
|
2195
|
+
return `-backend-config=environments/${env}/backend.hcl`;
|
|
2196
|
+
}
|
|
2197
|
+
function varFile2(env) {
|
|
2198
|
+
return `-var-file=environments/${env}/terraform.tfvars`;
|
|
2199
|
+
}
|
|
2200
|
+
function tfBoot2(projectRoot, args, subscription) {
|
|
2201
|
+
return run3("terraform", args, path10.join(projectRoot, TF_BOOTSTRAP_DIR2), subscription);
|
|
2202
|
+
}
|
|
2203
|
+
function captureBootstrap2(projectRoot, args, subscription) {
|
|
2204
|
+
return capture3("terraform", args, path10.join(projectRoot, TF_BOOTSTRAP_DIR2), subscription);
|
|
2205
|
+
}
|
|
2206
|
+
function tfvarsValue2(projectRoot, env, key) {
|
|
2207
|
+
try {
|
|
2208
|
+
return hclScalar(
|
|
2209
|
+
readFileSync8(path10.join(projectRoot, TF_DIR2, "environments", env, "terraform.tfvars"), "utf8"),
|
|
2210
|
+
key
|
|
2211
|
+
);
|
|
2212
|
+
} catch {
|
|
2213
|
+
return "";
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
function resolveSubscription(projectRoot, args, env) {
|
|
2217
|
+
if (args.subscription) return String(args.subscription);
|
|
2218
|
+
const pinned = tfvarsValue2(projectRoot, env, "subscription_id");
|
|
2219
|
+
if (pinned) return pinned;
|
|
2220
|
+
const exported = process.env.ARM_SUBSCRIPTION_ID || process.env.AZURE_SUBSCRIPTION_ID;
|
|
2221
|
+
if (exported) return exported;
|
|
2222
|
+
const r = captureWith(
|
|
2223
|
+
"az",
|
|
2224
|
+
["account", "show", "--query", "id", "--output", "tsv"],
|
|
2225
|
+
projectRoot,
|
|
2226
|
+
process.env
|
|
2227
|
+
);
|
|
2228
|
+
return r.status === 0 ? r.stdout.trim() : "";
|
|
2229
|
+
}
|
|
2230
|
+
function readBackend2(projectRoot, env) {
|
|
2231
|
+
try {
|
|
2232
|
+
const txt = readFileSync8(
|
|
2233
|
+
path10.join(projectRoot, TF_DIR2, "environments", env, "backend.hcl"),
|
|
2234
|
+
"utf8"
|
|
2235
|
+
);
|
|
2236
|
+
return {
|
|
2237
|
+
resourceGroup: hclScalar(txt, "resource_group_name"),
|
|
2238
|
+
storageAccount: hclScalar(txt, "storage_account_name"),
|
|
2239
|
+
container: hclScalar(txt, "container_name"),
|
|
2240
|
+
key: hclScalar(txt, "key")
|
|
2241
|
+
};
|
|
2242
|
+
} catch {
|
|
2243
|
+
return { resourceGroup: "", storageAccount: "", container: "", key: "" };
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
var envArg2 = {
|
|
2247
|
+
env: {
|
|
2248
|
+
type: "string",
|
|
2249
|
+
description: "Target environment (required) \u2014 one of iac/terraform/environments/*."
|
|
2250
|
+
},
|
|
2251
|
+
subscription: {
|
|
2252
|
+
type: "string",
|
|
2253
|
+
description: "Azure subscription id (default: subscription_id in the env tfvars, $ARM_SUBSCRIPTION_ID, or your az default)."
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
function listEnvironments2(projectRoot) {
|
|
2257
|
+
const base = path10.join(projectRoot, TF_ENVIRONMENTS_DIR2);
|
|
2258
|
+
try {
|
|
2259
|
+
return readdirSync3(base, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).filter(
|
|
2260
|
+
(name) => existsSync9(path10.join(base, name, "backend.hcl")) && existsSync9(path10.join(base, name, "terraform.tfvars"))
|
|
2261
|
+
).sort();
|
|
2262
|
+
} catch {
|
|
2263
|
+
return [];
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
function requireEnv2(projectRoot, args) {
|
|
2267
|
+
const envs = listEnvironments2(projectRoot);
|
|
2268
|
+
const available = envs.length ? envs.join(", ") : "(none \u2014 create one first)";
|
|
2269
|
+
const raw = args.env == null ? "" : String(args.env);
|
|
2270
|
+
if (!raw) {
|
|
2271
|
+
process.stderr.write(
|
|
2272
|
+
`
|
|
2273
|
+
\u2717 --env is required.
|
|
2274
|
+
Available environments: ${available}
|
|
2275
|
+
Create a new one with: dude iac new-env --env <name>
|
|
2276
|
+
|
|
2277
|
+
`
|
|
2278
|
+
);
|
|
2279
|
+
process.exit(1);
|
|
2280
|
+
}
|
|
2281
|
+
if (!/^[a-z][a-z0-9-]*$/.test(raw)) {
|
|
2282
|
+
process.stderr.write(`
|
|
2283
|
+
\u2717 invalid --env "${raw}" (expected lowercase kebab-case).
|
|
2284
|
+
|
|
2285
|
+
`);
|
|
2286
|
+
process.exit(1);
|
|
2287
|
+
}
|
|
2288
|
+
if (!envs.includes(raw)) {
|
|
2289
|
+
process.stderr.write(
|
|
2290
|
+
`
|
|
2291
|
+
\u2717 environment "${raw}" does not exist.
|
|
2292
|
+
An environment is a folder iac/terraform/environments/<name>/ with a
|
|
2293
|
+
backend.hcl and a terraform.tfvars. Available: ${available}
|
|
2294
|
+
Create it with: dude iac new-env --env ${raw}
|
|
2295
|
+
|
|
2296
|
+
`
|
|
2297
|
+
);
|
|
2298
|
+
process.exit(1);
|
|
2299
|
+
}
|
|
2300
|
+
return raw;
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
// src/commands/iac/providers/azure-aca/lib/terraform.ts
|
|
2304
|
+
var PROVIDER_ID2 = "azure-aca";
|
|
2305
|
+
function hasIac2(projectRoot) {
|
|
2306
|
+
return iacTarget(projectRoot) === PROVIDER_ID2 && existsSync10(path11.join(projectRoot, "iac", "terraform"));
|
|
2307
|
+
}
|
|
2308
|
+
function requireIac2(projectRoot) {
|
|
2309
|
+
if (!hasIac2(projectRoot)) {
|
|
2310
|
+
process.stderr.write(
|
|
2311
|
+
"\n \u2717 No Azure Container Apps IaC configuration found (iac/terraform).\n This project was not initialised with the azure-aca target.\n Re-scaffold with `--iac azure-aca` to enable it.\n\n"
|
|
2312
|
+
);
|
|
2313
|
+
return false;
|
|
2314
|
+
}
|
|
2315
|
+
return true;
|
|
2316
|
+
}
|
|
2317
|
+
function hasMigrations(projectRoot) {
|
|
2318
|
+
return existsSync10(path11.join(projectRoot, "backend", "alembic.ini"));
|
|
2319
|
+
}
|
|
2320
|
+
function resourceGroupFor(projectRoot, env) {
|
|
2321
|
+
return `${projectName(projectRoot)}-${env}-rg`;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
// src/commands/iac/azure/acr.ts
|
|
2325
|
+
import { spawnSync as spawnSync9 } from "child_process";
|
|
2326
|
+
import { createHash as createHash4 } from "crypto";
|
|
2327
|
+
var tagArg2 = {
|
|
2328
|
+
tag: {
|
|
2329
|
+
type: "string",
|
|
2330
|
+
description: "Image tag (default: git short SHA, plus -dirty-<hash> if there are uncommitted changes)."
|
|
2331
|
+
}
|
|
2332
|
+
};
|
|
2333
|
+
var platformArg2 = {
|
|
2334
|
+
platform: {
|
|
2335
|
+
type: "string",
|
|
2336
|
+
description: "Docker build platform (default linux/amd64, to match Azure x86 compute)."
|
|
2337
|
+
}
|
|
2338
|
+
};
|
|
2339
|
+
function reposFromEnvConfig(projectRoot, env) {
|
|
2340
|
+
const acrName = tfvarsValue2(projectRoot, env, "acr_name");
|
|
2341
|
+
if (!acrName || acrName.startsWith("CHANGE-ME")) return null;
|
|
2342
|
+
const registryHost = `${acrName}.azurecr.io`;
|
|
2343
|
+
const project = projectName(projectRoot);
|
|
2344
|
+
return {
|
|
2345
|
+
backend: `${registryHost}/${project}-backend`,
|
|
2346
|
+
frontend: `${registryHost}/${project}-frontend`,
|
|
2347
|
+
registryHost,
|
|
2348
|
+
registryName: acrName,
|
|
2349
|
+
location: tfvarsValue2(projectRoot, env, "location")
|
|
2350
|
+
};
|
|
2351
|
+
}
|
|
2352
|
+
function readAcrRepos(projectRoot, subscription, env) {
|
|
2353
|
+
const o = tfOutputs(projectRoot, subscription);
|
|
2354
|
+
const str = (k) => {
|
|
2355
|
+
const v = o?.[k]?.value;
|
|
2356
|
+
return typeof v === "string" ? v : "";
|
|
2357
|
+
};
|
|
2358
|
+
const backend = str("acr_backend_repository_url");
|
|
2359
|
+
const frontend = str("acr_frontend_repository_url");
|
|
2360
|
+
const registryHost = str("acr_login_server") || backend.split("/")[0] || "";
|
|
2361
|
+
if (!backend || !frontend || !registryHost) {
|
|
2362
|
+
return env ? reposFromEnvConfig(projectRoot, env) : null;
|
|
2363
|
+
}
|
|
2364
|
+
return {
|
|
2365
|
+
backend,
|
|
2366
|
+
frontend,
|
|
2367
|
+
registryHost,
|
|
2368
|
+
// `<name>.azurecr.io` → `<name>`; every `az acr` subcommand wants the bare name.
|
|
2369
|
+
registryName: registryHost.split(".")[0] ?? registryHost,
|
|
2370
|
+
location: str("location"),
|
|
2371
|
+
appUrl: str("app_url") || void 0
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
function requireAcrRepos(projectRoot, subscription, env) {
|
|
2375
|
+
const repos = readAcrRepos(projectRoot, subscription, env);
|
|
2376
|
+
if (!repos) {
|
|
2377
|
+
process.stderr.write(
|
|
2378
|
+
`
|
|
2379
|
+
\u2717 Could not determine the container registry for this environment.
|
|
2380
|
+
It is created by the bootstrap, which also records it in the env config:
|
|
2381
|
+
dude iac bootstrap --state-prefix <prefix> --env ${env ?? "<env>"} --yes
|
|
2382
|
+
|
|
2383
|
+
`
|
|
2384
|
+
);
|
|
2385
|
+
process.exit(1);
|
|
2386
|
+
}
|
|
2387
|
+
return repos;
|
|
2388
|
+
}
|
|
2389
|
+
function imagesPublished(projectRoot, subscription, tag, repos) {
|
|
2390
|
+
return [repos.backend, repos.frontend].every(
|
|
2391
|
+
(repo) => capture3(
|
|
2392
|
+
"az",
|
|
2393
|
+
[
|
|
2394
|
+
"acr",
|
|
2395
|
+
"repository",
|
|
2396
|
+
"show",
|
|
2397
|
+
"--name",
|
|
2398
|
+
repos.registryName,
|
|
2399
|
+
"--image",
|
|
2400
|
+
`${repoName2(repo)}:${tag}`,
|
|
2401
|
+
"--output",
|
|
2402
|
+
"none"
|
|
2403
|
+
],
|
|
2404
|
+
projectRoot,
|
|
2405
|
+
subscription
|
|
2406
|
+
).status === 0
|
|
2407
|
+
);
|
|
2408
|
+
}
|
|
2409
|
+
function resolveTag2(projectRoot, args) {
|
|
2410
|
+
if (args.tag) {
|
|
2411
|
+
const t = String(args.tag);
|
|
2412
|
+
if (!/^[\w][\w.-]{0,127}$/.test(t)) {
|
|
2413
|
+
process.stderr.write(`
|
|
2414
|
+
\u2717 invalid --tag "${t}" (not a valid Docker tag).
|
|
2415
|
+
|
|
2416
|
+
`);
|
|
2417
|
+
return null;
|
|
2418
|
+
}
|
|
2419
|
+
return t;
|
|
2420
|
+
}
|
|
2421
|
+
const sha = capture3("git", ["rev-parse", "--short=12", "HEAD"], projectRoot);
|
|
2422
|
+
if (sha.status !== 0 || !sha.stdout.trim()) {
|
|
2423
|
+
process.stderr.write(
|
|
2424
|
+
"\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"
|
|
2425
|
+
);
|
|
2426
|
+
return null;
|
|
2427
|
+
}
|
|
2428
|
+
const tag = sha.stdout.trim();
|
|
2429
|
+
const dirt = workingTreeDigest2(projectRoot);
|
|
2430
|
+
return dirt ? `${tag}-dirty-${dirt}` : tag;
|
|
2431
|
+
}
|
|
2432
|
+
function workingTreeDigest2(projectRoot) {
|
|
2433
|
+
const status = capture3("git", ["status", "--porcelain"], projectRoot);
|
|
2434
|
+
if (status.status !== 0 || status.stdout.trim() === "") return null;
|
|
2435
|
+
const diff = capture3("git", ["diff", "HEAD"], projectRoot);
|
|
2436
|
+
return createHash4("sha256").update(status.stdout).update(diff.status === 0 ? diff.stdout : "").digest("hex").slice(0, 8);
|
|
2437
|
+
}
|
|
2438
|
+
function repoName2(repositoryUrl) {
|
|
2439
|
+
return repositoryUrl.split("/").slice(1).join("/");
|
|
2440
|
+
}
|
|
2441
|
+
function warnTagExists(projectRoot, subscription, tag, repos) {
|
|
2442
|
+
const hit = [repos.backend, repos.frontend].find(
|
|
2443
|
+
(repo) => capture3(
|
|
2444
|
+
"az",
|
|
2445
|
+
[
|
|
2446
|
+
"acr",
|
|
2447
|
+
"repository",
|
|
2448
|
+
"show",
|
|
2449
|
+
"--name",
|
|
2450
|
+
repos.registryName,
|
|
2451
|
+
"--image",
|
|
2452
|
+
`${repoName2(repo)}:${tag}`,
|
|
2453
|
+
"--output",
|
|
2454
|
+
"none"
|
|
2455
|
+
],
|
|
2456
|
+
projectRoot,
|
|
2457
|
+
subscription
|
|
2458
|
+
).status === 0
|
|
2459
|
+
);
|
|
2460
|
+
if (!hit) return false;
|
|
2461
|
+
process.stderr.write(
|
|
2462
|
+
`
|
|
2463
|
+
\u26A0 ${hit}:${tag} already exists in the registry and will be overwritten.
|
|
2464
|
+
The default tag comes from your git state, so the same commit with the same
|
|
2465
|
+
uncommitted changes always resolves to the same tag. Commit (new SHA \u2192 new
|
|
2466
|
+
tag) or pass --tag to keep the published images distinguishable.
|
|
2467
|
+
|
|
2468
|
+
`
|
|
2469
|
+
);
|
|
2470
|
+
return true;
|
|
2471
|
+
}
|
|
2472
|
+
function dockerLogin2(repos, projectRoot, subscription) {
|
|
2473
|
+
const r = capture3(
|
|
2474
|
+
"az",
|
|
2475
|
+
["acr", "login", "--name", repos.registryName, "--expose-token", "--output", "json"],
|
|
2476
|
+
projectRoot,
|
|
2477
|
+
subscription
|
|
2478
|
+
);
|
|
2479
|
+
let token = "";
|
|
2480
|
+
let loginServer = repos.registryHost;
|
|
2481
|
+
if (r.status === 0) {
|
|
2482
|
+
try {
|
|
2483
|
+
const o = JSON.parse(r.stdout);
|
|
2484
|
+
token = o.accessToken ?? "";
|
|
2485
|
+
loginServer = o.loginServer || loginServer;
|
|
2486
|
+
} catch {
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
if (!token) {
|
|
2490
|
+
process.stderr.write(
|
|
2491
|
+
`
|
|
2492
|
+
\u2717 Could not obtain an ACR access token.
|
|
2493
|
+
Check you are signed in (dude iac login --env <env>) and that the
|
|
2494
|
+
registry "${repos.registryName}" exists in this subscription.
|
|
2495
|
+
|
|
2496
|
+
`
|
|
2497
|
+
);
|
|
2498
|
+
return 1;
|
|
2499
|
+
}
|
|
2500
|
+
const login = spawnSync9(
|
|
2501
|
+
"docker",
|
|
2502
|
+
["login", "--username", "00000000-0000-0000-0000-000000000000", "--password-stdin", loginServer],
|
|
2503
|
+
{
|
|
2504
|
+
cwd: projectRoot,
|
|
2505
|
+
input: token,
|
|
2506
|
+
stdio: ["pipe", "inherit", "inherit"],
|
|
2507
|
+
env: azureEnv(subscription)
|
|
2508
|
+
}
|
|
2509
|
+
);
|
|
2510
|
+
if (login.error) {
|
|
2511
|
+
const code = login.error.code;
|
|
2512
|
+
process.stderr.write(
|
|
2513
|
+
code === "ENOENT" ? "\n \u2717 `docker` not found on PATH. Install it and retry.\n\n" : `
|
|
2514
|
+
\u2717 failed to run docker: ${login.error.message}
|
|
2515
|
+
|
|
2516
|
+
`
|
|
2517
|
+
);
|
|
2518
|
+
return 1;
|
|
2519
|
+
}
|
|
2520
|
+
return login.status ?? 1;
|
|
2521
|
+
}
|
|
2522
|
+
function doBuild2(projectRoot, subscription, tag, repos, project, platform) {
|
|
2523
|
+
process.stdout.write(`
|
|
2524
|
+
\u2192 building backend ${repos.backend}:${tag} (${platform})
|
|
2525
|
+
`);
|
|
2526
|
+
let code = run3(
|
|
2527
|
+
"docker",
|
|
2528
|
+
[
|
|
2529
|
+
"build",
|
|
2530
|
+
"--platform",
|
|
2531
|
+
platform,
|
|
2532
|
+
"-f",
|
|
2533
|
+
"backend/Dockerfile.prod",
|
|
2534
|
+
"-t",
|
|
2535
|
+
`${repos.backend}:${tag}`,
|
|
2536
|
+
"backend"
|
|
2537
|
+
],
|
|
2538
|
+
projectRoot,
|
|
2539
|
+
subscription
|
|
2540
|
+
);
|
|
2541
|
+
if (code !== 0) return code;
|
|
2542
|
+
process.stdout.write(`
|
|
2543
|
+
\u2192 building frontend ${repos.frontend}:${tag} (${platform})
|
|
2544
|
+
`);
|
|
2545
|
+
code = run3(
|
|
2546
|
+
"docker",
|
|
2547
|
+
[
|
|
2548
|
+
"build",
|
|
2549
|
+
"--platform",
|
|
2550
|
+
platform,
|
|
2551
|
+
"-f",
|
|
2552
|
+
"frontend/Dockerfile.prod",
|
|
2553
|
+
"--build-arg",
|
|
2554
|
+
`VITE_APP_TITLE=${project}`,
|
|
2555
|
+
"-t",
|
|
2556
|
+
`${repos.frontend}:${tag}`,
|
|
2557
|
+
"frontend"
|
|
2558
|
+
],
|
|
2559
|
+
projectRoot,
|
|
2560
|
+
subscription
|
|
2561
|
+
);
|
|
2562
|
+
return code;
|
|
2563
|
+
}
|
|
2564
|
+
function doPush2(projectRoot, subscription, tag, repos) {
|
|
2565
|
+
let code = dockerLogin2(repos, projectRoot, subscription);
|
|
2566
|
+
if (code !== 0) return code;
|
|
2567
|
+
process.stdout.write(`
|
|
2568
|
+
\u2192 pushing ${repos.backend}:${tag}
|
|
2569
|
+
`);
|
|
2570
|
+
code = run3("docker", ["push", `${repos.backend}:${tag}`], projectRoot, subscription);
|
|
2571
|
+
if (code !== 0) return code;
|
|
2572
|
+
process.stdout.write(`
|
|
2573
|
+
\u2192 pushing ${repos.frontend}:${tag}
|
|
2574
|
+
`);
|
|
2575
|
+
return run3("docker", ["push", `${repos.frontend}:${tag}`], projectRoot, subscription);
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
// src/commands/iac/providers/azure-aca/lib/images.ts
|
|
2579
|
+
function recordImageTag(projectRoot, env, tag) {
|
|
2580
|
+
const tfvarsPath = path12.join(projectRoot, TF_DIR2, "environments", env, "terraform.tfvars");
|
|
2581
|
+
try {
|
|
2582
|
+
let tfvars = readFileSync9(tfvarsPath, "utf8");
|
|
2583
|
+
if (/^\s*image_tag\s*=/m.test(tfvars)) {
|
|
2584
|
+
tfvars = tfvars.replace(/^(\s*image_tag\s*=\s*).*$/m, `$1"${tag}"`);
|
|
2585
|
+
} else {
|
|
2586
|
+
tfvars += `
|
|
2587
|
+
image_tag = "${tag}"
|
|
2588
|
+
`;
|
|
2589
|
+
}
|
|
2590
|
+
writeFileSync4(tfvarsPath, tfvars);
|
|
2591
|
+
return true;
|
|
2592
|
+
} catch {
|
|
2593
|
+
process.stderr.write(`
|
|
2594
|
+
\u2717 Could not update ${tfvarsPath}.
|
|
2595
|
+
|
|
2596
|
+
`);
|
|
2597
|
+
return false;
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
function doDeploy2(projectRoot, subscription, env, tag, repos) {
|
|
2601
|
+
if (!recordImageTag(projectRoot, env, tag)) return 1;
|
|
2602
|
+
process.stdout.write(`
|
|
2603
|
+
\u2192 deploying :${tag} to "${env}"\u2026
|
|
2604
|
+
`);
|
|
2605
|
+
const code = tf2(projectRoot, ["apply", varFile2(env), "-auto-approve"], subscription);
|
|
2606
|
+
if (code === 0) {
|
|
2607
|
+
process.stdout.write(
|
|
2608
|
+
`
|
|
2609
|
+
\u2713 Container apps rolled onto :${tag}.
|
|
2610
|
+
Watch them with: dude iac status --env ${env}
|
|
2611
|
+
` + (repos.appUrl ? ` App URL: ${repos.appUrl}
|
|
2612
|
+
` : "")
|
|
2613
|
+
);
|
|
2614
|
+
}
|
|
2615
|
+
return code;
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
// src/commands/iac/providers/azure-aca/commands/apply/index.ts
|
|
2619
|
+
var iacApplyCommand2 = {
|
|
2620
|
+
available: hasIac2,
|
|
2621
|
+
description: "Provision/update the infrastructure for an environment.",
|
|
2622
|
+
args: {
|
|
2623
|
+
...envArg2,
|
|
2624
|
+
yes: { type: "boolean", description: "Skip the interactive approval (-auto-approve)." },
|
|
2625
|
+
"skip-image-check": {
|
|
2626
|
+
type: "boolean",
|
|
2627
|
+
description: "Apply even though the configured image_tag is not in the registry (it will fail unless Azure can pull it)."
|
|
2628
|
+
}
|
|
2629
|
+
},
|
|
2630
|
+
async run({ projectRoot, args }) {
|
|
2631
|
+
if (!requireIac2(projectRoot)) process.exit(1);
|
|
2632
|
+
const env = requireEnv2(projectRoot, args);
|
|
2633
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
2634
|
+
if (!args["skip-image-check"]) {
|
|
2635
|
+
const tag = tfvarsValue2(projectRoot, env, "image_tag") || "latest";
|
|
2636
|
+
const repos = requireAcrRepos(projectRoot, subscription, env);
|
|
2637
|
+
if (!imagesPublished(projectRoot, subscription, tag, repos)) {
|
|
2638
|
+
process.stderr.write(
|
|
2639
|
+
`
|
|
2640
|
+
\u2717 The images tagged "${tag}" are not in ${repos.registryHost}, and Container
|
|
2641
|
+
Apps refuses to create an app whose image it cannot pull.
|
|
2642
|
+
|
|
2643
|
+
On a first deploy this is expected \u2014 there is nothing published yet.
|
|
2644
|
+
Use ship, which builds and pushes before applying:
|
|
2645
|
+
|
|
2646
|
+
dude iac ship --env ${env}
|
|
2647
|
+
|
|
2648
|
+
To provision infrastructure only, past that point:
|
|
2649
|
+
dude iac apply --env ${env} --skip-image-check
|
|
2650
|
+
|
|
2651
|
+
`
|
|
2652
|
+
);
|
|
2653
|
+
process.exit(1);
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
const extra = args.yes ? ["-auto-approve"] : [];
|
|
2657
|
+
process.exit(tf2(projectRoot, ["apply", varFile2(env), ...extra], subscription));
|
|
2658
|
+
}
|
|
2659
|
+
};
|
|
2660
|
+
|
|
2661
|
+
// src/commands/iac/azure/commands.ts
|
|
2662
|
+
import { spawnSync as spawnSync10 } from "child_process";
|
|
2663
|
+
import { cpSync as cpSync2, readFileSync as readFileSync10, writeFileSync as writeFileSync5 } from "fs";
|
|
2664
|
+
import path13 from "pathe";
|
|
2665
|
+
function defineAzureInit(t) {
|
|
2666
|
+
return {
|
|
2667
|
+
available: t.hasIac,
|
|
2668
|
+
description: "Initialise Terraform for an environment (configures the Azure Storage remote backend).",
|
|
2669
|
+
args: { ...envArg2 },
|
|
2670
|
+
async run({ projectRoot, args }) {
|
|
2671
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
2672
|
+
const env = requireEnv2(projectRoot, args);
|
|
2673
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
2674
|
+
process.exit(tf2(projectRoot, ["init", "-reconfigure", backendConfig2(env)], subscription));
|
|
2675
|
+
}
|
|
2676
|
+
};
|
|
2677
|
+
}
|
|
2678
|
+
function defineAzurePlan(t) {
|
|
2679
|
+
return {
|
|
2680
|
+
available: t.hasIac,
|
|
2681
|
+
description: "Show the infrastructure changes Terraform would apply for an environment.",
|
|
2682
|
+
args: { ...envArg2 },
|
|
2683
|
+
async run({ projectRoot, args }) {
|
|
2684
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
2685
|
+
const env = requireEnv2(projectRoot, args);
|
|
2686
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
2687
|
+
process.exit(tf2(projectRoot, ["plan", varFile2(env)], subscription));
|
|
2688
|
+
}
|
|
2689
|
+
};
|
|
2690
|
+
}
|
|
2691
|
+
function defineAzureApply(t) {
|
|
2692
|
+
return {
|
|
2693
|
+
available: t.hasIac,
|
|
2694
|
+
description: "Provision/update the infrastructure for an environment.",
|
|
2695
|
+
args: {
|
|
2696
|
+
...envArg2,
|
|
2697
|
+
yes: { type: "boolean", description: "Skip the interactive approval (-auto-approve)." }
|
|
2698
|
+
},
|
|
2699
|
+
async run({ projectRoot, args }) {
|
|
2700
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
2701
|
+
const env = requireEnv2(projectRoot, args);
|
|
2702
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
2703
|
+
const extra = args.yes ? ["-auto-approve"] : [];
|
|
2704
|
+
process.exit(tf2(projectRoot, ["apply", varFile2(env), ...extra], subscription));
|
|
2705
|
+
}
|
|
2706
|
+
};
|
|
2707
|
+
}
|
|
2708
|
+
function defineAzureOutput(t) {
|
|
2709
|
+
return {
|
|
2710
|
+
available: t.hasIac,
|
|
2711
|
+
description: "Print Terraform outputs for an environment (registry URLs, app URL, database endpoint\u2026).",
|
|
2712
|
+
args: { ...envArg2, json: { type: "boolean", description: "Emit machine-readable JSON." } },
|
|
2713
|
+
async run({ projectRoot, args }) {
|
|
2714
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
2715
|
+
const env = requireEnv2(projectRoot, args);
|
|
2716
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
2717
|
+
process.exit(tf2(projectRoot, ["output", ...args.json ? ["-json"] : []], subscription));
|
|
2718
|
+
}
|
|
2719
|
+
};
|
|
2720
|
+
}
|
|
2721
|
+
function defineAzureFmt(t) {
|
|
2722
|
+
return {
|
|
2723
|
+
available: t.hasIac,
|
|
2724
|
+
description: "Format all Terraform files (terraform fmt -recursive).",
|
|
2725
|
+
async run({ projectRoot }) {
|
|
2726
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
2727
|
+
process.exit(tf2(projectRoot, ["fmt", "-recursive"]));
|
|
2728
|
+
}
|
|
2729
|
+
};
|
|
2730
|
+
}
|
|
2731
|
+
function defineAzureValidate(t) {
|
|
2732
|
+
return {
|
|
2733
|
+
available: t.hasIac,
|
|
2734
|
+
description: "Validate the Terraform configuration.",
|
|
2735
|
+
async run({ projectRoot }) {
|
|
2736
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
2737
|
+
process.exit(tf2(projectRoot, ["validate"]));
|
|
2738
|
+
}
|
|
2739
|
+
};
|
|
2740
|
+
}
|
|
2741
|
+
function defineAzureBuild(t) {
|
|
2742
|
+
return {
|
|
2743
|
+
available: t.hasIac,
|
|
2744
|
+
description: "Build the backend + frontend production images, tagged for the env registry.",
|
|
2745
|
+
args: { ...envArg2, ...tagArg2, ...platformArg2 },
|
|
2746
|
+
async run({ projectRoot, args }) {
|
|
2747
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
2748
|
+
const env = requireEnv2(projectRoot, args);
|
|
2749
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
2750
|
+
const tag = resolveTag2(projectRoot, args);
|
|
2751
|
+
if (!tag) process.exit(1);
|
|
2752
|
+
const repos = requireAcrRepos(projectRoot, subscription, env);
|
|
2753
|
+
const platform = String(args.platform ?? "linux/amd64");
|
|
2754
|
+
process.exit(
|
|
2755
|
+
doBuild2(projectRoot, subscription, tag, repos, projectName(projectRoot), platform)
|
|
2756
|
+
);
|
|
2757
|
+
}
|
|
2758
|
+
};
|
|
2759
|
+
}
|
|
2760
|
+
function defineAzurePush(t) {
|
|
2761
|
+
return {
|
|
2762
|
+
available: t.hasIac,
|
|
2763
|
+
description: "Log in to the registry and push the backend + frontend images (build them first).",
|
|
2764
|
+
args: { ...envArg2, ...tagArg2 },
|
|
2765
|
+
async run({ projectRoot, args }) {
|
|
2766
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
2767
|
+
const env = requireEnv2(projectRoot, args);
|
|
2768
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
2769
|
+
const tag = resolveTag2(projectRoot, args);
|
|
2770
|
+
if (!tag) process.exit(1);
|
|
2771
|
+
const repos = requireAcrRepos(projectRoot, subscription, env);
|
|
2772
|
+
warnTagExists(projectRoot, subscription, tag, repos);
|
|
2773
|
+
process.exit(doPush2(projectRoot, subscription, tag, repos));
|
|
2774
|
+
}
|
|
2775
|
+
};
|
|
2776
|
+
}
|
|
2777
|
+
function defineAzureLogin(t) {
|
|
2778
|
+
return {
|
|
2779
|
+
available: t.hasIac,
|
|
2780
|
+
description: "Sign in to Azure and verify the subscription an environment deploys into (runs az login when needed).",
|
|
2781
|
+
args: { ...envArg2 },
|
|
2782
|
+
async run({ projectRoot, args }) {
|
|
2783
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
2784
|
+
const env = requireEnv2(projectRoot, args);
|
|
2785
|
+
const signedIn = captureWith("az", ["account", "show", "--output", "none"], projectRoot, process.env).status === 0;
|
|
2786
|
+
if (!signedIn) {
|
|
2787
|
+
process.stdout.write("\n You are not signed in to Azure. Opening the login flow\u2026\n\n");
|
|
2788
|
+
const code = runWith("az", ["login"], projectRoot, process.env);
|
|
2789
|
+
if (code !== 0) {
|
|
2790
|
+
process.stderr.write(
|
|
2791
|
+
"\n \u2717 az login failed.\n On a machine without a browser, run: az login --use-device-code\n\n"
|
|
2792
|
+
);
|
|
2793
|
+
process.exit(code);
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
2797
|
+
if (!subscription) {
|
|
2798
|
+
process.stderr.write(
|
|
2799
|
+
`
|
|
2800
|
+
\u2717 No Azure subscription could be resolved for this environment.
|
|
2801
|
+
Pass --subscription <id>, or set subscription_id in
|
|
2802
|
+
iac/terraform/environments/${env}/terraform.tfvars.
|
|
2803
|
+
List the ones you can see with: az account list --output table
|
|
2804
|
+
|
|
2805
|
+
`
|
|
2806
|
+
);
|
|
2807
|
+
process.exit(1);
|
|
2808
|
+
}
|
|
2809
|
+
const who = captureWith(
|
|
2810
|
+
"az",
|
|
2811
|
+
["account", "show", "--subscription", subscription, "--output", "json"],
|
|
2812
|
+
projectRoot,
|
|
2813
|
+
process.env
|
|
2814
|
+
);
|
|
2815
|
+
if (who.status !== 0) {
|
|
2816
|
+
process.stderr.write(
|
|
2817
|
+
`
|
|
2818
|
+
\u2717 Subscription "${subscription}" is not accessible with your current Azure login.
|
|
2819
|
+
Check the id, or sign in with the right tenant:
|
|
2820
|
+
az login --tenant <tenant-id>
|
|
2821
|
+
|
|
2822
|
+
`
|
|
2823
|
+
);
|
|
2824
|
+
process.exit(1);
|
|
2825
|
+
}
|
|
2826
|
+
let name = "";
|
|
2827
|
+
let user = "";
|
|
2828
|
+
let tenant = "";
|
|
2829
|
+
try {
|
|
2830
|
+
const o = JSON.parse(who.stdout);
|
|
2831
|
+
name = o.name ?? "";
|
|
2832
|
+
tenant = o.tenantId ?? "";
|
|
2833
|
+
user = o.user?.name ?? "";
|
|
2834
|
+
} catch {
|
|
2835
|
+
}
|
|
2836
|
+
const pinned = tfvarsValue2(projectRoot, env, "subscription_id");
|
|
2837
|
+
const pinNote = pinned ? "" : `
|
|
2838
|
+
Tip: pin this subscription for the environment by setting
|
|
2839
|
+
subscription_id = "${subscription}"
|
|
2840
|
+
in iac/terraform/environments/${env}/terraform.tfvars
|
|
2841
|
+
`;
|
|
2842
|
+
process.stdout.write(
|
|
2843
|
+
`
|
|
2844
|
+
\u2713 Authenticated for env "${env}".
|
|
2845
|
+
subscription: ${name || subscription}
|
|
2846
|
+
id: ${subscription}
|
|
2847
|
+
tenant: ${tenant}
|
|
2848
|
+
user: ${user}
|
|
2849
|
+
` + pinNote + `
|
|
2850
|
+
Now: dude iac plan --env ${env}
|
|
2851
|
+
|
|
2852
|
+
`
|
|
2853
|
+
);
|
|
2854
|
+
}
|
|
2855
|
+
};
|
|
2856
|
+
}
|
|
2857
|
+
function defineAzureNewEnv(t) {
|
|
2858
|
+
return {
|
|
2859
|
+
available: t.hasIac,
|
|
2860
|
+
description: "Scaffold a new environment (iac/terraform/environments/<name>) by copying an existing one.",
|
|
2861
|
+
args: {
|
|
2862
|
+
env: {
|
|
2863
|
+
type: "string",
|
|
2864
|
+
description: "Name of the new environment to create (lowercase kebab-case).",
|
|
2865
|
+
required: true
|
|
2866
|
+
},
|
|
2867
|
+
from: {
|
|
2868
|
+
type: "string",
|
|
2869
|
+
description: "Existing environment to copy as a starting point (default: dev)."
|
|
2870
|
+
}
|
|
2871
|
+
},
|
|
2872
|
+
async run({ projectRoot, args }) {
|
|
2873
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
2874
|
+
const name = args.env == null ? "" : String(args.env);
|
|
2875
|
+
if (!name) {
|
|
2876
|
+
process.stderr.write(
|
|
2877
|
+
"\n \u2717 --env is required (the name of the environment to create).\n\n"
|
|
2878
|
+
);
|
|
2879
|
+
process.exit(1);
|
|
2880
|
+
}
|
|
2881
|
+
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
2882
|
+
process.stderr.write(`
|
|
2883
|
+
\u2717 invalid --env "${name}" (expected lowercase kebab-case).
|
|
2884
|
+
|
|
2885
|
+
`);
|
|
2886
|
+
process.exit(1);
|
|
2887
|
+
}
|
|
2888
|
+
const envs = listEnvironments2(projectRoot);
|
|
2889
|
+
if (envs.includes(name)) {
|
|
2890
|
+
process.stderr.write(`
|
|
2891
|
+
\u2717 environment "${name}" already exists.
|
|
2892
|
+
|
|
2893
|
+
`);
|
|
2894
|
+
process.exit(1);
|
|
2895
|
+
}
|
|
2896
|
+
if (!envs.length) {
|
|
2897
|
+
process.stderr.write(
|
|
2898
|
+
"\n \u2717 no existing environment to copy from (expected at least iac/terraform/environments/dev).\n\n"
|
|
2899
|
+
);
|
|
2900
|
+
process.exit(1);
|
|
2901
|
+
}
|
|
2902
|
+
const from = args.from == null ? "dev" : String(args.from);
|
|
2903
|
+
if (!envs.includes(from)) {
|
|
2904
|
+
process.stderr.write(
|
|
2905
|
+
`
|
|
2906
|
+
\u2717 --from "${from}" does not exist. Available: ${envs.join(", ")}
|
|
2907
|
+
|
|
2908
|
+
`
|
|
2909
|
+
);
|
|
2910
|
+
process.exit(1);
|
|
2911
|
+
}
|
|
2912
|
+
const base = path13.join(projectRoot, TF_ENVIRONMENTS_DIR2);
|
|
2913
|
+
const dst = path13.join(base, name);
|
|
2914
|
+
cpSync2(path13.join(base, from), dst, { recursive: true });
|
|
2915
|
+
const project = projectName(projectRoot);
|
|
2916
|
+
const tfvarsPath = path13.join(dst, "terraform.tfvars");
|
|
2917
|
+
let tfvars = readFileSync10(tfvarsPath, "utf8");
|
|
2918
|
+
tfvars = tfvars.replace(/^(\s*environment\s*=\s*).*$/m, `$1"${name}"`);
|
|
2919
|
+
tfvars = tfvars.replace(/^(\s*image_tag\s*=\s*).*$/m, `$1"latest"`);
|
|
2920
|
+
if (t.rewriteEnvTfvars) tfvars = t.rewriteEnvTfvars(tfvars, name, project);
|
|
2921
|
+
writeFileSync5(tfvarsPath, tfvars);
|
|
2922
|
+
const backendPath = path13.join(dst, "backend.hcl");
|
|
2923
|
+
writeFileSync5(
|
|
2924
|
+
backendPath,
|
|
2925
|
+
readFileSync10(backendPath, "utf8").replace(
|
|
2926
|
+
/^(\s*key\s*=\s*).*$/m,
|
|
2927
|
+
`$1"${project}/${name}/terraform.tfstate"`
|
|
2928
|
+
)
|
|
2929
|
+
);
|
|
2930
|
+
process.stdout.write(
|
|
2931
|
+
`
|
|
2932
|
+
\u2713 Created environment "${name}" (copied from "${from}").
|
|
2933
|
+
iac/terraform/environments/${name}/{backend.hcl,terraform.tfvars}
|
|
2934
|
+
|
|
2935
|
+
Next:
|
|
2936
|
+
1. Review iac/terraform/environments/${name}/terraform.tfvars (sizing, \u2026).
|
|
2937
|
+
2. First env on a brand-new state backend? Run:
|
|
2938
|
+
dude iac bootstrap --env ${name} --state-prefix <prefix>
|
|
2939
|
+
Otherwise it reuses the existing storage account \u2014 skip bootstrap.
|
|
2940
|
+
3. dude iac init --env ${name} && dude iac apply --env ${name}
|
|
2941
|
+
|
|
2942
|
+
`
|
|
2943
|
+
);
|
|
2944
|
+
}
|
|
2945
|
+
};
|
|
2946
|
+
}
|
|
2947
|
+
function setHclScalar(text, key, value) {
|
|
2948
|
+
const line = `${key} = "${value}"`;
|
|
2949
|
+
const re = new RegExp(`^\\s*${key}\\s*=\\s*".*"\\s*$`, "m");
|
|
2950
|
+
return re.test(text) ? text.replace(re, line) : `${text.trimEnd()}
|
|
2951
|
+
${line}
|
|
2952
|
+
`;
|
|
2953
|
+
}
|
|
2954
|
+
function defineAzureBootstrap(t) {
|
|
2955
|
+
return {
|
|
2956
|
+
available: t.hasIac,
|
|
2957
|
+
description: "One-time: create the shared resource group, Terraform state storage account and container registry, then write their names into the environment config.",
|
|
2958
|
+
args: {
|
|
2959
|
+
location: {
|
|
2960
|
+
type: "string",
|
|
2961
|
+
description: "Azure region for the shared resources.",
|
|
2962
|
+
default: "northeurope"
|
|
2963
|
+
},
|
|
2964
|
+
"state-prefix": {
|
|
2965
|
+
type: "string",
|
|
2966
|
+
description: "Prefix for the storage account + registry names \u2014 both are globally unique across Azure (e.g. your org slug).",
|
|
2967
|
+
required: true
|
|
2968
|
+
},
|
|
2969
|
+
env: { type: "string", description: "Environment whose config to update (required)." },
|
|
2970
|
+
subscription: {
|
|
2971
|
+
type: "string",
|
|
2972
|
+
description: "Azure subscription id (default: the env tfvars value, or your az default)."
|
|
2973
|
+
},
|
|
2974
|
+
yes: { type: "boolean", description: "Skip the interactive approval (-auto-approve)." }
|
|
2975
|
+
},
|
|
2976
|
+
async run({ projectRoot, args }) {
|
|
2977
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
2978
|
+
const env = requireEnv2(projectRoot, args);
|
|
2979
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
2980
|
+
const prefix = String(args["state-prefix"] ?? "");
|
|
2981
|
+
if (!prefix) {
|
|
2982
|
+
process.stderr.write(
|
|
2983
|
+
"\n \u2717 --state-prefix is required (e.g. your org slug \u2014 the storage account and\n container registry names must be globally unique across all of Azure).\n\n"
|
|
2984
|
+
);
|
|
2985
|
+
process.exit(1);
|
|
2986
|
+
}
|
|
2987
|
+
if (!/^[a-z0-9]{2,12}$/.test(prefix)) {
|
|
2988
|
+
process.stderr.write(
|
|
2989
|
+
`
|
|
2990
|
+
\u2717 invalid --state-prefix "${prefix}".
|
|
2991
|
+
Expected 2\u201312 lowercase letters/digits (no hyphens): Azure storage account
|
|
2992
|
+
and container registry names allow nothing else.
|
|
2993
|
+
|
|
2994
|
+
`
|
|
2995
|
+
);
|
|
2996
|
+
process.exit(1);
|
|
2997
|
+
}
|
|
2998
|
+
const location = String(args.location ?? "northeurope");
|
|
2999
|
+
if (!/^[a-z][a-z0-9]+$/.test(location)) {
|
|
3000
|
+
process.stderr.write(
|
|
3001
|
+
`
|
|
3002
|
+
\u2717 invalid --location "${location}" (expected e.g. northeurope, eastus).
|
|
3003
|
+
List them with: az account list-locations --query "[].name" -o tsv
|
|
3004
|
+
|
|
3005
|
+
`
|
|
3006
|
+
);
|
|
3007
|
+
process.exit(1);
|
|
3008
|
+
}
|
|
3009
|
+
const name = projectName(projectRoot);
|
|
3010
|
+
const autoTfvars = path13.join(projectRoot, TF_BOOTSTRAP_DIR2, "bootstrap.auto.tfvars");
|
|
3011
|
+
try {
|
|
3012
|
+
writeFileSync5(
|
|
3013
|
+
autoTfvars,
|
|
3014
|
+
`# Written by \`dude iac bootstrap\`. Terraform loads *.auto.tfvars on every
|
|
3015
|
+
# command, so \`destroy\` reproduces these names without being passed them.
|
|
3016
|
+
# Commit this file; changing it by hand will point the bootstrap at
|
|
3017
|
+
# different resources.
|
|
3018
|
+
|
|
3019
|
+
project_name = "${name}"
|
|
3020
|
+
location = "${location}"
|
|
3021
|
+
state_prefix = "${prefix}"
|
|
3022
|
+
`
|
|
3023
|
+
);
|
|
3024
|
+
} catch {
|
|
3025
|
+
process.stderr.write(`
|
|
3026
|
+
\u2717 Could not write ${autoTfvars}.
|
|
3027
|
+
|
|
3028
|
+
`);
|
|
3029
|
+
process.exit(1);
|
|
3030
|
+
}
|
|
3031
|
+
let status = tfBoot2(projectRoot, ["init", "-reconfigure"], subscription);
|
|
3032
|
+
if (status !== 0) process.exit(status);
|
|
3033
|
+
status = tfBoot2(
|
|
3034
|
+
projectRoot,
|
|
3035
|
+
["apply", ...args.yes ? ["-auto-approve"] : []],
|
|
3036
|
+
subscription
|
|
3037
|
+
);
|
|
3038
|
+
if (status !== 0) process.exit(status);
|
|
3039
|
+
const out = captureBootstrap2(projectRoot, ["output", "-json"], subscription);
|
|
3040
|
+
if (out.status !== 0) {
|
|
3041
|
+
process.stderr.write("\n \u2717 Could not read bootstrap outputs.\n\n");
|
|
3042
|
+
process.exit(1);
|
|
3043
|
+
}
|
|
3044
|
+
let resourceGroup = "";
|
|
3045
|
+
let storageAccount = "";
|
|
3046
|
+
let container = "";
|
|
3047
|
+
let acrName = "";
|
|
3048
|
+
let acrLoginServer = "";
|
|
3049
|
+
try {
|
|
3050
|
+
const o = JSON.parse(out.stdout);
|
|
3051
|
+
resourceGroup = o.resource_group_name?.value ?? "";
|
|
3052
|
+
storageAccount = o.storage_account_name?.value ?? "";
|
|
3053
|
+
container = o.container_name?.value ?? "";
|
|
3054
|
+
acrName = o.acr_name?.value ?? "";
|
|
3055
|
+
acrLoginServer = o.acr_login_server?.value ?? "";
|
|
3056
|
+
} catch {
|
|
3057
|
+
}
|
|
3058
|
+
if (!resourceGroup || !storageAccount || !container || !acrName) {
|
|
3059
|
+
process.stderr.write(
|
|
3060
|
+
"\n \u2717 Bootstrap outputs (resource_group_name / storage_account_name /\n container_name / acr_name) not found.\n\n"
|
|
3061
|
+
);
|
|
3062
|
+
process.exit(1);
|
|
3063
|
+
}
|
|
3064
|
+
const backendHclPath = path13.join(projectRoot, TF_DIR2, "environments", env, "backend.hcl");
|
|
3065
|
+
try {
|
|
3066
|
+
let hcl = readFileSync10(backendHclPath, "utf8");
|
|
3067
|
+
hcl = setHclScalar(hcl, "resource_group_name", resourceGroup);
|
|
3068
|
+
hcl = setHclScalar(hcl, "storage_account_name", storageAccount);
|
|
3069
|
+
hcl = setHclScalar(hcl, "container_name", container);
|
|
3070
|
+
writeFileSync5(backendHclPath, hcl);
|
|
3071
|
+
} catch {
|
|
3072
|
+
process.stderr.write(`
|
|
3073
|
+
\u2717 Could not update ${backendHclPath}.
|
|
3074
|
+
|
|
3075
|
+
`);
|
|
3076
|
+
process.exit(1);
|
|
3077
|
+
}
|
|
3078
|
+
const tfvarsPath = path13.join(projectRoot, TF_DIR2, "environments", env, "terraform.tfvars");
|
|
3079
|
+
try {
|
|
3080
|
+
let tfvars = readFileSync10(tfvarsPath, "utf8");
|
|
3081
|
+
tfvars = setHclScalar(tfvars, "acr_name", acrName);
|
|
3082
|
+
tfvars = setHclScalar(tfvars, "acr_resource_group", resourceGroup);
|
|
3083
|
+
writeFileSync5(tfvarsPath, tfvars);
|
|
3084
|
+
} catch {
|
|
3085
|
+
process.stderr.write(`
|
|
3086
|
+
\u2717 Could not update ${tfvarsPath}.
|
|
3087
|
+
|
|
3088
|
+
`);
|
|
3089
|
+
process.exit(1);
|
|
3090
|
+
}
|
|
3091
|
+
const ready = () => capture3(
|
|
3092
|
+
"az",
|
|
3093
|
+
[
|
|
3094
|
+
"storage",
|
|
3095
|
+
"blob",
|
|
3096
|
+
"list",
|
|
3097
|
+
"--account-name",
|
|
3098
|
+
storageAccount,
|
|
3099
|
+
"--container-name",
|
|
3100
|
+
container,
|
|
3101
|
+
"--auth-mode",
|
|
3102
|
+
"key",
|
|
3103
|
+
"--num-results",
|
|
3104
|
+
"1",
|
|
3105
|
+
"--output",
|
|
3106
|
+
"none"
|
|
3107
|
+
],
|
|
3108
|
+
projectRoot,
|
|
3109
|
+
subscription
|
|
3110
|
+
).status === 0;
|
|
3111
|
+
if (!ready()) {
|
|
3112
|
+
process.stdout.write("\n \u2192 Waiting for the state container to become reachable\u2026\n");
|
|
3113
|
+
let attempts = 0;
|
|
3114
|
+
while (attempts < 12 && !ready()) {
|
|
3115
|
+
sleepMs(15e3);
|
|
3116
|
+
attempts++;
|
|
3117
|
+
}
|
|
3118
|
+
if (attempts >= 12) {
|
|
3119
|
+
process.stderr.write(
|
|
3120
|
+
`
|
|
3121
|
+
\u26A0 The state container is not answering yet. The resources exist, so nothing
|
|
3122
|
+
is lost \u2014 a brand-new storage account's blob endpoint can take a few
|
|
3123
|
+
minutes. Re-run \`dude iac init --env ${env}\` shortly; if it keeps failing
|
|
3124
|
+
with a 404 on ListBlobs, check the account in the portal.
|
|
3125
|
+
|
|
3126
|
+
`
|
|
3127
|
+
);
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
process.stdout.write(
|
|
3131
|
+
`
|
|
3132
|
+
\u2713 Bootstrap complete.
|
|
3133
|
+
resource group: ${resourceGroup}
|
|
3134
|
+
state storage: ${storageAccount}/${container}
|
|
3135
|
+
registry: ${acrLoginServer || acrName}
|
|
3136
|
+
Updated: iac/terraform/environments/${env}/{backend.hcl,terraform.tfvars}
|
|
3137
|
+
|
|
3138
|
+
Next: dude iac init --env ${env}
|
|
3139
|
+
|
|
3140
|
+
`
|
|
3141
|
+
);
|
|
3142
|
+
}
|
|
3143
|
+
};
|
|
3144
|
+
}
|
|
3145
|
+
function defineAzureShell(t) {
|
|
3146
|
+
return {
|
|
3147
|
+
available: t.hasIac,
|
|
3148
|
+
description: `Open an interactive shell in the IaC runner container (${t.shellTools}) scoped to an environment.`,
|
|
3149
|
+
args: { ...envArg2 },
|
|
3150
|
+
async run({ projectRoot, args }) {
|
|
3151
|
+
if (!t.requireIac(projectRoot)) process.exit(1);
|
|
3152
|
+
if (!dockerAvailable2()) {
|
|
3153
|
+
process.stderr.write(
|
|
3154
|
+
"\n \u2717 Docker is required for `dude iac shell` (it runs the IaC toolchain in a container).\n Start Docker and retry.\n\n"
|
|
3155
|
+
);
|
|
3156
|
+
process.exit(1);
|
|
3157
|
+
}
|
|
3158
|
+
if (!hasRunnerDockerfile2(projectRoot)) {
|
|
3159
|
+
process.stderr.write(
|
|
3160
|
+
`
|
|
3161
|
+
\u2717 No runner Dockerfile found (iac/runner/Dockerfile).
|
|
3162
|
+
Re-scaffold with \`--iac ${t.id}\` or add it to enable the runner.
|
|
3163
|
+
|
|
3164
|
+
`
|
|
3165
|
+
);
|
|
3166
|
+
process.exit(1);
|
|
3167
|
+
}
|
|
3168
|
+
const env = requireEnv2(projectRoot, args);
|
|
3169
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
3170
|
+
process.stdout.write(
|
|
3171
|
+
`
|
|
3172
|
+
\u2192 Entering the IaC runner for env "${env}".
|
|
3173
|
+
The project is mounted at /work. Type "exit" to leave.
|
|
3174
|
+
|
|
3175
|
+
`
|
|
3176
|
+
);
|
|
3177
|
+
const r = spawnSync10(
|
|
3178
|
+
"docker",
|
|
3179
|
+
dockerShellArgs2(projectRoot, subscription, t.shellPrelude?.(projectRoot, env)),
|
|
3180
|
+
{ stdio: "inherit", cwd: projectRoot }
|
|
3181
|
+
);
|
|
3182
|
+
process.exit(r.status ?? 1);
|
|
3183
|
+
}
|
|
3184
|
+
};
|
|
3185
|
+
}
|
|
3186
|
+
|
|
3187
|
+
// src/commands/iac/providers/azure-aca/lib/target.ts
|
|
3188
|
+
var azureAcaTarget = {
|
|
3189
|
+
id: PROVIDER_ID2,
|
|
3190
|
+
hasIac: hasIac2,
|
|
3191
|
+
requireIac: requireIac2,
|
|
3192
|
+
// No kubectl/helm/k9s: there is no cluster to talk to. The runner carries
|
|
3193
|
+
// terraform and the Azure CLI, which is the whole toolchain this target needs.
|
|
3194
|
+
shellTools: "terraform, az"
|
|
3195
|
+
// No shellPrelude and no rewriteEnvTfvars: unlike the Kubernetes target there
|
|
3196
|
+
// is no cluster context to pin, and the public hostname is assigned by the
|
|
3197
|
+
// Container Apps environment rather than claimed from a DNS label that a new
|
|
3198
|
+
// environment would have to be given a distinct value for.
|
|
3199
|
+
};
|
|
3200
|
+
|
|
3201
|
+
// src/commands/iac/providers/azure-aca/commands/bootstrap/index.ts
|
|
3202
|
+
var iacBootstrapCommand2 = defineAzureBootstrap(azureAcaTarget);
|
|
3203
|
+
|
|
3204
|
+
// src/commands/iac/providers/azure-aca/commands/build/index.ts
|
|
3205
|
+
var iacBuildCommand2 = defineAzureBuild(azureAcaTarget);
|
|
3206
|
+
|
|
3207
|
+
// src/commands/iac/providers/azure-aca/commands/migrate/index.ts
|
|
3208
|
+
var TIMEOUT_MS = 10 * 60 * 1e3;
|
|
3209
|
+
var POLL_MS = 1e4;
|
|
3210
|
+
function runMigrations(projectRoot, subscription, env) {
|
|
3211
|
+
const job = tfOutputRaw2(projectRoot, "migrate_job_name", subscription);
|
|
3212
|
+
if (!job) return 0;
|
|
3213
|
+
const group = tfOutputRaw2(projectRoot, "resource_group_name", subscription) || resourceGroupFor(projectRoot, env);
|
|
3214
|
+
process.stdout.write(`
|
|
3215
|
+
\u2192 running database migrations (${job})\u2026
|
|
3216
|
+
`);
|
|
3217
|
+
const started = capture3(
|
|
3218
|
+
"az",
|
|
3219
|
+
["containerapp", "job", "start", "--name", job, "--resource-group", group, "--output", "json"],
|
|
3220
|
+
projectRoot,
|
|
3221
|
+
subscription
|
|
3222
|
+
);
|
|
3223
|
+
if (started.status !== 0) {
|
|
3224
|
+
process.stderr.write(
|
|
3225
|
+
`
|
|
3226
|
+
\u2717 Could not start the migration job "${job}".
|
|
3227
|
+
Inspect it with: az containerapp job show --name ${job} --resource-group ${group}
|
|
3228
|
+
|
|
3229
|
+
`
|
|
3230
|
+
);
|
|
3231
|
+
return 1;
|
|
3232
|
+
}
|
|
3233
|
+
let execution = "";
|
|
3234
|
+
try {
|
|
3235
|
+
const o = JSON.parse(started.stdout);
|
|
3236
|
+
execution = o.name ?? String(o.id ?? "").split("/").pop() ?? "";
|
|
3237
|
+
} catch {
|
|
3238
|
+
}
|
|
3239
|
+
if (!execution) {
|
|
3240
|
+
process.stderr.write(
|
|
3241
|
+
`
|
|
3242
|
+
\u26A0 The migration job started but did not report an execution name, so its
|
|
3243
|
+
result cannot be awaited. Check it with:
|
|
3244
|
+
az containerapp job execution list --name ${job} --resource-group ${group} -o table
|
|
3245
|
+
|
|
3246
|
+
`
|
|
3247
|
+
);
|
|
3248
|
+
return 0;
|
|
3249
|
+
}
|
|
3250
|
+
const deadline = Date.now() + TIMEOUT_MS;
|
|
3251
|
+
for (; ; ) {
|
|
3252
|
+
const r = capture3(
|
|
3253
|
+
"az",
|
|
3254
|
+
[
|
|
3255
|
+
"containerapp",
|
|
3256
|
+
"job",
|
|
3257
|
+
"execution",
|
|
3258
|
+
"show",
|
|
3259
|
+
"--name",
|
|
3260
|
+
job,
|
|
3261
|
+
"--job-execution-name",
|
|
3262
|
+
execution,
|
|
3263
|
+
"--resource-group",
|
|
3264
|
+
group,
|
|
3265
|
+
"--query",
|
|
3266
|
+
"properties.status",
|
|
3267
|
+
"--output",
|
|
3268
|
+
"tsv"
|
|
3269
|
+
],
|
|
3270
|
+
projectRoot,
|
|
3271
|
+
subscription
|
|
3272
|
+
);
|
|
3273
|
+
const status = r.status === 0 ? r.stdout.trim() : "";
|
|
3274
|
+
if (status === "Succeeded") {
|
|
3275
|
+
process.stdout.write(" \u2713 Migrations applied.\n\n");
|
|
3276
|
+
return 0;
|
|
3277
|
+
}
|
|
3278
|
+
if (status === "Failed" || status === "Degraded") {
|
|
3279
|
+
process.stderr.write(
|
|
3280
|
+
`
|
|
3281
|
+
\u2717 Migrations failed (${status}). Read the output with:
|
|
3282
|
+
az containerapp job logs show --name ${job} --resource-group ${group} \\
|
|
3283
|
+
--container migrate --execution ${execution}
|
|
3284
|
+
A finished replica is reaped quickly; if that reports no replicas, read the
|
|
3285
|
+
job's output from Log Analytics instead (ContainerAppConsoleLogs_CL).
|
|
3286
|
+
|
|
3287
|
+
`
|
|
3288
|
+
);
|
|
3289
|
+
return 1;
|
|
3290
|
+
}
|
|
3291
|
+
if (Date.now() > deadline) {
|
|
3292
|
+
process.stderr.write(
|
|
3293
|
+
`
|
|
3294
|
+
\u2717 Migrations did not finish within ${TIMEOUT_MS / 6e4} minutes (last status: ${status || "unknown"}).
|
|
3295
|
+
The job is still running; follow it with:
|
|
3296
|
+
az containerapp job execution list --name ${job} --resource-group ${group} -o table
|
|
3297
|
+
|
|
3298
|
+
`
|
|
3299
|
+
);
|
|
3300
|
+
return 1;
|
|
3301
|
+
}
|
|
3302
|
+
sleepMs(POLL_MS);
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3305
|
+
var iacMigrateCommand = {
|
|
3306
|
+
// Hidden entirely in a project scaffolded without a database: there is no
|
|
3307
|
+
// migration job to start, so offering the command would only ever produce an
|
|
3308
|
+
// explanation of why it cannot run.
|
|
3309
|
+
available: (projectRoot) => hasIac2(projectRoot) && hasMigrations(projectRoot),
|
|
3310
|
+
description: "Run database migrations (alembic upgrade head) as a one-off Container Apps job.",
|
|
3311
|
+
args: { ...envArg2 },
|
|
3312
|
+
async run({ projectRoot, args }) {
|
|
3313
|
+
if (!requireIac2(projectRoot)) process.exit(1);
|
|
3314
|
+
const env = requireEnv2(projectRoot, args);
|
|
3315
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
3316
|
+
const job = tfOutputRaw2(projectRoot, "migrate_job_name", subscription);
|
|
3317
|
+
if (!job) {
|
|
3318
|
+
process.stdout.write(
|
|
3319
|
+
"\n \u21B7 This project has no database, so there is no migration job.\n Re-scaffold with `--database postgres` if you expected one.\n\n"
|
|
3320
|
+
);
|
|
3321
|
+
process.exit(0);
|
|
3322
|
+
}
|
|
3323
|
+
process.exit(runMigrations(projectRoot, subscription, env));
|
|
3324
|
+
}
|
|
3325
|
+
};
|
|
3326
|
+
|
|
3327
|
+
// src/commands/iac/providers/azure-aca/commands/deploy/index.ts
|
|
3328
|
+
var iacDeployCommand2 = {
|
|
3329
|
+
available: hasIac2,
|
|
3330
|
+
description: "Deploy the app: record the image tag in terraform.tfvars and roll every container app onto it (terraform apply).",
|
|
3331
|
+
args: {
|
|
3332
|
+
...envArg2,
|
|
3333
|
+
...tagArg2,
|
|
3334
|
+
"skip-migrations": {
|
|
3335
|
+
type: "boolean",
|
|
3336
|
+
description: "Do not run the database migration job after rolling out."
|
|
3337
|
+
}
|
|
3338
|
+
},
|
|
3339
|
+
async run({ projectRoot, args }) {
|
|
3340
|
+
if (!requireIac2(projectRoot)) process.exit(1);
|
|
3341
|
+
const env = requireEnv2(projectRoot, args);
|
|
3342
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
3343
|
+
const tag = resolveTag2(projectRoot, args);
|
|
3344
|
+
if (!tag) process.exit(1);
|
|
3345
|
+
const repos = requireAcrRepos(projectRoot, subscription, env);
|
|
3346
|
+
const code = doDeploy2(projectRoot, subscription, env, tag, repos);
|
|
3347
|
+
if (code !== 0) process.exit(code);
|
|
3348
|
+
if (!args["skip-migrations"]) {
|
|
3349
|
+
const migrated = runMigrations(projectRoot, subscription, env);
|
|
3350
|
+
if (migrated !== 0) process.exit(migrated);
|
|
3351
|
+
}
|
|
3352
|
+
process.exit(0);
|
|
3353
|
+
}
|
|
3354
|
+
};
|
|
3355
|
+
|
|
3356
|
+
// src/commands/iac/azure/state.ts
|
|
3357
|
+
import { existsSync as existsSync11, mkdtempSync, readFileSync as readFileSync11, rmSync } from "fs";
|
|
3358
|
+
import os3 from "os";
|
|
3359
|
+
import path14 from "pathe";
|
|
3360
|
+
function envStateLiveness2(storageAccount, container, key, projectRoot, subscription) {
|
|
3361
|
+
if (!storageAccount || !container || !key) {
|
|
3362
|
+
return { live: false, reason: "no remote state configured" };
|
|
3363
|
+
}
|
|
3364
|
+
const dir = mkdtempSync(path14.join(os3.tmpdir(), "dude-tfstate-"));
|
|
3365
|
+
const file = path14.join(dir, "state.json");
|
|
3366
|
+
try {
|
|
3367
|
+
const r = capture3(
|
|
3368
|
+
"az",
|
|
3369
|
+
[
|
|
3370
|
+
"storage",
|
|
3371
|
+
"blob",
|
|
3372
|
+
"download",
|
|
3373
|
+
"--account-name",
|
|
3374
|
+
storageAccount,
|
|
3375
|
+
"--container-name",
|
|
3376
|
+
container,
|
|
3377
|
+
"--name",
|
|
3378
|
+
key,
|
|
3379
|
+
// Key auth, matching the Terraform backend: `login` would additionally
|
|
3380
|
+
// require the data-plane role "Storage Blob Data Contributor", which
|
|
3381
|
+
// subscription Owners do not get automatically — and this read decides
|
|
3382
|
+
// whether a sibling environment is still alive, so a permissions 403
|
|
3383
|
+
// here would be read as "no state blob" and could wave through a
|
|
3384
|
+
// teardown of state another environment still needs.
|
|
3385
|
+
"--auth-mode",
|
|
3386
|
+
"key",
|
|
3387
|
+
"--file",
|
|
3388
|
+
file,
|
|
3389
|
+
"--no-progress",
|
|
3390
|
+
"--output",
|
|
3391
|
+
"none"
|
|
3392
|
+
],
|
|
3393
|
+
projectRoot,
|
|
3394
|
+
subscription
|
|
3395
|
+
);
|
|
3396
|
+
if (r.status !== 0) {
|
|
3397
|
+
return { live: false, reason: "no state blob (never applied, or already removed)" };
|
|
3398
|
+
}
|
|
3399
|
+
const state = JSON.parse(readFileSync11(file, "utf8"));
|
|
3400
|
+
const n = Array.isArray(state.resources) ? state.resources.length : 0;
|
|
3401
|
+
return n > 0 ? { live: true, reason: `${n} resource(s) still in state` } : { live: false, reason: "state is empty (already destroyed)" };
|
|
3402
|
+
} catch {
|
|
3403
|
+
return { live: true, reason: "state present but unreadable \u2014 keeping to be safe" };
|
|
3404
|
+
} finally {
|
|
3405
|
+
rmSync(dir, { recursive: true, force: true });
|
|
3406
|
+
}
|
|
3407
|
+
}
|
|
3408
|
+
function resourceGroupExists(name, projectRoot, subscription) {
|
|
3409
|
+
if (!name) return false;
|
|
3410
|
+
const r = capture3(
|
|
3411
|
+
"az",
|
|
3412
|
+
["group", "exists", "--name", name, "--output", "tsv"],
|
|
3413
|
+
projectRoot,
|
|
3414
|
+
subscription
|
|
3415
|
+
);
|
|
3416
|
+
return r.status === 0 && r.stdout.trim() === "true";
|
|
3417
|
+
}
|
|
3418
|
+
function bootstrapStateIsEmpty(projectRoot) {
|
|
3419
|
+
const file = path14.join(projectRoot, TF_BOOTSTRAP_DIR2, "terraform.tfstate");
|
|
3420
|
+
if (!existsSync11(file)) return true;
|
|
3421
|
+
try {
|
|
3422
|
+
const state = JSON.parse(readFileSync11(file, "utf8"));
|
|
3423
|
+
return !Array.isArray(state.resources) || state.resources.length === 0;
|
|
3424
|
+
} catch {
|
|
3425
|
+
return false;
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3429
|
+
// src/commands/iac/providers/azure-aca/commands/destroy/index.ts
|
|
3430
|
+
var iacDestroyCommand2 = {
|
|
3431
|
+
available: hasIac2,
|
|
3432
|
+
description: "Tear down everything for an environment: destroy the Terraform infrastructure (resource group, Container Apps environment, database), then destroy the shared bootstrap (state storage account + container registry). Use --keep-backend to preserve the shared resources.",
|
|
3433
|
+
args: {
|
|
3434
|
+
...envArg2,
|
|
3435
|
+
yes: { type: "boolean", description: "Skip the interactive approval (-auto-approve)." },
|
|
3436
|
+
"keep-backend": {
|
|
3437
|
+
type: "boolean",
|
|
3438
|
+
description: "Keep the shared bootstrap (Terraform state storage account + container registry). It is kept automatically while any other environment still uses it; pass this to force-keep it even when destroying the last environment."
|
|
3439
|
+
},
|
|
3440
|
+
"skip-tf": {
|
|
3441
|
+
type: "boolean",
|
|
3442
|
+
description: "Skip the Terraform destroy of the environment \u2014 only run the bootstrap teardown (unless --keep-backend)."
|
|
3443
|
+
}
|
|
3444
|
+
},
|
|
3445
|
+
async run({ projectRoot, args }) {
|
|
3446
|
+
if (!requireIac2(projectRoot)) process.exit(1);
|
|
3447
|
+
const env = requireEnv2(projectRoot, args);
|
|
3448
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
3449
|
+
const extra = args.yes ? ["-auto-approve"] : [];
|
|
3450
|
+
const resourceGroup = tfOutputRaw2(projectRoot, "resource_group_name", subscription) || resourceGroupFor(projectRoot, env);
|
|
3451
|
+
if (!args["skip-tf"]) {
|
|
3452
|
+
process.stdout.write(`
|
|
3453
|
+
\u2192 destroying the "${env}" infrastructure\u2026
|
|
3454
|
+
`);
|
|
3455
|
+
const code = tf2(projectRoot, ["destroy", varFile2(env), ...extra], subscription);
|
|
3456
|
+
if (code !== 0) process.exit(code);
|
|
3457
|
+
if (resourceGroupExists(resourceGroup, projectRoot, subscription)) {
|
|
3458
|
+
process.stderr.write(
|
|
3459
|
+
`
|
|
3460
|
+
\u26A0 Resource group "${resourceGroup}" still exists.
|
|
3461
|
+
Azure may still be deleting it (this can take several minutes), or a
|
|
3462
|
+
resource lock is blocking it. Check with:
|
|
3463
|
+
az group show --name ${resourceGroup} --query properties.provisioningState -o tsv
|
|
3464
|
+
|
|
3465
|
+
`
|
|
3466
|
+
);
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3469
|
+
if (args["keep-backend"]) {
|
|
3470
|
+
process.stdout.write(
|
|
3471
|
+
" \u21B7 Keeping the shared state storage + registry (--keep-backend). Done.\n\n"
|
|
3472
|
+
);
|
|
3473
|
+
process.exit(0);
|
|
3474
|
+
}
|
|
3475
|
+
const backend = readBackend2(projectRoot, env);
|
|
3476
|
+
if (!backend.storageAccount) {
|
|
3477
|
+
process.stdout.write(" \u21B7 No shared backend configured to tear down. Done.\n\n");
|
|
3478
|
+
process.exit(0);
|
|
3479
|
+
}
|
|
3480
|
+
const siblings = listEnvironments2(projectRoot).filter(
|
|
3481
|
+
(e) => e !== env && readBackend2(projectRoot, e).storageAccount === backend.storageAccount
|
|
3482
|
+
);
|
|
3483
|
+
const live = [];
|
|
3484
|
+
if (siblings.length) {
|
|
3485
|
+
process.stdout.write(` \u2192 checking sibling environments on this backend\u2026
|
|
3486
|
+
`);
|
|
3487
|
+
for (const e of siblings) {
|
|
3488
|
+
const b = readBackend2(projectRoot, e);
|
|
3489
|
+
const { live: isLive, reason } = envStateLiveness2(
|
|
3490
|
+
b.storageAccount,
|
|
3491
|
+
b.container,
|
|
3492
|
+
b.key,
|
|
3493
|
+
projectRoot,
|
|
3494
|
+
subscription
|
|
3495
|
+
);
|
|
3496
|
+
process.stdout.write(` \u2022 ${e}: ${isLive ? "still live" : "not live"} \u2014 ${reason}
|
|
3497
|
+
`);
|
|
3498
|
+
if (isLive) live.push(e);
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
if (live.length) {
|
|
3502
|
+
process.stdout.write(
|
|
3503
|
+
`
|
|
3504
|
+
\u21B7 Keeping the shared state storage + registry \u2014 still used by: ${live.join(", ")}.
|
|
3505
|
+
Destroying them would wipe their state and registry. Destroy those
|
|
3506
|
+
environments first, or pass --keep-backend. Done.
|
|
3507
|
+
|
|
3508
|
+
`
|
|
3509
|
+
);
|
|
3510
|
+
process.exit(0);
|
|
3511
|
+
}
|
|
3512
|
+
process.stdout.write(
|
|
3513
|
+
`
|
|
3514
|
+
\u2192 tearing down the shared bootstrap (state storage + container registry)\u2026
|
|
3515
|
+
resource group: ${backend.resourceGroup || "(none)"} storage: ${backend.storageAccount}
|
|
3516
|
+
`
|
|
3517
|
+
);
|
|
3518
|
+
const bootstrapWasEmpty = bootstrapStateIsEmpty(projectRoot);
|
|
3519
|
+
tfBoot2(projectRoot, ["init", "-input=false"], subscription);
|
|
3520
|
+
const bootCode = tfBoot2(projectRoot, ["destroy", ...extra], subscription);
|
|
3521
|
+
if (bootCode !== 0) {
|
|
3522
|
+
process.stderr.write(
|
|
3523
|
+
`
|
|
3524
|
+
\u2717 Could not destroy the shared bootstrap. Inspect it with:
|
|
3525
|
+
az group show --name ${backend.resourceGroup}
|
|
3526
|
+
|
|
3527
|
+
`
|
|
3528
|
+
);
|
|
3529
|
+
process.exit(bootCode);
|
|
3530
|
+
}
|
|
3531
|
+
if (resourceGroupExists(backend.resourceGroup, projectRoot, subscription)) {
|
|
3532
|
+
process.stderr.write(
|
|
3533
|
+
bootstrapWasEmpty ? `
|
|
3534
|
+
\u2717 Shared resource group "${backend.resourceGroup}" still exists, and the
|
|
3535
|
+
bootstrap's Terraform state was already empty before it ran \u2014 so the
|
|
3536
|
+
destroy above had nothing to act on.
|
|
3537
|
+
|
|
3538
|
+
The bootstrap keeps LOCAL state (it is what creates the remote backend,
|
|
3539
|
+
so it cannot use it) and iac/.gitignore excludes *.tfstate. That state
|
|
3540
|
+
therefore exists only where \`dude iac bootstrap\` was run: a fresh clone,
|
|
3541
|
+
a re-scaffold or a teammate's machine all start empty.
|
|
3542
|
+
|
|
3543
|
+
Remove the shared resources directly:
|
|
3544
|
+
az group delete --name ${backend.resourceGroup} --yes
|
|
3545
|
+
|
|
3546
|
+
` : `
|
|
3547
|
+
\u26A0 Shared resource group "${backend.resourceGroup}" still exists \u2014 Azure may
|
|
3548
|
+
still be deleting it. Re-check in a few minutes.
|
|
3549
|
+
|
|
3550
|
+
`
|
|
3551
|
+
);
|
|
3552
|
+
process.exit(1);
|
|
3553
|
+
}
|
|
3554
|
+
process.stdout.write(" \u2713 Shared bootstrap removed.\n\n");
|
|
3555
|
+
process.exit(0);
|
|
3556
|
+
}
|
|
3557
|
+
};
|
|
3558
|
+
|
|
3559
|
+
// src/commands/iac/providers/azure-aca/commands/fmt/index.ts
|
|
3560
|
+
var iacFmtCommand2 = defineAzureFmt(azureAcaTarget);
|
|
3561
|
+
|
|
3562
|
+
// src/commands/iac/providers/azure-aca/commands/init/index.ts
|
|
3563
|
+
var iacInitCommand2 = defineAzureInit(azureAcaTarget);
|
|
3564
|
+
|
|
3565
|
+
// src/commands/iac/providers/azure-aca/lib/apps.ts
|
|
3566
|
+
function listApps(projectRoot, resourceGroup, subscription) {
|
|
3567
|
+
const r = capture3(
|
|
3568
|
+
"az",
|
|
3569
|
+
["containerapp", "list", "--resource-group", resourceGroup, "--output", "json"],
|
|
3570
|
+
projectRoot,
|
|
3571
|
+
subscription
|
|
3572
|
+
);
|
|
3573
|
+
if (r.status !== 0) return [];
|
|
3574
|
+
try {
|
|
3575
|
+
const raw = JSON.parse(r.stdout);
|
|
3576
|
+
return raw.map((a) => {
|
|
3577
|
+
const props = a.properties ?? {};
|
|
3578
|
+
const cfg = props.configuration ?? {};
|
|
3579
|
+
const ingress = cfg.ingress ?? {};
|
|
3580
|
+
const template = props.template ?? {};
|
|
3581
|
+
const scale = template.scale ?? {};
|
|
3582
|
+
return {
|
|
3583
|
+
name: String(a.name ?? ""),
|
|
3584
|
+
runningStatus: String(props.runningStatus ?? "\u2014"),
|
|
3585
|
+
latestRevision: String(props.latestRevisionName ?? "\u2014"),
|
|
3586
|
+
fqdn: String(ingress.fqdn ?? ""),
|
|
3587
|
+
replicas: Number(scale.minReplicas ?? 0)
|
|
3588
|
+
};
|
|
3589
|
+
}).filter((a) => a.name).sort((a, b) => a.name.localeCompare(b.name));
|
|
3590
|
+
} catch {
|
|
3591
|
+
return [];
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
function resolveApp(apps, wanted) {
|
|
3595
|
+
return apps.find((a) => a.name === wanted) ?? apps.find((a) => a.name.endsWith(`-${wanted}`));
|
|
3596
|
+
}
|
|
3597
|
+
|
|
3598
|
+
// src/commands/iac/providers/azure-aca/commands/logs/index.ts
|
|
3599
|
+
var iacLogsCommand = {
|
|
3600
|
+
available: hasIac2,
|
|
3601
|
+
description: "Stream a container app's logs (az containerapp logs show).",
|
|
3602
|
+
args: {
|
|
3603
|
+
...envArg2,
|
|
3604
|
+
service: {
|
|
3605
|
+
type: "string",
|
|
3606
|
+
description: "Which app to read: backend (default), frontend, worker, beat, redis \u2014 or a full app name."
|
|
3607
|
+
},
|
|
3608
|
+
tail: { type: "string", description: "How many past lines to show first (default: 50)." },
|
|
3609
|
+
follow: { type: "boolean", description: "Keep streaming new output (like tail -f)." }
|
|
3610
|
+
},
|
|
3611
|
+
async run({ projectRoot, args }) {
|
|
3612
|
+
if (!requireIac2(projectRoot)) process.exit(1);
|
|
3613
|
+
const env = requireEnv2(projectRoot, args);
|
|
3614
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
3615
|
+
const group = tfOutputRaw2(projectRoot, "resource_group_name", subscription) || resourceGroupFor(projectRoot, env);
|
|
3616
|
+
const apps = listApps(projectRoot, group, subscription);
|
|
3617
|
+
if (!apps.length) {
|
|
3618
|
+
process.stderr.write(
|
|
3619
|
+
`
|
|
3620
|
+
\u2717 No container apps found in "${group}".
|
|
3621
|
+
Has this environment been provisioned? Try: dude iac apply --env ${env}
|
|
3622
|
+
|
|
3623
|
+
`
|
|
3624
|
+
);
|
|
3625
|
+
process.exit(1);
|
|
3626
|
+
}
|
|
3627
|
+
const wanted = String(args.service ?? "backend");
|
|
3628
|
+
const app = resolveApp(apps, wanted);
|
|
3629
|
+
if (!app) {
|
|
3630
|
+
process.stderr.write(
|
|
3631
|
+
`
|
|
3632
|
+
\u2717 No app matching "${wanted}" in this environment.
|
|
3633
|
+
Available: ${apps.map((a) => a.name).join(", ")}
|
|
3634
|
+
|
|
3635
|
+
`
|
|
3636
|
+
);
|
|
3637
|
+
process.exit(1);
|
|
3638
|
+
}
|
|
3639
|
+
const cliArgs = [
|
|
3640
|
+
"containerapp",
|
|
3641
|
+
"logs",
|
|
3642
|
+
"show",
|
|
3643
|
+
"--name",
|
|
3644
|
+
app.name,
|
|
3645
|
+
"--resource-group",
|
|
3646
|
+
group,
|
|
3647
|
+
"--tail",
|
|
3648
|
+
String(args.tail ?? "50")
|
|
3649
|
+
];
|
|
3650
|
+
if (args.follow) cliArgs.push("--follow");
|
|
3651
|
+
process.exit(run3("az", cliArgs, projectRoot, subscription));
|
|
3652
|
+
}
|
|
3653
|
+
};
|
|
3654
|
+
|
|
3655
|
+
// src/commands/iac/providers/azure-aca/commands/login/index.ts
|
|
3656
|
+
var iacLoginCommand2 = defineAzureLogin(azureAcaTarget);
|
|
3657
|
+
|
|
3658
|
+
// src/commands/iac/providers/azure-aca/commands/new-env/index.ts
|
|
3659
|
+
var iacNewEnvCommand2 = defineAzureNewEnv(azureAcaTarget);
|
|
3660
|
+
|
|
3661
|
+
// src/commands/iac/providers/azure-aca/commands/output/index.ts
|
|
3662
|
+
var iacOutputCommand2 = defineAzureOutput(azureAcaTarget);
|
|
3663
|
+
|
|
3664
|
+
// src/commands/iac/providers/azure-aca/commands/plan/index.ts
|
|
3665
|
+
var iacPlanCommand2 = defineAzurePlan(azureAcaTarget);
|
|
3666
|
+
|
|
3667
|
+
// src/commands/iac/providers/azure-aca/commands/push/index.ts
|
|
3668
|
+
var iacPushCommand2 = defineAzurePush(azureAcaTarget);
|
|
3669
|
+
|
|
3670
|
+
// src/commands/iac/providers/azure-aca/commands/shell/index.ts
|
|
3671
|
+
var iacShellCommand2 = defineAzureShell(azureAcaTarget);
|
|
3672
|
+
|
|
3673
|
+
// src/commands/iac/providers/azure-aca/commands/ship/index.ts
|
|
3674
|
+
var iacShipCommand2 = {
|
|
3675
|
+
available: hasIac2,
|
|
3676
|
+
description: "Build, push, and deploy in one step (the local inner loop).",
|
|
3677
|
+
args: {
|
|
3678
|
+
...envArg2,
|
|
3679
|
+
...tagArg2,
|
|
3680
|
+
...platformArg2,
|
|
3681
|
+
"skip-migrations": {
|
|
3682
|
+
type: "boolean",
|
|
3683
|
+
description: "Do not run the database migration job after rolling out."
|
|
3684
|
+
}
|
|
3685
|
+
},
|
|
3686
|
+
async run({ projectRoot, args }) {
|
|
3687
|
+
if (!requireIac2(projectRoot)) process.exit(1);
|
|
3688
|
+
const env = requireEnv2(projectRoot, args);
|
|
3689
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
3690
|
+
const tag = resolveTag2(projectRoot, args);
|
|
3691
|
+
if (!tag) process.exit(1);
|
|
3692
|
+
const repos = requireAcrRepos(projectRoot, subscription, env);
|
|
3693
|
+
const platform = String(args.platform ?? "linux/amd64");
|
|
3694
|
+
const project = projectName(projectRoot);
|
|
3695
|
+
warnTagExists(projectRoot, subscription, tag, repos);
|
|
3696
|
+
let code = doBuild2(projectRoot, subscription, tag, repos, project, platform);
|
|
3697
|
+
if (code !== 0) process.exit(code);
|
|
3698
|
+
code = doPush2(projectRoot, subscription, tag, repos);
|
|
3699
|
+
if (code !== 0) process.exit(code);
|
|
3700
|
+
code = doDeploy2(projectRoot, subscription, env, tag, repos);
|
|
3701
|
+
if (code !== 0) process.exit(code);
|
|
3702
|
+
if (!args["skip-migrations"]) {
|
|
3703
|
+
code = runMigrations(projectRoot, subscription, env);
|
|
3704
|
+
if (code !== 0) process.exit(code);
|
|
3705
|
+
}
|
|
3706
|
+
process.stdout.write(`
|
|
3707
|
+
\u2713 Shipped ${project}:${tag} to "${env}".
|
|
3708
|
+
`);
|
|
3709
|
+
if (repos.appUrl) process.stdout.write(` ${repos.appUrl}
|
|
3710
|
+
`);
|
|
3711
|
+
process.stdout.write("\n");
|
|
3712
|
+
process.exit(0);
|
|
3713
|
+
}
|
|
3714
|
+
};
|
|
3715
|
+
|
|
3716
|
+
// src/commands/iac/providers/azure-aca/commands/status/index.ts
|
|
3717
|
+
var iacStatusCommand2 = {
|
|
3718
|
+
available: hasIac2,
|
|
3719
|
+
description: "Show the container apps in an environment: running state, revision and public URL.",
|
|
3720
|
+
args: { ...envArg2 },
|
|
3721
|
+
async run({ projectRoot, args }) {
|
|
3722
|
+
if (!requireIac2(projectRoot)) process.exit(1);
|
|
3723
|
+
const env = requireEnv2(projectRoot, args);
|
|
3724
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
3725
|
+
const group = tfOutputRaw2(projectRoot, "resource_group_name", subscription) || resourceGroupFor(projectRoot, env);
|
|
3726
|
+
const apps = listApps(projectRoot, group, subscription);
|
|
3727
|
+
if (!apps.length) {
|
|
3728
|
+
process.stderr.write(
|
|
3729
|
+
`
|
|
3730
|
+
\u2717 No container apps found in "${group}".
|
|
3731
|
+
Has this environment been provisioned? Try: dude iac apply --env ${env}
|
|
3732
|
+
|
|
3733
|
+
`
|
|
3734
|
+
);
|
|
3735
|
+
process.exit(1);
|
|
3736
|
+
}
|
|
3737
|
+
const w = Math.max(...apps.map((a) => a.name.length), 4);
|
|
3738
|
+
process.stdout.write(`
|
|
3739
|
+
Resource group: ${group}
|
|
3740
|
+
|
|
3741
|
+
`);
|
|
3742
|
+
process.stdout.write(` ${"APP".padEnd(w)} ${"STATUS".padEnd(10)} REVISION
|
|
3743
|
+
`);
|
|
3744
|
+
for (const a of apps) {
|
|
3745
|
+
process.stdout.write(
|
|
3746
|
+
` ${a.name.padEnd(w)} ${a.runningStatus.padEnd(10)} ${a.latestRevision}
|
|
3747
|
+
`
|
|
3748
|
+
);
|
|
3749
|
+
}
|
|
3750
|
+
const exposed = apps.filter((a) => a.fqdn);
|
|
3751
|
+
if (exposed.length) {
|
|
3752
|
+
process.stdout.write("\n Public endpoints:\n");
|
|
3753
|
+
for (const a of exposed) process.stdout.write(` ${a.name}: https://${a.fqdn}/
|
|
3754
|
+
`);
|
|
3755
|
+
}
|
|
3756
|
+
process.stdout.write(`
|
|
3757
|
+
Logs: dude iac logs --env ${env} --service <app>
|
|
3758
|
+
|
|
3759
|
+
`);
|
|
3760
|
+
}
|
|
3761
|
+
};
|
|
3762
|
+
|
|
3763
|
+
// src/commands/iac/providers/azure-aca/commands/validate/index.ts
|
|
3764
|
+
var iacValidateCommand2 = defineAzureValidate(azureAcaTarget);
|
|
3765
|
+
|
|
3766
|
+
// src/commands/iac/providers/azure-aca/index.ts
|
|
3767
|
+
var azureAcaProvider = {
|
|
3768
|
+
id: PROVIDER_ID2,
|
|
3769
|
+
label: "Azure Container Apps (Terraform)",
|
|
3770
|
+
detect: hasIac2,
|
|
3771
|
+
commands: {
|
|
3772
|
+
login: iacLoginCommand2,
|
|
3773
|
+
"new-env": iacNewEnvCommand2,
|
|
3774
|
+
bootstrap: iacBootstrapCommand2,
|
|
3775
|
+
init: iacInitCommand2,
|
|
3776
|
+
plan: iacPlanCommand2,
|
|
3777
|
+
apply: iacApplyCommand2,
|
|
3778
|
+
destroy: iacDestroyCommand2,
|
|
3779
|
+
output: iacOutputCommand2,
|
|
3780
|
+
fmt: iacFmtCommand2,
|
|
3781
|
+
validate: iacValidateCommand2,
|
|
3782
|
+
build: iacBuildCommand2,
|
|
3783
|
+
push: iacPushCommand2,
|
|
3784
|
+
deploy: iacDeployCommand2,
|
|
3785
|
+
ship: iacShipCommand2,
|
|
3786
|
+
status: iacStatusCommand2,
|
|
3787
|
+
logs: iacLogsCommand,
|
|
3788
|
+
migrate: iacMigrateCommand,
|
|
3789
|
+
shell: iacShellCommand2
|
|
3790
|
+
}
|
|
3791
|
+
};
|
|
3792
|
+
|
|
3793
|
+
// src/commands/iac/providers/azure-aks/lib/terraform.ts
|
|
3794
|
+
import { existsSync as existsSync12 } from "fs";
|
|
3795
|
+
import path15 from "pathe";
|
|
3796
|
+
var PROVIDER_ID3 = "azure-aks";
|
|
3797
|
+
var HELM_CHART2 = path15.join("iac", "helm", "app");
|
|
3798
|
+
function hasIac3(projectRoot) {
|
|
3799
|
+
return iacTarget(projectRoot) === PROVIDER_ID3 && existsSync12(path15.join(projectRoot, "iac", "terraform"));
|
|
3800
|
+
}
|
|
3801
|
+
function requireIac3(projectRoot) {
|
|
3802
|
+
if (!hasIac3(projectRoot)) {
|
|
3803
|
+
process.stderr.write(
|
|
3804
|
+
"\n \u2717 No Azure AKS IaC configuration found (iac/terraform).\n This project was not initialised with the azure-aks target.\n Re-scaffold with `--iac azure-aks` to enable it.\n\n"
|
|
3805
|
+
);
|
|
3806
|
+
return false;
|
|
3807
|
+
}
|
|
3808
|
+
return true;
|
|
3809
|
+
}
|
|
3810
|
+
function kubeTarget2(projectRoot, env, namespace) {
|
|
3811
|
+
return {
|
|
3812
|
+
cluster: `${projectName(projectRoot)}-${env}`,
|
|
3813
|
+
resourceGroup: `${projectName(projectRoot)}-${env}-rg`,
|
|
3814
|
+
namespace
|
|
3815
|
+
};
|
|
3816
|
+
}
|
|
3817
|
+
|
|
3818
|
+
// src/commands/iac/providers/azure-aks/lib/runner.ts
|
|
3819
|
+
function kubePrelude(t, verbose) {
|
|
3820
|
+
if (!t?.cluster || !t?.resourceGroup) return void 0;
|
|
3821
|
+
const lines = [
|
|
3822
|
+
"export KUBECONFIG=/tmp/dude-kubeconfig",
|
|
3823
|
+
`if az aks get-credentials --resource-group ${shq2(t.resourceGroup)} --name ${shq2(t.cluster)} --file "$KUBECONFIG" --overwrite-existing >/dev/null 2>&1; then`,
|
|
3824
|
+
` kubectl config set-context --current --namespace=${shq2(t.namespace)} >/dev/null 2>&1`
|
|
3825
|
+
];
|
|
3826
|
+
if (verbose) lines.push(` echo " \u2713 context \u2192 ${t.cluster} namespace \u2192 ${t.namespace}"; echo`);
|
|
3827
|
+
lines.push("else", " unset KUBECONFIG");
|
|
3828
|
+
lines.push(
|
|
3829
|
+
verbose ? ` echo " \u26A0 couldn't reach cluster ${t.cluster} \u2014 using your mounted ~/.kube as-is."; echo` : ` echo "dude: couldn't target cluster ${t.cluster}; using the mounted kubeconfig as-is." >&2`
|
|
3830
|
+
);
|
|
3831
|
+
lines.push("fi");
|
|
3832
|
+
return lines;
|
|
3833
|
+
}
|
|
3834
|
+
|
|
3835
|
+
// src/commands/iac/providers/azure-aks/lib/target.ts
|
|
3836
|
+
var azureAksTarget = {
|
|
3837
|
+
id: PROVIDER_ID3,
|
|
3838
|
+
hasIac: hasIac3,
|
|
3839
|
+
requireIac: requireIac3,
|
|
3840
|
+
shellTools: "terraform, kubectl, helm, k9s, az",
|
|
3841
|
+
// `dns_label` names the Azure-assigned public hostname. Left at the source
|
|
3842
|
+
// env's value, a new environment would either collide with it or quietly
|
|
3843
|
+
// serve on the old environment's URL.
|
|
3844
|
+
rewriteEnvTfvars: (tfvars, env, project) => tfvars.replace(/^(\s*dns_label\s*=\s*).*$/m, `$1"${project}-${env}"`),
|
|
3845
|
+
// Open the shell with kubectl/helm/k9s already pointed at this env's cluster,
|
|
3846
|
+
// so it never inherits whatever context the host happened to be on.
|
|
3847
|
+
shellPrelude: (projectRoot, env) => kubePrelude(
|
|
3848
|
+
{
|
|
3849
|
+
cluster: `${projectName(projectRoot)}-${env}`,
|
|
3850
|
+
resourceGroup: `${projectName(projectRoot)}-${env}-rg`,
|
|
3851
|
+
namespace: env
|
|
3852
|
+
},
|
|
3853
|
+
true
|
|
3854
|
+
)
|
|
3855
|
+
};
|
|
3856
|
+
|
|
3857
|
+
// src/commands/iac/providers/azure-aks/commands/apply/index.ts
|
|
3858
|
+
var iacApplyCommand3 = defineAzureApply(azureAksTarget);
|
|
3859
|
+
|
|
3860
|
+
// src/commands/iac/providers/azure-aks/commands/bootstrap/index.ts
|
|
3861
|
+
var iacBootstrapCommand3 = defineAzureBootstrap(azureAksTarget);
|
|
3862
|
+
|
|
3863
|
+
// src/commands/iac/providers/azure-aks/commands/build/index.ts
|
|
3864
|
+
var iacBuildCommand3 = defineAzureBuild(azureAksTarget);
|
|
3865
|
+
|
|
3866
|
+
// src/commands/iac/providers/azure-aks/lib/images.ts
|
|
3867
|
+
import { existsSync as existsSync13 } from "fs";
|
|
3868
|
+
import path16 from "pathe";
|
|
3869
|
+
|
|
3870
|
+
// src/commands/iac/providers/azure-aks/lib/exec.ts
|
|
3871
|
+
function run4(cmd, args, cwd, subscription, kube) {
|
|
3872
|
+
return run3(cmd, args, cwd, subscription, kubePrelude(kube, false));
|
|
3873
|
+
}
|
|
3874
|
+
function capture4(cmd, args, cwd, subscription, kube) {
|
|
3875
|
+
return capture3(cmd, args, cwd, subscription, kubePrelude(kube, false));
|
|
3876
|
+
}
|
|
3877
|
+
|
|
3878
|
+
// src/commands/iac/providers/azure-aks/lib/images.ts
|
|
3879
|
+
function readReleaseExtras(projectRoot, subscription) {
|
|
3880
|
+
const o = tfOutputs(projectRoot, subscription);
|
|
3881
|
+
if (!o) return {};
|
|
3882
|
+
const str = (k) => {
|
|
3883
|
+
const v = o[k]?.value;
|
|
3884
|
+
return typeof v === "string" && v ? v : void 0;
|
|
3885
|
+
};
|
|
3886
|
+
return { host: str("app_host"), databaseUrl: str("database_url") };
|
|
3887
|
+
}
|
|
3888
|
+
function doDeploy3(projectRoot, subscription, env, ns, tag, repos) {
|
|
3889
|
+
const helmArgs = [
|
|
3890
|
+
"upgrade",
|
|
3891
|
+
"--install",
|
|
3892
|
+
projectName(projectRoot),
|
|
3893
|
+
HELM_CHART2,
|
|
3894
|
+
"--namespace",
|
|
3895
|
+
ns,
|
|
3896
|
+
"--create-namespace"
|
|
3897
|
+
];
|
|
3898
|
+
const valuesFile = path16.join(HELM_CHART2, `values-${env}.yaml`);
|
|
3899
|
+
if (existsSync13(path16.join(projectRoot, valuesFile))) helmArgs.push("--values", valuesFile);
|
|
3900
|
+
helmArgs.push(
|
|
3901
|
+
"--set",
|
|
3902
|
+
`image.registry=${repos.registryHost}`,
|
|
3903
|
+
"--set",
|
|
3904
|
+
`image.backend.tag=${tag}`,
|
|
3905
|
+
"--set",
|
|
3906
|
+
`image.frontend.tag=${tag}`
|
|
3907
|
+
);
|
|
3908
|
+
const extras = readReleaseExtras(projectRoot, subscription);
|
|
3909
|
+
if (extras.host) helmArgs.push("--set", `ingress.host=${extras.host}`);
|
|
3910
|
+
if (extras.databaseUrl) helmArgs.push("--set-string", `secrets.DATABASE_URL=${extras.databaseUrl}`);
|
|
3911
|
+
return run4("helm", helmArgs, projectRoot, subscription, kubeTarget2(projectRoot, env, ns));
|
|
3912
|
+
}
|
|
3913
|
+
|
|
3914
|
+
// src/commands/iac/providers/azure-aks/commands/deploy/index.ts
|
|
3915
|
+
var iacDeployCommand3 = {
|
|
3916
|
+
available: hasIac3,
|
|
3917
|
+
description: "Deploy the application (helm upgrade --install) \u2014 auto-wires the ACR registry, image tag and public hostname.",
|
|
3918
|
+
args: {
|
|
3919
|
+
...envArg2,
|
|
3920
|
+
...tagArg2,
|
|
3921
|
+
namespace: { type: "string", description: "Kubernetes namespace (default: the environment)." }
|
|
3922
|
+
},
|
|
3923
|
+
async run({ projectRoot, args }) {
|
|
3924
|
+
if (!requireIac3(projectRoot)) process.exit(1);
|
|
3925
|
+
const env = requireEnv2(projectRoot, args);
|
|
3926
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
3927
|
+
const tag = resolveTag2(projectRoot, args);
|
|
3928
|
+
if (!tag) process.exit(1);
|
|
3929
|
+
const repos = requireAcrRepos(projectRoot, subscription, env);
|
|
3930
|
+
const ns = String(args.namespace ?? env);
|
|
3931
|
+
process.exit(doDeploy3(projectRoot, subscription, env, ns, tag, repos));
|
|
3932
|
+
}
|
|
3933
|
+
};
|
|
3934
|
+
|
|
3935
|
+
// src/commands/iac/providers/azure-aks/commands/destroy/index.ts
|
|
3936
|
+
var iacDestroyCommand3 = {
|
|
3937
|
+
available: hasIac3,
|
|
3938
|
+
description: "Tear down everything for an environment: uninstall the Helm release, destroy the Terraform infrastructure (resource group, AKS, database), then destroy the shared bootstrap (state storage account + container registry). Use --keep-backend to preserve the shared resources.",
|
|
3939
|
+
args: {
|
|
3940
|
+
...envArg2,
|
|
3941
|
+
yes: { type: "boolean", description: "Skip the interactive approval (-auto-approve)." },
|
|
3942
|
+
namespace: {
|
|
3943
|
+
type: "string",
|
|
3944
|
+
description: "Kubernetes namespace the release lives in (default: the environment)."
|
|
3945
|
+
},
|
|
3946
|
+
"skip-helm": {
|
|
3947
|
+
type: "boolean",
|
|
3948
|
+
description: "Skip the Helm uninstall step \u2014 use when the release is already gone."
|
|
3949
|
+
},
|
|
3950
|
+
"keep-backend": {
|
|
3951
|
+
type: "boolean",
|
|
3952
|
+
description: "Keep the shared bootstrap (Terraform state storage account + container registry). It is kept automatically while any other environment still uses it; pass this to force-keep it even when destroying the last environment."
|
|
3953
|
+
},
|
|
3954
|
+
"skip-tf": {
|
|
3955
|
+
type: "boolean",
|
|
3956
|
+
description: "Skip the Terraform destroy of the environment \u2014 only run the Helm uninstall (and the bootstrap teardown unless --keep-backend)."
|
|
3957
|
+
}
|
|
3958
|
+
},
|
|
3959
|
+
async run({ projectRoot, args }) {
|
|
3960
|
+
if (!requireIac3(projectRoot)) process.exit(1);
|
|
3961
|
+
const env = requireEnv2(projectRoot, args);
|
|
3962
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
3963
|
+
const ns = String(args.namespace ?? env);
|
|
3964
|
+
const release = projectName(projectRoot);
|
|
3965
|
+
const kube = kubeTarget2(projectRoot, env, ns);
|
|
3966
|
+
const extra = args.yes ? ["-auto-approve"] : [];
|
|
3967
|
+
if (!args["skip-helm"]) {
|
|
3968
|
+
const helmCheck = capture4(
|
|
3969
|
+
"helm",
|
|
3970
|
+
["status", release, "--namespace", ns],
|
|
3971
|
+
projectRoot,
|
|
3972
|
+
subscription,
|
|
3973
|
+
kube
|
|
3974
|
+
);
|
|
3975
|
+
if (helmCheck.status === 0) {
|
|
3976
|
+
process.stdout.write(
|
|
3977
|
+
`
|
|
3978
|
+
\u2192 uninstalling Helm release "${release}" from namespace "${ns}"\u2026
|
|
3979
|
+
`
|
|
3980
|
+
);
|
|
3981
|
+
const code = run4(
|
|
3982
|
+
"helm",
|
|
3983
|
+
["uninstall", release, "--namespace", ns],
|
|
3984
|
+
projectRoot,
|
|
3985
|
+
subscription,
|
|
3986
|
+
kube
|
|
3987
|
+
);
|
|
3988
|
+
if (code !== 0) {
|
|
3989
|
+
process.stderr.write(
|
|
3990
|
+
"\n \u2717 Helm uninstall failed. Retry or re-run with --skip-helm if you removed it manually.\n\n"
|
|
3991
|
+
);
|
|
3992
|
+
process.exit(code);
|
|
3993
|
+
}
|
|
3994
|
+
process.stdout.write(" \u2192 waiting for the Ingress to be removed\u2026\n");
|
|
3995
|
+
run4(
|
|
3996
|
+
"kubectl",
|
|
3997
|
+
["wait", "--for=delete", `ingress/${release}`, "--namespace", ns, "--timeout=3m"],
|
|
3998
|
+
projectRoot,
|
|
3999
|
+
subscription,
|
|
4000
|
+
kube
|
|
4001
|
+
);
|
|
4002
|
+
} else {
|
|
4003
|
+
process.stdout.write(
|
|
4004
|
+
` \u21B7 Helm release "${release}" not found in namespace "${ns}", skipping uninstall.
|
|
4005
|
+
`
|
|
4006
|
+
);
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
4009
|
+
const resourceGroup = tfOutputRaw2(projectRoot, "resource_group_name", subscription) || `${release}-${env}-rg`;
|
|
4010
|
+
if (!args["skip-tf"]) {
|
|
4011
|
+
process.stdout.write(`
|
|
4012
|
+
\u2192 destroying the "${env}" infrastructure\u2026
|
|
4013
|
+
`);
|
|
4014
|
+
const code = tf2(projectRoot, ["destroy", varFile2(env), ...extra], subscription);
|
|
4015
|
+
if (code !== 0) process.exit(code);
|
|
4016
|
+
if (resourceGroupExists(resourceGroup, projectRoot, subscription)) {
|
|
4017
|
+
process.stderr.write(
|
|
4018
|
+
`
|
|
4019
|
+
\u26A0 Resource group "${resourceGroup}" still exists.
|
|
4020
|
+
Azure may still be deleting it (this can take several minutes), or a
|
|
4021
|
+
resource lock is blocking it. Check with:
|
|
4022
|
+
az group show --name ${resourceGroup} --query properties.provisioningState -o tsv
|
|
4023
|
+
|
|
4024
|
+
`
|
|
4025
|
+
);
|
|
4026
|
+
}
|
|
4027
|
+
}
|
|
4028
|
+
if (args["keep-backend"]) {
|
|
4029
|
+
process.stdout.write(" \u21B7 Keeping the shared state storage + registry (--keep-backend). Done.\n\n");
|
|
4030
|
+
process.exit(0);
|
|
4031
|
+
}
|
|
4032
|
+
const backend = readBackend2(projectRoot, env);
|
|
4033
|
+
if (!backend.storageAccount) {
|
|
4034
|
+
process.stdout.write(" \u21B7 No shared backend configured to tear down. Done.\n\n");
|
|
4035
|
+
process.exit(0);
|
|
4036
|
+
}
|
|
4037
|
+
const siblings = listEnvironments2(projectRoot).filter(
|
|
4038
|
+
(e) => e !== env && readBackend2(projectRoot, e).storageAccount === backend.storageAccount
|
|
4039
|
+
);
|
|
4040
|
+
const live = [];
|
|
4041
|
+
if (siblings.length) {
|
|
4042
|
+
process.stdout.write(` \u2192 checking sibling environments on this backend\u2026
|
|
4043
|
+
`);
|
|
4044
|
+
for (const e of siblings) {
|
|
4045
|
+
const b = readBackend2(projectRoot, e);
|
|
4046
|
+
const { live: isLive, reason } = envStateLiveness2(
|
|
4047
|
+
b.storageAccount,
|
|
4048
|
+
b.container,
|
|
4049
|
+
b.key,
|
|
4050
|
+
projectRoot,
|
|
4051
|
+
subscription
|
|
4052
|
+
);
|
|
4053
|
+
process.stdout.write(` \u2022 ${e}: ${isLive ? "still live" : "not live"} \u2014 ${reason}
|
|
4054
|
+
`);
|
|
4055
|
+
if (isLive) live.push(e);
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
4058
|
+
if (live.length) {
|
|
4059
|
+
process.stdout.write(
|
|
4060
|
+
`
|
|
4061
|
+
\u21B7 Keeping the shared state storage + registry \u2014 still used by: ${live.join(", ")}.
|
|
4062
|
+
Destroying them would wipe their state and registry. Destroy those
|
|
4063
|
+
environments first, or pass --keep-backend. Done.
|
|
4064
|
+
|
|
4065
|
+
`
|
|
4066
|
+
);
|
|
4067
|
+
process.exit(0);
|
|
4068
|
+
}
|
|
4069
|
+
process.stdout.write(
|
|
4070
|
+
`
|
|
4071
|
+
\u2192 tearing down the shared bootstrap (state storage + container registry)\u2026
|
|
4072
|
+
resource group: ${backend.resourceGroup || "(none)"} storage: ${backend.storageAccount}
|
|
4073
|
+
`
|
|
4074
|
+
);
|
|
4075
|
+
const bootstrapWasEmpty = bootstrapStateIsEmpty(projectRoot);
|
|
4076
|
+
tfBoot2(projectRoot, ["init", "-input=false"], subscription);
|
|
4077
|
+
const bootCode = tfBoot2(projectRoot, ["destroy", ...extra], subscription);
|
|
4078
|
+
if (bootCode !== 0) {
|
|
4079
|
+
process.stderr.write(
|
|
4080
|
+
`
|
|
4081
|
+
\u2717 Could not destroy the shared bootstrap. Inspect it with:
|
|
4082
|
+
az group show --name ${backend.resourceGroup}
|
|
4083
|
+
|
|
4084
|
+
`
|
|
4085
|
+
);
|
|
4086
|
+
process.exit(bootCode);
|
|
4087
|
+
}
|
|
4088
|
+
if (resourceGroupExists(backend.resourceGroup, projectRoot, subscription)) {
|
|
4089
|
+
process.stderr.write(
|
|
4090
|
+
bootstrapWasEmpty ? `
|
|
4091
|
+
\u2717 Shared resource group "${backend.resourceGroup}" still exists, and the
|
|
4092
|
+
bootstrap's Terraform state was already empty before it ran \u2014 so the
|
|
4093
|
+
destroy above had nothing to act on.
|
|
4094
|
+
|
|
4095
|
+
The bootstrap keeps LOCAL state (it is what creates the remote backend,
|
|
4096
|
+
so it cannot use it) and iac/.gitignore excludes *.tfstate. That state
|
|
4097
|
+
therefore exists only where \`dude iac bootstrap\` was run: a fresh clone,
|
|
4098
|
+
a re-scaffold or a teammate's machine all start empty.
|
|
4099
|
+
|
|
4100
|
+
Remove the shared resources directly:
|
|
4101
|
+
az group delete --name ${backend.resourceGroup} --yes
|
|
4102
|
+
|
|
4103
|
+
` : `
|
|
4104
|
+
\u26A0 Shared resource group "${backend.resourceGroup}" still exists \u2014 Azure may
|
|
4105
|
+
still be deleting it. Re-check in a few minutes.
|
|
4106
|
+
|
|
4107
|
+
`
|
|
4108
|
+
);
|
|
4109
|
+
process.exit(1);
|
|
4110
|
+
}
|
|
4111
|
+
process.stdout.write(" \u2713 Shared bootstrap removed.\n\n");
|
|
4112
|
+
process.exit(0);
|
|
4113
|
+
}
|
|
4114
|
+
};
|
|
4115
|
+
|
|
4116
|
+
// src/commands/iac/providers/azure-aks/commands/fmt/index.ts
|
|
4117
|
+
var iacFmtCommand3 = defineAzureFmt(azureAksTarget);
|
|
4118
|
+
|
|
4119
|
+
// src/commands/iac/providers/azure-aks/commands/init/index.ts
|
|
4120
|
+
var iacInitCommand3 = defineAzureInit(azureAksTarget);
|
|
4121
|
+
|
|
4122
|
+
// src/commands/iac/providers/azure-aks/commands/kubeconfig/index.ts
|
|
4123
|
+
var iacKubeconfigCommand2 = {
|
|
4124
|
+
available: hasIac3,
|
|
4125
|
+
description: "Update your kubeconfig to point at the provisioned AKS cluster.",
|
|
4126
|
+
args: { ...envArg2 },
|
|
4127
|
+
async run({ projectRoot, args }) {
|
|
4128
|
+
if (!requireIac3(projectRoot)) process.exit(1);
|
|
4129
|
+
const env = requireEnv2(projectRoot, args);
|
|
4130
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
4131
|
+
const out = capture4(
|
|
4132
|
+
"terraform",
|
|
4133
|
+
[`-chdir=${TF_DIR2}`, "output", "-json"],
|
|
4134
|
+
projectRoot,
|
|
4135
|
+
subscription
|
|
4136
|
+
);
|
|
4137
|
+
let cluster = "";
|
|
4138
|
+
let group = "";
|
|
4139
|
+
if (out.status === 0) {
|
|
4140
|
+
try {
|
|
4141
|
+
const o = JSON.parse(out.stdout);
|
|
4142
|
+
cluster = o.cluster_name?.value ?? "";
|
|
4143
|
+
group = o.resource_group_name?.value ?? "";
|
|
4144
|
+
} catch {
|
|
4145
|
+
}
|
|
4146
|
+
}
|
|
4147
|
+
cluster ||= `${projectName(projectRoot)}-${env}`;
|
|
4148
|
+
group ||= `${projectName(projectRoot)}-${env}-rg`;
|
|
4149
|
+
process.exit(
|
|
4150
|
+
runWith(
|
|
4151
|
+
"az",
|
|
4152
|
+
[
|
|
4153
|
+
"aks",
|
|
4154
|
+
"get-credentials",
|
|
4155
|
+
"--resource-group",
|
|
4156
|
+
group,
|
|
4157
|
+
"--name",
|
|
4158
|
+
cluster,
|
|
4159
|
+
"--overwrite-existing"
|
|
4160
|
+
],
|
|
4161
|
+
projectRoot,
|
|
4162
|
+
azureEnv(subscription)
|
|
4163
|
+
)
|
|
4164
|
+
);
|
|
4165
|
+
}
|
|
4166
|
+
};
|
|
4167
|
+
|
|
4168
|
+
// src/commands/iac/providers/azure-aks/commands/login/index.ts
|
|
4169
|
+
var iacLoginCommand3 = defineAzureLogin(azureAksTarget);
|
|
4170
|
+
|
|
4171
|
+
// src/commands/iac/providers/azure-aks/commands/new-env/index.ts
|
|
4172
|
+
var iacNewEnvCommand3 = defineAzureNewEnv(azureAksTarget);
|
|
4173
|
+
|
|
4174
|
+
// src/commands/iac/providers/azure-aks/commands/output/index.ts
|
|
4175
|
+
var iacOutputCommand3 = defineAzureOutput(azureAksTarget);
|
|
4176
|
+
|
|
4177
|
+
// src/commands/iac/providers/azure-aks/commands/plan/index.ts
|
|
4178
|
+
var iacPlanCommand3 = defineAzurePlan(azureAksTarget);
|
|
4179
|
+
|
|
4180
|
+
// src/commands/iac/providers/azure-aks/commands/push/index.ts
|
|
4181
|
+
var iacPushCommand3 = defineAzurePush(azureAksTarget);
|
|
4182
|
+
|
|
4183
|
+
// src/commands/iac/providers/azure-aks/commands/shell/index.ts
|
|
4184
|
+
var iacShellCommand3 = defineAzureShell(azureAksTarget);
|
|
4185
|
+
|
|
4186
|
+
// src/commands/iac/providers/azure-aks/commands/ship/index.ts
|
|
4187
|
+
var iacShipCommand3 = {
|
|
4188
|
+
available: hasIac3,
|
|
4189
|
+
description: "Build, push, and deploy in one step (the local inner loop).",
|
|
4190
|
+
args: {
|
|
4191
|
+
...envArg2,
|
|
4192
|
+
...tagArg2,
|
|
4193
|
+
...platformArg2,
|
|
4194
|
+
namespace: { type: "string", description: "Kubernetes namespace (default: the environment)." }
|
|
4195
|
+
},
|
|
4196
|
+
async run({ projectRoot, args }) {
|
|
4197
|
+
if (!requireIac3(projectRoot)) process.exit(1);
|
|
4198
|
+
const env = requireEnv2(projectRoot, args);
|
|
4199
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
4200
|
+
const tag = resolveTag2(projectRoot, args);
|
|
4201
|
+
if (!tag) process.exit(1);
|
|
4202
|
+
const repos = requireAcrRepos(projectRoot, subscription, env);
|
|
4203
|
+
const ns = String(args.namespace ?? env);
|
|
4204
|
+
const platform = String(args.platform ?? "linux/amd64");
|
|
4205
|
+
const project = projectName(projectRoot);
|
|
4206
|
+
warnTagExists(projectRoot, subscription, tag, repos);
|
|
4207
|
+
let code = doBuild2(projectRoot, subscription, tag, repos, project, platform);
|
|
4208
|
+
if (code !== 0) process.exit(code);
|
|
4209
|
+
code = doPush2(projectRoot, subscription, tag, repos);
|
|
4210
|
+
if (code !== 0) process.exit(code);
|
|
4211
|
+
code = doDeploy3(projectRoot, subscription, env, ns, tag, repos);
|
|
4212
|
+
if (code === 0) {
|
|
4213
|
+
process.stdout.write(`
|
|
4214
|
+
\u2713 Shipped ${project}:${tag} to "${env}".
|
|
4215
|
+
`);
|
|
4216
|
+
if (repos.appUrl) process.stdout.write(` ${repos.appUrl}
|
|
4217
|
+
`);
|
|
4218
|
+
process.stdout.write("\n");
|
|
4219
|
+
}
|
|
4220
|
+
process.exit(code);
|
|
4221
|
+
}
|
|
4222
|
+
};
|
|
4223
|
+
|
|
4224
|
+
// src/commands/iac/providers/azure-aks/commands/status/index.ts
|
|
4225
|
+
var iacStatusCommand3 = {
|
|
4226
|
+
available: hasIac3,
|
|
4227
|
+
description: "Show the deployed release status and pods.",
|
|
4228
|
+
args: {
|
|
4229
|
+
...envArg2,
|
|
4230
|
+
namespace: { type: "string", description: "Kubernetes namespace (default: the environment)." }
|
|
4231
|
+
},
|
|
4232
|
+
async run({ projectRoot, args }) {
|
|
4233
|
+
if (!requireIac3(projectRoot)) process.exit(1);
|
|
4234
|
+
const env = requireEnv2(projectRoot, args);
|
|
4235
|
+
const subscription = resolveSubscription(projectRoot, args, env);
|
|
4236
|
+
const ns = String(args.namespace ?? env);
|
|
4237
|
+
const release = projectName(projectRoot);
|
|
4238
|
+
const kube = kubeTarget2(projectRoot, env, ns);
|
|
4239
|
+
const s = run4("helm", ["status", release, "--namespace", ns], projectRoot, subscription, kube);
|
|
4240
|
+
run4("kubectl", ["get", "pods", "--namespace", ns], projectRoot, subscription, kube);
|
|
4241
|
+
process.exit(s);
|
|
4242
|
+
}
|
|
4243
|
+
};
|
|
4244
|
+
|
|
4245
|
+
// src/commands/iac/providers/azure-aks/commands/validate/index.ts
|
|
4246
|
+
var iacValidateCommand3 = defineAzureValidate(azureAksTarget);
|
|
4247
|
+
|
|
4248
|
+
// src/commands/iac/providers/azure-aks/index.ts
|
|
4249
|
+
var azureAksProvider = {
|
|
4250
|
+
id: PROVIDER_ID3,
|
|
4251
|
+
label: "Azure AKS (Terraform + Helm)",
|
|
4252
|
+
detect: hasIac3,
|
|
4253
|
+
commands: {
|
|
4254
|
+
login: iacLoginCommand3,
|
|
4255
|
+
"new-env": iacNewEnvCommand3,
|
|
4256
|
+
bootstrap: iacBootstrapCommand3,
|
|
4257
|
+
init: iacInitCommand3,
|
|
4258
|
+
plan: iacPlanCommand3,
|
|
4259
|
+
apply: iacApplyCommand3,
|
|
4260
|
+
destroy: iacDestroyCommand3,
|
|
4261
|
+
output: iacOutputCommand3,
|
|
4262
|
+
fmt: iacFmtCommand3,
|
|
4263
|
+
validate: iacValidateCommand3,
|
|
4264
|
+
build: iacBuildCommand3,
|
|
4265
|
+
push: iacPushCommand3,
|
|
4266
|
+
kubeconfig: iacKubeconfigCommand2,
|
|
4267
|
+
deploy: iacDeployCommand3,
|
|
4268
|
+
ship: iacShipCommand3,
|
|
4269
|
+
status: iacStatusCommand3,
|
|
4270
|
+
shell: iacShellCommand3
|
|
4271
|
+
}
|
|
4272
|
+
};
|
|
4273
|
+
|
|
4274
|
+
// src/commands/iac/index.ts
|
|
4275
|
+
var iacProviders = [awsEksProvider, azureAksProvider, azureAcaProvider];
|
|
4276
|
+
function activeIacProvider(projectRoot = process.cwd()) {
|
|
4277
|
+
return iacProviders.find((p) => p.detect(projectRoot));
|
|
4278
|
+
}
|
|
4279
|
+
var provider = activeIacProvider() ?? iacProviders[0];
|
|
4280
|
+
var iacCommands = provider?.commands ?? {};
|
|
4281
|
+
|
|
4282
|
+
// src/commands/_docker.ts
|
|
4283
|
+
import { spawnSync as spawnSync11 } from "child_process";
|
|
4284
|
+
function dc(args) {
|
|
4285
|
+
const result = spawnSync11("docker", ["compose", ...args], { stdio: "inherit" });
|
|
4286
|
+
process.exit(result.status ?? 0);
|
|
4287
|
+
}
|
|
4288
|
+
|
|
4289
|
+
// src/commands/down/index.ts
|
|
4290
|
+
var downCommand = {
|
|
4291
|
+
description: "Stop and remove all service containers (docker compose down).",
|
|
4292
|
+
args: {},
|
|
4293
|
+
async run() {
|
|
4294
|
+
dc(["down"]);
|
|
4295
|
+
}
|
|
4296
|
+
};
|
|
4297
|
+
|
|
4298
|
+
// src/commands/format/index.ts
|
|
4299
|
+
import { spawnSync as spawnSync12 } from "child_process";
|
|
4300
|
+
import { existsSync as existsSync14 } from "fs";
|
|
4301
|
+
import path17 from "pathe";
|
|
4302
|
+
function shouldUseShell2() {
|
|
4303
|
+
return process.platform === "win32";
|
|
4304
|
+
}
|
|
4305
|
+
function isAvailable(cmd) {
|
|
4306
|
+
const r = spawnSync12(cmd, ["--version"], { stdio: "ignore", shell: shouldUseShell2() });
|
|
4307
|
+
return r.error == null;
|
|
4308
|
+
}
|
|
4309
|
+
function exec(cmd, args, cwd) {
|
|
4310
|
+
const result = spawnSync12(cmd, args, { cwd, stdio: "inherit", shell: shouldUseShell2() });
|
|
4311
|
+
if (result.error) {
|
|
4312
|
+
process.stderr.write(`error: failed to run ${cmd}: ${result.error.message}
|
|
4313
|
+
`);
|
|
4314
|
+
return false;
|
|
4315
|
+
}
|
|
4316
|
+
return result.status === 0;
|
|
4317
|
+
}
|
|
4318
|
+
function hasLocalExecutable(dir, executable) {
|
|
4319
|
+
const localBin = path17.join(dir, "node_modules", ".bin", executable);
|
|
4320
|
+
return existsSync14(localBin);
|
|
4321
|
+
}
|
|
4322
|
+
function ensureNodeModules(dir, executable) {
|
|
4323
|
+
const nodeModulesDir = path17.join(dir, "node_modules");
|
|
4324
|
+
const hasDeps = existsSync14(nodeModulesDir);
|
|
4325
|
+
const hasExecutable = executable == null || hasLocalExecutable(dir, executable);
|
|
4326
|
+
if (hasDeps && hasExecutable) return true;
|
|
4327
|
+
process.stdout.write(
|
|
4328
|
+
hasDeps ? `${executable ?? "required dependency"} not found \u2014 running npm install\u2026
|
|
4329
|
+
` : "node_modules not found \u2014 running npm install\u2026\n"
|
|
4330
|
+
);
|
|
4331
|
+
return exec("npm", ["install", "--prefix", dir, "--silent"], dir);
|
|
4332
|
+
}
|
|
4333
|
+
function ensureVenv(dir) {
|
|
4334
|
+
const venvRuff = path17.join(dir, ".venv", "bin", "ruff");
|
|
4335
|
+
if (existsSync14(venvRuff)) return true;
|
|
4336
|
+
process.stdout.write(".venv not found \u2014 running uv sync\u2026\n");
|
|
4337
|
+
return exec("uv", ["sync"], dir);
|
|
4338
|
+
}
|
|
4339
|
+
function isDockerServiceRunning(service, cwd) {
|
|
4340
|
+
const r = spawnSync12("docker", ["compose", "ps", "--status", "running", "-q", service], {
|
|
4341
|
+
stdio: "pipe",
|
|
4342
|
+
cwd
|
|
4343
|
+
});
|
|
4344
|
+
return r.status === 0 && r.stdout != null && r.stdout.toString().trim().length > 0;
|
|
4345
|
+
}
|
|
4346
|
+
var formatCommand = {
|
|
4347
|
+
description: "Format backend (ruff) and frontend (prettier) source files.",
|
|
4348
|
+
args: {
|
|
4349
|
+
check: {
|
|
4350
|
+
type: "boolean",
|
|
4351
|
+
description: "Check formatting without writing changes (exits 1 if any file would change).",
|
|
4352
|
+
default: false
|
|
4353
|
+
}
|
|
4354
|
+
},
|
|
4355
|
+
async run({ projectRoot, args }) {
|
|
4356
|
+
const check = Boolean(args.check);
|
|
4357
|
+
const backendDir = path17.join(projectRoot, "backend");
|
|
4358
|
+
const frontendDir = path17.join(projectRoot, "frontend");
|
|
4359
|
+
const e2eDir = path17.join(projectRoot, "e2e");
|
|
4360
|
+
const backendExists = existsSync14(backendDir);
|
|
4361
|
+
const backendContainerUp = backendExists && isDockerServiceRunning("backend", projectRoot);
|
|
4362
|
+
const missing = [];
|
|
4363
|
+
if (backendExists && !backendContainerUp && !isAvailable("uv"))
|
|
4364
|
+
missing.push("uv \u2192 https://docs.astral.sh/uv/getting-started/installation/");
|
|
4365
|
+
if ((existsSync14(frontendDir) || existsSync14(e2eDir)) && !isAvailable("pnpm"))
|
|
4366
|
+
missing.push("pnpm \u2192 https://pnpm.io/installation");
|
|
4367
|
+
if (missing.length > 0) {
|
|
4368
|
+
process.stderr.write(
|
|
4369
|
+
"error: the following tools are required but were not found on your PATH:\n\n"
|
|
4370
|
+
);
|
|
4371
|
+
for (const m of missing) process.stderr.write(` \u2022 ${m}
|
|
4372
|
+
`);
|
|
4373
|
+
process.stderr.write("\n");
|
|
4374
|
+
process.exit(1);
|
|
4375
|
+
}
|
|
4376
|
+
let ok = true;
|
|
4377
|
+
if (backendExists) {
|
|
4378
|
+
process.stdout.write(check ? "Checking backend formatting\u2026\n" : "Formatting backend\u2026\n");
|
|
4379
|
+
if (backendContainerUp) {
|
|
4380
|
+
ok = exec(
|
|
4381
|
+
"docker",
|
|
4382
|
+
[
|
|
4383
|
+
"compose",
|
|
4384
|
+
"exec",
|
|
4385
|
+
"backend",
|
|
4386
|
+
"uv",
|
|
4387
|
+
"run",
|
|
4388
|
+
"ruff",
|
|
4389
|
+
"format",
|
|
4390
|
+
...check ? ["--check"] : [],
|
|
4391
|
+
"app/"
|
|
4392
|
+
],
|
|
4393
|
+
projectRoot
|
|
4394
|
+
) && ok;
|
|
4395
|
+
ok = exec(
|
|
4396
|
+
"docker",
|
|
4397
|
+
[
|
|
4398
|
+
"compose",
|
|
4399
|
+
"exec",
|
|
4400
|
+
"backend",
|
|
4401
|
+
"uv",
|
|
4402
|
+
"run",
|
|
4403
|
+
"ruff",
|
|
4404
|
+
"check",
|
|
4405
|
+
"--select",
|
|
4406
|
+
"I",
|
|
4407
|
+
...check ? [] : ["--fix"],
|
|
4408
|
+
"app/"
|
|
4409
|
+
],
|
|
4410
|
+
projectRoot
|
|
4411
|
+
) && ok;
|
|
4412
|
+
} else {
|
|
4413
|
+
const venvReady = ensureVenv(backendDir);
|
|
4414
|
+
if (!venvReady) {
|
|
4415
|
+
process.stderr.write("error: uv sync failed in backend/\n");
|
|
4416
|
+
ok = false;
|
|
4417
|
+
}
|
|
4418
|
+
if (venvReady) {
|
|
4419
|
+
ok = exec("uv", ["run", "ruff", "format", ...check ? ["--check"] : [], "."], backendDir) && ok;
|
|
4420
|
+
ok = exec(
|
|
4421
|
+
"uv",
|
|
4422
|
+
["run", "ruff", "check", "--select", "I", ...check ? [] : ["--fix"], "."],
|
|
4423
|
+
backendDir
|
|
4424
|
+
) && ok;
|
|
4425
|
+
}
|
|
4426
|
+
}
|
|
4427
|
+
}
|
|
4428
|
+
if (existsSync14(frontendDir)) {
|
|
4429
|
+
process.stdout.write(check ? "Checking frontend formatting\u2026\n" : "Formatting frontend\u2026\n");
|
|
4430
|
+
const prettierBin = path17.join(frontendDir, "node_modules", ".bin", "prettier");
|
|
4431
|
+
if (!existsSync14(prettierBin)) {
|
|
4432
|
+
ensureNodeModules(frontendDir, "prettier");
|
|
4433
|
+
}
|
|
4434
|
+
if (!existsSync14(prettierBin)) {
|
|
4435
|
+
process.stderr.write(" prettier not found \u2014 run: cd frontend && npm install\n");
|
|
4436
|
+
ok = false;
|
|
4437
|
+
} else {
|
|
4438
|
+
ok = exec(prettierBin, [...check ? ["--check"] : ["--write"], "src/"], frontendDir) && ok;
|
|
4439
|
+
}
|
|
4440
|
+
}
|
|
4441
|
+
if (existsSync14(e2eDir)) {
|
|
4442
|
+
process.stdout.write(check ? "Checking e2e formatting\u2026\n" : "Formatting e2e\u2026\n");
|
|
4443
|
+
const prettierBin = path17.join(e2eDir, "node_modules", ".bin", "prettier");
|
|
4444
|
+
if (!existsSync14(prettierBin)) {
|
|
4445
|
+
ensureNodeModules(e2eDir, "prettier");
|
|
4446
|
+
}
|
|
4447
|
+
if (!existsSync14(prettierBin)) {
|
|
4448
|
+
process.stderr.write(" prettier not found \u2014 run: cd e2e && npm install\n");
|
|
4449
|
+
ok = false;
|
|
4450
|
+
} else {
|
|
4451
|
+
ok = exec(
|
|
4452
|
+
prettierBin,
|
|
4453
|
+
[
|
|
4454
|
+
...check ? ["--check"] : ["--write"],
|
|
4455
|
+
"**/*.{ts,json}",
|
|
4456
|
+
"--ignore-path",
|
|
4457
|
+
".prettierignore"
|
|
4458
|
+
],
|
|
4459
|
+
e2eDir
|
|
4460
|
+
) && ok;
|
|
4461
|
+
}
|
|
4462
|
+
}
|
|
4463
|
+
if (!ok) process.exit(1);
|
|
4464
|
+
}
|
|
4465
|
+
};
|
|
4466
|
+
|
|
4467
|
+
// src/commands/lint/index.ts
|
|
4468
|
+
import { defineLintCommand } from "@cubocicloide/dude";
|
|
4469
|
+
var lintCommand = defineLintCommand();
|
|
4470
|
+
|
|
4471
|
+
// src/commands/logs/index.ts
|
|
4472
|
+
var logsCommand = {
|
|
4473
|
+
description: "Follow service logs (docker compose logs -f [service]).",
|
|
4474
|
+
args: {
|
|
4475
|
+
service: {
|
|
4476
|
+
type: "string",
|
|
4477
|
+
description: "Service name (omit to follow all services).",
|
|
4478
|
+
required: false
|
|
4479
|
+
}
|
|
4480
|
+
},
|
|
4481
|
+
async run({ args }) {
|
|
4482
|
+
const svc = typeof args.service === "string" && args.service ? args.service : null;
|
|
4483
|
+
dc(svc ? ["logs", "-f", svc] : ["logs", "-f"]);
|
|
4484
|
+
}
|
|
4485
|
+
};
|
|
4486
|
+
|
|
4487
|
+
// src/commands/review/index.ts
|
|
4488
|
+
import { spawnSync as spawnSync13 } from "child_process";
|
|
4489
|
+
import { existsSync as existsSync15 } from "fs";
|
|
4490
|
+
import path18 from "pathe";
|
|
4491
|
+
import { runLint, formatDiagnostic } from "@cubocicloide/dude";
|
|
4492
|
+
function shouldUseShell3() {
|
|
4493
|
+
return process.platform === "win32";
|
|
4494
|
+
}
|
|
4495
|
+
function isAvailable2(cmd) {
|
|
4496
|
+
const r = spawnSync13(cmd, ["--version"], { stdio: "ignore", shell: shouldUseShell3() });
|
|
4497
|
+
return r.error == null;
|
|
4498
|
+
}
|
|
4499
|
+
function exec2(cmd, args, cwd) {
|
|
4500
|
+
const r = spawnSync13(cmd, args, { cwd, stdio: "inherit", shell: shouldUseShell3() });
|
|
4501
|
+
if (r.error) {
|
|
4502
|
+
process.stderr.write(`error: failed to run ${cmd}: ${r.error.message}
|
|
4503
|
+
`);
|
|
4504
|
+
return false;
|
|
4505
|
+
}
|
|
4506
|
+
return r.status === 0;
|
|
4507
|
+
}
|
|
4508
|
+
function section(title) {
|
|
4509
|
+
const isTTY = process.stdout.isTTY;
|
|
4510
|
+
const line = "\u2500".repeat(Math.max(0, 52 - title.length));
|
|
4511
|
+
const header = `\u2500\u2500 ${title} ${line}`;
|
|
4512
|
+
process.stdout.write(isTTY ? `
|
|
4513
|
+
\x1B[1m${header}\x1B[0m
|
|
4514
|
+
` : `
|
|
4515
|
+
${header}
|
|
4516
|
+
`);
|
|
4517
|
+
}
|
|
4518
|
+
var reviewCommand2 = {
|
|
4519
|
+
description: "Run all checks: custom lint, ESLint, and API contract review.",
|
|
4520
|
+
async run({ projectRoot, stackRoot }) {
|
|
4521
|
+
const frontendDir = path18.join(projectRoot, "frontend");
|
|
4522
|
+
const e2eDir = path18.join(projectRoot, "e2e");
|
|
4523
|
+
const isTTY = process.stdout.isTTY;
|
|
4524
|
+
let ok = true;
|
|
4525
|
+
const missing = [];
|
|
4526
|
+
if ((existsSync15(frontendDir) || existsSync15(e2eDir)) && !isAvailable2("pnpm"))
|
|
4527
|
+
missing.push("pnpm \u2192 https://pnpm.io/installation");
|
|
4528
|
+
if (missing.length > 0) {
|
|
4529
|
+
process.stderr.write("error: required tools not found on your PATH:\n\n");
|
|
2257
4530
|
for (const m of missing) process.stderr.write(` \u2022 ${m}
|
|
2258
4531
|
`);
|
|
2259
4532
|
process.stderr.write("\n");
|
|
@@ -2270,20 +4543,20 @@ var reviewCommand2 = {
|
|
|
2270
4543
|
}
|
|
2271
4544
|
}
|
|
2272
4545
|
ok = errorCount === 0 && ok;
|
|
2273
|
-
if (
|
|
4546
|
+
if (existsSync15(frontendDir)) {
|
|
2274
4547
|
section("eslint");
|
|
2275
|
-
const eslintBin =
|
|
2276
|
-
if (!
|
|
4548
|
+
const eslintBin = path18.join(frontendDir, "node_modules", ".bin", "eslint");
|
|
4549
|
+
if (!existsSync15(eslintBin)) {
|
|
2277
4550
|
process.stderr.write(" eslint not found \u2014 run: cd frontend && pnpm install\n");
|
|
2278
4551
|
ok = false;
|
|
2279
4552
|
} else {
|
|
2280
4553
|
ok = exec2(eslintBin, ["src/"], frontendDir) && ok;
|
|
2281
4554
|
}
|
|
2282
4555
|
}
|
|
2283
|
-
if (
|
|
4556
|
+
if (existsSync15(e2eDir)) {
|
|
2284
4557
|
section("eslint (e2e)");
|
|
2285
|
-
const eslintBin =
|
|
2286
|
-
if (!
|
|
4558
|
+
const eslintBin = path18.join(e2eDir, "node_modules", ".bin", "eslint");
|
|
4559
|
+
if (!existsSync15(eslintBin)) {
|
|
2287
4560
|
process.stderr.write(" eslint not found \u2014 run: cd e2e && pnpm install\n");
|
|
2288
4561
|
ok = false;
|
|
2289
4562
|
} else {
|
|
@@ -2303,12 +4576,12 @@ var reviewCommand2 = {
|
|
|
2303
4576
|
};
|
|
2304
4577
|
|
|
2305
4578
|
// src/commands/security/index.ts
|
|
2306
|
-
import { spawnSync as
|
|
2307
|
-
import { cpSync as
|
|
2308
|
-
import
|
|
4579
|
+
import { spawnSync as spawnSync14 } from "child_process";
|
|
4580
|
+
import { cpSync as cpSync3, existsSync as existsSync18, mkdirSync as mkdirSync3, readFileSync as readFileSync13, rmSync as rmSync2, writeFileSync as writeFileSync7 } from "fs";
|
|
4581
|
+
import path21 from "pathe";
|
|
2309
4582
|
|
|
2310
4583
|
// src/commands/security/models.ts
|
|
2311
|
-
import { createHash as
|
|
4584
|
+
import { createHash as createHash5 } from "crypto";
|
|
2312
4585
|
var SEV_LABEL = {
|
|
2313
4586
|
[0 /* UNKNOWN */]: "UNKNOWN",
|
|
2314
4587
|
[1 /* INFO */]: "INFO",
|
|
@@ -2319,7 +4592,7 @@ var SEV_LABEL = {
|
|
|
2319
4592
|
};
|
|
2320
4593
|
function fingerprint(f) {
|
|
2321
4594
|
const raw = [f.tool, f.ruleId, f.file, f.title.trim().toLowerCase()].join("|");
|
|
2322
|
-
return
|
|
4595
|
+
return createHash5("sha256").update(raw, "utf8").digest("hex").slice(0, 16);
|
|
2323
4596
|
}
|
|
2324
4597
|
function findingToRecord(f) {
|
|
2325
4598
|
return {
|
|
@@ -2337,16 +4610,16 @@ function findingToRecord(f) {
|
|
|
2337
4610
|
}
|
|
2338
4611
|
|
|
2339
4612
|
// src/commands/security/baseline.ts
|
|
2340
|
-
import { existsSync as
|
|
2341
|
-
import
|
|
4613
|
+
import { existsSync as existsSync16, readFileSync as readFileSync12, writeFileSync as writeFileSync6, mkdirSync as mkdirSync2 } from "fs";
|
|
4614
|
+
import path19 from "pathe";
|
|
2342
4615
|
var Baseline = class _Baseline {
|
|
2343
4616
|
constructor(entries = /* @__PURE__ */ new Map()) {
|
|
2344
4617
|
this.entries = entries;
|
|
2345
4618
|
}
|
|
2346
4619
|
entries;
|
|
2347
4620
|
static load(filePath) {
|
|
2348
|
-
if (!
|
|
2349
|
-
const raw =
|
|
4621
|
+
if (!existsSync16(filePath)) return new _Baseline();
|
|
4622
|
+
const raw = readFileSync12(filePath, "utf8") || "{}";
|
|
2350
4623
|
const data = JSON.parse(raw);
|
|
2351
4624
|
const entries = /* @__PURE__ */ new Map();
|
|
2352
4625
|
for (const [fp, row] of Object.entries(data.entries ?? {})) {
|
|
@@ -2364,7 +4637,7 @@ var Baseline = class _Baseline {
|
|
|
2364
4637
|
return new _Baseline(entries);
|
|
2365
4638
|
}
|
|
2366
4639
|
save(filePath) {
|
|
2367
|
-
mkdirSync2(
|
|
4640
|
+
mkdirSync2(path19.dirname(filePath), { recursive: true });
|
|
2368
4641
|
const sorted = [...this.entries.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
2369
4642
|
const payload = {
|
|
2370
4643
|
generated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -2383,7 +4656,7 @@ var Baseline = class _Baseline {
|
|
|
2383
4656
|
])
|
|
2384
4657
|
)
|
|
2385
4658
|
};
|
|
2386
|
-
|
|
4659
|
+
writeFileSync6(filePath, JSON.stringify(payload, null, 2) + "\n");
|
|
2387
4660
|
}
|
|
2388
4661
|
updateFrom(findings) {
|
|
2389
4662
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -2412,10 +4685,10 @@ var Baseline = class _Baseline {
|
|
|
2412
4685
|
};
|
|
2413
4686
|
|
|
2414
4687
|
// src/commands/security/adapters.ts
|
|
2415
|
-
import { existsSync as
|
|
2416
|
-
import
|
|
4688
|
+
import { existsSync as existsSync17 } from "fs";
|
|
4689
|
+
import path20 from "pathe";
|
|
2417
4690
|
function reportInContainer(projectRoot, runDir, name) {
|
|
2418
|
-
return `/src/${
|
|
4691
|
+
return `/src/${path20.relative(projectRoot, path20.join(runDir, `${name}.json`))}`;
|
|
2419
4692
|
}
|
|
2420
4693
|
var BANDIT_SEV = {
|
|
2421
4694
|
UNDEFINED: 0 /* UNKNOWN */,
|
|
@@ -2593,7 +4866,7 @@ var trivyFsAdapter = {
|
|
|
2593
4866
|
name: "trivy-fs",
|
|
2594
4867
|
buildCommand(projectRoot, runDir, opts) {
|
|
2595
4868
|
const report = reportInContainer(projectRoot, runDir, "trivy-fs");
|
|
2596
|
-
const ignoreFile =
|
|
4869
|
+
const ignoreFile = existsSync17(path20.join(projectRoot, TRIVY_IGNORE_FILE)) ? ["--ignorefile", TRIVY_IGNORE_FILE] : [];
|
|
2597
4870
|
return [
|
|
2598
4871
|
"docker",
|
|
2599
4872
|
"run",
|
|
@@ -2794,7 +5067,7 @@ function parseSeverityArg(value, fallback) {
|
|
|
2794
5067
|
return map[value.trim().toUpperCase()] ?? fallback;
|
|
2795
5068
|
}
|
|
2796
5069
|
function ensureDocker() {
|
|
2797
|
-
const r =
|
|
5070
|
+
const r = spawnSync14("docker", ["info"], { stdio: "ignore" });
|
|
2798
5071
|
if (r.error != null || r.status !== 0) {
|
|
2799
5072
|
process.stderr.write(
|
|
2800
5073
|
"[security] docker is required but is not available or the daemon is not running.\n"
|
|
@@ -2808,13 +5081,13 @@ function truncate(text) {
|
|
|
2808
5081
|
return cleaned.length > MAX_MESSAGE_LEN ? cleaned.slice(0, MAX_MESSAGE_LEN - 1) + "\u2026" : cleaned;
|
|
2809
5082
|
}
|
|
2810
5083
|
function writeFindingsJson(findings, filePath) {
|
|
2811
|
-
mkdirSync3(
|
|
5084
|
+
mkdirSync3(path21.dirname(filePath), { recursive: true });
|
|
2812
5085
|
const payload = {
|
|
2813
5086
|
generated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2814
5087
|
count: findings.length,
|
|
2815
5088
|
findings: findings.map(findingToRecord)
|
|
2816
5089
|
};
|
|
2817
|
-
|
|
5090
|
+
writeFileSync7(filePath, JSON.stringify(payload, null, 2) + "\n");
|
|
2818
5091
|
}
|
|
2819
5092
|
function writeMarkdownSummary(newFindings, knownFindings, resolved, filePath, minSeverity) {
|
|
2820
5093
|
const lines = [];
|
|
@@ -2882,18 +5155,18 @@ function writeMarkdownSummary(newFindings, knownFindings, resolved, filePath, mi
|
|
|
2882
5155
|
for (const fp of resolved.slice(0, 50)) lines.push(`- \`${fp}\``);
|
|
2883
5156
|
if (resolved.length > 50) lines.push(`- \u2026 and ${resolved.length - 50} more`);
|
|
2884
5157
|
}
|
|
2885
|
-
mkdirSync3(
|
|
2886
|
-
|
|
5158
|
+
mkdirSync3(path21.dirname(filePath), { recursive: true });
|
|
5159
|
+
writeFileSync7(filePath, lines.join("\n").trimEnd() + "\n");
|
|
2887
5160
|
}
|
|
2888
5161
|
function runScan(config) {
|
|
2889
5162
|
ensureDocker();
|
|
2890
5163
|
const now = /* @__PURE__ */ new Date();
|
|
2891
5164
|
const pad = (n) => String(n).padStart(2, "0");
|
|
2892
5165
|
const timestamp = `${now.getUTCFullYear()}${pad(now.getUTCMonth() + 1)}${pad(now.getUTCDate())}T${pad(now.getUTCHours())}${pad(now.getUTCMinutes())}${pad(now.getUTCSeconds())}Z`;
|
|
2893
|
-
const runDir =
|
|
2894
|
-
const latestDir =
|
|
5166
|
+
const runDir = path21.join(config.reportsRoot, timestamp);
|
|
5167
|
+
const latestDir = path21.join(config.reportsRoot, "latest");
|
|
2895
5168
|
mkdirSync3(runDir, { recursive: true });
|
|
2896
|
-
const cachePrefix =
|
|
5169
|
+
const cachePrefix = path21.basename(config.projectRoot);
|
|
2897
5170
|
const opts = { cachePrefix };
|
|
2898
5171
|
const findings = [];
|
|
2899
5172
|
for (const name of config.adapterNames) {
|
|
@@ -2909,12 +5182,12 @@ function runScan(config) {
|
|
|
2909
5182
|
const [bin, ...cmdArgs] = cmd;
|
|
2910
5183
|
process.stderr.write(`[security] running ${name}: ${cmd.join(" ")}
|
|
2911
5184
|
`);
|
|
2912
|
-
const result =
|
|
5185
|
+
const result = spawnSync14(bin ?? "docker", cmdArgs, {
|
|
2913
5186
|
cwd: config.projectRoot,
|
|
2914
5187
|
stdio: ["ignore", "pipe", "pipe"]
|
|
2915
5188
|
});
|
|
2916
|
-
const reportPath =
|
|
2917
|
-
if (!
|
|
5189
|
+
const reportPath = path21.join(runDir, `${name}.json`);
|
|
5190
|
+
if (!existsSync18(reportPath)) {
|
|
2918
5191
|
const stdout = result.stdout?.toString() ?? "";
|
|
2919
5192
|
const stderr = result.stderr?.toString() ?? "";
|
|
2920
5193
|
process.stderr.write(
|
|
@@ -2926,7 +5199,7 @@ function runScan(config) {
|
|
|
2926
5199
|
continue;
|
|
2927
5200
|
}
|
|
2928
5201
|
try {
|
|
2929
|
-
const data = JSON.parse(
|
|
5202
|
+
const data = JSON.parse(readFileSync13(reportPath, "utf8") || "{}");
|
|
2930
5203
|
findings.push(...adapter.parse(data));
|
|
2931
5204
|
} catch (err) {
|
|
2932
5205
|
process.stderr.write(`[security] ${name}: invalid JSON (${String(err)})
|
|
@@ -2935,17 +5208,17 @@ function runScan(config) {
|
|
|
2935
5208
|
}
|
|
2936
5209
|
const baseline = Baseline.load(config.baselinePath);
|
|
2937
5210
|
const { newFindings, knownFindings, resolved } = baseline.classify(findings);
|
|
2938
|
-
writeFindingsJson(findings,
|
|
2939
|
-
writeFindingsJson(newFindings,
|
|
5211
|
+
writeFindingsJson(findings, path21.join(runDir, "findings.json"));
|
|
5212
|
+
writeFindingsJson(newFindings, path21.join(runDir, "findings.new.json"));
|
|
2940
5213
|
writeMarkdownSummary(
|
|
2941
5214
|
newFindings,
|
|
2942
5215
|
knownFindings,
|
|
2943
5216
|
resolved,
|
|
2944
|
-
|
|
5217
|
+
path21.join(runDir, "summary.md"),
|
|
2945
5218
|
config.minSeverity
|
|
2946
5219
|
);
|
|
2947
|
-
if (
|
|
2948
|
-
|
|
5220
|
+
if (existsSync18(latestDir)) rmSync2(latestDir, { recursive: true, force: true });
|
|
5221
|
+
cpSync3(runDir, latestDir, { recursive: true });
|
|
2949
5222
|
if (config.updateBaseline) {
|
|
2950
5223
|
baseline.updateFrom(findings);
|
|
2951
5224
|
for (const fp of resolved) baseline.entries.delete(fp);
|
|
@@ -2988,8 +5261,8 @@ var securityScanCommand = {
|
|
|
2988
5261
|
}
|
|
2989
5262
|
},
|
|
2990
5263
|
async run({ projectRoot, args }) {
|
|
2991
|
-
const reportsRoot =
|
|
2992
|
-
const baselinePath =
|
|
5264
|
+
const reportsRoot = path21.join(projectRoot, "private", "sast-reports");
|
|
5265
|
+
const baselinePath = path21.join(projectRoot, "security", "baseline.json");
|
|
2993
5266
|
section2("security scan");
|
|
2994
5267
|
const result = runScan({
|
|
2995
5268
|
projectRoot,
|
|
@@ -3004,9 +5277,9 @@ var securityScanCommand = {
|
|
|
3004
5277
|
`[security] done. run_dir=${result.runDir} total=${result.findings.length} new=${result.newFindings.length} known=${result.knownFindings.length} resolved=${result.resolved.length}
|
|
3005
5278
|
`
|
|
3006
5279
|
);
|
|
3007
|
-
const summaryPath =
|
|
3008
|
-
if (
|
|
3009
|
-
process.stdout.write(
|
|
5280
|
+
const summaryPath = path21.join(result.latestDir, "summary.md");
|
|
5281
|
+
if (existsSync18(summaryPath)) {
|
|
5282
|
+
process.stdout.write(readFileSync13(summaryPath, "utf8"));
|
|
3010
5283
|
}
|
|
3011
5284
|
if (result.exitCode !== 0) process.exit(result.exitCode);
|
|
3012
5285
|
}
|
|
@@ -3020,8 +5293,8 @@ var securityAcceptCommand = {
|
|
|
3020
5293
|
}
|
|
3021
5294
|
},
|
|
3022
5295
|
async run({ projectRoot, args }) {
|
|
3023
|
-
const reportsRoot =
|
|
3024
|
-
const baselinePath =
|
|
5296
|
+
const reportsRoot = path21.join(projectRoot, "private", "sast-reports");
|
|
5297
|
+
const baselinePath = path21.join(projectRoot, "security", "baseline.json");
|
|
3025
5298
|
section2("security accept");
|
|
3026
5299
|
const result = runScan({
|
|
3027
5300
|
projectRoot,
|
|
@@ -3059,8 +5332,8 @@ var securityVerifyCommand = {
|
|
|
3059
5332
|
}
|
|
3060
5333
|
},
|
|
3061
5334
|
async run({ projectRoot, args }) {
|
|
3062
|
-
const reportsRoot =
|
|
3063
|
-
const baselinePath =
|
|
5335
|
+
const reportsRoot = path21.join(projectRoot, "private", "sast-reports");
|
|
5336
|
+
const baselinePath = path21.join(projectRoot, "security", "baseline.json");
|
|
3064
5337
|
const isTTY = process.stdout.isTTY;
|
|
3065
5338
|
section2("security verify");
|
|
3066
5339
|
const result = runScan({
|
|
@@ -3137,7 +5410,7 @@ Review and commit the change.
|
|
|
3137
5410
|
};
|
|
3138
5411
|
|
|
3139
5412
|
// src/commands/shell/index.ts
|
|
3140
|
-
import { spawnSync as
|
|
5413
|
+
import { spawnSync as spawnSync15 } from "child_process";
|
|
3141
5414
|
var shellCommand = {
|
|
3142
5415
|
description: "Open an interactive shell in a service container.",
|
|
3143
5416
|
args: {
|
|
@@ -3149,7 +5422,7 @@ var shellCommand = {
|
|
|
3149
5422
|
},
|
|
3150
5423
|
async run({ args }) {
|
|
3151
5424
|
const svc = String(args.service);
|
|
3152
|
-
const bash =
|
|
5425
|
+
const bash = spawnSync15("docker", ["compose", "exec", svc, "/bin/bash"], { stdio: "inherit" });
|
|
3153
5426
|
if (bash.status !== 0) {
|
|
3154
5427
|
dc(["exec", svc, "/bin/sh"]);
|
|
3155
5428
|
} else {
|
|
@@ -3159,18 +5432,18 @@ var shellCommand = {
|
|
|
3159
5432
|
};
|
|
3160
5433
|
|
|
3161
5434
|
// src/commands/test/index.ts
|
|
3162
|
-
import { spawnSync as
|
|
3163
|
-
import { existsSync as
|
|
3164
|
-
import
|
|
5435
|
+
import { spawnSync as spawnSync16 } from "child_process";
|
|
5436
|
+
import { existsSync as existsSync19 } from "fs";
|
|
5437
|
+
import path22 from "pathe";
|
|
3165
5438
|
function shouldUseShell4() {
|
|
3166
5439
|
return process.platform === "win32";
|
|
3167
5440
|
}
|
|
3168
5441
|
function isAvailable3(cmd) {
|
|
3169
|
-
const r =
|
|
5442
|
+
const r = spawnSync16(cmd, ["--version"], { stdio: "ignore", shell: shouldUseShell4() });
|
|
3170
5443
|
return r.error == null;
|
|
3171
5444
|
}
|
|
3172
5445
|
function exec3(cmd, args, cwd, env) {
|
|
3173
|
-
const r =
|
|
5446
|
+
const r = spawnSync16(cmd, args, {
|
|
3174
5447
|
cwd,
|
|
3175
5448
|
stdio: "inherit",
|
|
3176
5449
|
env: { ...process.env, ...env },
|
|
@@ -3218,8 +5491,8 @@ var testCommand = {
|
|
|
3218
5491
|
}
|
|
3219
5492
|
},
|
|
3220
5493
|
async run({ projectRoot, args }) {
|
|
3221
|
-
const backendDir =
|
|
3222
|
-
const e2eDir =
|
|
5494
|
+
const backendDir = path22.join(projectRoot, "backend");
|
|
5495
|
+
const e2eDir = path22.join(projectRoot, "e2e");
|
|
3223
5496
|
const flagBackend = Boolean(args.backend);
|
|
3224
5497
|
const flagE2e = Boolean(args.e2e);
|
|
3225
5498
|
const headed = Boolean(args.headed);
|
|
@@ -3227,8 +5500,8 @@ var testCommand = {
|
|
|
3227
5500
|
const runAll = !flagBackend && !flagE2e;
|
|
3228
5501
|
const runBackend = flagBackend || runAll;
|
|
3229
5502
|
const runE2e = flagE2e || runAll;
|
|
3230
|
-
const hasBackend =
|
|
3231
|
-
const hasE2e =
|
|
5503
|
+
const hasBackend = existsSync19(backendDir);
|
|
5504
|
+
const hasE2e = existsSync19(e2eDir);
|
|
3232
5505
|
const missing = [];
|
|
3233
5506
|
if (runBackend && hasBackend && !isAvailable3("uv"))
|
|
3234
5507
|
missing.push("uv \u2192 https://docs.astral.sh/uv/getting-started/installation/");
|
|
@@ -3257,8 +5530,8 @@ var testCommand = {
|
|
|
3257
5530
|
if (runE2e && hasE2e) {
|
|
3258
5531
|
const script = report ? "test:report" : "test";
|
|
3259
5532
|
section3(`cucumber${headed ? " (headed)" : ""}${report ? " + report" : ""}`);
|
|
3260
|
-
const nmDir =
|
|
3261
|
-
if (!
|
|
5533
|
+
const nmDir = path22.join(e2eDir, "node_modules");
|
|
5534
|
+
if (!existsSync19(nmDir)) {
|
|
3262
5535
|
process.stdout.write("node_modules not found \u2014 running pnpm install\u2026\n");
|
|
3263
5536
|
const installed = exec3("pnpm", ["install"], e2eDir);
|
|
3264
5537
|
if (!installed) {
|
|
@@ -3308,6 +5581,15 @@ var upCommand = {
|
|
|
3308
5581
|
var src_default = defineStack({
|
|
3309
5582
|
name: "react-fastapi",
|
|
3310
5583
|
version: "0.1.0",
|
|
5584
|
+
// Deliberately NOT raised for the multi-target `docs.iac` below, even though
|
|
5585
|
+
// declaring it as a LIST is behaviour the CLI only gained in 0.18.0.
|
|
5586
|
+
//
|
|
5587
|
+
// An older CLI rejects that manifest inside `loadStack`, which throws — and the
|
|
5588
|
+
// `minDudeVersion` gate runs only once loading has succeeded, so it could never
|
|
5589
|
+
// fire for the very users it would be describing. They are already served well:
|
|
5590
|
+
// `cli.ts` catches the load failure and points at `dude upgrade --cli`. Raising
|
|
5591
|
+
// the floor would buy those users nothing while breaking every in-repo test
|
|
5592
|
+
// that drives the workspace CLI, whose version only becomes 0.18.0 at release.
|
|
3311
5593
|
minDudeVersion: "0.1.0",
|
|
3312
5594
|
description: "React (Vite + TypeScript) frontend with a FastAPI backend.",
|
|
3313
5595
|
variables: [
|
|
@@ -3340,27 +5622,32 @@ var src_default = defineStack({
|
|
|
3340
5622
|
{
|
|
3341
5623
|
name: "iac",
|
|
3342
5624
|
type: "select",
|
|
3343
|
-
prompt: "Infrastructure-as-Code (Terraform
|
|
3344
|
-
choices: ["none", "aws-eks"],
|
|
5625
|
+
prompt: "Infrastructure-as-Code (Terraform; Helm on the Kubernetes targets)",
|
|
5626
|
+
choices: ["none", "aws-eks", "azure-aks", "azure-aca"],
|
|
3345
5627
|
default: "none"
|
|
3346
5628
|
}
|
|
3347
5629
|
],
|
|
3348
5630
|
docs: {
|
|
3349
|
-
tagline: "React (Vite) frontend with a FastAPI backend \u2014 Postgres, Celery and AWS
|
|
5631
|
+
tagline: "React (Vite) frontend with a FastAPI backend \u2014 Postgres, Celery, and Kubernetes IaC on AWS or Azure when you need them.",
|
|
3350
5632
|
useCases: [
|
|
3351
5633
|
"A CRUD/product web app that needs a typed REST API behind a modern SPA",
|
|
3352
|
-
"A Python + TypeScript team that wants Kubernetes-grade IaC (AWS EKS) once it scales",
|
|
5634
|
+
"A Python + TypeScript team that wants Kubernetes-grade IaC (AWS EKS or Azure AKS) once it scales",
|
|
5635
|
+
"A project whose hosting cloud is the customer\u2019s decision, not the code\u2019s",
|
|
3353
5636
|
"Background/async work (Celery + Celery Beat) without leaving the Python backend"
|
|
3354
5637
|
],
|
|
3355
5638
|
technologies: ["React 19", "Vite", "FastAPI", "SQLModel", "Alembic", "Celery"],
|
|
3356
|
-
iac:
|
|
5639
|
+
iac: [
|
|
5640
|
+
{ provider: "aws-eks", flag: "--iac aws-eks" },
|
|
5641
|
+
{ provider: "azure-aks", flag: "--iac azure-aks" },
|
|
5642
|
+
{ provider: "azure-aca", flag: "--iac azure-aca" }
|
|
5643
|
+
],
|
|
3357
5644
|
pages: [
|
|
3358
5645
|
{ file: "index.md", title: "Home" },
|
|
3359
5646
|
{ file: "dude.md", title: "Working with dude" },
|
|
3360
5647
|
{ file: "api.md", title: "Command reference" },
|
|
3361
5648
|
{ file: "cheatsheet.md", title: "Cheatsheet" },
|
|
3362
5649
|
{ file: "mkdocs.md", title: "Writing docs" },
|
|
3363
|
-
{ file: "deploy.md", title: "Deploy
|
|
5650
|
+
{ file: "deploy.md", title: "Deploy to the cloud", when: "withIac" }
|
|
3364
5651
|
]
|
|
3365
5652
|
},
|
|
3366
5653
|
async scaffold(ctx) {
|
|
@@ -3369,7 +5656,12 @@ var src_default = defineStack({
|
|
|
3369
5656
|
const withCeleryBeat = Boolean(answers.celeryBeat);
|
|
3370
5657
|
const withCelery = Boolean(answers.celery) || withCeleryBeat;
|
|
3371
5658
|
const withRedis = withCelery;
|
|
3372
|
-
const
|
|
5659
|
+
const withAwsEks = answers.iac === "aws-eks";
|
|
5660
|
+
const withAzureAks = answers.iac === "azure-aks";
|
|
5661
|
+
const withAzureAca = answers.iac === "azure-aca";
|
|
5662
|
+
const withIac = withAwsEks || withAzureAks || withAzureAca;
|
|
5663
|
+
const withKubernetes = withAwsEks || withAzureAks;
|
|
5664
|
+
const iacLabel = withAwsEks ? "AWS EKS" : withAzureAks ? "Azure AKS" : withAzureAca ? "Azure Container Apps" : "";
|
|
3373
5665
|
const data = {
|
|
3374
5666
|
...answers,
|
|
3375
5667
|
withPostgres,
|
|
@@ -3377,27 +5669,38 @@ var src_default = defineStack({
|
|
|
3377
5669
|
withCeleryBeat,
|
|
3378
5670
|
withRedis,
|
|
3379
5671
|
withIac,
|
|
5672
|
+
withAwsEks,
|
|
5673
|
+
withAzureAks,
|
|
5674
|
+
withAzureAca,
|
|
5675
|
+
withKubernetes,
|
|
5676
|
+
iacLabel,
|
|
3380
5677
|
dudeVersion,
|
|
3381
5678
|
stackVersion
|
|
3382
5679
|
};
|
|
3383
|
-
const templates =
|
|
3384
|
-
await renderTemplateTree({ src:
|
|
5680
|
+
const templates = path23.join(stackRoot, "templates");
|
|
5681
|
+
await renderTemplateTree({ src: path23.join(templates, "base"), dest, data });
|
|
3385
5682
|
if (withPostgres) {
|
|
3386
|
-
await renderTemplateTree({ src:
|
|
5683
|
+
await renderTemplateTree({ src: path23.join(templates, "postgres"), dest, data });
|
|
3387
5684
|
}
|
|
3388
5685
|
if (withCelery) {
|
|
3389
|
-
await renderTemplateTree({ src:
|
|
5686
|
+
await renderTemplateTree({ src: path23.join(templates, "celery"), dest, data });
|
|
3390
5687
|
}
|
|
3391
5688
|
if (withCeleryBeat) {
|
|
3392
|
-
await renderTemplateTree({ src:
|
|
5689
|
+
await renderTemplateTree({ src: path23.join(templates, "celerybeat"), dest, data });
|
|
5690
|
+
}
|
|
5691
|
+
if (withAwsEks) {
|
|
5692
|
+
await renderTemplateTree({ src: path23.join(templates, "aws-eks"), dest, data });
|
|
3393
5693
|
}
|
|
3394
|
-
if (
|
|
3395
|
-
await renderTemplateTree({ src:
|
|
5694
|
+
if (withAzureAks) {
|
|
5695
|
+
await renderTemplateTree({ src: path23.join(templates, "azure-aks"), dest, data });
|
|
3396
5696
|
}
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
5697
|
+
if (withAzureAca) {
|
|
5698
|
+
await renderTemplateTree({ src: path23.join(templates, "azure-aca"), dest, data });
|
|
5699
|
+
}
|
|
5700
|
+
const openapiYamlPath = path23.join(dest, "frontend", "src", "openapi", "utils", "openapi.yaml");
|
|
5701
|
+
if (existsSync20(openapiYamlPath)) {
|
|
5702
|
+
const spec = yaml2.parse(readFileSync14(openapiYamlPath, "utf8"));
|
|
5703
|
+
await generateClientFromSpec(spec, path23.join(dest, "frontend", "src", "openapi"), dest);
|
|
3401
5704
|
}
|
|
3402
5705
|
},
|
|
3403
5706
|
hooks: {
|
|
@@ -3405,7 +5708,9 @@ var src_default = defineStack({
|
|
|
3405
5708
|
const name = String(ctx.answers.projectName ?? "your-project");
|
|
3406
5709
|
const withPostgres = ctx.answers.database === "postgres";
|
|
3407
5710
|
const withCelery = Boolean(ctx.answers.celery) || Boolean(ctx.answers.celeryBeat);
|
|
3408
|
-
const
|
|
5711
|
+
const withAwsEks = ctx.answers.iac === "aws-eks";
|
|
5712
|
+
const withAzureAks = ctx.answers.iac === "azure-aks";
|
|
5713
|
+
const withAzureAca = ctx.answers.iac === "azure-aca";
|
|
3409
5714
|
ctx.logger.info("Project scaffolded. Next steps:");
|
|
3410
5715
|
ctx.logger.info("");
|
|
3411
5716
|
ctx.logger.info(" 1. Install the dude launcher once (globally), then provision the project:");
|
|
@@ -3437,7 +5742,7 @@ var src_default = defineStack({
|
|
|
3437
5742
|
if (withPostgres) {
|
|
3438
5743
|
ctx.logger.info(" Users: http://localhost:8000/api/users");
|
|
3439
5744
|
}
|
|
3440
|
-
if (
|
|
5745
|
+
if (withAwsEks) {
|
|
3441
5746
|
ctx.logger.info("");
|
|
3442
5747
|
ctx.logger.info(" Deploy to AWS EKS (Terraform + Helm) \u2014 see iac/README.md:");
|
|
3443
5748
|
ctx.logger.info(" dude iac login --env dev");
|
|
@@ -3445,6 +5750,26 @@ var src_default = defineStack({
|
|
|
3445
5750
|
ctx.logger.info(" dude iac init --env dev && dude iac apply --env dev");
|
|
3446
5751
|
ctx.logger.info(" dude iac kubeconfig --env dev && dude iac ship --env dev");
|
|
3447
5752
|
}
|
|
5753
|
+
if (withAzureAks) {
|
|
5754
|
+
ctx.logger.info("");
|
|
5755
|
+
ctx.logger.info(" Deploy to Azure AKS (Terraform + Helm) \u2014 see iac/README.md:");
|
|
5756
|
+
ctx.logger.info(" dude iac login --env dev");
|
|
5757
|
+
ctx.logger.info(" dude iac bootstrap --state-prefix <your-org> --env dev --yes");
|
|
5758
|
+
ctx.logger.info(" dude iac init --env dev && dude iac apply --env dev");
|
|
5759
|
+
ctx.logger.info(" dude iac kubeconfig --env dev && dude iac ship --env dev");
|
|
5760
|
+
ctx.logger.info(" The app is published on Azure\u2019s own hostname:");
|
|
5761
|
+
ctx.logger.info(` http://${name}-dev.northeurope.cloudapp.azure.com/`);
|
|
5762
|
+
}
|
|
5763
|
+
if (withAzureAca) {
|
|
5764
|
+
ctx.logger.info("");
|
|
5765
|
+
ctx.logger.info(" Deploy to Azure Container Apps (Terraform) \u2014 see iac/README.md:");
|
|
5766
|
+
ctx.logger.info(" dude iac login --env dev");
|
|
5767
|
+
ctx.logger.info(" dude iac bootstrap --state-prefix <your-org> --env dev --yes");
|
|
5768
|
+
ctx.logger.info(" dude iac init --env dev && dude iac apply --env dev");
|
|
5769
|
+
ctx.logger.info(" dude iac ship --env dev");
|
|
5770
|
+
ctx.logger.info(" The app is served over HTTPS on an Azure-managed hostname");
|
|
5771
|
+
ctx.logger.info(" (no domain or certificate needed) \u2014 dude iac output prints it.");
|
|
5772
|
+
}
|
|
3448
5773
|
}
|
|
3449
5774
|
},
|
|
3450
5775
|
rules: [],
|