@happyvertical/smrt-config 0.61.0 → 0.61.1
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 +13 -0
- package/README.md +8 -0
- package/dist/chunks/hosted-app-BomhfPIt.js +813 -0
- package/dist/chunks/hosted-app-BomhfPIt.js.map +1 -0
- package/dist/deployment/compose-source.d.ts +55 -0
- package/dist/deployment/compose-source.d.ts.map +1 -0
- package/dist/deployment/hosted-app-applier.d.ts +32 -0
- package/dist/deployment/hosted-app-applier.d.ts.map +1 -0
- package/dist/deployment/hosted-app.d.ts +131 -0
- package/dist/deployment/hosted-app.d.ts.map +1 -0
- package/dist/deployment/sha256.d.ts +9 -0
- package/dist/deployment/sha256.d.ts.map +1 -0
- package/dist/deployment-hosting.d.ts +12 -0
- package/dist/deployment-hosting.d.ts.map +1 -0
- package/dist/deployment-hosting.js +122 -0
- package/dist/deployment-hosting.js.map +1 -0
- package/dist/deployment.d.ts +4 -2
- package/dist/deployment.d.ts.map +1 -1
- package/dist/deployment.js +4 -506
- package/dist/deployment.js.map +1 -1
- package/dist/smrt-knowledge.okf.md +3 -2
- package/package.json +8 -3
|
@@ -0,0 +1,813 @@
|
|
|
1
|
+
//#region src/deployment/compose-contract.ts
|
|
2
|
+
var X_HAPPYVERTICAL_KEY = "x-happyvertical";
|
|
3
|
+
var X_HAPPYVERTICAL_VERSION = 1;
|
|
4
|
+
var X_HAPPYVERTICAL_SCHEMA_ID = "https://s-m-r-t.dev/schemas/x-happyvertical/v1.schema.json";
|
|
5
|
+
var X_HAPPYVERTICAL_PRESETS = ["smrt"];
|
|
6
|
+
var X_HAPPYVERTICAL_ROLES = ["web", "worker"];
|
|
7
|
+
var X_HAPPYVERTICAL_BINDINGS = [
|
|
8
|
+
"postgres",
|
|
9
|
+
"bucket",
|
|
10
|
+
"email",
|
|
11
|
+
"ai"
|
|
12
|
+
];
|
|
13
|
+
var SERVICE_NAME = /^[a-z][a-z0-9-]{0,30}$/;
|
|
14
|
+
var DIGEST_IMAGE = /^[a-zA-Z0-9./:_-]+@sha256:[a-f0-9]{64}$/;
|
|
15
|
+
var DOMAIN = /^([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z][a-z0-9-]{0,61}[a-z0-9]$/;
|
|
16
|
+
var HEALTH_PATH = /^\/\S*$/;
|
|
17
|
+
var PLAIN_COMMAND = /^[A-Za-z0-9_./:=@,+-]+( +[A-Za-z0-9_./:=@,+-]+)*$/;
|
|
18
|
+
var INTERPOLATION = /\$\{[^}]*\}|\$[A-Za-z_][A-Za-z0-9_]*/g;
|
|
19
|
+
var APPLICATION_FIELDS = [
|
|
20
|
+
"version",
|
|
21
|
+
"preset",
|
|
22
|
+
"domain",
|
|
23
|
+
"migrate"
|
|
24
|
+
];
|
|
25
|
+
var MIGRATE_FIELDS = ["service", "command"];
|
|
26
|
+
var SERVICE_FIELDS = [
|
|
27
|
+
"role",
|
|
28
|
+
"health",
|
|
29
|
+
"binding"
|
|
30
|
+
];
|
|
31
|
+
var HEALTH_FIELDS = ["path", "command"];
|
|
32
|
+
function isRecord(value) {
|
|
33
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34
|
+
}
|
|
35
|
+
function isStringList(value) {
|
|
36
|
+
return Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === "string" && item.length > 0);
|
|
37
|
+
}
|
|
38
|
+
function describe(value) {
|
|
39
|
+
if (typeof value === "string") return value.length > 80 ? `${value.slice(0, 80)}\u2026` : value;
|
|
40
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") return `${value}`;
|
|
41
|
+
if (value === null || value === void 0) return "an empty value";
|
|
42
|
+
if (Array.isArray(value)) return "a list";
|
|
43
|
+
return typeof value === "object" ? "a mapping" : `a ${typeof value}`;
|
|
44
|
+
}
|
|
45
|
+
function refuseVariables(values, path, what, issues, service) {
|
|
46
|
+
if (!values.some((value) => value.includes("$"))) return false;
|
|
47
|
+
issues.error("interpolated-value", path, `${what} contains \`$\`. Compose replaces variables before it runs the stack, but the platform reads the file as written, so the two would not run the same thing.`, "Write the literal value. Settings that differ between environments belong in the environment the application reads, not in this line.", service);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
function findMergeKey(root) {
|
|
51
|
+
const seen = /* @__PURE__ */ new Set();
|
|
52
|
+
const pending = [[root, ""]];
|
|
53
|
+
while (pending.length > 0) {
|
|
54
|
+
const [value, path] = pending.pop();
|
|
55
|
+
if (typeof value !== "object" || value === null || seen.has(value)) continue;
|
|
56
|
+
seen.add(value);
|
|
57
|
+
if (Array.isArray(value)) {
|
|
58
|
+
value.forEach((item, index) => {
|
|
59
|
+
pending.push([item, `${path}[${index}]`]);
|
|
60
|
+
});
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
for (const [key, item] of Object.entries(value)) {
|
|
64
|
+
const here = path ? `${path}.${key}` : key;
|
|
65
|
+
if (key === "<<") return here;
|
|
66
|
+
pending.push([item, here]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function isLiteral(value) {
|
|
71
|
+
return !value.includes("$");
|
|
72
|
+
}
|
|
73
|
+
function quoteList(values) {
|
|
74
|
+
return values.map((value) => `\`${value}\``).join(", ");
|
|
75
|
+
}
|
|
76
|
+
function unknownFields(value, known) {
|
|
77
|
+
return Object.keys(value).filter((key) => !known.includes(key));
|
|
78
|
+
}
|
|
79
|
+
var IssueCollector = class {
|
|
80
|
+
errors = [];
|
|
81
|
+
warnings = [];
|
|
82
|
+
error(code, path, message, fix, service) {
|
|
83
|
+
this.errors.push({
|
|
84
|
+
code,
|
|
85
|
+
severity: "error",
|
|
86
|
+
path,
|
|
87
|
+
...service ? { service } : {},
|
|
88
|
+
message,
|
|
89
|
+
fix
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
warning(code, path, message, fix, service) {
|
|
93
|
+
this.warnings.push({
|
|
94
|
+
code,
|
|
95
|
+
severity: "warning",
|
|
96
|
+
path,
|
|
97
|
+
...service ? { service } : {},
|
|
98
|
+
message,
|
|
99
|
+
fix
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
function parseApplication(document, issues) {
|
|
104
|
+
const path = X_HAPPYVERTICAL_KEY;
|
|
105
|
+
const block = document[X_HAPPYVERTICAL_KEY];
|
|
106
|
+
if (block === void 0) {
|
|
107
|
+
issues.error("contract-missing", path, `The file has no top-level \`${X_HAPPYVERTICAL_KEY}\` block, so it is an ordinary Compose file and not a deployment declaration.`, `Add a top-level \`${X_HAPPYVERTICAL_KEY}\` block with \`version: 1\`, \`preset: smrt\` and a \`migrate\` command.`);
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
if (!isRecord(block)) {
|
|
111
|
+
issues.error("contract-invalid", path, `The top-level \`${X_HAPPYVERTICAL_KEY}\` block must be a mapping of fields.`, "Write it as indented `key: value` lines: `version`, `preset`, `domain`, `migrate`.");
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
const parsed = {};
|
|
115
|
+
for (const field of unknownFields(block, APPLICATION_FIELDS)) issues.error("contract-invalid", `${path}.${field}`, `\`${field}\` is not a field of the version 1 contract.`, `Remove it or fix the spelling. The top-level fields are ${quoteList(APPLICATION_FIELDS)}.`);
|
|
116
|
+
if (block.version !== 1) issues.error("version-unsupported", `${path}.version`, block.version === void 0 ? "The contract version is missing." : `Contract version \`${describe(block.version)}\` is not supported here.`, "Set `version: 1` (a number, without quotes).");
|
|
117
|
+
if (typeof block.preset === "string" && X_HAPPYVERTICAL_PRESETS.includes(block.preset)) parsed.preset = block.preset;
|
|
118
|
+
else issues.error("preset-unknown", `${path}.preset`, block.preset === void 0 ? "The preset is missing, so the platform does not know what kind of application this is." : `\`${describe(block.preset)}\` is not a preset the platform knows.`, `Set \`preset\` to one of: ${quoteList(X_HAPPYVERTICAL_PRESETS)}.`);
|
|
119
|
+
if (block.domain !== void 0) if (typeof block.domain === "string" && block.domain.length <= 253 && DOMAIN.test(block.domain)) parsed.domain = block.domain;
|
|
120
|
+
else issues.error("domain-invalid", `${path}.domain`, `\`${describe(block.domain)}\` is not a hostname.`, "Write only the hostname in lowercase, for example `app.example.com`: no `https://`, no port, no path.");
|
|
121
|
+
const migrate = block.migrate;
|
|
122
|
+
if (migrate === void 0) {
|
|
123
|
+
issues.error("migrate-missing", `${path}.migrate`, "There is no `migrate` entry, so the platform does not know how to prepare the database before a release starts.", "Add `migrate:` with a `command` list, for example `command: [\"pnpm\", \"exec\", \"smrt\", \"db:migrate\"]`.");
|
|
124
|
+
return parsed;
|
|
125
|
+
}
|
|
126
|
+
if (!isRecord(migrate)) {
|
|
127
|
+
issues.error("migrate-invalid", `${path}.migrate`, "`migrate` must be a mapping with a `command`.", "Write `migrate:` followed by an indented `command:` list.");
|
|
128
|
+
return parsed;
|
|
129
|
+
}
|
|
130
|
+
for (const field of unknownFields(migrate, MIGRATE_FIELDS)) issues.error("migrate-invalid", `${path}.migrate.${field}`, `\`${field}\` is not a field of \`migrate\`.`, `Remove it or fix the spelling. \`migrate\` takes ${quoteList(MIGRATE_FIELDS)}.`);
|
|
131
|
+
if (isStringList(migrate.command)) {
|
|
132
|
+
if (!refuseVariables(migrate.command, `${path}.migrate.command`, "The migration command", issues)) parsed.migrateCommand = [...migrate.command];
|
|
133
|
+
} else issues.error("migrate-invalid", `${path}.migrate.command`, "The migration command must be a list with one argument per item.", "Write it as a list, for example `command: [\"pnpm\", \"exec\", \"smrt\", \"db:migrate\"]`.");
|
|
134
|
+
if (migrate.service !== void 0) if (typeof migrate.service === "string" && migrate.service.length > 0) parsed.migrateService = migrate.service;
|
|
135
|
+
else issues.error("migrate-invalid", `${path}.migrate.service`, "`migrate.service` must be the name of a service in this file.", "Name your web or worker service, or remove the line to use the web service.");
|
|
136
|
+
return parsed;
|
|
137
|
+
}
|
|
138
|
+
function parseHealth(name, role, health, issues) {
|
|
139
|
+
const path = `services.${name}.${X_HAPPYVERTICAL_KEY}.health`;
|
|
140
|
+
if (health === void 0) {
|
|
141
|
+
issues.error("health-missing", path, `Service \`${name}\` has no health check, so the platform cannot tell when it is ready.`, role === "web" ? "Add `health:` with a `path` that answers 200 when the app is ready, for example `path: /api/health`." : "Add `health:` with a `command` list that exits 0 when the worker is ready.", name);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!isRecord(health)) {
|
|
145
|
+
issues.error("health-invalid", path, `The health check of \`${name}\` must be a mapping with either \`path\` or \`command\`.`, "Write `health:` followed by an indented `path:` or `command:`.", name);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const extra = unknownFields(health, HEALTH_FIELDS);
|
|
149
|
+
if (extra.length > 0) {
|
|
150
|
+
issues.error("health-invalid", `${path}.${extra[0]}`, `\`${extra[0]}\` is not a field of a health check.`, `Remove it or fix the spelling. A health check takes ${quoteList(HEALTH_FIELDS)}.`, name);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const hasPath = health.path !== void 0;
|
|
154
|
+
if (hasPath === (health.command !== void 0)) {
|
|
155
|
+
issues.error("health-invalid", path, hasPath ? `The health check of \`${name}\` has both \`path\` and \`command\`.` : `The health check of \`${name}\` is empty.`, "Keep exactly one: `path` for an HTTP check, or `command` for a check run inside the container.", name);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (hasPath) {
|
|
159
|
+
if (role === "worker") {
|
|
160
|
+
issues.error("worker-health-needs-command", `${path}.path`, `Worker \`${name}\` has an HTTP health path, but workers do not serve HTTP.`, "Use `command:` with a list that exits 0 when the worker is ready.", name);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (typeof health.path !== "string" || !HEALTH_PATH.test(health.path)) {
|
|
164
|
+
issues.error("health-invalid", `${path}.path`, `The health path of \`${name}\` must start with \`/\` and contain no spaces.`, "Write a path such as `/api/health`.", name);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (refuseVariables([health.path], `${path}.path`, `The health path of \`${name}\``, issues, name)) return;
|
|
168
|
+
return { path: health.path };
|
|
169
|
+
}
|
|
170
|
+
if (!isStringList(health.command)) {
|
|
171
|
+
issues.error("health-invalid", `${path}.command`, `The health command of \`${name}\` must be a list with one argument per item.`, "Write it as a list, for example `command: [\"pnpm\", \"exec\", \"smrt\", \"app\", \"doctor\"]`.", name);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (refuseVariables(health.command, `${path}.command`, `The health command of \`${name}\``, issues, name)) return;
|
|
175
|
+
return { command: [...health.command] };
|
|
176
|
+
}
|
|
177
|
+
function parseCommand(name, field, value, issues) {
|
|
178
|
+
if (value === void 0 || value === null) return void 0;
|
|
179
|
+
if (Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "") return [];
|
|
180
|
+
const path = `services.${name}.${field}`;
|
|
181
|
+
const what = `The \`${field}\` of \`${name}\``;
|
|
182
|
+
if (isStringList(value)) return refuseVariables(value, path, what, issues, name) ? void 0 : [...value];
|
|
183
|
+
if (typeof value === "string") {
|
|
184
|
+
if (refuseVariables([value], path, what, issues, name)) return void 0;
|
|
185
|
+
if (PLAIN_COMMAND.test(value.trim())) return value.trim().split(/ +/);
|
|
186
|
+
}
|
|
187
|
+
issues.error("command-not-list", `services.${name}.${field}`, `The \`${field}\` of \`${name}\` uses quoting or shell syntax, or is not text, which Compose and the platform would read differently.`, `Write \`${field}\` as a list with one argument per item, for example \`["node", "build"]\`.`, name);
|
|
188
|
+
}
|
|
189
|
+
function scanPortEntry(name, field, entry, index, issues) {
|
|
190
|
+
const path = `services.${name}.${field}[${index}]`;
|
|
191
|
+
const invalid = (reason) => {
|
|
192
|
+
issues.error("ingress-port-invalid", path, `Port entry \`${describe(entry)}\` of \`${name}\` ${reason}.`, "Publish one fixed TCP port, for example `\"3000:3000\"`.", name);
|
|
193
|
+
};
|
|
194
|
+
if (typeof entry === "number") return Number.isInteger(entry) && entry > 0 && entry < 65536 ? entry : invalid("is not a valid port number");
|
|
195
|
+
if (typeof entry === "string") {
|
|
196
|
+
const [address, protocol] = entry.replace(INTERPOLATION, "\0").split("/");
|
|
197
|
+
if (protocol !== void 0 && protocol.toLowerCase() !== "tcp") return invalid("is not TCP");
|
|
198
|
+
const container = address.split(":").at(-1) ?? "";
|
|
199
|
+
if (!/^\d+$/.test(container)) return invalid(container.includes("-") ? "is a port range" : "does not name a fixed container port");
|
|
200
|
+
const port = Number(container);
|
|
201
|
+
return port > 0 && port < 65536 ? port : invalid("is not a valid port number");
|
|
202
|
+
}
|
|
203
|
+
if (isRecord(entry)) {
|
|
204
|
+
if (entry.mode !== void 0 && entry.mode !== "ingress") {
|
|
205
|
+
issues.error("host-network", path, `Service \`${name}\` publishes a port in \`${describe(entry.mode)}\` mode, which binds it to the network of the machine it runs on.`, "Remove the `mode` line. The platform routes traffic to the container for you.", name);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (entry.protocol !== void 0 && !(typeof entry.protocol === "string" && entry.protocol.toLowerCase() === "tcp")) return invalid("is not TCP");
|
|
209
|
+
const target = typeof entry.target === "number" ? entry.target : typeof entry.target === "string" && /^\d+$/.test(entry.target) ? Number(entry.target) : NaN;
|
|
210
|
+
return Number.isInteger(target) && target > 0 && target < 65536 ? target : invalid("does not name a fixed container port in `target`");
|
|
211
|
+
}
|
|
212
|
+
return invalid("is not a port");
|
|
213
|
+
}
|
|
214
|
+
function scanPorts(name, field, value, issues) {
|
|
215
|
+
if (value === void 0 || value === null) return {
|
|
216
|
+
ports: [],
|
|
217
|
+
invalid: false
|
|
218
|
+
};
|
|
219
|
+
if (!Array.isArray(value)) {
|
|
220
|
+
issues.error("ingress-port-invalid", `services.${name}.${field}`, `\`${field}\` of \`${name}\` must be a list.`, "Publish one fixed TCP port, for example `ports: [\"3000:3000\"]`.", name);
|
|
221
|
+
return {
|
|
222
|
+
ports: [],
|
|
223
|
+
invalid: true
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const before = issues.errors.length;
|
|
227
|
+
const ports = /* @__PURE__ */ new Set();
|
|
228
|
+
value.forEach((entry, index) => {
|
|
229
|
+
const port = scanPortEntry(name, field, entry, index, issues);
|
|
230
|
+
if (port !== void 0) ports.add(port);
|
|
231
|
+
});
|
|
232
|
+
return {
|
|
233
|
+
ports: [...ports],
|
|
234
|
+
invalid: issues.errors.length > before
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function isHostPath(source) {
|
|
238
|
+
return source.startsWith(".") || source.startsWith("/") || source.startsWith("~") || source.includes("$") || source.includes("\\") || /^[A-Za-z]:/.test(source);
|
|
239
|
+
}
|
|
240
|
+
function scanVolumes(name, service, declared, issues) {
|
|
241
|
+
const volumes = [];
|
|
242
|
+
const notDeclared = (path, what) => {
|
|
243
|
+
issues.error("volume-not-declared", path, `Service \`${name}\` ${what}. The platform only keeps data in volumes the file declares.`, "Declare a named volume under top-level `volumes:` and mount it as `name:/path/in/container`. Files the app needs belong in its image.", name);
|
|
244
|
+
};
|
|
245
|
+
const useNamed = (path, source, target, readOnly) => {
|
|
246
|
+
if (!Object.hasOwn(declared, source)) {
|
|
247
|
+
notDeclared(path, `mounts the volume \`${source}\`, which is not declared in this file`);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const definition = declared[source];
|
|
251
|
+
if (isRecord(definition)) {
|
|
252
|
+
const external = definition.external !== void 0 && definition.external !== false;
|
|
253
|
+
const customDriver = definition.driver !== void 0 && definition.driver !== "local";
|
|
254
|
+
if (external || customDriver || definition.driver_opts !== void 0) {
|
|
255
|
+
issues.error("volume-not-plain", `volumes.${source}`, `Volume \`${source}\` is external or uses driver options, so its contents live somewhere this file does not describe.`, "Declare it as a plain named volume (just `name:` with nothing under it).", name);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (refuseVariables([target], path, `The mount path of volume \`${source}\` in \`${name}\``, issues, name)) return;
|
|
260
|
+
volumes.push({
|
|
261
|
+
name: source,
|
|
262
|
+
target,
|
|
263
|
+
readOnly
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
if (Array.isArray(service.volumes_from) ? service.volumes_from.length > 0 : service.volumes_from !== void 0 && service.volumes_from !== null) notDeclared(`services.${name}.volumes_from`, "borrows another container's volumes with `volumes_from`");
|
|
267
|
+
const entries = service.volumes;
|
|
268
|
+
if (entries === void 0 || entries === null) return volumes;
|
|
269
|
+
if (!Array.isArray(entries)) {
|
|
270
|
+
notDeclared(`services.${name}.volumes`, "has a `volumes` entry that is not a list");
|
|
271
|
+
return volumes;
|
|
272
|
+
}
|
|
273
|
+
entries.forEach((entry, index) => {
|
|
274
|
+
const path = `services.${name}.volumes[${index}]`;
|
|
275
|
+
if (typeof entry === "string") {
|
|
276
|
+
if (/^[A-Za-z]:[\\/]/.test(entry) || entry.includes("\\")) {
|
|
277
|
+
notDeclared(path, `mounts \`${describe(entry)}\` from the machine it runs on (a bind mount)`);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
const [source, target, mode] = entry.split(":");
|
|
281
|
+
if (target === void 0) notDeclared(path, `mounts an unnamed volume at \`${entry}\``);
|
|
282
|
+
else if (isHostPath(source)) notDeclared(path, `mounts \`${source}\` from the machine it runs on (a bind mount)`);
|
|
283
|
+
else useNamed(path, source, target, (mode ?? "").split(",").includes("ro"));
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (isRecord(entry)) {
|
|
287
|
+
const type = entry.type ?? "volume";
|
|
288
|
+
if (type === "tmpfs") return;
|
|
289
|
+
if (type !== "volume") {
|
|
290
|
+
notDeclared(path, `uses a \`${describe(type)}\` mount, which reads from the machine it runs on`);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (typeof entry.source !== "string" || entry.source.length === 0) {
|
|
294
|
+
notDeclared(path, "mounts an unnamed volume");
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (typeof entry.target !== "string" || entry.target.length === 0) {
|
|
298
|
+
notDeclared(path, "has a volume entry with no `target` path");
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
useNamed(path, entry.source, entry.target, entry.read_only !== void 0 && entry.read_only !== false);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
notDeclared(path, "has a volume entry that is not a mount");
|
|
305
|
+
});
|
|
306
|
+
return volumes;
|
|
307
|
+
}
|
|
308
|
+
function resolveImage(entry, options, stage, issues) {
|
|
309
|
+
const { name, definition } = entry;
|
|
310
|
+
const declared = typeof definition.image === "string" && definition.image.length > 0 ? definition.image : void 0;
|
|
311
|
+
const hasBuild = definition.build !== void 0 && definition.build !== null;
|
|
312
|
+
const supplied = options.images && Object.hasOwn(options.images, name) ? options.images[name] : void 0;
|
|
313
|
+
if (declared === void 0 && !hasBuild) issues.error("service-no-image", `services.${name}`, `Service \`${name}\` has neither \`image\` nor \`build\`, so nothing can run it.`, "Add `build: .` to build it locally, or `image:` with the image to run.", name);
|
|
314
|
+
if (stage === "declare") {
|
|
315
|
+
const image = supplied ?? declared;
|
|
316
|
+
return image !== void 0 && isLiteral(image) ? image : void 0;
|
|
317
|
+
}
|
|
318
|
+
const effective = supplied ?? declared;
|
|
319
|
+
if (effective !== void 0 && DIGEST_IMAGE.test(effective)) return effective;
|
|
320
|
+
issues.error("image-not-digest", `services.${name}.image`, effective === void 0 ? `Service \`${name}\` is only built locally. The platform deploys an image that CI already built and pushed; it never runs \`build:\`.` : `The image of \`${name}\` (\`${effective}\`) is a tag, which can change after it was tested. The platform deploys exact image digests only.`, `Supply the digest CI pushed for \`${name}\`, in the form \`registry/name@sha256:\` followed by 64 hex characters.`, name);
|
|
321
|
+
}
|
|
322
|
+
function checkRoleService(entry, declaredVolumes, options, stage, issues) {
|
|
323
|
+
const { name, role, definition } = entry;
|
|
324
|
+
const before = issues.errors.length;
|
|
325
|
+
if (definition.extends !== void 0) issues.error("not-self-contained", `services.${name}.extends`, `Service \`${name}\` takes part of its definition from another service with \`extends\`, so what it runs is not written here.`, "Write the service out in full. The platform reads each service as written, in this one file.", name);
|
|
326
|
+
const image = resolveImage(entry, options, stage, issues);
|
|
327
|
+
if (definition.privileged !== void 0 && definition.privileged !== null && definition.privileged !== false) issues.error("privileged", `services.${name}.privileged`, `Service \`${name}\` sets \`privileged\`. Privileged mode gives a container control of the machine it runs on, and Compose accepts more spellings of "yes" than can be told apart here.`, "Remove the `privileged` line. The platform never runs privileged containers.", name);
|
|
328
|
+
if (definition.network_mode === "host") issues.error("host-network", `services.${name}.network_mode`, `Service \`${name}\` uses the host's network instead of its own.`, "Remove `network_mode: host`. Services reach each other by service name, and the platform routes outside traffic to the web service.", name);
|
|
329
|
+
const volumes = scanVolumes(name, definition, declaredVolumes, issues);
|
|
330
|
+
const entrypoint = parseCommand(name, "entrypoint", definition.entrypoint, issues);
|
|
331
|
+
const command = parseCommand(name, "command", definition.command, issues);
|
|
332
|
+
let port;
|
|
333
|
+
const publishesNothing = definition.ports === void 0 || definition.ports === null || Array.isArray(definition.ports) && definition.ports.length === 0;
|
|
334
|
+
const published = role === "web" ? scanPorts(name, "ports", definition.ports, issues) : {
|
|
335
|
+
ports: [],
|
|
336
|
+
invalid: false
|
|
337
|
+
};
|
|
338
|
+
if (role === "web") {
|
|
339
|
+
const exposed = published.ports.length === 0 && !published.invalid ? scanPorts(name, "expose", definition.expose, issues) : {
|
|
340
|
+
ports: [],
|
|
341
|
+
invalid: false
|
|
342
|
+
};
|
|
343
|
+
const ports = published.ports.length > 0 ? published.ports : exposed.ports;
|
|
344
|
+
if (!published.invalid && !exposed.invalid && ports.length !== 1) issues.error("ingress-port-count", `services.${name}.ports`, ports.length === 0 ? `Web service \`${name}\` publishes no port, so there is nothing to send visitors to.` : `Web service \`${name}\` publishes ${ports.length} ports (${ports.join(", ")}). The platform routes visitors to exactly one.`, "Publish exactly one port, the one the app listens on, for example `ports: [\"3000:3000\"]`.", name);
|
|
345
|
+
port = ports[0];
|
|
346
|
+
} else if (!publishesNothing) issues.error("worker-publishes-port", `services.${name}.ports`, `Worker \`${name}\` publishes a port, but only the web service receives traffic.`, "Remove `ports` from the worker, or give the service `role: web` if it is the one visitors reach.", name);
|
|
347
|
+
if (issues.errors.length > before || entry.health === void 0) return;
|
|
348
|
+
return {
|
|
349
|
+
name,
|
|
350
|
+
role,
|
|
351
|
+
...image !== void 0 ? { image } : {},
|
|
352
|
+
...entrypoint ? { entrypoint } : {},
|
|
353
|
+
...command ? { command } : {},
|
|
354
|
+
...port !== void 0 ? { port } : {},
|
|
355
|
+
health: entry.health,
|
|
356
|
+
volumes
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function validateComposeDeployment(document, options = {}) {
|
|
360
|
+
const issues = new IssueCollector();
|
|
361
|
+
const stage = options.stage ?? "declare";
|
|
362
|
+
const finish = (declaration) => ({
|
|
363
|
+
ok: issues.errors.length === 0,
|
|
364
|
+
errors: issues.errors,
|
|
365
|
+
warnings: issues.warnings,
|
|
366
|
+
...issues.errors.length === 0 && declaration ? { declaration } : {}
|
|
367
|
+
});
|
|
368
|
+
if (!isRecord(document)) {
|
|
369
|
+
issues.error("document-invalid", "", "This is not a Compose file: the top level must be a mapping with `services`.", "Check that the file is valid YAML and starts with top-level keys such as `services:`.");
|
|
370
|
+
return finish();
|
|
371
|
+
}
|
|
372
|
+
const mergeKey = findMergeKey(document);
|
|
373
|
+
if (mergeKey !== void 0) {
|
|
374
|
+
issues.error("merge-key-unresolved", mergeKey, "The file still contains a YAML merge key (`<<`), so the part of it that comes from an anchor was not read.", "Parse the file with YAML merge keys enabled, as Compose does (`smrt deploy:check` does this for you).");
|
|
375
|
+
return finish();
|
|
376
|
+
}
|
|
377
|
+
if (document.include !== void 0) issues.error("not-self-contained", "include", "The file pulls in other Compose files with `include`.", "Put every service in this one file. The platform reads this file and nothing else.");
|
|
378
|
+
const application = parseApplication(document, issues);
|
|
379
|
+
const services = document.services;
|
|
380
|
+
if (!isRecord(services) || Object.keys(services).length === 0) {
|
|
381
|
+
issues.error("services-missing", "services", "The file declares no services.", "Add your application under `services:`, with at least a web service.");
|
|
382
|
+
return finish();
|
|
383
|
+
}
|
|
384
|
+
const declaredVolumes = isRecord(document.volumes) ? document.volumes : {};
|
|
385
|
+
const roleServices = [];
|
|
386
|
+
const bindings = [];
|
|
387
|
+
const localOnly = [];
|
|
388
|
+
for (const [name, definition] of Object.entries(services)) {
|
|
389
|
+
if (!isRecord(definition)) {
|
|
390
|
+
issues.error("service-invalid", `services.${name}`, `Service \`${name}\` is empty or not a mapping.`, "Give it an `image` or `build` and the settings it needs, or remove it.", name);
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
const annotationPath = `services.${name}.${X_HAPPYVERTICAL_KEY}`;
|
|
394
|
+
const annotation = definition[X_HAPPYVERTICAL_KEY];
|
|
395
|
+
if (annotation === void 0) {
|
|
396
|
+
localOnly.push(name);
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
if (!isRecord(annotation)) {
|
|
400
|
+
issues.error("annotation-invalid", annotationPath, `The \`${X_HAPPYVERTICAL_KEY}\` block of \`${name}\` must be a mapping.`, "Write `role: web` or `role: worker` with a `health` check, or `binding:` with the platform service it stands in for.", name);
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
const extra = unknownFields(annotation, SERVICE_FIELDS);
|
|
404
|
+
if (extra.length > 0) {
|
|
405
|
+
issues.error("annotation-invalid", `${annotationPath}.${extra[0]}`, `\`${extra[0]}\` is not a field of a service annotation.`, `Remove it or fix the spelling. A service takes ${quoteList(SERVICE_FIELDS)}.`, name);
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
const hasRole = annotation.role !== void 0;
|
|
409
|
+
const hasBinding = annotation.binding !== void 0;
|
|
410
|
+
if (hasRole && hasBinding) {
|
|
411
|
+
issues.error("role-and-binding", annotationPath, `Service \`${name}\` has both \`role\` and \`binding\`. A service is either part of your application or a stand-in for a platform service.`, "Keep `role` for something you build and run, or `binding` for something the platform provides.", name);
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
if (!hasRole && !hasBinding) {
|
|
415
|
+
issues.error("annotation-invalid", annotationPath, `The \`${X_HAPPYVERTICAL_KEY}\` block of \`${name}\` says neither what the service is nor what it stands in for.`, "Add `role: web`, `role: worker`, or `binding:`. Remove the block if the service is only for local use.", name);
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (!SERVICE_NAME.test(name)) issues.error("service-name-invalid", `services.${name}`, `The service name \`${name}\` cannot be used as a platform resource name.`, "Rename it using lowercase letters, digits and hyphens, starting with a letter, at most 31 characters.", name);
|
|
419
|
+
if (hasBinding) {
|
|
420
|
+
const kind = annotation.binding;
|
|
421
|
+
if (typeof kind !== "string" || !X_HAPPYVERTICAL_BINDINGS.includes(kind)) {
|
|
422
|
+
issues.error("binding-unknown", `${annotationPath}.binding`, `\`${describe(kind)}\` is not a platform service this contract knows.`, `Set \`binding\` to one of: ${quoteList(X_HAPPYVERTICAL_BINDINGS)}.`, name);
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (annotation.health !== void 0) issues.error("binding-with-health", `${annotationPath}.health`, `Binding \`${name}\` has a \`health\` check, but the platform runs its own service in place of this container.`, "Remove `health` from the annotation. A Compose `healthcheck:` on the service is fine for local use.", name);
|
|
426
|
+
const hasImage = typeof definition.image === "string" && definition.image.length > 0;
|
|
427
|
+
const hasBuild = definition.build !== void 0 && definition.build !== null;
|
|
428
|
+
if (!hasImage && !hasBuild) issues.error("binding-no-local-image", `services.${name}.image`, `Binding \`${name}\` has no local image, so the stack cannot run anywhere the platform is not providing ${kind}.`, "Add the image you run locally, for example `image: postgres:18-alpine`, so the file stays a complete working stack on its own.", name);
|
|
429
|
+
const duplicate = bindings.find((binding) => binding.kind === kind);
|
|
430
|
+
if (duplicate) {
|
|
431
|
+
issues.error("binding-duplicate", `${annotationPath}.binding`, `Services \`${duplicate.name}\` and \`${name}\` both stand in for \`${kind}\`. Version 1 binds each platform service once.`, `Keep one \`${kind}\` binding.`, name);
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
bindings.push({
|
|
435
|
+
name,
|
|
436
|
+
kind
|
|
437
|
+
});
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
const role = annotation.role;
|
|
441
|
+
if (typeof role !== "string" || !X_HAPPYVERTICAL_ROLES.includes(role)) {
|
|
442
|
+
issues.error("role-unknown", `${annotationPath}.role`, `\`${describe(role)}\` is not a role.`, `Set \`role\` to one of: ${quoteList(X_HAPPYVERTICAL_ROLES)}.`, name);
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
roleServices.push({
|
|
446
|
+
name,
|
|
447
|
+
role,
|
|
448
|
+
definition,
|
|
449
|
+
health: parseHealth(name, role, annotation.health, issues)
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
const webServices = roleServices.filter((entry) => entry.role === "web");
|
|
453
|
+
if (webServices.length !== 1) issues.error("web-service-count", "services", webServices.length === 0 ? "No service has `role: web`, so there is nothing for visitors to reach." : `${webServices.length} services have \`role: web\` (${quoteList(webServices.map((entry) => entry.name))}). The platform routes visitors to exactly one.`, "Give exactly one service `role: web`. Anything else you run is `role: worker`.");
|
|
454
|
+
const workloads = [];
|
|
455
|
+
for (const entry of roleServices) {
|
|
456
|
+
const workload = checkRoleService(entry, declaredVolumes, options, stage, issues);
|
|
457
|
+
if (workload) workloads.push(workload);
|
|
458
|
+
}
|
|
459
|
+
for (const name of Object.keys(options.images ?? {})) if (!roleServices.some((entry) => entry.name === name)) issues.error("image-for-unknown-service", `services.${name}`, `An image digest was supplied for \`${name}\`, which is not a web or worker service in this file.`, `Supply digests only for: ${quoteList(roleServices.map((entry) => entry.name))}.`, name);
|
|
460
|
+
const migrateService = application.migrateService ?? webServices[0]?.name;
|
|
461
|
+
if (application.migrateService !== void 0 && !roleServices.some((entry) => entry.name === application.migrateService)) issues.error("migrate-service-not-role", `${X_HAPPYVERTICAL_KEY}.migrate.service`, `\`migrate.service\` names \`${application.migrateService}\`, which is not a web or worker service in this file. The migration ships inside one of your application images.`, `Name one of: ${quoteList(roleServices.map((entry) => entry.name))}, or remove the line to use the web service.`);
|
|
462
|
+
for (const name of localOnly) issues.warning("local-only-service", `services.${name}`, `Service \`${name}\` has no \`${X_HAPPYVERTICAL_KEY}\` annotation. It runs on your machine only; the platform will not run it.`, "Nothing to do if that is intended. Otherwise give it `role: web`, `role: worker` or a `binding`.", name);
|
|
463
|
+
if (issues.errors.length > 0 || application.preset === void 0 || application.migrateCommand === void 0 || migrateService === void 0) return finish();
|
|
464
|
+
const migrateImage = workloads.find((workload) => workload.name === migrateService)?.image;
|
|
465
|
+
return finish({
|
|
466
|
+
version: 1,
|
|
467
|
+
preset: application.preset,
|
|
468
|
+
stage,
|
|
469
|
+
...typeof document.name === "string" && document.name.length > 0 && isLiteral(document.name) ? { name: document.name } : {},
|
|
470
|
+
...application.domain !== void 0 ? { domain: application.domain } : {},
|
|
471
|
+
migrate: {
|
|
472
|
+
service: migrateService,
|
|
473
|
+
command: application.migrateCommand,
|
|
474
|
+
...migrateImage !== void 0 ? { image: migrateImage } : {}
|
|
475
|
+
},
|
|
476
|
+
workloads,
|
|
477
|
+
bindings,
|
|
478
|
+
localOnly
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
function formatIssue(issue, index) {
|
|
482
|
+
const where = issue.path ? `${issue.path}: ` : "";
|
|
483
|
+
return `${index + 1}. ${where}${issue.message}
|
|
484
|
+
Fix: ${issue.fix}`;
|
|
485
|
+
}
|
|
486
|
+
function formatComposeDeploymentReport(result) {
|
|
487
|
+
const lines = [];
|
|
488
|
+
if (result.ok) {
|
|
489
|
+
lines.push("The deployment declaration is valid.");
|
|
490
|
+
const declaration = result.declaration;
|
|
491
|
+
if (declaration) {
|
|
492
|
+
const describe2 = (workload) => workload.port !== void 0 ? `${workload.name} (${workload.role}, port ${workload.port})` : `${workload.name} (${workload.role})`;
|
|
493
|
+
lines.push(`Preset: ${declaration.preset}`, `Runs: ${declaration.workloads.map(describe2).join(", ")}`, `Migration: ${declaration.migrate.command.join(" ")} (in the ${declaration.migrate.service} image)`, `Platform services: ${declaration.bindings.length > 0 ? declaration.bindings.map((binding) => `${binding.kind} (local: ${binding.name})`).join(", ") : "none"}`);
|
|
494
|
+
if (declaration.domain) lines.push(`Domain: ${declaration.domain}`);
|
|
495
|
+
}
|
|
496
|
+
} else {
|
|
497
|
+
const count = result.errors.length;
|
|
498
|
+
lines.push(`The deployment declaration has ${count} problem${count === 1 ? "" : "s"}.`, "", ...result.errors.map(formatIssue));
|
|
499
|
+
}
|
|
500
|
+
if (result.warnings.length > 0) lines.push("", `Runs only on your machine (the platform will not run it): ${result.warnings.map((warning) => warning.service ?? warning.path).join(", ")}`);
|
|
501
|
+
return lines.join("\n");
|
|
502
|
+
}
|
|
503
|
+
//#endregion
|
|
504
|
+
//#region src/deployment/sha256.ts
|
|
505
|
+
var K = new Uint32Array([
|
|
506
|
+
1116352408,
|
|
507
|
+
1899447441,
|
|
508
|
+
3049323471,
|
|
509
|
+
3921009573,
|
|
510
|
+
961987163,
|
|
511
|
+
1508970993,
|
|
512
|
+
2453635748,
|
|
513
|
+
2870763221,
|
|
514
|
+
3624381080,
|
|
515
|
+
310598401,
|
|
516
|
+
607225278,
|
|
517
|
+
1426881987,
|
|
518
|
+
1925078388,
|
|
519
|
+
2162078206,
|
|
520
|
+
2614888103,
|
|
521
|
+
3248222580,
|
|
522
|
+
3835390401,
|
|
523
|
+
4022224774,
|
|
524
|
+
264347078,
|
|
525
|
+
604807628,
|
|
526
|
+
770255983,
|
|
527
|
+
1249150122,
|
|
528
|
+
1555081692,
|
|
529
|
+
1996064986,
|
|
530
|
+
2554220882,
|
|
531
|
+
2821834349,
|
|
532
|
+
2952996808,
|
|
533
|
+
3210313671,
|
|
534
|
+
3336571891,
|
|
535
|
+
3584528711,
|
|
536
|
+
113926993,
|
|
537
|
+
338241895,
|
|
538
|
+
666307205,
|
|
539
|
+
773529912,
|
|
540
|
+
1294757372,
|
|
541
|
+
1396182291,
|
|
542
|
+
1695183700,
|
|
543
|
+
1986661051,
|
|
544
|
+
2177026350,
|
|
545
|
+
2456956037,
|
|
546
|
+
2730485921,
|
|
547
|
+
2820302411,
|
|
548
|
+
3259730800,
|
|
549
|
+
3345764771,
|
|
550
|
+
3516065817,
|
|
551
|
+
3600352804,
|
|
552
|
+
4094571909,
|
|
553
|
+
275423344,
|
|
554
|
+
430227734,
|
|
555
|
+
506948616,
|
|
556
|
+
659060556,
|
|
557
|
+
883997877,
|
|
558
|
+
958139571,
|
|
559
|
+
1322822218,
|
|
560
|
+
1537002063,
|
|
561
|
+
1747873779,
|
|
562
|
+
1955562222,
|
|
563
|
+
2024104815,
|
|
564
|
+
2227730452,
|
|
565
|
+
2361852424,
|
|
566
|
+
2428436474,
|
|
567
|
+
2756734187,
|
|
568
|
+
3204031479,
|
|
569
|
+
3329325298
|
|
570
|
+
]);
|
|
571
|
+
function rotr(value, bits) {
|
|
572
|
+
return value >>> bits | value << 32 - bits;
|
|
573
|
+
}
|
|
574
|
+
function sha256Hex(text) {
|
|
575
|
+
const bytes = new TextEncoder().encode(text);
|
|
576
|
+
const padded = new Uint8Array(bytes.length + 9 + 63 >> 6 << 6);
|
|
577
|
+
padded.set(bytes);
|
|
578
|
+
padded[bytes.length] = 128;
|
|
579
|
+
const view = new DataView(padded.buffer);
|
|
580
|
+
const bitLength = bytes.length * 8;
|
|
581
|
+
view.setUint32(padded.length - 8, Math.floor(bitLength / 4294967296));
|
|
582
|
+
view.setUint32(padded.length - 4, bitLength >>> 0);
|
|
583
|
+
const h = new Uint32Array([
|
|
584
|
+
1779033703,
|
|
585
|
+
3144134277,
|
|
586
|
+
1013904242,
|
|
587
|
+
2773480762,
|
|
588
|
+
1359893119,
|
|
589
|
+
2600822924,
|
|
590
|
+
528734635,
|
|
591
|
+
1541459225
|
|
592
|
+
]);
|
|
593
|
+
const w = /* @__PURE__ */ new Uint32Array(64);
|
|
594
|
+
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
595
|
+
for (let i = 0; i < 16; i++) w[i] = view.getUint32(offset + i * 4);
|
|
596
|
+
for (let i = 16; i < 64; i++) {
|
|
597
|
+
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ w[i - 15] >>> 3;
|
|
598
|
+
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ w[i - 2] >>> 10;
|
|
599
|
+
w[i] = w[i - 16] + s0 + w[i - 7] + s1 | 0;
|
|
600
|
+
}
|
|
601
|
+
let [a, b, c, d, e, f, g, hh] = h;
|
|
602
|
+
for (let i = 0; i < 64; i++) {
|
|
603
|
+
const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
604
|
+
const choose = e & f ^ ~e & g;
|
|
605
|
+
const t1 = hh + s1 + choose + K[i] + w[i] | 0;
|
|
606
|
+
const t2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) | 0;
|
|
607
|
+
hh = g;
|
|
608
|
+
g = f;
|
|
609
|
+
f = e;
|
|
610
|
+
e = d + t1 | 0;
|
|
611
|
+
d = c;
|
|
612
|
+
c = b;
|
|
613
|
+
b = a;
|
|
614
|
+
a = t1 + t2 | 0;
|
|
615
|
+
}
|
|
616
|
+
h[0] += a;
|
|
617
|
+
h[1] += b;
|
|
618
|
+
h[2] += c;
|
|
619
|
+
h[3] += d;
|
|
620
|
+
h[4] += e;
|
|
621
|
+
h[5] += f;
|
|
622
|
+
h[6] += g;
|
|
623
|
+
h[7] += hh;
|
|
624
|
+
}
|
|
625
|
+
return Array.from(h, (word) => word.toString(16).padStart(8, "0")).join("");
|
|
626
|
+
}
|
|
627
|
+
//#endregion
|
|
628
|
+
//#region src/deployment/hosted-app.ts
|
|
629
|
+
var HOSTED_APP_API_VERSION = "hosting.happyvertical.com/v1alpha1";
|
|
630
|
+
var HOSTED_APP_KIND = "HostedApp";
|
|
631
|
+
var HOSTED_APP_PRESET = "smrt";
|
|
632
|
+
var HOSTED_APP_NAME_MAX_LENGTH = 40;
|
|
633
|
+
var HOSTED_APP_TIERS = [
|
|
634
|
+
"T1",
|
|
635
|
+
"T2",
|
|
636
|
+
"T3"
|
|
637
|
+
];
|
|
638
|
+
var HOSTED_APP_WORKER_ROLES = [
|
|
639
|
+
"background",
|
|
640
|
+
"schedule",
|
|
641
|
+
"task"
|
|
642
|
+
];
|
|
643
|
+
var COMMIT_PATTERN = /^[a-f0-9]{7,64}$/;
|
|
644
|
+
var DNS_LABEL = /^[a-z]([-a-z0-9]*[a-z0-9])?$/;
|
|
645
|
+
var QUANTITY = /^[1-9][0-9]*(Ki|Mi|Gi|Ti|k|M|G|T)?$/;
|
|
646
|
+
var LABEL_KEY = /^([a-z0-9.-]{1,253}\/)?[A-Za-z0-9]([-A-Za-z0-9_.]{0,61}[A-Za-z0-9])?$/;
|
|
647
|
+
var LABEL_VALUE = /^([A-Za-z0-9]([-A-Za-z0-9_.]{0,61}[A-Za-z0-9])?)?$/;
|
|
648
|
+
function hostedAppReleaseId(commit, digests) {
|
|
649
|
+
const hash = sha256Hex(JSON.stringify(Object.entries(digests).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0))).slice(0, 8);
|
|
650
|
+
return `rel-${commit.slice(0, 12)}-${hash}`;
|
|
651
|
+
}
|
|
652
|
+
function isHostedAppCommit(commit) {
|
|
653
|
+
return typeof commit === "string" && COMMIT_PATTERN.test(commit);
|
|
654
|
+
}
|
|
655
|
+
function issueToRejection(issue) {
|
|
656
|
+
return {
|
|
657
|
+
code: issue.code,
|
|
658
|
+
message: `${issue.message} ${issue.fix}`.trim()
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
function reject(code, message) {
|
|
662
|
+
return {
|
|
663
|
+
ok: false,
|
|
664
|
+
rejections: [{
|
|
665
|
+
code,
|
|
666
|
+
message
|
|
667
|
+
}]
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
function labelProblem(labels) {
|
|
671
|
+
if (labels === void 0) return void 0;
|
|
672
|
+
if (typeof labels !== "object" || labels === null || Array.isArray(labels)) return "The labels must be an object of strings.";
|
|
673
|
+
for (const [key, value] of Object.entries(labels)) if (!LABEL_KEY.test(key) || typeof value !== "string" || !LABEL_VALUE.test(value)) return "A label is not a valid Kubernetes label.";
|
|
674
|
+
}
|
|
675
|
+
function composeHostedApp(input) {
|
|
676
|
+
const { app, entitlements, commit, digests } = input;
|
|
677
|
+
if (!isHostedAppCommit(commit)) return reject("commit-invalid", "The commit must be 7 to 64 hex digits.");
|
|
678
|
+
if (typeof app.name !== "string" || !DNS_LABEL.test(app.name) || app.name.length > 40) return reject("platform-name-invalid", `The app name must be a DNS label of at most 40 characters.`);
|
|
679
|
+
if (!HOSTED_APP_TIERS.includes(app.tier)) return reject("tier-invalid", `The tier must be one of: ${HOSTED_APP_TIERS.join(", ")}.`);
|
|
680
|
+
if (typeof app.poolRef !== "string" || app.poolRef === "") return reject("pool-invalid", "The app has no pool to run in.");
|
|
681
|
+
const labelIssue = labelProblem(app.labels);
|
|
682
|
+
if (labelIssue) return reject("labels-invalid", labelIssue);
|
|
683
|
+
const workerRole = input.preset?.workerRole;
|
|
684
|
+
if (workerRole !== void 0 && !HOSTED_APP_WORKER_ROLES.includes(workerRole)) return reject("worker-role-invalid", `The worker role must be one of: ${HOSTED_APP_WORKER_ROLES.join(", ")}.`);
|
|
685
|
+
const validated = validateComposeDeployment(input.document, {
|
|
686
|
+
stage: "deploy",
|
|
687
|
+
images: digests
|
|
688
|
+
});
|
|
689
|
+
const warnings = validated.warnings.map(issueToRejection);
|
|
690
|
+
if (!validated.ok || !validated.declaration) return {
|
|
691
|
+
ok: false,
|
|
692
|
+
rejections: validated.errors.map(issueToRejection)
|
|
693
|
+
};
|
|
694
|
+
const declaration = validated.declaration;
|
|
695
|
+
const rejections = [];
|
|
696
|
+
const workers = declaration.workloads.filter((workload) => workload.role === "worker");
|
|
697
|
+
if (workers.length > 1) rejections.push({
|
|
698
|
+
code: "multiple-workers-unsupported",
|
|
699
|
+
message: `The hosted preset runs one worker, and this file has ${workers.length} (${workers.map((worker) => worker.name).join(", ")}). Merge them into one worker service.`
|
|
700
|
+
});
|
|
701
|
+
const approved = new Set(entitlements.bindings);
|
|
702
|
+
for (const binding of declaration.bindings) if (!approved.has(binding.kind)) rejections.push({
|
|
703
|
+
code: "binding-not-entitled",
|
|
704
|
+
message: `This app asks for a ${binding.kind} binding, which is not approved for it. Ask the platform operator to approve it or remove it from the compose file.`
|
|
705
|
+
});
|
|
706
|
+
const domains = [];
|
|
707
|
+
if (declaration.domain && declaration.domain !== entitlements.platformHost) if (entitlements.domains?.includes(declaration.domain)) domains.push(declaration.domain);
|
|
708
|
+
else rejections.push({
|
|
709
|
+
code: "domain-not-verified",
|
|
710
|
+
message: `The domain ${declaration.domain} has not been verified for this app. Point its DNS at the platform and verify it first.`
|
|
711
|
+
});
|
|
712
|
+
if (declaration.workloads.some((workload) => workload.volumes.length > 0)) {
|
|
713
|
+
if (entitlements.volumeSize === void 0) rejections.push({
|
|
714
|
+
code: "volume-not-entitled",
|
|
715
|
+
message: "This app declares a data volume, but no volume size is approved for it. Ask the platform operator or remove the volume from the compose file."
|
|
716
|
+
});
|
|
717
|
+
else if (!QUANTITY.test(entitlements.volumeSize)) rejections.push({
|
|
718
|
+
code: "volume-size-invalid",
|
|
719
|
+
message: "The approved volume size is not a valid quantity such as 5Gi."
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
const images = {};
|
|
723
|
+
for (const workload of declaration.workloads) if (workload.image !== void 0) images[workload.role] = workload.image;
|
|
724
|
+
if (!images.web) rejections.push({
|
|
725
|
+
code: "web-image-missing",
|
|
726
|
+
message: "The release has no web image digest."
|
|
727
|
+
});
|
|
728
|
+
for (const workload of declaration.workloads) {
|
|
729
|
+
const declared = workload.entrypoint !== void 0 || workload.command !== void 0;
|
|
730
|
+
const argv = [...workload.entrypoint ?? [], ...workload.command ?? []];
|
|
731
|
+
if (declared && argv.length === 0) rejections.push({
|
|
732
|
+
code: "startup-command-unsupported",
|
|
733
|
+
message: `The ${workload.name} service discards its image's command (empty entrypoint/command), which the hosted preset cannot represent. Declare the command to run, or remove the empty entrypoint/command.`
|
|
734
|
+
});
|
|
735
|
+
if (workload.role === "web" && "command" in workload.health) rejections.push({
|
|
736
|
+
code: "web-health-command-unsupported",
|
|
737
|
+
message: `The ${workload.name} service declares a command health check, but the hosted preset only supports a web health path. Declare health.path instead.`
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
if (rejections.length > 0) return {
|
|
741
|
+
ok: false,
|
|
742
|
+
rejections
|
|
743
|
+
};
|
|
744
|
+
const bindings = declaration.bindings.map((binding) => ({
|
|
745
|
+
name: binding.name,
|
|
746
|
+
type: binding.kind
|
|
747
|
+
}));
|
|
748
|
+
return {
|
|
749
|
+
ok: true,
|
|
750
|
+
manifest: {
|
|
751
|
+
apiVersion: HOSTED_APP_API_VERSION,
|
|
752
|
+
kind: HOSTED_APP_KIND,
|
|
753
|
+
metadata: {
|
|
754
|
+
name: app.name,
|
|
755
|
+
labels: { ...app.labels ?? {} }
|
|
756
|
+
},
|
|
757
|
+
spec: {
|
|
758
|
+
poolRef: app.poolRef,
|
|
759
|
+
tier: app.tier,
|
|
760
|
+
...app.resourceClass ? { resourceClass: app.resourceClass } : {},
|
|
761
|
+
release: {
|
|
762
|
+
id: hostedAppReleaseId(commit, digests),
|
|
763
|
+
commit
|
|
764
|
+
},
|
|
765
|
+
...domains.length > 0 ? { domains } : {},
|
|
766
|
+
preset: {
|
|
767
|
+
name: HOSTED_APP_PRESET,
|
|
768
|
+
images,
|
|
769
|
+
parameters: presetParameters(declaration, entitlements.volumeSize, input.preset)
|
|
770
|
+
},
|
|
771
|
+
...bindings.length > 0 ? { bindings } : {}
|
|
772
|
+
}
|
|
773
|
+
},
|
|
774
|
+
declaration,
|
|
775
|
+
warnings
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
function presetParameters(declaration, volumeSize, options) {
|
|
779
|
+
const parameters = { migrateCommand: JSON.stringify(declaration.migrate.command) };
|
|
780
|
+
if (declaration.workloads.find((workload) => workload.name === declaration.migrate.service)?.role === "worker") parameters.migrateService = "worker";
|
|
781
|
+
if (options?.workerRole) parameters.workerRole = options.workerRole;
|
|
782
|
+
if (options?.environment) parameters.environment = options.environment;
|
|
783
|
+
if (options?.runtimeProfile) parameters.runtimeProfile = options.runtimeProfile;
|
|
784
|
+
const volumes = /* @__PURE__ */ new Map();
|
|
785
|
+
for (const workload of declaration.workloads) {
|
|
786
|
+
const prefix = workload.role;
|
|
787
|
+
const argv = [...workload.entrypoint ?? [], ...workload.command ?? []];
|
|
788
|
+
if (argv.length > 0) parameters[`${prefix}Command`] = JSON.stringify(argv);
|
|
789
|
+
if (workload.role === "web") {
|
|
790
|
+
if (workload.port !== void 0) parameters.webPort = String(workload.port);
|
|
791
|
+
if ("path" in workload.health) parameters.webHealthPath = workload.health.path;
|
|
792
|
+
} else if ("command" in workload.health) parameters.workerHealthCommand = JSON.stringify(workload.health.command);
|
|
793
|
+
for (const volume of workload.volumes) {
|
|
794
|
+
const entry = volumes.get(volume.name) ?? {
|
|
795
|
+
name: volume.name,
|
|
796
|
+
size: volumeSize,
|
|
797
|
+
mounts: []
|
|
798
|
+
};
|
|
799
|
+
entry.mounts.push({
|
|
800
|
+
workload: workload.role,
|
|
801
|
+
path: volume.target,
|
|
802
|
+
...volume.readOnly ? { readOnly: true } : {}
|
|
803
|
+
});
|
|
804
|
+
volumes.set(volume.name, entry);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
if (volumes.size > 0) parameters.volumes = JSON.stringify([...volumes.values()]);
|
|
808
|
+
return parameters;
|
|
809
|
+
}
|
|
810
|
+
//#endregion
|
|
811
|
+
export { validateComposeDeployment as _, HOSTED_APP_TIERS as a, hostedAppReleaseId as c, X_HAPPYVERTICAL_KEY as d, X_HAPPYVERTICAL_PRESETS as f, formatComposeDeploymentReport as g, X_HAPPYVERTICAL_VERSION as h, HOSTED_APP_PRESET as i, isHostedAppCommit as l, X_HAPPYVERTICAL_SCHEMA_ID as m, HOSTED_APP_KIND as n, HOSTED_APP_WORKER_ROLES as o, X_HAPPYVERTICAL_ROLES as p, HOSTED_APP_NAME_MAX_LENGTH as r, composeHostedApp as s, HOSTED_APP_API_VERSION as t, X_HAPPYVERTICAL_BINDINGS as u };
|
|
812
|
+
|
|
813
|
+
//# sourceMappingURL=hosted-app-BomhfPIt.js.map
|