@elumixor/devkit 0.12.4 → 0.12.5
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/README.md
CHANGED
|
@@ -258,6 +258,10 @@ immutable — its own S3 prefix and Lambda version — so a rollback is two writ
|
|
|
258
258
|
}
|
|
259
259
|
```
|
|
260
260
|
|
|
261
|
+
A `domains` entry starting with `*.` (say `*.desk.atmagaming.com`) only adds a wildcard alias to the
|
|
262
|
+
distribution: every hostname under it then rides one certificate name, which keeps the shared
|
|
263
|
+
certificate under ACM's per-certificate name quota. List it next to the hosts it covers.
|
|
264
|
+
|
|
261
265
|
`devkit deploy` builds, then: reconciles the function, role, log group, URL, schedules and domains;
|
|
262
266
|
uploads the static files (unchanged files are copied server-side); publishes a new function
|
|
263
267
|
version; runs `predeploy` with the stage's env; invokes the new version's `/api/health`; and only
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import { CloudError, log } from "../aws.ts";
|
|
|
2
2
|
import { deleteStageEnv } from "../env.ts";
|
|
3
3
|
import { stage as names } from "../names.ts";
|
|
4
4
|
import { deleteRecord } from "../reconcile/cloudflare.ts";
|
|
5
|
-
import {
|
|
5
|
+
import { needsDns, reconcileAliases } from "../reconcile/edge.ts";
|
|
6
6
|
import { deleteRole } from "../reconcile/iam.ts";
|
|
7
7
|
import { updateKeys } from "../reconcile/kvs.ts";
|
|
8
8
|
import { deleteFunction } from "../reconcile/lambda.ts";
|
|
@@ -20,7 +20,7 @@ export async function destroy(project: string | undefined, stageFlag: string | u
|
|
|
20
20
|
|
|
21
21
|
await updateKeys({}, recorded.hostnames);
|
|
22
22
|
log(" routes removed");
|
|
23
|
-
const custom = recorded.hostnames.filter(
|
|
23
|
+
const custom = recorded.hostnames.filter(needsDns);
|
|
24
24
|
if (custom.length) {
|
|
25
25
|
await reconcileAliases([], custom);
|
|
26
26
|
for (const host of custom) await deleteRecord(host, "CNAME");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { bold, dim } from "../../ansi.ts";
|
|
2
2
|
import { CloudError, log } from "../aws.ts";
|
|
3
3
|
import { deleteRecord } from "../reconcile/cloudflare.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { needsDns, reconcileAliases } from "../reconcile/edge.ts";
|
|
5
5
|
import { deleteRoute, getRoute, putRoutes } from "../reconcile/kvs.ts";
|
|
6
6
|
import { readRegistry, updateRegistryHostname } from "../records.ts";
|
|
7
7
|
import { targetByName } from "./context.ts";
|
|
@@ -34,7 +34,7 @@ export async function removeDomain(project: string, host: string, stageFlag?: st
|
|
|
34
34
|
const { target } = await targetByName(project, stageFlag);
|
|
35
35
|
if (host === target.defaultHost) throw new CloudError(`${host} is the stage's default hostname and stays`);
|
|
36
36
|
await deleteRoute(host);
|
|
37
|
-
if (
|
|
37
|
+
if (needsDns(host)) {
|
|
38
38
|
await reconcileAliases([], [host]);
|
|
39
39
|
await deleteRecord(host, "CNAME");
|
|
40
40
|
}
|
package/src/cloud/project.ts
CHANGED
|
@@ -32,7 +32,10 @@ export interface AwsTargetOptions extends Omit<WebBuildOptions, "host"> {
|
|
|
32
32
|
timeout?: number;
|
|
33
33
|
/** Scheduled calls into the API. */
|
|
34
34
|
crons?: CronConfig[];
|
|
35
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Custom hostnames per stage, besides the default `<project>.devkit.atmagaming.com`. A `*.` entry is a
|
|
37
|
+
* wildcard alias only (no route or DNS): hostnames under it then share one certificate name.
|
|
38
|
+
*/
|
|
36
39
|
domains?: Record<string, string[]>;
|
|
37
40
|
/** Shell command run with the stage's env after the code is published and before it goes live — migrations. */
|
|
38
41
|
predeploy?: string;
|
|
@@ -82,7 +85,7 @@ export class Target {
|
|
|
82
85
|
}
|
|
83
86
|
/** Every hostname that routes to this stage; the first custom domain is the one the app calls its own. */
|
|
84
87
|
get hostnames(): readonly string[] {
|
|
85
|
-
return [...this.domains, this.defaultHost];
|
|
88
|
+
return [...this.domains.filter((host) => !host.startsWith("*.")), this.defaultHost];
|
|
86
89
|
}
|
|
87
90
|
get primaryHost() {
|
|
88
91
|
return this.hostnames[0] as string;
|
|
@@ -38,13 +38,23 @@ export async function requireDistribution() {
|
|
|
38
38
|
return distribution;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
export const isWildcard = (hostname: string) => hostname.startsWith("*.");
|
|
42
|
+
|
|
43
|
+
/** A wildcard alias covers exactly one label under it: `*.desk.example.com` covers `keep.desk.example.com`. */
|
|
44
|
+
const covers = (alias: string, hostname: string) =>
|
|
45
|
+
isWildcard(alias) &&
|
|
46
|
+
!isWildcard(hostname) &&
|
|
47
|
+
hostname.endsWith(alias.slice(1)) &&
|
|
48
|
+
hostname.split(".").length === alias.split(".").length;
|
|
49
|
+
|
|
50
|
+
/** Default hostnames ride the platform's wildcard alias and DNS record; any other hostname needs a DNS record. */
|
|
51
|
+
export const needsDns = (hostname: string) => !isWildcard(hostname) && !covers(WILDCARD_DOMAIN, hostname);
|
|
44
52
|
|
|
45
53
|
/**
|
|
46
54
|
* Adds hostnames as aliases, swapping in a certificate that covers them all when the current one
|
|
47
|
-
* doesn't, and points each at the distribution in DNS.
|
|
55
|
+
* doesn't, and points each at the distribution in DNS. A hostname a wildcard alias already covers
|
|
56
|
+
* (`*.desk.example.com`, listed in a config's `domains` like any host) takes no alias or certificate
|
|
57
|
+
* name of its own, which keeps the certificate under ACM's name quota. Removing works in reverse.
|
|
48
58
|
*/
|
|
49
59
|
export async function reconcileAliases(add: readonly string[], remove: readonly string[] = []) {
|
|
50
60
|
const distribution = await requireDistribution();
|
|
@@ -54,12 +64,13 @@ export async function reconcileAliases(add: readonly string[], remove: readonly
|
|
|
54
64
|
if (!config || !ETag) throw new CloudError("CloudFront returned no distribution config");
|
|
55
65
|
|
|
56
66
|
const current = config.Aliases?.Items ?? [];
|
|
67
|
+
const kept = [...PLATFORM_ALIASES, ...current.filter((alias) => !remove.includes(alias)), ...add.filter(isWildcard)];
|
|
57
68
|
const wanted = [
|
|
58
|
-
...new Set([...
|
|
69
|
+
...new Set([...kept, ...add.filter((host) => !kept.includes(host) && !kept.some((alias) => covers(alias, host)))]),
|
|
59
70
|
].sort();
|
|
60
71
|
const unchanged = wanted.length === current.length && wanted.every((alias) => current.includes(alias));
|
|
61
72
|
|
|
62
|
-
for (const hostname of add.filter(
|
|
73
|
+
for (const hostname of add.filter(needsDns)) {
|
|
63
74
|
const outcome = await ensureRecord(hostname, "CNAME", distribution.domainName);
|
|
64
75
|
if (outcome !== "unchanged") log(` DNS ${hostname} → ${distribution.domainName} ${outcome}`);
|
|
65
76
|
}
|