@otwld/nx-argo 0.0.10 → 0.0.12
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 +7 -0
- package/README.md +7 -6
- package/package.json +1 -1
- package/src/executors/validate-application-set/validate-application-set.js +8 -7
- package/src/generators/stack-project/schema.d.ts +1 -3
- package/src/generators/stack-project/schema.json +3 -3
- package/src/generators/stack-project/stack-project.js +5 -9
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -12,14 +12,15 @@ pnpm exec nx g @otwld/nx-argo:environment-project web \
|
|
|
12
12
|
--imageLock --applicationFile=application.yaml
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
`preview-project` creates `gitops/previews/<name>/project.json` with optional `dependencies`, generic preview metadata, and `validate-application-set`. `applicationSetFile` defaults to `application-set.yaml`. The optional `github-pr-preview` policy is the only GitHub-specific behavior.
|
|
15
|
+
`preview-project` creates `gitops/previews/<name>/project.json` with optional `dependencies`, generic preview metadata, and `validate-application-set`. `applicationSetFile` defaults to `application-set.yaml`. The optional `github-pr-preview` policy is the only GitHub-specific behavior. Environment and preview projects are validation boundaries only; they do not declare `delivery:stack-*` targets. Only `stack-project` explicitly opts into application-stack delivery.
|
|
16
16
|
|
|
17
17
|
```shell
|
|
18
18
|
pnpm exec nx g @otwld/nx-argo:preview-project web \
|
|
19
19
|
--dependencies=frontend,backend --policy=github-pr-preview
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
`stack-project` creates one complete boundary at `gitops/<stack
|
|
22
|
+
`stack-project` creates one complete boundary at `gitops/<stack>` and registers
|
|
23
|
+
its Argo resources in the repository-root `kustomization.yaml`. It writes
|
|
23
24
|
staging and production Applications, stable staging/production/preview values,
|
|
24
25
|
and an optional GitHub pull-request ApplicationSet. The stack project declares
|
|
25
26
|
the chart and every mapped application as `implicitDependencies` and records the
|
|
@@ -46,7 +47,6 @@ The canonical metadata shape is:
|
|
|
46
47
|
"staging": "values-staging.yaml",
|
|
47
48
|
"production": "values-production.yaml",
|
|
48
49
|
"preview": "values-preview.yaml",
|
|
49
|
-
"pullRequest": "values-pr.yaml",
|
|
50
50
|
},
|
|
51
51
|
"applications": { "services.api": "api" },
|
|
52
52
|
},
|
|
@@ -59,15 +59,16 @@ The canonical metadata shape is:
|
|
|
59
59
|
the generated values files. `chartPath`, repository identity, namespace prefix,
|
|
60
60
|
and all file paths are explicit; the generator does not assume a frontend,
|
|
61
61
|
backend, web, or repository name. The pull-request policy requires repository
|
|
62
|
-
owner/name and
|
|
62
|
+
owner/name and uses `values-preview.yaml` as its final Helm value file. Its
|
|
63
63
|
ApplicationSet resolves the chart and values sources from the same `preview/pr-N`
|
|
64
|
-
snapshot revision
|
|
64
|
+
snapshot revision and defaults to the platform-provided `argocd-github-otwld`
|
|
65
|
+
token Secret; use `githubTokenSecretName` only for an explicit override.
|
|
65
66
|
|
|
66
67
|
## Contracts
|
|
67
68
|
|
|
68
69
|
`validate-application` validates Application kind and spec. Its optional `finalValueFile` requires that basename to end each declared Helm `valueFiles` list; image locks are never implied.
|
|
69
70
|
|
|
70
|
-
`validate-application-set` validates ApplicationSet kind, spec, template, and template spec. By default it imposes no provider rules. With `policy: github-pr-preview`, it also requires a pull request generator, literal template project, automated `enabled`, `prune`, and `selfHeal`, no `preserveResourcesOnDeletion`, and
|
|
71
|
+
`validate-application-set` validates ApplicationSet kind, spec, template, and template spec. By default it imposes no provider rules. With `policy: github-pr-preview`, it also requires a pull request generator, literal template project, automated `enabled`, `prune`, and `selfHeal`, no `preserveResourcesOnDeletion`, and `values-preview.yaml` as the final Helm values file.
|
|
71
72
|
|
|
72
73
|
`validate-image-lock` uses canonical `image.repository`, `image.digest`, `artifact.service`, and `artifact.sourceRevision` paths unless mappings are supplied. `write-image-lock` requires explicit mapping paths. A pending lock contains exactly empty values; a completed lock has a nonempty repository, service, source revision, and SHA-256 digest. Writes require an existing project-local file, complete valid pending locks, and are idempotent for identical source-revision values.
|
|
73
74
|
|
package/package.json
CHANGED
|
@@ -34,7 +34,7 @@ function validateGithubPrPreview(spec, templateSpec, filePath) {
|
|
|
34
34
|
automated['prune'] !== true ||
|
|
35
35
|
automated['selfHeal'] !== true ||
|
|
36
36
|
(0, shared_1.getPath)(spec, ['syncPolicy', 'preserveResourcesOnDeletion']) === true ||
|
|
37
|
-
!
|
|
37
|
+
!hasPreviewValuesAsFinalValue(templateSpec)) {
|
|
38
38
|
throw new Error(`[nx-argo] Invalid github-pr-preview ApplicationSet policy: ${filePath}`);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -47,8 +47,8 @@ function containsPullRequestGenerator(value) {
|
|
|
47
47
|
((0, shared_1.isMap)(value['pullRequest']) ||
|
|
48
48
|
Object.values(value).some(containsPullRequestGenerator)));
|
|
49
49
|
}
|
|
50
|
-
/** Requires
|
|
51
|
-
function
|
|
50
|
+
/** Requires the canonical preview values file as the final Helm values file. */
|
|
51
|
+
function hasPreviewValuesAsFinalValue(templateSpec) {
|
|
52
52
|
const sources = [
|
|
53
53
|
...((0, shared_1.isMap)(templateSpec['source']) ? [templateSpec['source']] : []),
|
|
54
54
|
...(Array.isArray(templateSpec['sources'])
|
|
@@ -59,11 +59,12 @@ function hasPrLockAsFinalValue(templateSpec) {
|
|
|
59
59
|
const valueFiles = (0, shared_1.getPath)(source, ['helm', 'valueFiles']);
|
|
60
60
|
return (Array.isArray(valueFiles) &&
|
|
61
61
|
typeof valueFiles.at(-1) === 'string' &&
|
|
62
|
-
|
|
62
|
+
isPreviewValuesFile(valueFiles.at(-1)));
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
/** Accepts
|
|
66
|
-
function
|
|
67
|
-
return valueFile
|
|
65
|
+
/** Accepts only the canonical flat preview values contract. */
|
|
66
|
+
function isPreviewValuesFile(valueFile) {
|
|
67
|
+
return (valueFile === 'values-preview.yaml' ||
|
|
68
|
+
valueFile.endsWith('/values-preview.yaml'));
|
|
68
69
|
}
|
|
69
70
|
exports.default = runExecutor;
|
|
@@ -18,8 +18,6 @@ export interface StackValueFiles {
|
|
|
18
18
|
production?: string;
|
|
19
19
|
/** Preview base value file relative to the GitOps project. */
|
|
20
20
|
preview?: string;
|
|
21
|
-
/** Pull-request value-file pattern relative to the GitOps project. */
|
|
22
|
-
pullRequest?: string;
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
/** Options accepted by the generic GitOps stack project generator. */
|
|
@@ -42,7 +40,7 @@ export interface StackProjectGeneratorSchema {
|
|
|
42
40
|
argoProject?: string;
|
|
43
41
|
/** Optional ApplicationSet policy for GitHub pull-request previews. */
|
|
44
42
|
policy?: 'github-pr-preview';
|
|
45
|
-
/** GitHub token secret name used by the optional preview generator. */
|
|
43
|
+
/** GitHub token secret name used by the optional preview generator. Defaults to the organization credential. */
|
|
46
44
|
githubTokenSecretName?: string;
|
|
47
45
|
/** GitHub token secret key used by the optional preview generator. */
|
|
48
46
|
githubTokenSecretKey?: string;
|
|
@@ -57,8 +57,7 @@
|
|
|
57
57
|
"properties": {
|
|
58
58
|
"staging": { "type": "string", "minLength": 1 },
|
|
59
59
|
"production": { "type": "string", "minLength": 1 },
|
|
60
|
-
"preview": { "type": "string", "minLength": 1 }
|
|
61
|
-
"pullRequest": { "type": "string", "minLength": 1 }
|
|
60
|
+
"preview": { "type": "string", "minLength": 1 }
|
|
62
61
|
},
|
|
63
62
|
"additionalProperties": false
|
|
64
63
|
},
|
|
@@ -74,7 +73,8 @@
|
|
|
74
73
|
},
|
|
75
74
|
"githubTokenSecretName": {
|
|
76
75
|
"type": "string",
|
|
77
|
-
"description": "GitHub token secret name for the preview generator."
|
|
76
|
+
"description": "GitHub token secret name for the preview generator.",
|
|
77
|
+
"default": "argocd-github-otwld"
|
|
78
78
|
},
|
|
79
79
|
"githubTokenSecretKey": {
|
|
80
80
|
"type": "string",
|
|
@@ -7,7 +7,6 @@ const defaultValues = {
|
|
|
7
7
|
staging: 'values-staging.yaml',
|
|
8
8
|
production: 'values-production.yaml',
|
|
9
9
|
preview: 'values-preview.yaml',
|
|
10
|
-
pullRequest: 'values-pr.yaml',
|
|
11
10
|
};
|
|
12
11
|
/** Creates one generic GitOps project boundary for a complete Helm stack. */
|
|
13
12
|
async function stackProjectGenerator(tree, options) {
|
|
@@ -82,7 +81,7 @@ async function stackProjectGenerator(tree, options) {
|
|
|
82
81
|
}
|
|
83
82
|
/** Registers generated Argo resources in the workspace GitOps catalog. */
|
|
84
83
|
function updateKustomization(tree, generatedFiles) {
|
|
85
|
-
const file = '
|
|
84
|
+
const file = 'kustomization.yaml';
|
|
86
85
|
const document = tree.exists(file)
|
|
87
86
|
? (0, yaml_1.parse)(tree.read(file, 'utf8') ?? '')
|
|
88
87
|
: {
|
|
@@ -101,7 +100,7 @@ function updateKustomization(tree, generatedFiles) {
|
|
|
101
100
|
...(generatedFiles.applicationSetFile
|
|
102
101
|
? [generatedFiles.applicationSetFile]
|
|
103
102
|
: []),
|
|
104
|
-
]
|
|
103
|
+
];
|
|
105
104
|
document['resources'] = [...new Set([...resources, ...generatedResources])];
|
|
106
105
|
tree.write(file, (0, yaml_1.stringify)(document, { lineWidth: 0 }));
|
|
107
106
|
}
|
|
@@ -118,13 +117,10 @@ function getGeneratedFiles(directory, stack, chartPath, namespacePrefix, reposit
|
|
|
118
117
|
for (const environment of ['staging', 'production', 'preview']) {
|
|
119
118
|
files[(0, devkit_1.joinPathFragments)(directory, values[environment])] = (0, yaml_1.stringify)(createValues(applications, environment), { lineWidth: 0 });
|
|
120
119
|
}
|
|
121
|
-
if (!values.pullRequest.includes('{{')) {
|
|
122
|
-
files[(0, devkit_1.joinPathFragments)(directory, values.pullRequest)] = (0, yaml_1.stringify)(createValues(applications, 'preview'), { lineWidth: 0 });
|
|
123
|
-
}
|
|
124
120
|
let applicationSetFile;
|
|
125
121
|
if (options.policy === 'github-pr-preview') {
|
|
126
122
|
applicationSetFile = (0, devkit_1.joinPathFragments)(directory, 'application-set.yaml');
|
|
127
|
-
files[applicationSetFile] = (0, yaml_1.stringify)(createApplicationSet(stack, chartPath, namespacePrefix, repository, values.
|
|
123
|
+
files[applicationSetFile] = (0, yaml_1.stringify)(createApplicationSet(stack, chartPath, namespacePrefix, repository, values.preview, directory, options), { lineWidth: 0 });
|
|
128
124
|
}
|
|
129
125
|
return { applicationFiles, applicationSetFile, files };
|
|
130
126
|
}
|
|
@@ -169,10 +165,10 @@ function createApplication(stack, environment, chartPath, namespacePrefix, repos
|
|
|
169
165
|
},
|
|
170
166
|
};
|
|
171
167
|
}
|
|
172
|
-
/** Creates the optional
|
|
168
|
+
/** Creates the optional GitHub pull-request ApplicationSet using preview values. */
|
|
173
169
|
function createApplicationSet(stack, chartPath, namespacePrefix, repository, valuesFile, directory, options) {
|
|
174
170
|
const repositoryUrl = repository.url;
|
|
175
|
-
const secretName = options.githubTokenSecretName?.trim() ||
|
|
171
|
+
const secretName = options.githubTokenSecretName?.trim() || 'argocd-github-otwld';
|
|
176
172
|
const secretKey = options.githubTokenSecretKey?.trim() || 'token';
|
|
177
173
|
const previewLabel = options.previewLabel?.trim() || 'preview-ready';
|
|
178
174
|
const revision = options.requeueAfterSeconds ?? 1800;
|