@intentius/behold 0.29.50 → 0.29.52
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 +1311 -622
- 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 +55 -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 +62 -0
- package/example-three-cloud/gcp/chant.config.ts +1 -0
- package/example-three-cloud/gcp/src/site.ts +86 -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 +411 -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.35 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,55 @@
|
|
|
1
|
+
import { LogAnalyticsWorkspace, ManagedIdentity, VirtualNetwork, managedEnvironments, containerApps, output } from "@intentius/chant-lexicon-azure";
|
|
2
|
+
|
|
3
|
+
// The website on Azure Container Apps in West Europe, set up the way a
|
|
4
|
+
// production environment is: the environment sits in its own VNet subnet and
|
|
5
|
+
// ships its logs to a Log Analytics workspace, and the app runs as a
|
|
6
|
+
// user-assigned identity. Container Apps brings its own ingress and load
|
|
7
|
+
// balancing, so there is no load balancer to declare.
|
|
8
|
+
const location = "westeurope";
|
|
9
|
+
|
|
10
|
+
export const logs = new LogAnalyticsWorkspace({ name: "three-cloud-logs", location, sku: { name: "PerGB2018" }, retentionInDays: 30 });
|
|
11
|
+
|
|
12
|
+
// A Container Apps environment on workload profiles takes a /23 or larger,
|
|
13
|
+
// delegated to it. The subnet is declared inside the VNet: chant's own Subnet
|
|
14
|
+
// resource writes the ARM type as virtualNetworks_subnets (reported to chant).
|
|
15
|
+
export const vnet = new VirtualNetwork({
|
|
16
|
+
name: "three-cloud-vnet",
|
|
17
|
+
location,
|
|
18
|
+
addressSpace: { addressPrefixes: ["10.40.0.0/16"] },
|
|
19
|
+
subnets: [{ name: "apps", properties: { addressPrefix: "10.40.0.0/23", delegations: [{ name: "apps", properties: { serviceName: "Microsoft.App/environments" } }] } }],
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const identity = new ManagedIdentity({ name: "three-cloud-web", location });
|
|
23
|
+
|
|
24
|
+
export const env = new managedEnvironments({
|
|
25
|
+
name: "three-cloud",
|
|
26
|
+
location,
|
|
27
|
+
// concat() rather than resourceId('.../virtualNetworks/subnets', vnet, subnet):
|
|
28
|
+
// chant 0.124.34's apply evaluates the latter to the wrong path (fixed by
|
|
29
|
+
// INTENTIUS/chant#4234, not yet released).
|
|
30
|
+
vnetConfiguration: { infrastructureSubnetId: "[concat(resourceId('Microsoft.Network/virtualNetworks', 'three-cloud-vnet'), '/subnets/apps')]", internal: false },
|
|
31
|
+
appLogsConfiguration: {
|
|
32
|
+
destination: "log-analytics",
|
|
33
|
+
logAnalyticsConfiguration: {
|
|
34
|
+
customerId: "[reference('three-cloud-logs').customerId]",
|
|
35
|
+
sharedKey: "[listKeys(resourceId('Microsoft.OperationalInsights/workspaces', 'three-cloud-logs'), '2023-09-01').primarySharedKey]",
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
workloadProfiles: [{ name: "Consumption", workloadProfileType: "Consumption" }],
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const app = new containerApps({
|
|
42
|
+
name: "web",
|
|
43
|
+
location,
|
|
44
|
+
identity: { type: "UserAssigned", userAssignedIdentities: { "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', 'three-cloud-web')]": {} } },
|
|
45
|
+
managedEnvironmentId: env.id,
|
|
46
|
+
workloadProfileName: "Consumption",
|
|
47
|
+
configuration: { ingress: { external: true, targetPort: 80, transport: "auto" } },
|
|
48
|
+
template: {
|
|
49
|
+
containers: [{ name: "web", image: "traefik/whoami:v1.10", resources: { cpu: 0.25, memory: "0.5Gi" } }],
|
|
50
|
+
scale: { minReplicas: 1, maxReplicas: 1 },
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// The dns member reads this as its `azureEndpoint` parameter.
|
|
55
|
+
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,62 @@
|
|
|
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. GCP's load balancer has an IP address rather than a hostname, so
|
|
11
|
+
// it gets a name of its own (an A record) and the latency record points at
|
|
12
|
+
// that, as a GCP load balancer is usually published.
|
|
13
|
+
//
|
|
14
|
+
// Each endpoint arrives as a parameter named like the output the cloud's
|
|
15
|
+
// member publishes, which is the join behold draws the cross-member edge on.
|
|
16
|
+
|
|
17
|
+
const NAME = "www.three-cloud.example.";
|
|
18
|
+
|
|
19
|
+
export const zone = new HostedZone({ Name: "three-cloud.example." });
|
|
20
|
+
|
|
21
|
+
export const awsEndpoint = new Parameter("String", { description: "The aws member's load balancer hostname" });
|
|
22
|
+
export const azureEndpoint = new Parameter("String", { description: "The azure member's Container App hostname" });
|
|
23
|
+
export const gcpEndpoint = new Parameter("String", { description: "The gcp member's load balancer IP address" });
|
|
24
|
+
|
|
25
|
+
function healthCheck(endpoint: Parameter) {
|
|
26
|
+
return new HealthCheck({
|
|
27
|
+
HealthCheckConfig: {
|
|
28
|
+
Type: "HTTP",
|
|
29
|
+
FullyQualifiedDomainName: endpoint,
|
|
30
|
+
ResourcePath: "/",
|
|
31
|
+
RequestInterval: 10,
|
|
32
|
+
FailureThreshold: 1,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function latencyRecord(id: string, region: string, endpoint: Parameter | string, check: HealthCheck) {
|
|
38
|
+
return new RecordSet({
|
|
39
|
+
HostedZoneId: zone.Id,
|
|
40
|
+
Name: NAME,
|
|
41
|
+
Type: "CNAME",
|
|
42
|
+
TTL: "60",
|
|
43
|
+
SetIdentifier: id,
|
|
44
|
+
Region: region,
|
|
45
|
+
ResourceRecords: [endpoint as unknown as string],
|
|
46
|
+
HealthCheckId: check.HealthCheckId,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const awsCheck = healthCheck(awsEndpoint);
|
|
51
|
+
export const azureCheck = healthCheck(azureEndpoint);
|
|
52
|
+
// The check on GCP probes the load balancer's address directly.
|
|
53
|
+
export const gcpCheck = new HealthCheck({
|
|
54
|
+
HealthCheckConfig: { Type: "HTTP", IPAddress: gcpEndpoint, Port: 80, ResourcePath: "/", RequestInterval: 10, FailureThreshold: 1 },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const GCP_ORIGIN = "gcp.three-cloud.example.";
|
|
58
|
+
export const gcpOrigin = new RecordSet({ HostedZoneId: zone.Id, Name: GCP_ORIGIN, Type: "A", TTL: "60", ResourceRecords: [gcpEndpoint as unknown as string] });
|
|
59
|
+
|
|
60
|
+
export const awsRecord = latencyRecord("aws", "us-east-1", awsEndpoint, awsCheck);
|
|
61
|
+
export const azureRecord = latencyRecord("azure", "eu-west-1", azureEndpoint, azureCheck);
|
|
62
|
+
export const gcpRecord = latencyRecord("gcp", "ap-northeast-1", GCP_ORIGIN, gcpCheck);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default { lexicons: ["gcp"], sourceDir: "src", environments: ["local"] };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BackendService,
|
|
3
|
+
CloudRunServiceComposite,
|
|
4
|
+
ComputeAddress,
|
|
5
|
+
ForwardingRule,
|
|
6
|
+
GCPServiceAccount,
|
|
7
|
+
RegionNetworkEndpointGroup,
|
|
8
|
+
TargetHTTPProxy,
|
|
9
|
+
URLMap,
|
|
10
|
+
output,
|
|
11
|
+
} from "@intentius/chant-lexicon-gcp";
|
|
12
|
+
|
|
13
|
+
// The website on Cloud Run in Tokyo, running as its own service account, behind
|
|
14
|
+
// a global external Application Load Balancer as production sets it up: a
|
|
15
|
+
// static address and a forwarding rule, an HTTP proxy, a URL map, a backend
|
|
16
|
+
// service, and a serverless network endpoint group that names the service.
|
|
17
|
+
// The load balancer kinds apply with chant 0.124.35 or newer (chant#4233).
|
|
18
|
+
//
|
|
19
|
+
// Each reference is Config Connector's `{ name }`, spelled out: chant writes
|
|
20
|
+
// an attribute reference's `.name` as the logical id rather than the
|
|
21
|
+
// resource's metadata.name (reported to chant).
|
|
22
|
+
const region = "asia-northeast1";
|
|
23
|
+
|
|
24
|
+
export const runtime = new GCPServiceAccount({
|
|
25
|
+
metadata: { name: "three-cloud-run" },
|
|
26
|
+
displayName: "three-cloud website runtime",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const web = CloudRunServiceComposite({
|
|
30
|
+
name: "three-cloud-site",
|
|
31
|
+
image: "traefik/whoami:v1.10",
|
|
32
|
+
projectId: "three-cloud",
|
|
33
|
+
location: region,
|
|
34
|
+
port: 80,
|
|
35
|
+
minInstanceCount: 1,
|
|
36
|
+
maxInstanceCount: 1,
|
|
37
|
+
publicAccess: true,
|
|
38
|
+
serviceAccount: "three-cloud-run",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const neg = new RegionNetworkEndpointGroup({
|
|
42
|
+
metadata: { name: "three-cloud-neg" },
|
|
43
|
+
region,
|
|
44
|
+
networkEndpointType: "SERVERLESS",
|
|
45
|
+
cloudRun: { serviceRef: { name: "three-cloud-site" } },
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// A backend service over a serverless NEG takes no health check: Cloud Run
|
|
49
|
+
// reports its own readiness.
|
|
50
|
+
export const backend = new BackendService({
|
|
51
|
+
metadata: { name: "three-cloud-backend" },
|
|
52
|
+
location: "global",
|
|
53
|
+
loadBalancingScheme: "EXTERNAL_MANAGED",
|
|
54
|
+
protocol: "HTTP",
|
|
55
|
+
backend: [{ group: { networkEndpointGroupRef: { name: "three-cloud-neg" } } }],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const urlMap = new URLMap({
|
|
59
|
+
metadata: { name: "three-cloud-map" },
|
|
60
|
+
location: "global",
|
|
61
|
+
defaultService: { backendServiceRef: { name: "three-cloud-backend" } },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export const proxy = new TargetHTTPProxy({
|
|
65
|
+
metadata: { name: "three-cloud-proxy" },
|
|
66
|
+
location: "global",
|
|
67
|
+
urlMapRef: { name: "three-cloud-map" },
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const address = new ComputeAddress({ metadata: { name: "three-cloud-ip" }, location: "global" });
|
|
71
|
+
|
|
72
|
+
export const rule = new ForwardingRule({
|
|
73
|
+
metadata: { name: "three-cloud-rule" },
|
|
74
|
+
location: "global",
|
|
75
|
+
loadBalancingScheme: "EXTERNAL_MANAGED",
|
|
76
|
+
portRange: "80",
|
|
77
|
+
ipAddress: { addressRef: { name: "three-cloud-ip" } },
|
|
78
|
+
target: { targetHTTPProxyRef: { name: "three-cloud-proxy" } },
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// The dns member reads this as its `gcpEndpoint` parameter: the load
|
|
82
|
+
// balancer's front end, whose IP is the reserved address. Config Connector
|
|
83
|
+
// YAML has no outputs and neither kind exposes the IP as an attribute, so
|
|
84
|
+
// this declares the join for the graph, and scripts/front-door.ts reads the
|
|
85
|
+
// IP from the emulator.
|
|
86
|
+
export const gcpEndpoint = output(rule.status_selfLink, "gcpEndpoint");
|