@intentius/behold 0.29.50 → 0.29.51
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/AGENTS.md +52 -0
- package/demos.json +15 -0
- package/dist/cli.js +1222 -614
- package/example-three-cloud/README.md +38 -0
- package/example-three-cloud/aws/chant.config.ts +8 -0
- package/example-three-cloud/aws/src/site.ts +20 -0
- package/example-three-cloud/azure/chant.config.ts +1 -0
- package/example-three-cloud/azure/src/site.ts +19 -0
- package/example-three-cloud/chant.workspace.json +10 -0
- package/example-three-cloud/dns/chant.config.ts +1 -0
- package/example-three-cloud/dns/ops/front-door.op.ts +21 -0
- package/example-three-cloud/dns/src/route53.ts +54 -0
- package/example-three-cloud/gcp/chant.config.ts +1 -0
- package/example-three-cloud/gcp/src/site.ts +19 -0
- package/example-three-cloud/package-lock.json +715 -0
- package/example-three-cloud/package.json +16 -0
- package/example-three-cloud/scripts/emulators-up.sh +46 -0
- package/example-three-cloud/scripts/front-door.ts +400 -0
- package/package.json +3 -2
- package/web/app.js +132 -6
- package/web/composite-members.js +21 -0
- package/web/composite-members.test.js +25 -0
- package/web/export-note.js +35 -0
- package/web/export-note.test.js +45 -0
- package/web/health-marks.js +146 -0
- package/web/health-marks.test.js +67 -0
- package/web/index.html +7 -0
- package/web/view-url.js +25 -0
- package/web/view-url.test.js +24 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# three-cloud
|
|
2
|
+
|
|
3
|
+
A small website in AWS, Azure and GCP behind Route 53, as a chant workspace on
|
|
4
|
+
the floci emulators. It is behold's `three-cloud` demo, and its exported page
|
|
5
|
+
asks one question: turn Azure off, and where does traffic go?
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
chant.workspace.json the workspace: dns, aws, azure, gcp
|
|
9
|
+
dns/src/route53.ts hosted zone, a health check and a latency CNAME per cloud
|
|
10
|
+
dns/ops/front-door.op.ts the Op that rebuilds the page
|
|
11
|
+
aws/src/site.ts ECS on Fargate behind a load balancer (FargateAlb)
|
|
12
|
+
azure/src/site.ts a Container Apps environment and app
|
|
13
|
+
gcp/src/site.ts Cloud Run (CloudRunServiceComposite)
|
|
14
|
+
scripts/emulators-up.sh boots floci, floci-az and floci-gcp
|
|
15
|
+
scripts/front-door.ts the Op's steps: apply, turn Azure off, wait, export
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Each cloud publishes its endpoint with `output()` and `dns` reads it as a
|
|
19
|
+
parameter of the same name.
|
|
20
|
+
|
|
21
|
+
## Run it
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npx @intentius/behold demo three-cloud
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or by hand, from this directory (needs Docker):
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm install
|
|
31
|
+
npm run emulators # floci :4566, floci-az :4577, floci-gcp :4588
|
|
32
|
+
npm run front-door # apply, turn Azure off, wait for Route 53, export to ./export
|
|
33
|
+
npx serve export
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`cd dns && npx chant run front-door` runs the same steps as an Op.
|
|
37
|
+
|
|
38
|
+
Needs chant 0.124.34 or newer.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The aws member's stack is named for the workspace, so it doesn't share the
|
|
2
|
+
// stack named after the environment ("local") with the dns member.
|
|
3
|
+
export default {
|
|
4
|
+
lexicons: ["aws"],
|
|
5
|
+
sourceDir: "src",
|
|
6
|
+
environments: ["local"],
|
|
7
|
+
stacks: [{ name: "three-cloud-aws", src: "src" }],
|
|
8
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FargateAlb, Parameter, output } from "@intentius/chant-lexicon-aws";
|
|
2
|
+
|
|
3
|
+
// The website on ECS Fargate in us-east-1, behind its own load balancer: the
|
|
4
|
+
// ALB's DNS name is the stable hostname Route 53 points at. The VPC and its
|
|
5
|
+
// subnets come in as parameters, so no networking is declared here.
|
|
6
|
+
export const vpcId = new Parameter("AWS::EC2::VPC::Id", { description: "The VPC (the default one is fine)" });
|
|
7
|
+
export const subnetIds = new Parameter("List<AWS::EC2::Subnet::Id>", { description: "Two public subnets in different zones" });
|
|
8
|
+
|
|
9
|
+
export const web = FargateAlb({
|
|
10
|
+
image: "traefik/whoami:v1.10",
|
|
11
|
+
containerPort: 80,
|
|
12
|
+
desiredCount: 1,
|
|
13
|
+
vpcId: vpcId as unknown as string,
|
|
14
|
+
publicSubnetIds: subnetIds as unknown as string[],
|
|
15
|
+
privateSubnetIds: subnetIds as unknown as string[],
|
|
16
|
+
logRetentionDays: 7,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// The dns member reads this as its `awsEndpoint` parameter.
|
|
20
|
+
export const awsEndpoint = output(web.alb.DNSName, "awsEndpoint");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default { lexicons: ["azure"], sourceDir: "src", environments: ["local"] };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { managedEnvironments, containerApps, output } from "@intentius/chant-lexicon-azure";
|
|
2
|
+
|
|
3
|
+
// The website on Azure Container Apps in West Europe: one environment and one
|
|
4
|
+
// app with external ingress.
|
|
5
|
+
export const env = new managedEnvironments({ name: "three-cloud", location: "westeurope" });
|
|
6
|
+
|
|
7
|
+
export const app = new containerApps({
|
|
8
|
+
name: "web",
|
|
9
|
+
location: "westeurope",
|
|
10
|
+
managedEnvironmentId: env.id,
|
|
11
|
+
configuration: { ingress: { external: true, targetPort: 80, transport: "auto" } },
|
|
12
|
+
template: {
|
|
13
|
+
containers: [{ name: "web", image: "traefik/whoami:v1.10", resources: { cpu: 0.25, memory: "0.5Gi" } }],
|
|
14
|
+
scale: { minReplicas: 1, maxReplicas: 1 },
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// The dns member reads this as its `azureEndpoint` parameter.
|
|
19
|
+
export const azureEndpoint = output(app.configuration_ingress_fqdn, "azureEndpoint");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "three-cloud",
|
|
3
|
+
"schema": 1,
|
|
4
|
+
"members": [
|
|
5
|
+
{ "name": "dns", "dir": "dns", "kind": "chant" },
|
|
6
|
+
{ "name": "aws", "dir": "aws", "kind": "chant" },
|
|
7
|
+
{ "name": "azure", "dir": "azure", "kind": "chant" },
|
|
8
|
+
{ "name": "gcp", "dir": "gcp", "kind": "chant" }
|
|
9
|
+
]
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default { lexicons: ["aws"], sourceDir: "src", environments: ["local"] };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Op, phase, shell } from "@intentius/chant/op";
|
|
2
|
+
|
|
3
|
+
// The front door's page, rebuilt from nothing on the floci emulators that
|
|
4
|
+
// `behold demo three-cloud` boots: apply the four members, turn Azure off,
|
|
5
|
+
// wait until Route 53's check on it fails, and export the page. Each phase is
|
|
6
|
+
// one step of ../../scripts/front-door.ts, which says what it does and why.
|
|
7
|
+
//
|
|
8
|
+
// chant run front-door (from this directory)
|
|
9
|
+
// npm run front-door (from the workspace root, the same steps without chant)
|
|
10
|
+
const step = (args: string) => shell(`cd .. && ./node_modules/.bin/tsx scripts/front-door.ts ${args}`, { timeout: "15m" });
|
|
11
|
+
|
|
12
|
+
export default Op({
|
|
13
|
+
name: "front-door",
|
|
14
|
+
overview: "Apply dns, aws, azure and gcp to the emulators, turn Azure off, wait for its health check to fail, export the page to ../export",
|
|
15
|
+
phases: [
|
|
16
|
+
phase("Apply", [step("apply")]),
|
|
17
|
+
phase("Turn Azure off", [step("azure-off")]),
|
|
18
|
+
phase("Wait for Route 53", [step("wait")]),
|
|
19
|
+
phase("Export", [step("export --out export")]),
|
|
20
|
+
],
|
|
21
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { HostedZone, HealthCheck, RecordSet, Parameter } from "@intentius/chant-lexicon-aws";
|
|
2
|
+
|
|
3
|
+
// Route 53 in front of the three clouds: one latency record per cloud, each
|
|
4
|
+
// guarded by a health check on that cloud's endpoint. A record whose check
|
|
5
|
+
// fails stops answering, and the other two take its traffic.
|
|
6
|
+
//
|
|
7
|
+
// Latency records name an AWS region, so Azure (West Europe) answers as
|
|
8
|
+
// eu-west-1 and GCP (Tokyo) as ap-northeast-1. All three are CNAMEs, since an
|
|
9
|
+
// alias can only point at an AWS target and records sharing a name must share
|
|
10
|
+
// a type.
|
|
11
|
+
//
|
|
12
|
+
// Each endpoint arrives as a parameter named like the output the cloud's
|
|
13
|
+
// member publishes, which is the join behold draws the cross-member edge on.
|
|
14
|
+
|
|
15
|
+
const NAME = "www.three-cloud.example.";
|
|
16
|
+
|
|
17
|
+
export const zone = new HostedZone({ Name: "three-cloud.example." });
|
|
18
|
+
|
|
19
|
+
export const awsEndpoint = new Parameter("String", { description: "The aws member's load balancer hostname" });
|
|
20
|
+
export const azureEndpoint = new Parameter("String", { description: "The azure member's Container App hostname" });
|
|
21
|
+
export const gcpEndpoint = new Parameter("String", { description: "The gcp member's Cloud Run hostname" });
|
|
22
|
+
|
|
23
|
+
function healthCheck(endpoint: Parameter) {
|
|
24
|
+
return new HealthCheck({
|
|
25
|
+
HealthCheckConfig: {
|
|
26
|
+
Type: "HTTP",
|
|
27
|
+
FullyQualifiedDomainName: endpoint,
|
|
28
|
+
ResourcePath: "/",
|
|
29
|
+
RequestInterval: 10,
|
|
30
|
+
FailureThreshold: 1,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function latencyRecord(id: string, region: string, endpoint: Parameter, check: HealthCheck) {
|
|
36
|
+
return new RecordSet({
|
|
37
|
+
HostedZoneId: zone.Id,
|
|
38
|
+
Name: NAME,
|
|
39
|
+
Type: "CNAME",
|
|
40
|
+
TTL: "60",
|
|
41
|
+
SetIdentifier: id,
|
|
42
|
+
Region: region,
|
|
43
|
+
ResourceRecords: [endpoint as unknown as string],
|
|
44
|
+
HealthCheckId: check.HealthCheckId,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const awsCheck = healthCheck(awsEndpoint);
|
|
49
|
+
export const azureCheck = healthCheck(azureEndpoint);
|
|
50
|
+
export const gcpCheck = healthCheck(gcpEndpoint);
|
|
51
|
+
|
|
52
|
+
export const awsRecord = latencyRecord("aws", "us-east-1", awsEndpoint, awsCheck);
|
|
53
|
+
export const azureRecord = latencyRecord("azure", "eu-west-1", azureEndpoint, azureCheck);
|
|
54
|
+
export const gcpRecord = latencyRecord("gcp", "ap-northeast-1", gcpEndpoint, gcpCheck);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default { lexicons: ["gcp"], sourceDir: "src", environments: ["local"] };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CloudRunServiceComposite, output } from "@intentius/chant-lexicon-gcp";
|
|
2
|
+
|
|
3
|
+
// The website on Cloud Run in Tokyo, open to unauthenticated callers.
|
|
4
|
+
export const web = CloudRunServiceComposite({
|
|
5
|
+
name: "web",
|
|
6
|
+
image: "traefik/whoami:v1.10",
|
|
7
|
+
projectId: "three-cloud",
|
|
8
|
+
location: "asia-northeast1",
|
|
9
|
+
port: 80,
|
|
10
|
+
minInstanceCount: 1,
|
|
11
|
+
maxInstanceCount: 1,
|
|
12
|
+
publicAccess: true,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// The dns member reads this as its `gcpEndpoint` parameter. Config Connector
|
|
16
|
+
// YAML has no outputs, so `chant build` warns that this one is not written:
|
|
17
|
+
// the graph still joins it to dns, and scripts/front-door.ts reads the URI
|
|
18
|
+
// from the emulator to pass it on.
|
|
19
|
+
export const gcpEndpoint = output(web.service.status_uri, "gcpEndpoint");
|