@otwld/nx-argo 0.0.6 → 0.0.8
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/CHANGELOG.md +10 -1
- package/README.md +14 -13
- package/executors.json +34 -9
- package/package.json +1 -1
- package/src/executors/copy-image-lock/copy-image-lock.d.ts +5 -0
- package/src/executors/copy-image-lock/copy-image-lock.js +14 -0
- package/src/executors/copy-image-lock/schema.d.ts +19 -0
- package/src/executors/copy-image-lock/schema.json +48 -0
- package/src/executors/copy-source-revision/copy-source-revision.d.ts +5 -0
- package/src/executors/copy-source-revision/copy-source-revision.js +29 -0
- package/src/executors/copy-source-revision/schema.d.ts +19 -0
- package/src/executors/copy-source-revision/schema.json +41 -0
- package/src/executors/image-lock.d.ts +16 -0
- package/src/executors/image-lock.js +53 -0
- package/src/executors/set-source-revision/schema.d.ts +15 -0
- package/src/executors/set-source-revision/schema.json +28 -0
- package/src/executors/set-source-revision/set-source-revision.d.ts +5 -0
- package/src/executors/set-source-revision/set-source-revision.js +20 -0
- package/src/executors/shared.d.ts +28 -0
- package/src/executors/shared.js +112 -0
- package/src/executors/source-revision.d.ts +9 -0
- package/src/executors/source-revision.js +30 -0
- package/src/executors/validate-application/schema.d.ts +7 -0
- package/src/executors/validate-application/schema.json +19 -0
- package/src/executors/validate-application/validate-application.d.ts +5 -0
- package/src/executors/validate-application/validate-application.js +38 -0
- package/src/executors/validate-application-set/schema.d.ts +7 -0
- package/src/executors/validate-application-set/schema.json +20 -0
- package/src/executors/validate-application-set/validate-application-set.d.ts +5 -0
- package/src/executors/validate-application-set/validate-application-set.js +65 -0
- package/src/executors/validate-image-lock/schema.d.ts +15 -0
- package/src/executors/validate-image-lock/schema.json +36 -0
- package/src/executors/validate-image-lock/validate-image-lock.d.ts +5 -0
- package/src/executors/validate-image-lock/validate-image-lock.js +11 -0
- package/src/executors/{write-artifact-lock → write-image-lock}/schema.d.ts +5 -5
- package/src/executors/{write-artifact-lock → write-image-lock}/schema.json +21 -10
- package/src/executors/write-image-lock/write-image-lock.d.ts +5 -0
- package/src/executors/write-image-lock/write-image-lock.js +55 -0
- package/src/generators/environment-project/environment-project.d.ts +1 -1
- package/src/generators/environment-project/environment-project.js +56 -35
- package/src/generators/environment-project/schema.d.ts +11 -3
- package/src/generators/environment-project/schema.json +25 -7
- package/src/generators/preview-project/preview-project.d.ts +1 -1
- package/src/generators/preview-project/preview-project.js +16 -11
- package/src/generators/preview-project/schema.d.ts +6 -2
- package/src/generators/preview-project/schema.json +15 -7
- package/src/index.d.ts +14 -0
- package/src/index.js +15 -1
- package/src/executors/validate/schema.d.ts +0 -11
- package/src/executors/validate/schema.json +0 -28
- package/src/executors/validate/validate.d.ts +0 -5
- package/src/executors/validate/validate.js +0 -174
- package/src/executors/write-artifact-lock/write-artifact-lock.d.ts +0 -5
- package/src/executors/write-artifact-lock/write-artifact-lock.js +0 -167
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.selectSource = selectSource;
|
|
4
|
+
const shared_1 = require("./shared");
|
|
5
|
+
/** Finds exactly one matching source in an Application spec. */
|
|
6
|
+
function selectSource(application, selector) {
|
|
7
|
+
if (!(0, shared_1.isNonEmptyString)(selector.repoURL) ||
|
|
8
|
+
![selector.chart, selector.path, selector.ref].some(shared_1.isNonEmptyString)) {
|
|
9
|
+
throw new Error('[nx-argo] repoURL and one of chart, path, or ref are required.');
|
|
10
|
+
}
|
|
11
|
+
const spec = application['spec'];
|
|
12
|
+
if (!(0, shared_1.isMap)(spec)) {
|
|
13
|
+
throw new Error('[nx-argo] Application spec must be a mapping.');
|
|
14
|
+
}
|
|
15
|
+
const sources = [
|
|
16
|
+
...((0, shared_1.isMap)(spec['source']) ? [spec['source']] : []),
|
|
17
|
+
...(Array.isArray(spec['sources']) ? spec['sources'].filter(shared_1.isMap) : []),
|
|
18
|
+
];
|
|
19
|
+
const criteria = {
|
|
20
|
+
repoURL: selector.repoURL,
|
|
21
|
+
chart: selector.chart,
|
|
22
|
+
path: selector.path,
|
|
23
|
+
ref: selector.ref,
|
|
24
|
+
};
|
|
25
|
+
const matches = sources.filter((source) => Object.entries(criteria).every(([key, value]) => value === undefined || source[key] === value));
|
|
26
|
+
if (matches.length !== 1) {
|
|
27
|
+
throw new Error('[nx-argo] Source selector must match exactly one Application source.');
|
|
28
|
+
}
|
|
29
|
+
return matches[0];
|
|
30
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Options accepted by the Application validator. */
|
|
2
|
+
export interface ValidateApplicationExecutorSchema {
|
|
3
|
+
/** Application manifest relative to the owning Nx project root. */
|
|
4
|
+
file: string;
|
|
5
|
+
/** Optional basename required at the end of each Helm values list. */
|
|
6
|
+
finalValueFile?: string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"title": "Validate Argo CD Application",
|
|
5
|
+
"description": "Validate an Application manifest relative to its Nx project root.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"file": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Application manifest relative to the owning Nx project root."
|
|
11
|
+
},
|
|
12
|
+
"finalValueFile": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "Optional basename required at the end of each declared Helm valueFiles list."
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"required": ["file"],
|
|
18
|
+
"additionalProperties": false
|
|
19
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PromiseExecutor } from '@nx/devkit';
|
|
2
|
+
import type { ValidateApplicationExecutorSchema } from './schema';
|
|
3
|
+
/** Validates an Argo CD Application and an optional final Helm values file. */
|
|
4
|
+
declare const runExecutor: PromiseExecutor<ValidateApplicationExecutorSchema>;
|
|
5
|
+
export default runExecutor;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const shared_1 = require("../shared");
|
|
4
|
+
/** Validates an Argo CD Application and an optional final Helm values file. */
|
|
5
|
+
const runExecutor = async (options, context) => {
|
|
6
|
+
const filePath = (0, shared_1.resolveProjectFile)((0, shared_1.getProjectRoot)(context), options.file, 'Application file');
|
|
7
|
+
const application = (0, shared_1.readYamlMapping)(filePath, 'Argo CD Application');
|
|
8
|
+
if (application['apiVersion'] !== 'argoproj.io/v1alpha1' ||
|
|
9
|
+
application['kind'] !== 'Application' ||
|
|
10
|
+
!(0, shared_1.isMap)(application['spec'])) {
|
|
11
|
+
throw new Error(`[nx-argo] Invalid Argo CD Application: ${filePath}`);
|
|
12
|
+
}
|
|
13
|
+
if (options.finalValueFile) {
|
|
14
|
+
for (const valueFiles of getHelmValueFiles(application)) {
|
|
15
|
+
if (valueFiles.at(-1)?.split('/').at(-1) !== options.finalValueFile) {
|
|
16
|
+
throw new Error(`[nx-argo] ${options.finalValueFile} must be the final Helm values file: ${filePath}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return { success: true };
|
|
21
|
+
};
|
|
22
|
+
/** Returns Helm values lists from every declared Application source. */
|
|
23
|
+
function getHelmValueFiles(application) {
|
|
24
|
+
const spec = application['spec'];
|
|
25
|
+
const sources = [
|
|
26
|
+
...((0, shared_1.isMap)(spec['source']) ? [spec['source']] : []),
|
|
27
|
+
...(Array.isArray(spec['sources']) ? spec['sources'].filter(shared_1.isMap) : []),
|
|
28
|
+
];
|
|
29
|
+
return sources.flatMap((source) => {
|
|
30
|
+
const helm = source['helm'];
|
|
31
|
+
return (0, shared_1.isMap)(helm) && Array.isArray(helm['valueFiles'])
|
|
32
|
+
? [
|
|
33
|
+
helm['valueFiles'].filter((value) => typeof value === 'string'),
|
|
34
|
+
]
|
|
35
|
+
: [];
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.default = runExecutor;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Options accepted by the ApplicationSet validator. */
|
|
2
|
+
export interface ValidateApplicationSetExecutorSchema {
|
|
3
|
+
/** ApplicationSet manifest relative to the owning Nx project root. */
|
|
4
|
+
file: string;
|
|
5
|
+
/** Optional policy to enforce. */
|
|
6
|
+
policy?: 'github-pr-preview';
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"title": "Validate Argo CD ApplicationSet",
|
|
5
|
+
"description": "Validate ApplicationSet structure and an optional policy.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"file": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "ApplicationSet manifest relative to the owning Nx project root."
|
|
11
|
+
},
|
|
12
|
+
"policy": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"enum": ["github-pr-preview"],
|
|
15
|
+
"description": "Optional policy to enforce."
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"required": ["file"],
|
|
19
|
+
"additionalProperties": false
|
|
20
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PromiseExecutor } from '@nx/devkit';
|
|
2
|
+
import type { ValidateApplicationSetExecutorSchema } from './schema';
|
|
3
|
+
/** Validates ApplicationSet structure and optionally enforces a named policy. */
|
|
4
|
+
declare const runExecutor: PromiseExecutor<ValidateApplicationSetExecutorSchema>;
|
|
5
|
+
export default runExecutor;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const shared_1 = require("../shared");
|
|
4
|
+
/** Validates ApplicationSet structure and optionally enforces a named policy. */
|
|
5
|
+
const runExecutor = async (options, context) => {
|
|
6
|
+
const filePath = (0, shared_1.resolveProjectFile)((0, shared_1.getProjectRoot)(context), options.file, 'ApplicationSet file');
|
|
7
|
+
const applicationSet = (0, shared_1.readYamlMapping)(filePath, 'Argo CD ApplicationSet');
|
|
8
|
+
const spec = applicationSet['spec'];
|
|
9
|
+
if (applicationSet['apiVersion'] !== 'argoproj.io/v1alpha1' ||
|
|
10
|
+
applicationSet['kind'] !== 'ApplicationSet' ||
|
|
11
|
+
!(0, shared_1.isMap)(spec)) {
|
|
12
|
+
throw new Error(`[nx-argo] Invalid Argo CD ApplicationSet: ${filePath}`);
|
|
13
|
+
}
|
|
14
|
+
if (options.policy === 'github-pr-preview') {
|
|
15
|
+
const template = spec['template'];
|
|
16
|
+
const templateSpec = (0, shared_1.isMap)(template) ? template['spec'] : undefined;
|
|
17
|
+
if (!(0, shared_1.isMap)(templateSpec)) {
|
|
18
|
+
throw new Error(`[nx-argo] Invalid github-pr-preview ApplicationSet policy: ${filePath}`);
|
|
19
|
+
}
|
|
20
|
+
validateGithubPrPreview(spec, templateSpec, filePath);
|
|
21
|
+
}
|
|
22
|
+
return { success: true };
|
|
23
|
+
};
|
|
24
|
+
/** Enforces the optional GitHub pull-request preview lifecycle policy. */
|
|
25
|
+
function validateGithubPrPreview(spec, templateSpec, filePath) {
|
|
26
|
+
const project = templateSpec['project'];
|
|
27
|
+
const automated = (0, shared_1.getPath)(templateSpec, ['syncPolicy', 'automated']);
|
|
28
|
+
if (!containsPullRequestGenerator(spec['generators']) ||
|
|
29
|
+
typeof project !== 'string' ||
|
|
30
|
+
!project.trim() ||
|
|
31
|
+
/{{|}}/.test(project) ||
|
|
32
|
+
!(0, shared_1.isMap)(automated) ||
|
|
33
|
+
automated['enabled'] !== true ||
|
|
34
|
+
automated['prune'] !== true ||
|
|
35
|
+
automated['selfHeal'] !== true ||
|
|
36
|
+
(0, shared_1.getPath)(spec, ['syncPolicy', 'preserveResourcesOnDeletion']) === true ||
|
|
37
|
+
!hasPrLockAsFinalValue(templateSpec)) {
|
|
38
|
+
throw new Error(`[nx-argo] Invalid github-pr-preview ApplicationSet policy: ${filePath}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Finds a pull request generator in direct, matrix, or merge generator trees. */
|
|
42
|
+
function containsPullRequestGenerator(value) {
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
return value.some(containsPullRequestGenerator);
|
|
45
|
+
}
|
|
46
|
+
return ((0, shared_1.isMap)(value) &&
|
|
47
|
+
((0, shared_1.isMap)(value['pullRequest']) ||
|
|
48
|
+
Object.values(value).some(containsPullRequestGenerator)));
|
|
49
|
+
}
|
|
50
|
+
/** Requires a PR-scoped final Helm values file for the optional preview policy. */
|
|
51
|
+
function hasPrLockAsFinalValue(templateSpec) {
|
|
52
|
+
const sources = [
|
|
53
|
+
...((0, shared_1.isMap)(templateSpec['source']) ? [templateSpec['source']] : []),
|
|
54
|
+
...(Array.isArray(templateSpec['sources'])
|
|
55
|
+
? templateSpec['sources'].filter(shared_1.isMap)
|
|
56
|
+
: []),
|
|
57
|
+
];
|
|
58
|
+
return sources.some((source) => {
|
|
59
|
+
const valueFiles = (0, shared_1.getPath)(source, ['helm', 'valueFiles']);
|
|
60
|
+
return (Array.isArray(valueFiles) &&
|
|
61
|
+
typeof valueFiles.at(-1) === 'string' &&
|
|
62
|
+
valueFiles.at(-1).includes('/locks/pr-'));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
exports.default = runExecutor;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Options accepted by the image-lock validator. */
|
|
2
|
+
export interface ValidateImageLockExecutorSchema {
|
|
3
|
+
/** Image lock file relative to the owning Nx project root. */
|
|
4
|
+
file: string;
|
|
5
|
+
/** Optional repository YAML path. */
|
|
6
|
+
repositoryPath?: string;
|
|
7
|
+
/** Optional digest YAML path. */
|
|
8
|
+
digestPath?: string;
|
|
9
|
+
/** Optional service YAML path. */
|
|
10
|
+
servicePath?: string;
|
|
11
|
+
/** Optional source revision YAML path. */
|
|
12
|
+
sourceRevisionPath?: string;
|
|
13
|
+
/** Whether a fully empty pending lock is valid. */
|
|
14
|
+
allowPending?: boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"title": "Validate image lock",
|
|
5
|
+
"description": "Validate a pending or completed image lock.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"file": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Image lock file relative to the owning Nx project root."
|
|
11
|
+
},
|
|
12
|
+
"repositoryPath": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "Optional repository YAML path; defaults to image.repository."
|
|
15
|
+
},
|
|
16
|
+
"digestPath": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Optional digest YAML path; defaults to image.digest."
|
|
19
|
+
},
|
|
20
|
+
"servicePath": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Optional service YAML path; defaults to artifact.service."
|
|
23
|
+
},
|
|
24
|
+
"sourceRevisionPath": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "Optional source revision YAML path; defaults to artifact.sourceRevision."
|
|
27
|
+
},
|
|
28
|
+
"allowPending": {
|
|
29
|
+
"type": "boolean",
|
|
30
|
+
"default": true,
|
|
31
|
+
"description": "Whether a fully empty pending lock is valid."
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"required": ["file"],
|
|
35
|
+
"additionalProperties": false
|
|
36
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PromiseExecutor } from '@nx/devkit';
|
|
2
|
+
import type { ValidateImageLockExecutorSchema } from './schema';
|
|
3
|
+
/** Validates a project-local pending or completed canonical image lock. */
|
|
4
|
+
declare const runExecutor: PromiseExecutor<ValidateImageLockExecutorSchema>;
|
|
5
|
+
export default runExecutor;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const image_lock_1 = require("../image-lock");
|
|
4
|
+
const shared_1 = require("../shared");
|
|
5
|
+
/** Validates a project-local pending or completed canonical image lock. */
|
|
6
|
+
const runExecutor = async (options, context) => {
|
|
7
|
+
const filePath = (0, shared_1.resolveProjectFile)((0, shared_1.getProjectRoot)(context), options.file, 'Image lock file');
|
|
8
|
+
(0, image_lock_1.validateImageLock)((0, shared_1.readYamlMapping)(filePath, 'image lock'), (0, image_lock_1.getImageLockPaths)(options), filePath, options.allowPending ?? true);
|
|
9
|
+
return { success: true };
|
|
10
|
+
};
|
|
11
|
+
exports.default = runExecutor;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/** Options accepted by the
|
|
2
|
-
export interface
|
|
3
|
-
/**
|
|
1
|
+
/** Options accepted by the image-lock writer. */
|
|
2
|
+
export interface WriteImageLockExecutorSchema {
|
|
3
|
+
/** Image lock file relative to the owning Nx project root. */
|
|
4
4
|
file: string;
|
|
5
5
|
/** Dot-separated YAML path for the image repository. */
|
|
6
6
|
repositoryPath: string;
|
|
@@ -10,9 +10,9 @@ export interface WriteArtifactLockExecutorSchema {
|
|
|
10
10
|
servicePath: string;
|
|
11
11
|
/** Dot-separated YAML path for the source revision. */
|
|
12
12
|
sourceRevisionPath: string;
|
|
13
|
-
/**
|
|
13
|
+
/** Service identity to write. */
|
|
14
14
|
service: string;
|
|
15
|
-
/** Source revision
|
|
15
|
+
/** Source revision to write. */
|
|
16
16
|
sourceRevision: string;
|
|
17
17
|
/** Image repository to write. */
|
|
18
18
|
repository: string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"version": 2,
|
|
4
|
-
"title": "Write
|
|
5
|
-
"description": "Write
|
|
4
|
+
"title": "Write image lock",
|
|
5
|
+
"description": "Write or verify an immutable image lock.",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"properties": {
|
|
8
8
|
"file": {
|
|
9
9
|
"type": "string",
|
|
10
|
-
"description": "
|
|
10
|
+
"description": "Image lock file relative to the owning Nx project root."
|
|
11
11
|
},
|
|
12
12
|
"repositoryPath": {
|
|
13
13
|
"type": "string",
|
|
@@ -27,24 +27,35 @@
|
|
|
27
27
|
},
|
|
28
28
|
"service": {
|
|
29
29
|
"type": "string",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"minLength": 1,
|
|
31
|
+
"description": "Service identity to write."
|
|
32
32
|
},
|
|
33
33
|
"sourceRevision": {
|
|
34
34
|
"type": "string",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
35
|
+
"minLength": 1,
|
|
36
|
+
"description": "Source revision to write."
|
|
37
37
|
},
|
|
38
38
|
"repository": {
|
|
39
39
|
"type": "string",
|
|
40
|
+
"minLength": 1,
|
|
40
41
|
"description": "Image repository to write."
|
|
41
42
|
},
|
|
42
43
|
"digest": {
|
|
43
44
|
"type": "string",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
45
|
+
"pattern": "^sha256:[a-f0-9]{64}$",
|
|
46
|
+
"description": "Immutable image digest to write."
|
|
46
47
|
}
|
|
47
48
|
},
|
|
48
|
-
"required": [
|
|
49
|
+
"required": [
|
|
50
|
+
"file",
|
|
51
|
+
"repositoryPath",
|
|
52
|
+
"digestPath",
|
|
53
|
+
"servicePath",
|
|
54
|
+
"sourceRevisionPath",
|
|
55
|
+
"service",
|
|
56
|
+
"sourceRevision",
|
|
57
|
+
"repository",
|
|
58
|
+
"digest"
|
|
59
|
+
],
|
|
49
60
|
"additionalProperties": false
|
|
50
61
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PromiseExecutor } from '@nx/devkit';
|
|
2
|
+
import type { WriteImageLockExecutorSchema } from './schema';
|
|
3
|
+
/** Writes or verifies an immutable image lock for a source revision. */
|
|
4
|
+
declare const runExecutor: PromiseExecutor<WriteImageLockExecutorSchema>;
|
|
5
|
+
export default runExecutor;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const image_lock_1 = require("../image-lock");
|
|
4
|
+
const shared_1 = require("../shared");
|
|
5
|
+
/** Writes or verifies an immutable image lock for a source revision. */
|
|
6
|
+
const runExecutor = async (options, context) => {
|
|
7
|
+
if (!(0, shared_1.isNonEmptyString)(options.repository) || !(0, shared_1.isDigest)(options.digest)) {
|
|
8
|
+
throw new Error('[nx-argo] An image repository and immutable sha256 digest are required.');
|
|
9
|
+
}
|
|
10
|
+
if (!(0, shared_1.isNonEmptyString)(options.service) ||
|
|
11
|
+
!(0, shared_1.isNonEmptyString)(options.sourceRevision)) {
|
|
12
|
+
throw new Error('[nx-argo] A service and source revision are required.');
|
|
13
|
+
}
|
|
14
|
+
const filePath = (0, shared_1.resolveProjectFile)((0, shared_1.getProjectRoot)(context), options.file, 'Image lock file');
|
|
15
|
+
const lock = (0, shared_1.readYamlMapping)(filePath, 'image lock');
|
|
16
|
+
const paths = (0, image_lock_1.getImageLockPaths)(options);
|
|
17
|
+
const isPending = (0, shared_1.getPath)(lock, ['artifact', 'pending']) === true;
|
|
18
|
+
if (isPending) {
|
|
19
|
+
const pendingValues = [
|
|
20
|
+
(0, shared_1.getPath)(lock, paths.repository),
|
|
21
|
+
(0, shared_1.getPath)(lock, paths.digest),
|
|
22
|
+
(0, shared_1.getPath)(lock, paths.service),
|
|
23
|
+
(0, shared_1.getPath)(lock, paths.sourceRevision),
|
|
24
|
+
];
|
|
25
|
+
if (!pendingValues.every((value) => value === '')) {
|
|
26
|
+
throw new Error('[nx-argo] Pending image locks require empty image-lock values.');
|
|
27
|
+
}
|
|
28
|
+
(0, shared_1.setPath)(lock, ['artifact', 'pending'], false);
|
|
29
|
+
}
|
|
30
|
+
const existingRevision = (0, shared_1.getPath)(lock, paths.sourceRevision);
|
|
31
|
+
if (!isPending &&
|
|
32
|
+
existingRevision !== undefined &&
|
|
33
|
+
!(0, shared_1.isNonEmptyString)(existingRevision)) {
|
|
34
|
+
throw new Error('[nx-argo] Image-lock source revision must be a string.');
|
|
35
|
+
}
|
|
36
|
+
if (!isPending && existingRevision === options.sourceRevision) {
|
|
37
|
+
verifyValue(lock, paths.repository, options.repository, 'repository');
|
|
38
|
+
verifyValue(lock, paths.digest, options.digest, 'digest');
|
|
39
|
+
verifyValue(lock, paths.service, options.service, 'service');
|
|
40
|
+
return { success: true };
|
|
41
|
+
}
|
|
42
|
+
(0, shared_1.setPath)(lock, paths.repository, options.repository);
|
|
43
|
+
(0, shared_1.setPath)(lock, paths.digest, options.digest);
|
|
44
|
+
(0, shared_1.setPath)(lock, paths.service, options.service);
|
|
45
|
+
(0, shared_1.setPath)(lock, paths.sourceRevision, options.sourceRevision);
|
|
46
|
+
(0, shared_1.writeYamlMapping)(filePath, lock);
|
|
47
|
+
return { success: true };
|
|
48
|
+
};
|
|
49
|
+
/** Verifies a value recorded for an idempotent source-revision write. */
|
|
50
|
+
function verifyValue(lock, path, expected, label) {
|
|
51
|
+
if ((0, shared_1.getPath)(lock, path) !== expected) {
|
|
52
|
+
throw new Error(`[nx-argo] Image-lock ${label} conflicts with the existing source revision.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.default = runExecutor;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Tree } from '@nx/devkit';
|
|
2
2
|
import type { EnvironmentProjectGeneratorSchema } from './schema';
|
|
3
|
-
/** Creates a GitOps project boundary for one
|
|
3
|
+
/** Creates a generic GitOps project boundary for one environment. */
|
|
4
4
|
export default function environmentProjectGenerator(tree: Tree, options: EnvironmentProjectGeneratorSchema): Promise<void>;
|
|
@@ -2,62 +2,83 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = environmentProjectGenerator;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
/** Creates a GitOps project boundary for one
|
|
5
|
+
/** Creates a generic GitOps project boundary for one environment. */
|
|
6
6
|
async function environmentProjectGenerator(tree, options) {
|
|
7
|
+
const name = getName(options.name, 'name');
|
|
7
8
|
const service = getName(options.service, 'service');
|
|
8
9
|
const environment = getName(options.environment, 'environment');
|
|
9
|
-
const directory = (0, devkit_1.joinPathFragments)(options.directory?.trim() || 'gitops/environments',
|
|
10
|
+
const directory = (0, devkit_1.joinPathFragments)(options.directory?.trim() || 'gitops/environments', name, environment);
|
|
10
11
|
const projectFile = (0, devkit_1.joinPathFragments)(directory, 'project.json');
|
|
11
12
|
if (tree.exists(projectFile)) {
|
|
12
13
|
throw new Error(`[nx-argo] A GitOps environment project already exists at ${directory}.`);
|
|
13
14
|
}
|
|
14
15
|
(0, devkit_1.writeJson)(tree, projectFile, {
|
|
15
|
-
name: `gitops-${
|
|
16
|
+
name: `gitops-${name}-${environment}`,
|
|
16
17
|
root: directory,
|
|
17
18
|
projectType: 'application',
|
|
18
|
-
tags: [
|
|
19
|
-
|
|
19
|
+
tags: [
|
|
20
|
+
'type:gitops',
|
|
21
|
+
`deployment:${name}`,
|
|
22
|
+
`service:${service}`,
|
|
23
|
+
`environment:${environment}`,
|
|
24
|
+
],
|
|
25
|
+
implicitDependencies: getDependencies(options),
|
|
20
26
|
metadata: {
|
|
21
27
|
delivery: {
|
|
28
|
+
name,
|
|
22
29
|
service,
|
|
23
|
-
|
|
24
|
-
file: 'artifacts.yaml',
|
|
25
|
-
image: {
|
|
26
|
-
repositoryPath: 'image.repository',
|
|
27
|
-
digestPath: 'image.digest',
|
|
28
|
-
},
|
|
29
|
-
sourceRevisionPath: 'artifact.sourceRevision',
|
|
30
|
-
servicePath: 'artifact.service',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
targets: {
|
|
35
|
-
validate: {
|
|
36
|
-
executor: '@otwld/nx-argo:validate',
|
|
37
|
-
options: {
|
|
38
|
-
mode: 'environment',
|
|
39
|
-
artifactsFile: 'artifacts.yaml',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
'write-artifact-lock': {
|
|
43
|
-
executor: '@otwld/nx-argo:write-artifact-lock',
|
|
44
|
-
cache: false,
|
|
45
|
-
options: {
|
|
46
|
-
file: 'artifacts.yaml',
|
|
47
|
-
repositoryPath: 'image.repository',
|
|
48
|
-
digestPath: 'image.digest',
|
|
49
|
-
servicePath: 'artifact.service',
|
|
50
|
-
sourceRevisionPath: 'artifact.sourceRevision',
|
|
51
|
-
},
|
|
30
|
+
environment,
|
|
52
31
|
},
|
|
53
32
|
},
|
|
33
|
+
targets: getTargets(options),
|
|
54
34
|
});
|
|
55
35
|
tree.write((0, devkit_1.joinPathFragments)(directory, 'values.yaml'), '# Environment configuration owned by humans.\n{}\n');
|
|
56
|
-
|
|
36
|
+
if (options.imageLock) {
|
|
37
|
+
tree.write((0, devkit_1.joinPathFragments)(directory, 'artifacts.yaml'), "# Immutable image lock written by automation.\nartifact:\n pending: true\n service: ''\n sourceRevision: ''\nimage:\n repository: ''\n digest: ''\n");
|
|
38
|
+
}
|
|
57
39
|
if (!options.skipFormat) {
|
|
58
40
|
await (0, devkit_1.formatFiles)(tree);
|
|
59
41
|
}
|
|
60
42
|
}
|
|
43
|
+
/** Declares only the targets needed by files selected for this project. */
|
|
44
|
+
function getTargets(options) {
|
|
45
|
+
const targets = {};
|
|
46
|
+
if (options.applicationFile) {
|
|
47
|
+
targets['validate-application'] = {
|
|
48
|
+
executor: '@otwld/nx-argo:validate-application',
|
|
49
|
+
options: {
|
|
50
|
+
file: options.applicationFile,
|
|
51
|
+
...(options.imageLock ? { finalValueFile: 'artifacts.yaml' } : {}),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (options.imageLock) {
|
|
56
|
+
targets['validate-image-lock'] = {
|
|
57
|
+
executor: '@otwld/nx-argo:validate-image-lock',
|
|
58
|
+
options: { file: 'artifacts.yaml' },
|
|
59
|
+
};
|
|
60
|
+
targets['write-image-lock'] = {
|
|
61
|
+
executor: '@otwld/nx-argo:write-image-lock',
|
|
62
|
+
cache: false,
|
|
63
|
+
options: {
|
|
64
|
+
file: 'artifacts.yaml',
|
|
65
|
+
repositoryPath: 'image.repository',
|
|
66
|
+
digestPath: 'image.digest',
|
|
67
|
+
servicePath: 'artifact.service',
|
|
68
|
+
sourceRevisionPath: 'artifact.sourceRevision',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return targets;
|
|
73
|
+
}
|
|
74
|
+
/** Builds deduplicated project dependencies from all selected inputs. */
|
|
75
|
+
function getDependencies(options) {
|
|
76
|
+
return [
|
|
77
|
+
...new Set([...(options.dependencies ?? []), options.chartProject]
|
|
78
|
+
.filter((dependency) => Boolean(dependency?.trim()))
|
|
79
|
+
.map((dependency) => dependency.trim())),
|
|
80
|
+
];
|
|
81
|
+
}
|
|
61
82
|
/** Normalizes an identifier used in directory and tag names. */
|
|
62
83
|
function getName(value, label) {
|
|
63
84
|
const normalized = (0, devkit_1.names)(requireValue(value, label)).fileName;
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
/** Options accepted by the GitOps environment project generator. */
|
|
2
2
|
export interface EnvironmentProjectGeneratorSchema {
|
|
3
|
-
/** Deployment
|
|
3
|
+
/** Deployment name used for the project boundary and directory. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Deployment service identity recorded in metadata. */
|
|
4
6
|
service: string;
|
|
5
7
|
/** Environment represented by the generated GitOps project. */
|
|
6
8
|
environment: string;
|
|
7
|
-
/** Nx
|
|
8
|
-
|
|
9
|
+
/** Nx projects this GitOps project implicitly depends on. */
|
|
10
|
+
dependencies?: string[];
|
|
11
|
+
/** Optional Nx chart project dependency. */
|
|
12
|
+
chartProject?: string;
|
|
13
|
+
/** Create the canonical artifacts.yaml image lock and its targets. */
|
|
14
|
+
imageLock?: boolean;
|
|
15
|
+
/** Optional declared Application file relative to the generated project. */
|
|
16
|
+
applicationFile?: string;
|
|
9
17
|
/** Parent directory for generated GitOps environments. */
|
|
10
18
|
directory?: string;
|
|
11
19
|
/** Skip Prettier formatting after generation. */
|
|
@@ -2,24 +2,42 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"$id": "NxArgoEnvironmentProjectGeneratorSchema",
|
|
4
4
|
"title": "GitOps environment project generator",
|
|
5
|
-
"description": "Create an Nx GitOps project for one
|
|
5
|
+
"description": "Create an Nx GitOps project for one environment.",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"properties": {
|
|
8
|
-
"
|
|
8
|
+
"name": {
|
|
9
9
|
"type": "string",
|
|
10
|
-
"description": "Deployment
|
|
10
|
+
"description": "Deployment name used for the project boundary and directory.",
|
|
11
11
|
"$default": { "source": "argv", "index": 0 },
|
|
12
12
|
"x-priority": "important"
|
|
13
13
|
},
|
|
14
|
+
"service": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "Deployment service identity recorded in metadata.",
|
|
17
|
+
"x-priority": "important"
|
|
18
|
+
},
|
|
14
19
|
"environment": {
|
|
15
20
|
"type": "string",
|
|
16
21
|
"description": "Environment represented by this GitOps project.",
|
|
17
22
|
"x-priority": "important"
|
|
18
23
|
},
|
|
19
|
-
"
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"type": "array",
|
|
26
|
+
"description": "Nx projects this GitOps project implicitly depends on.",
|
|
27
|
+
"items": { "type": "string" }
|
|
28
|
+
},
|
|
29
|
+
"chartProject": {
|
|
20
30
|
"type": "string",
|
|
21
|
-
"description": "
|
|
22
|
-
|
|
31
|
+
"description": "Optional Nx chart project dependency."
|
|
32
|
+
},
|
|
33
|
+
"imageLock": {
|
|
34
|
+
"type": "boolean",
|
|
35
|
+
"description": "Create the canonical artifacts.yaml image lock and its targets.",
|
|
36
|
+
"default": false
|
|
37
|
+
},
|
|
38
|
+
"applicationFile": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"description": "Optional declared Application file relative to the generated project."
|
|
23
41
|
},
|
|
24
42
|
"directory": {
|
|
25
43
|
"type": "string",
|
|
@@ -32,6 +50,6 @@
|
|
|
32
50
|
"default": false
|
|
33
51
|
}
|
|
34
52
|
},
|
|
35
|
-
"required": ["
|
|
53
|
+
"required": ["name", "service", "environment"],
|
|
36
54
|
"additionalProperties": false
|
|
37
55
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type Tree } from '@nx/devkit';
|
|
2
2
|
import type { PreviewProjectGeneratorSchema } from './schema';
|
|
3
|
-
/** Creates a GitOps project boundary for an
|
|
3
|
+
/** Creates a generic GitOps project boundary for an ApplicationSet workflow. */
|
|
4
4
|
export default function previewProjectGenerator(tree: Tree, options: PreviewProjectGeneratorSchema): Promise<void>;
|