@gebit/stax-cli 1.15.0 → 1.16.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/README.md +2 -1
- package/dist/templates.js +1 -0
- package/dist/validate.js +96 -4
- package/package.json +1 -1
- package/schema/deploy-config.schema.json +10 -2
package/README.md
CHANGED
|
@@ -76,8 +76,9 @@ stax validate config other-dir -r --strict
|
|
|
76
76
|
|---|---|
|
|
77
77
|
| Invalid YAML; wrong field types (e.g. `local_backend: "false"` instead of a boolean) | Fields the schema does not know (often typos such as `depend_on`) |
|
|
78
78
|
| Missing `id` or `type`; unknown `type`; more than one `github-pages-site-deploy` stack or `destroy` on it | `depends_on` or `stack.<id>.var.<key>` pointing to a stack in another config |
|
|
79
|
-
| Type-specific required fields: `folder` for `terraform`/`opentofu`/`function-build-deploy`, Packer `packer_directory`/`packer_version`, `s3-site-deploy` `location`, `script` `script`, `bizep` `template`, `function-build-deploy` `runtime` | `source_repo` alias not defined in this file (configs deployed together share `externalRepos`) |
|
|
79
|
+
| Type-specific required fields: `folder` for `terraform`/`opentofu`/`function-build-deploy`, Packer `packer_directory`/`packer_version`, `s3-site-deploy` `location`, `script` `script`, `bizep` `template`, `function-build-deploy` `runtime`, `ansible` `ansible_inventory`/`ansible_playbook`/`runs-on` | `source_repo` alias not defined in this file (configs deployed together share `externalRepos`) |
|
|
80
80
|
| Packer paths that are absolute, contain `..`, backslashes, empty segments or control characters; non-exact `packer_version`; `build_target: hetzner` without `hetzner`; destination fields for a different build target (also rejected by deployment setup) | No stacks defined; deprecated Gallery aliases (`gallery_name` and the other top-level Gallery fields); `build_target: aws` (reserved, the workflow rejects it) |
|
|
81
|
+
| Ansible: inventory or playbook paths that are not repository-relative `.yml`/`.yaml` files; inputs that are not single-key mappings, or use invalid, duplicate or reserved names (`ansible_*`, `hostvars`, `environment` and other Ansible variables); `source_repo`, outputs or `destroy`; two Ansible stacks on one inventory in the same level | |
|
|
81
82
|
| Duplicate stack ids; malformed `stack.<id>.var.<key>` references | |
|
|
82
83
|
| Dependency cycles (including through `stack.<id>...` inputs); dependency chains deeper than 14 levels | |
|
|
83
84
|
|
package/dist/templates.js
CHANGED
package/dist/validate.js
CHANGED
|
@@ -102,8 +102,8 @@ function checkUnknownKeys(value, known, path, report) {
|
|
|
102
102
|
report.add("warning", [...path, key], "unknown field");
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
/** Mirrors validateRelativePosixPath in gh-create-deploy-config (Packer paths). */
|
|
106
|
-
function
|
|
105
|
+
/** Mirrors validateRelativePosixPath in gh-create-deploy-config (Packer and Ansible paths). */
|
|
106
|
+
function relativePathProblem(value) {
|
|
107
107
|
if (/^[A-Za-z]:/.test(value) || value.startsWith("/"))
|
|
108
108
|
return "must be repository-relative";
|
|
109
109
|
if (/[\u0000-\u001f\u007f]/.test(value))
|
|
@@ -184,10 +184,74 @@ function checkPackerScan(stack, index, report) {
|
|
|
184
184
|
const goss = stack.scan.goss;
|
|
185
185
|
if (!isRecord(goss) || typeof goss.spec !== "string")
|
|
186
186
|
return;
|
|
187
|
-
const problem =
|
|
187
|
+
const problem = relativePathProblem(goss.spec);
|
|
188
188
|
if (problem)
|
|
189
189
|
report.add("error", ["stacks", index, "scan", "goss", "spec"], problem);
|
|
190
190
|
}
|
|
191
|
+
/** Variables Ansible sets itself; mirrors validateAnsibleConfig in gh-create-deploy-config. */
|
|
192
|
+
const ANSIBLE_RESERVED_VARIABLES = new Set([
|
|
193
|
+
"inventory_hostname",
|
|
194
|
+
"inventory_hostname_short",
|
|
195
|
+
"inventory_file",
|
|
196
|
+
"inventory_dir",
|
|
197
|
+
"playbook_dir",
|
|
198
|
+
"group_names",
|
|
199
|
+
"groups",
|
|
200
|
+
"hostvars",
|
|
201
|
+
"omit",
|
|
202
|
+
"environment",
|
|
203
|
+
]);
|
|
204
|
+
/** Ansible rules the schema cannot express; mirrors validateAnsibleConfig in gh-create-deploy-config. */
|
|
205
|
+
function checkAnsibleStack(stack, index, deploymentBackend, report) {
|
|
206
|
+
// a-wf-ansible resolves inputs from GitHub secrets and variables only.
|
|
207
|
+
if ((stack.secret_backend ?? deploymentBackend ?? "gh") !== "gh") {
|
|
208
|
+
report.add("error", ["stacks", index, "secret_backend"], "ansible stacks support only secret_backend gh");
|
|
209
|
+
}
|
|
210
|
+
if (typeof stack.id === "string" && !/^[A-Za-z0-9_-]+$/.test(stack.id)) {
|
|
211
|
+
report.add("error", ["stacks", index, "id"], "an ansible id may contain only letters, digits, underscores and hyphens");
|
|
212
|
+
}
|
|
213
|
+
for (const field of ["ansible_inventory", "ansible_playbook"]) {
|
|
214
|
+
const value = stack[field];
|
|
215
|
+
const problem = typeof value === "string" ? relativePathProblem(value) : undefined;
|
|
216
|
+
if (problem)
|
|
217
|
+
report.add("error", ["stacks", index, field], problem);
|
|
218
|
+
}
|
|
219
|
+
if (typeof stack["runs-on"] === "string" && !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(stack["runs-on"])) {
|
|
220
|
+
report.add("error", ["stacks", index, "runs-on"], "must be one runner label");
|
|
221
|
+
}
|
|
222
|
+
const names = new Set();
|
|
223
|
+
(Array.isArray(stack.input) ? stack.input : []).forEach((entry, inputIndex) => {
|
|
224
|
+
const path = ["stacks", index, "input", inputIndex];
|
|
225
|
+
const keys = isRecord(entry) ? Object.keys(entry) : [];
|
|
226
|
+
const name = keys[0];
|
|
227
|
+
if (keys.length !== 1 || name === undefined) {
|
|
228
|
+
report.add("error", path, "ansible inputs must be single-key mappings, e.g. app_token: gh.secret.APP_TOKEN");
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) {
|
|
232
|
+
report.add("error", [...path, name], "not a valid Ansible variable name");
|
|
233
|
+
}
|
|
234
|
+
else if (/^ansible_/i.test(name) || ANSIBLE_RESERVED_VARIABLES.has(name.toLowerCase())) {
|
|
235
|
+
report.add("error", [...path, name], "reserved for Ansible");
|
|
236
|
+
}
|
|
237
|
+
else if (names.has(name)) {
|
|
238
|
+
report.add("error", [...path, name], "declared twice");
|
|
239
|
+
}
|
|
240
|
+
names.add(name);
|
|
241
|
+
});
|
|
242
|
+
for (const field of ["source_repo", "source_version"]) {
|
|
243
|
+
if (stack[field])
|
|
244
|
+
report.add("error", ["stacks", index, field], "ansible stacks run the calling repository; external sources are not supported");
|
|
245
|
+
}
|
|
246
|
+
for (const field of ["output-var", "output-secret"]) {
|
|
247
|
+
const value = stack[field];
|
|
248
|
+
if (Array.isArray(value) && value.length > 0)
|
|
249
|
+
report.add("error", ["stacks", index, field], "ansible stacks publish no outputs");
|
|
250
|
+
}
|
|
251
|
+
if (stack.destroy === true || stack.destroy === "true") {
|
|
252
|
+
report.add("error", ["stacks", index, "destroy"], "ansible does not support destroy");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
191
255
|
/** Collects stack.<id>.var|secret.<key> references in an input value, like update_deploy_config. */
|
|
192
256
|
function collectStackReferences(value, path, out) {
|
|
193
257
|
if (typeof value === "string") {
|
|
@@ -224,6 +288,8 @@ function checkPipelineRules(data, report) {
|
|
|
224
288
|
// Cross-config references are a normal multi-config pattern: report each referenced id once per file.
|
|
225
289
|
const externalDependsOn = new Map();
|
|
226
290
|
const externalReferences = new Map();
|
|
291
|
+
// Stacks that depend on another config, by depends_on or stack.* reference: merged configs can move them later.
|
|
292
|
+
const externallyLinked = new Set();
|
|
227
293
|
const noteExternal = (seen, id, path) => {
|
|
228
294
|
const entry = seen.get(id);
|
|
229
295
|
if (entry)
|
|
@@ -247,7 +313,7 @@ function checkPipelineRules(data, report) {
|
|
|
247
313
|
if (stack.type === "packer") {
|
|
248
314
|
for (const field of ["packer_directory", "packer_template"]) {
|
|
249
315
|
const value = stack[field];
|
|
250
|
-
const problem = typeof value === "string" ?
|
|
316
|
+
const problem = typeof value === "string" ? relativePathProblem(value) : undefined;
|
|
251
317
|
if (problem)
|
|
252
318
|
report.add("error", ["stacks", index, field], problem);
|
|
253
319
|
}
|
|
@@ -255,6 +321,8 @@ function checkPipelineRules(data, report) {
|
|
|
255
321
|
checkPackerScan(stack, index, report);
|
|
256
322
|
}
|
|
257
323
|
else {
|
|
324
|
+
if (stack.type === "ansible")
|
|
325
|
+
checkAnsibleStack(stack, index, isRecord(data.deployment) ? data.deployment.secret_backend : undefined, report);
|
|
258
326
|
if (stack.build_target !== undefined) {
|
|
259
327
|
report.add("warning", ["stacks", index, "build_target"], "applies to packer stacks only");
|
|
260
328
|
}
|
|
@@ -287,6 +355,7 @@ function checkPipelineRules(data, report) {
|
|
|
287
355
|
}
|
|
288
356
|
else {
|
|
289
357
|
noteExternal(externalDependsOn, dependency, ["stacks", index, "depends_on", depIndex]);
|
|
358
|
+
externallyLinked.add(String(stack.id));
|
|
290
359
|
}
|
|
291
360
|
});
|
|
292
361
|
}
|
|
@@ -302,6 +371,7 @@ function checkPipelineRules(data, report) {
|
|
|
302
371
|
}
|
|
303
372
|
else {
|
|
304
373
|
noteExternal(externalReferences, referencedId, path);
|
|
374
|
+
externallyLinked.add(stack.id);
|
|
305
375
|
}
|
|
306
376
|
}
|
|
307
377
|
});
|
|
@@ -336,6 +406,28 @@ function checkPipelineRules(data, report) {
|
|
|
336
406
|
report.add("error", ["stacks", index, "id"], `"${id}" needs dependency level l${stackLevel}; the pipeline runs at most ${MAX_LEVELS} levels (l0-l${MAX_LEVELS - 1})`);
|
|
337
407
|
}
|
|
338
408
|
}
|
|
409
|
+
// Mirrors validateAnsibleLayerOverlap: Ansible stacks of one level run in parallel.
|
|
410
|
+
// A stack linked to another config, directly or through local dependencies, may run later than this file shows.
|
|
411
|
+
const levelUncertain = (id, seen = new Set()) => {
|
|
412
|
+
if (externallyLinked.has(id))
|
|
413
|
+
return true;
|
|
414
|
+
seen.add(id);
|
|
415
|
+
return [...(dependencies.get(id) ?? [])].some((dep) => !seen.has(dep) && levelUncertain(dep, seen));
|
|
416
|
+
};
|
|
417
|
+
const inventoryOwners = new Map();
|
|
418
|
+
stacks.forEach((stack, index) => {
|
|
419
|
+
if (!isRecord(stack) || stack.type !== "ansible" || typeof stack.id !== "string" || typeof stack.ansible_inventory !== "string")
|
|
420
|
+
return;
|
|
421
|
+
const stackLevel = level.get(stack.id);
|
|
422
|
+
if (stackLevel === undefined || levelUncertain(stack.id) || firstIndexById.get(stack.id) !== index)
|
|
423
|
+
return;
|
|
424
|
+
const key = `${stackLevel}|${stack.ansible_inventory.split("/").filter((segment) => segment !== ".").join("/")}`;
|
|
425
|
+
const owner = inventoryOwners.get(key);
|
|
426
|
+
if (owner === undefined)
|
|
427
|
+
inventoryOwners.set(key, stack.id);
|
|
428
|
+
else
|
|
429
|
+
report.add("error", ["stacks", index, "ansible_inventory"], `shared with "${owner}" in the same level; add depends_on so they run one after the other`);
|
|
430
|
+
});
|
|
339
431
|
}
|
|
340
432
|
const AWS_OPTION_DEFAULTS = {
|
|
341
433
|
aws_endpoint_url: "",
|
package/package.json
CHANGED
|
@@ -107,7 +107,8 @@
|
|
|
107
107
|
"s3-site-deploy",
|
|
108
108
|
"script",
|
|
109
109
|
"bizep",
|
|
110
|
-
"github-pages-site-deploy"
|
|
110
|
+
"github-pages-site-deploy",
|
|
111
|
+
"ansible"
|
|
111
112
|
]
|
|
112
113
|
},
|
|
113
114
|
"if": { "description": "Deploy only when this JavaScript condition holds; {stage} and other pipeline values are substituted first.", "type": "string", "examples": ["'{stage}' == 'prod'"], "x-stax-types": "all" },
|
|
@@ -322,7 +323,10 @@
|
|
|
322
323
|
|
|
323
324
|
"script": { "description": "Script path relative to the source checkout.", "type": "string", "minLength": 1, "examples": ["scripts/deploy.sh"], "x-stax-types": ["script"] },
|
|
324
325
|
"resource_prefix": { "type": "string", "examples": ["app"], "x-stax-types": ["script", "bizep"] },
|
|
325
|
-
"template": { "description": "Bicep template path for bizep stacks.", "type": "string", "minLength": 1, "examples": ["bicep/main.bicep"], "x-stax-types": ["bizep"] }
|
|
326
|
+
"template": { "description": "Bicep template path for bizep stacks.", "type": "string", "minLength": 1, "examples": ["bicep/main.bicep"], "x-stax-types": ["bizep"] },
|
|
327
|
+
|
|
328
|
+
"ansible_inventory": { "description": "YAML inventory path relative to the repository root.", "type": "string", "pattern": "\\.ya?ml$", "examples": ["ansible/inventory.yml"], "x-stax-types": ["ansible"] },
|
|
329
|
+
"ansible_playbook": { "description": "Playbook path relative to the repository root.", "type": "string", "pattern": "\\.ya?ml$", "examples": ["ansible/site.yml"], "x-stax-types": ["ansible"] }
|
|
326
330
|
},
|
|
327
331
|
"required": ["id", "type"],
|
|
328
332
|
"allOf": [
|
|
@@ -360,6 +364,10 @@
|
|
|
360
364
|
"if": { "properties": { "type": { "const": "bizep" } }, "required": ["type"] },
|
|
361
365
|
"then": { "required": ["template"] }
|
|
362
366
|
},
|
|
367
|
+
{
|
|
368
|
+
"if": { "properties": { "type": { "const": "ansible" } }, "required": ["type"] },
|
|
369
|
+
"then": { "required": ["ansible_inventory", "ansible_playbook", "runs-on"] }
|
|
370
|
+
},
|
|
363
371
|
{
|
|
364
372
|
"if": { "properties": { "type": { "const": "function-build-deploy" } }, "required": ["type"] },
|
|
365
373
|
"then": { "required": ["runtime"] }
|