@otwld/nx-argo 0.0.7 → 0.0.9
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 +6 -3
- package/README.md +56 -13
- package/executors.json +34 -9
- package/generators.json +5 -0
- 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 +69 -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 +10 -9
- 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/generators/stack-project/schema.d.ts +55 -0
- package/src/generators/stack-project/schema.json +110 -0
- package/src/generators/stack-project/stack-project.d.ts +4 -0
- package/src/generators/stack-project/stack-project.js +428 -0
- package/src/index.d.ts +16 -0
- package/src/index.js +17 -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 -190
- package/src/executors/write-artifact-lock/write-artifact-lock.d.ts +0 -5
- package/src/executors/write-artifact-lock/write-artifact-lock.js +0 -168
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = stackProjectGenerator;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const yaml_1 = require("yaml");
|
|
6
|
+
const defaultValues = {
|
|
7
|
+
staging: 'values-staging.yaml',
|
|
8
|
+
production: 'values-production.yaml',
|
|
9
|
+
preview: 'values-preview.yaml',
|
|
10
|
+
pullRequest: 'values-pr.yaml',
|
|
11
|
+
};
|
|
12
|
+
/** Creates one generic GitOps project boundary for a complete Helm stack. */
|
|
13
|
+
async function stackProjectGenerator(tree, options) {
|
|
14
|
+
const stack = normalizeName(options.name, 'name');
|
|
15
|
+
const chartPath = normalizeRelativePath(options.chartPath, 'chartPath');
|
|
16
|
+
const chartProject = requireValue(options.chartProject, 'chartProject');
|
|
17
|
+
const namespacePrefix = normalizeName(options.namespacePrefix, 'namespacePrefix');
|
|
18
|
+
const applications = normalizeApplications(options.applications);
|
|
19
|
+
const repository = normalizeRepository(options.repository);
|
|
20
|
+
const values = normalizeValues(options.values);
|
|
21
|
+
const directory = (0, devkit_1.joinPathFragments)('gitops', stack);
|
|
22
|
+
const projectFile = (0, devkit_1.joinPathFragments)(directory, 'project.json');
|
|
23
|
+
if (tree.exists(projectFile)) {
|
|
24
|
+
throw new Error(`[nx-argo] A GitOps stack project already exists at ${directory}.`);
|
|
25
|
+
}
|
|
26
|
+
if (options.policy && (!repository.owner || !repository.name)) {
|
|
27
|
+
throw new Error('[nx-argo] github-pr-preview requires repository.owner and repository.name.');
|
|
28
|
+
}
|
|
29
|
+
const generatedFiles = getGeneratedFiles(directory, stack, chartPath, namespacePrefix, repository, values, applications, options);
|
|
30
|
+
const validationTargets = getValidationTargets(generatedFiles, options);
|
|
31
|
+
(0, devkit_1.writeJson)(tree, projectFile, {
|
|
32
|
+
name: `gitops-${stack}`,
|
|
33
|
+
root: directory,
|
|
34
|
+
projectType: 'application',
|
|
35
|
+
tags: ['type:gitops', `stack:${stack}`],
|
|
36
|
+
implicitDependencies: [
|
|
37
|
+
...new Set([chartProject, ...Object.values(applications)]),
|
|
38
|
+
],
|
|
39
|
+
metadata: {
|
|
40
|
+
delivery: {
|
|
41
|
+
stack: {
|
|
42
|
+
chartPath,
|
|
43
|
+
values,
|
|
44
|
+
applications,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
targets: {
|
|
49
|
+
validate: {
|
|
50
|
+
executor: 'nx:noop',
|
|
51
|
+
dependsOn: [
|
|
52
|
+
...Object.keys(validationTargets),
|
|
53
|
+
`${chartProject}:helm:validate`,
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
...validationTargets,
|
|
57
|
+
'delivery:stack-stage': {
|
|
58
|
+
executor: '@otwld/nx-delivery:stack-stage',
|
|
59
|
+
cache: false,
|
|
60
|
+
},
|
|
61
|
+
'delivery:stack-promote': {
|
|
62
|
+
executor: '@otwld/nx-delivery:stack-promote',
|
|
63
|
+
cache: false,
|
|
64
|
+
},
|
|
65
|
+
'delivery:stack-preview': {
|
|
66
|
+
executor: '@otwld/nx-delivery:stack-preview',
|
|
67
|
+
cache: false,
|
|
68
|
+
},
|
|
69
|
+
'delivery:stack-snapshot': {
|
|
70
|
+
executor: '@otwld/nx-delivery:stack-snapshot',
|
|
71
|
+
cache: false,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
for (const [file, content] of Object.entries(generatedFiles.files)) {
|
|
76
|
+
tree.write(file, content);
|
|
77
|
+
}
|
|
78
|
+
updateKustomization(tree, generatedFiles);
|
|
79
|
+
if (!options.skipFormat) {
|
|
80
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Registers generated Argo resources in the workspace GitOps catalog. */
|
|
84
|
+
function updateKustomization(tree, generatedFiles) {
|
|
85
|
+
const file = 'gitops/kustomization.yaml';
|
|
86
|
+
const document = tree.exists(file)
|
|
87
|
+
? (0, yaml_1.parse)(tree.read(file, 'utf8') ?? '')
|
|
88
|
+
: {
|
|
89
|
+
apiVersion: 'kustomize.config.k8s.io/v1beta1',
|
|
90
|
+
kind: 'Kustomization',
|
|
91
|
+
resources: [],
|
|
92
|
+
};
|
|
93
|
+
if (!isRecord(document)) {
|
|
94
|
+
throw new Error(`[nx-argo] Invalid Kustomization: ${file}`);
|
|
95
|
+
}
|
|
96
|
+
const resources = Array.isArray(document['resources'])
|
|
97
|
+
? document['resources'].filter((resource) => typeof resource === 'string')
|
|
98
|
+
: [];
|
|
99
|
+
const generatedResources = [
|
|
100
|
+
...Object.values(generatedFiles.applicationFiles),
|
|
101
|
+
...(generatedFiles.applicationSetFile
|
|
102
|
+
? [generatedFiles.applicationSetFile]
|
|
103
|
+
: []),
|
|
104
|
+
].map((resource) => resource.replace(/^gitops\//, ''));
|
|
105
|
+
document['resources'] = [...new Set([...resources, ...generatedResources])];
|
|
106
|
+
tree.write(file, (0, yaml_1.stringify)(document, { lineWidth: 0 }));
|
|
107
|
+
}
|
|
108
|
+
/** Builds all Argo manifests and stable value files owned by the boundary. */
|
|
109
|
+
function getGeneratedFiles(directory, stack, chartPath, namespacePrefix, repository, values, applications, options) {
|
|
110
|
+
const applicationFiles = {
|
|
111
|
+
staging: (0, devkit_1.joinPathFragments)(directory, 'application-staging.yaml'),
|
|
112
|
+
production: (0, devkit_1.joinPathFragments)(directory, 'application-production.yaml'),
|
|
113
|
+
};
|
|
114
|
+
const files = {
|
|
115
|
+
[applicationFiles.staging]: (0, yaml_1.stringify)(createApplication(stack, 'staging', chartPath, namespacePrefix, repository, values.staging, directory, options.argoProject), { lineWidth: 0 }),
|
|
116
|
+
[applicationFiles.production]: (0, yaml_1.stringify)(createApplication(stack, 'production', chartPath, namespacePrefix, repository, values.production, directory, options.argoProject), { lineWidth: 0 }),
|
|
117
|
+
};
|
|
118
|
+
for (const environment of ['staging', 'production', 'preview']) {
|
|
119
|
+
files[(0, devkit_1.joinPathFragments)(directory, values[environment])] = (0, yaml_1.stringify)(createValues(applications, environment), { lineWidth: 0 });
|
|
120
|
+
}
|
|
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
|
+
let applicationSetFile;
|
|
125
|
+
if (options.policy === 'github-pr-preview') {
|
|
126
|
+
applicationSetFile = (0, devkit_1.joinPathFragments)(directory, 'application-set.yaml');
|
|
127
|
+
files[applicationSetFile] = (0, yaml_1.stringify)(createApplicationSet(stack, chartPath, namespacePrefix, repository, values.pullRequest, directory, options), { lineWidth: 0 });
|
|
128
|
+
}
|
|
129
|
+
return { applicationFiles, applicationSetFile, files };
|
|
130
|
+
}
|
|
131
|
+
/** Creates one stable Argo CD Application for an environment value file. */
|
|
132
|
+
function createApplication(stack, environment, chartPath, namespacePrefix, repository, valuesFile, directory, argoProject = 'default') {
|
|
133
|
+
const repositoryUrl = repository.url;
|
|
134
|
+
const repositoryRevision = repository.revision;
|
|
135
|
+
const gitopsValuesPath = (0, devkit_1.joinPathFragments)(directory, valuesFile);
|
|
136
|
+
return {
|
|
137
|
+
apiVersion: 'argoproj.io/v1alpha1',
|
|
138
|
+
kind: 'Application',
|
|
139
|
+
metadata: {
|
|
140
|
+
name: `${stack}-${environment}`,
|
|
141
|
+
namespace: 'argocd',
|
|
142
|
+
},
|
|
143
|
+
spec: {
|
|
144
|
+
project: argoProject,
|
|
145
|
+
sources: [
|
|
146
|
+
{
|
|
147
|
+
repoURL: repositoryUrl,
|
|
148
|
+
targetRevision: repositoryRevision,
|
|
149
|
+
path: chartPath,
|
|
150
|
+
helm: { valueFiles: [`$values/${gitopsValuesPath}`] },
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
repoURL: repositoryUrl,
|
|
154
|
+
targetRevision: repositoryRevision,
|
|
155
|
+
ref: 'values',
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
destination: {
|
|
159
|
+
server: 'https://kubernetes.default.svc',
|
|
160
|
+
namespace: `${namespacePrefix}-${environment}`,
|
|
161
|
+
},
|
|
162
|
+
syncPolicy: {
|
|
163
|
+
syncOptions: ['CreateNamespace=true'],
|
|
164
|
+
managedNamespaceMetadata: {
|
|
165
|
+
labels: { 'delivery.otwld.com/managed': 'true' },
|
|
166
|
+
},
|
|
167
|
+
automated: { enabled: true, prune: true, selfHeal: true },
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/** Creates the optional generic GitHub pull-request ApplicationSet. */
|
|
173
|
+
function createApplicationSet(stack, chartPath, namespacePrefix, repository, valuesFile, directory, options) {
|
|
174
|
+
const repositoryUrl = repository.url;
|
|
175
|
+
const secretName = options.githubTokenSecretName?.trim() || `argocd-github-${stack}`;
|
|
176
|
+
const secretKey = options.githubTokenSecretKey?.trim() || 'token';
|
|
177
|
+
const previewLabel = options.previewLabel?.trim() || 'preview-ready';
|
|
178
|
+
const revision = options.requeueAfterSeconds ?? 1800;
|
|
179
|
+
const gitopsValuesPath = (0, devkit_1.joinPathFragments)(directory, valuesFile);
|
|
180
|
+
return {
|
|
181
|
+
apiVersion: 'argoproj.io/v1alpha1',
|
|
182
|
+
kind: 'ApplicationSet',
|
|
183
|
+
metadata: { name: `${stack}-preview`, namespace: 'argocd' },
|
|
184
|
+
spec: {
|
|
185
|
+
goTemplate: true,
|
|
186
|
+
goTemplateOptions: ['missingkey=error'],
|
|
187
|
+
generators: [
|
|
188
|
+
{
|
|
189
|
+
matrix: {
|
|
190
|
+
generators: [
|
|
191
|
+
{
|
|
192
|
+
pullRequest: {
|
|
193
|
+
github: {
|
|
194
|
+
owner: repository.owner,
|
|
195
|
+
repo: repository.name,
|
|
196
|
+
tokenRef: { secretName, key: secretKey },
|
|
197
|
+
labels: [previewLabel],
|
|
198
|
+
},
|
|
199
|
+
requeueAfterSeconds: revision,
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
git: {
|
|
204
|
+
repoURL: repositoryUrl,
|
|
205
|
+
revision: 'preview/pr-{{ .number }}',
|
|
206
|
+
files: [{ path: gitopsValuesPath }],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
template: {
|
|
214
|
+
metadata: {
|
|
215
|
+
name: `${stack}-pr-{{ .number }}`,
|
|
216
|
+
finalizers: ['resources-finalizer.argocd.argoproj.io'],
|
|
217
|
+
labels: {
|
|
218
|
+
'app.kubernetes.io/part-of': stack,
|
|
219
|
+
'delivery.otwld.com/preview': stack,
|
|
220
|
+
'delivery.otwld.com/pull-request': '{{ .number }}',
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
spec: {
|
|
224
|
+
project: options.argoProject?.trim() || 'default',
|
|
225
|
+
sources: [
|
|
226
|
+
{
|
|
227
|
+
repoURL: repositoryUrl,
|
|
228
|
+
targetRevision: '{{ .global.sourceRevision }}',
|
|
229
|
+
path: chartPath,
|
|
230
|
+
helm: {
|
|
231
|
+
valueFiles: [`$values/${gitopsValuesPath}`],
|
|
232
|
+
parameters: [
|
|
233
|
+
{ name: 'global.previewId', value: 'pr-{{ .number }}' },
|
|
234
|
+
],
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
repoURL: repositoryUrl,
|
|
239
|
+
targetRevision: 'preview/pr-{{ .number }}',
|
|
240
|
+
ref: 'values',
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
destination: {
|
|
244
|
+
server: 'https://kubernetes.default.svc',
|
|
245
|
+
namespace: `${namespacePrefix}-pr-{{ .number }}`,
|
|
246
|
+
},
|
|
247
|
+
syncPolicy: {
|
|
248
|
+
managedNamespaceMetadata: {
|
|
249
|
+
labels: { 'delivery.otwld.com/managed': 'true' },
|
|
250
|
+
annotations: {
|
|
251
|
+
'argocd.argoproj.io/tracking-id': `${stack}-pr-{{ .number }}:/Namespace:/${namespacePrefix}-pr-{{ .number }}`,
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
syncOptions: ['CreateNamespace=true'],
|
|
255
|
+
automated: { enabled: true, prune: true, selfHeal: true },
|
|
256
|
+
retry: {
|
|
257
|
+
limit: 3,
|
|
258
|
+
backoff: { duration: '5s', factor: 2, maxDuration: '3m' },
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
/** Creates one image-value skeleton for every mapped application. */
|
|
267
|
+
function createValues(applications, environment) {
|
|
268
|
+
const values = {
|
|
269
|
+
global: { environment, sourceRevision: '' },
|
|
270
|
+
};
|
|
271
|
+
for (const [valuesKey, project] of Object.entries(applications)) {
|
|
272
|
+
setPath(values, parseValuePath(valuesKey), {
|
|
273
|
+
project,
|
|
274
|
+
image: { repository: '', digest: '' },
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
return values;
|
|
278
|
+
}
|
|
279
|
+
/** Declares Argo validation targets for generated manifests. */
|
|
280
|
+
function getValidationTargets(files, options) {
|
|
281
|
+
const targets = {
|
|
282
|
+
'validate-application-staging': {
|
|
283
|
+
executor: '@otwld/nx-argo:validate-application',
|
|
284
|
+
options: { file: relativeToProject(files.applicationFiles.staging) },
|
|
285
|
+
},
|
|
286
|
+
'validate-application-production': {
|
|
287
|
+
executor: '@otwld/nx-argo:validate-application',
|
|
288
|
+
options: { file: relativeToProject(files.applicationFiles.production) },
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
if (options.policy === 'github-pr-preview' && files.applicationSetFile) {
|
|
292
|
+
targets['validate-application-set'] = {
|
|
293
|
+
executor: '@otwld/nx-argo:validate-application-set',
|
|
294
|
+
options: {
|
|
295
|
+
file: relativeToProject(files.applicationSetFile),
|
|
296
|
+
policy: options.policy,
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
return targets;
|
|
301
|
+
}
|
|
302
|
+
/** Converts a generated project path into its project-relative target option. */
|
|
303
|
+
function relativeToProject(path) {
|
|
304
|
+
const marker = path.indexOf('gitops/');
|
|
305
|
+
if (marker < 0) {
|
|
306
|
+
throw new Error(`[nx-argo] Generated project path is invalid: ${path}`);
|
|
307
|
+
}
|
|
308
|
+
const projectPath = path.slice(marker);
|
|
309
|
+
const slash = projectPath.indexOf('/');
|
|
310
|
+
return slash < 0
|
|
311
|
+
? ''
|
|
312
|
+
: projectPath.slice(projectPath.indexOf('/', slash + 1) + 1);
|
|
313
|
+
}
|
|
314
|
+
/** Normalizes a repository URL or owner/name identity object. */
|
|
315
|
+
function normalizeRepository(value) {
|
|
316
|
+
if (typeof value === 'string') {
|
|
317
|
+
const url = requireValue(value, 'repository');
|
|
318
|
+
const identity = parseGitHubIdentity(url);
|
|
319
|
+
return { ...identity, url, revision: 'main' };
|
|
320
|
+
}
|
|
321
|
+
if (!value || typeof value !== 'object') {
|
|
322
|
+
throw new Error('[nx-argo] A repository URL or identity is required.');
|
|
323
|
+
}
|
|
324
|
+
const owner = readValue(value.owner);
|
|
325
|
+
const name = readValue(value.name);
|
|
326
|
+
const url = readValue(value.url) ||
|
|
327
|
+
(owner && name ? `https://github.com/${owner}/${name}.git` : undefined);
|
|
328
|
+
if (!url) {
|
|
329
|
+
throw new Error('[nx-argo] repository.url or repository.owner/name is required.');
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
url,
|
|
333
|
+
...(owner ? { owner } : {}),
|
|
334
|
+
...(name ? { name } : {}),
|
|
335
|
+
revision: readValue(value.revision) || 'main',
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
/** Derives GitHub owner/name values when a GitHub URL is supplied. */
|
|
339
|
+
function parseGitHubIdentity(url) {
|
|
340
|
+
const match = url.match(/github\.com[/:]([^/]+)\/([^/#]+?)(?:\.git)?$/i);
|
|
341
|
+
return match ? { owner: match[1], name: match[2] } : {};
|
|
342
|
+
}
|
|
343
|
+
/** Normalizes project-local values paths while preserving the PR template. */
|
|
344
|
+
function normalizeValues(value) {
|
|
345
|
+
const normalized = {
|
|
346
|
+
...defaultValues,
|
|
347
|
+
...value,
|
|
348
|
+
};
|
|
349
|
+
for (const [key, path] of Object.entries(normalized)) {
|
|
350
|
+
normalized[key] = normalizeRelativePath(path, `values.${key}`);
|
|
351
|
+
}
|
|
352
|
+
return normalized;
|
|
353
|
+
}
|
|
354
|
+
/** Normalizes values-key mappings without inventing project names. */
|
|
355
|
+
function normalizeApplications(value) {
|
|
356
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
357
|
+
throw new Error('[nx-argo] applications must map values keys to Nx projects.');
|
|
358
|
+
}
|
|
359
|
+
const applications = {};
|
|
360
|
+
for (const [valuesKey, project] of Object.entries(value)) {
|
|
361
|
+
const key = parseValuePath(valuesKey).join('.');
|
|
362
|
+
applications[key] = requireValue(project, `applications.${key}`);
|
|
363
|
+
}
|
|
364
|
+
if (Object.keys(applications).length === 0) {
|
|
365
|
+
throw new Error('[nx-argo] At least one application mapping is required.');
|
|
366
|
+
}
|
|
367
|
+
return applications;
|
|
368
|
+
}
|
|
369
|
+
/** Parses a dot-separated values mapping path. */
|
|
370
|
+
function parseValuePath(value) {
|
|
371
|
+
const segments = value.split('.').map((segment) => segment.trim());
|
|
372
|
+
if (!value.trim() ||
|
|
373
|
+
segments.some((segment) => !segment ||
|
|
374
|
+
segment === '..' ||
|
|
375
|
+
segment.includes('/') ||
|
|
376
|
+
segment.includes('\\'))) {
|
|
377
|
+
throw new Error(`[nx-argo] Invalid values key: ${value}`);
|
|
378
|
+
}
|
|
379
|
+
return segments;
|
|
380
|
+
}
|
|
381
|
+
/** Sets a nested mapping path for generated values. */
|
|
382
|
+
function setPath(root, path, value) {
|
|
383
|
+
let current = root;
|
|
384
|
+
for (const segment of path.slice(0, -1)) {
|
|
385
|
+
const child = current[segment];
|
|
386
|
+
if (child === undefined) {
|
|
387
|
+
current[segment] = {};
|
|
388
|
+
}
|
|
389
|
+
else if (!isRecord(child)) {
|
|
390
|
+
throw new Error(`[nx-argo] Values key conflicts at ${segment}.`);
|
|
391
|
+
}
|
|
392
|
+
current = current[segment];
|
|
393
|
+
}
|
|
394
|
+
current[path.at(-1)] = value;
|
|
395
|
+
}
|
|
396
|
+
/** Narrows a generated value to a mapping. */
|
|
397
|
+
function isRecord(value) {
|
|
398
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
399
|
+
}
|
|
400
|
+
/** Normalizes a project or namespace identifier. */
|
|
401
|
+
function normalizeName(value, label) {
|
|
402
|
+
const normalized = (0, devkit_1.names)(requireValue(value, label)).fileName;
|
|
403
|
+
if (!normalized) {
|
|
404
|
+
throw new Error(`[nx-argo] A ${label} is required.`);
|
|
405
|
+
}
|
|
406
|
+
return normalized;
|
|
407
|
+
}
|
|
408
|
+
/** Validates a project-relative path without allowing escapes. */
|
|
409
|
+
function normalizeRelativePath(value, label) {
|
|
410
|
+
const normalized = requireValue(value, label).replaceAll('\\', '/');
|
|
411
|
+
if (normalized.startsWith('/') ||
|
|
412
|
+
normalized.split('/').some((segment) => segment === '..' || !segment)) {
|
|
413
|
+
throw new Error(`[nx-argo] ${label} must stay within the project root.`);
|
|
414
|
+
}
|
|
415
|
+
return normalized;
|
|
416
|
+
}
|
|
417
|
+
/** Requires a non-empty string scalar. */
|
|
418
|
+
function requireValue(value, label) {
|
|
419
|
+
const normalized = value?.trim();
|
|
420
|
+
if (!normalized) {
|
|
421
|
+
throw new Error(`[nx-argo] A ${label} is required.`);
|
|
422
|
+
}
|
|
423
|
+
return normalized;
|
|
424
|
+
}
|
|
425
|
+
/** Returns a trimmed optional string. */
|
|
426
|
+
function readValue(value) {
|
|
427
|
+
return value?.trim() || undefined;
|
|
428
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -3,3 +3,19 @@ export { default as environmentProjectGenerator } from './generators/environment
|
|
|
3
3
|
export type { EnvironmentProjectGeneratorSchema } from './generators/environment-project/schema';
|
|
4
4
|
export { default as previewProjectGenerator } from './generators/preview-project/preview-project';
|
|
5
5
|
export type { PreviewProjectGeneratorSchema } from './generators/preview-project/schema';
|
|
6
|
+
export { default as stackProjectGenerator } from './generators/stack-project/stack-project';
|
|
7
|
+
export type { StackProjectGeneratorSchema, StackRepository, StackValueFiles, } from './generators/stack-project/schema';
|
|
8
|
+
export { default as validateApplication } from './executors/validate-application/validate-application';
|
|
9
|
+
export type { ValidateApplicationExecutorSchema } from './executors/validate-application/schema';
|
|
10
|
+
export { default as validateApplicationSet } from './executors/validate-application-set/validate-application-set';
|
|
11
|
+
export type { ValidateApplicationSetExecutorSchema } from './executors/validate-application-set/schema';
|
|
12
|
+
export { default as validateImageLock } from './executors/validate-image-lock/validate-image-lock';
|
|
13
|
+
export type { ValidateImageLockExecutorSchema } from './executors/validate-image-lock/schema';
|
|
14
|
+
export { default as writeImageLock } from './executors/write-image-lock/write-image-lock';
|
|
15
|
+
export type { WriteImageLockExecutorSchema } from './executors/write-image-lock/schema';
|
|
16
|
+
export { default as copyImageLock } from './executors/copy-image-lock/copy-image-lock';
|
|
17
|
+
export type { CopyImageLockExecutorSchema } from './executors/copy-image-lock/schema';
|
|
18
|
+
export { default as setSourceRevision } from './executors/set-source-revision/set-source-revision';
|
|
19
|
+
export type { SetSourceRevisionExecutorSchema } from './executors/set-source-revision/schema';
|
|
20
|
+
export { default as copySourceRevision } from './executors/copy-source-revision/copy-source-revision';
|
|
21
|
+
export type { CopySourceRevisionExecutorSchema } from './executors/copy-source-revision/schema';
|
package/src/index.js
CHANGED
|
@@ -3,9 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.previewProjectGenerator = exports.environmentProjectGenerator = void 0;
|
|
6
|
+
exports.copySourceRevision = exports.setSourceRevision = exports.copyImageLock = exports.writeImageLock = exports.validateImageLock = exports.validateApplicationSet = exports.validateApplication = exports.stackProjectGenerator = exports.previewProjectGenerator = exports.environmentProjectGenerator = void 0;
|
|
7
7
|
/** Public generator and executor exports for the Argo CD package. */
|
|
8
8
|
var environment_project_1 = require("./generators/environment-project/environment-project");
|
|
9
9
|
Object.defineProperty(exports, "environmentProjectGenerator", { enumerable: true, get: function () { return __importDefault(environment_project_1).default; } });
|
|
10
10
|
var preview_project_1 = require("./generators/preview-project/preview-project");
|
|
11
11
|
Object.defineProperty(exports, "previewProjectGenerator", { enumerable: true, get: function () { return __importDefault(preview_project_1).default; } });
|
|
12
|
+
var stack_project_1 = require("./generators/stack-project/stack-project");
|
|
13
|
+
Object.defineProperty(exports, "stackProjectGenerator", { enumerable: true, get: function () { return __importDefault(stack_project_1).default; } });
|
|
14
|
+
var validate_application_1 = require("./executors/validate-application/validate-application");
|
|
15
|
+
Object.defineProperty(exports, "validateApplication", { enumerable: true, get: function () { return __importDefault(validate_application_1).default; } });
|
|
16
|
+
var validate_application_set_1 = require("./executors/validate-application-set/validate-application-set");
|
|
17
|
+
Object.defineProperty(exports, "validateApplicationSet", { enumerable: true, get: function () { return __importDefault(validate_application_set_1).default; } });
|
|
18
|
+
var validate_image_lock_1 = require("./executors/validate-image-lock/validate-image-lock");
|
|
19
|
+
Object.defineProperty(exports, "validateImageLock", { enumerable: true, get: function () { return __importDefault(validate_image_lock_1).default; } });
|
|
20
|
+
var write_image_lock_1 = require("./executors/write-image-lock/write-image-lock");
|
|
21
|
+
Object.defineProperty(exports, "writeImageLock", { enumerable: true, get: function () { return __importDefault(write_image_lock_1).default; } });
|
|
22
|
+
var copy_image_lock_1 = require("./executors/copy-image-lock/copy-image-lock");
|
|
23
|
+
Object.defineProperty(exports, "copyImageLock", { enumerable: true, get: function () { return __importDefault(copy_image_lock_1).default; } });
|
|
24
|
+
var set_source_revision_1 = require("./executors/set-source-revision/set-source-revision");
|
|
25
|
+
Object.defineProperty(exports, "setSourceRevision", { enumerable: true, get: function () { return __importDefault(set_source_revision_1).default; } });
|
|
26
|
+
var copy_source_revision_1 = require("./executors/copy-source-revision/copy-source-revision");
|
|
27
|
+
Object.defineProperty(exports, "copySourceRevision", { enumerable: true, get: function () { return __importDefault(copy_source_revision_1).default; } });
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** Options accepted by the Argo CD validation executor. */
|
|
2
|
-
export interface ValidateExecutorSchema {
|
|
3
|
-
/** GitOps project contract to validate. */
|
|
4
|
-
mode: 'environment' | 'preview';
|
|
5
|
-
/** Optional Application manifest relative to the owning Nx project root. */
|
|
6
|
-
applicationFile?: string;
|
|
7
|
-
/** ApplicationSet manifest relative to the owning Nx project root. */
|
|
8
|
-
applicationSetFile?: string;
|
|
9
|
-
/** Artifact lock file relative to the owning Nx project root. */
|
|
10
|
-
artifactsFile?: string;
|
|
11
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/schema",
|
|
3
|
-
"version": 2,
|
|
4
|
-
"title": "Validate Argo CD configuration",
|
|
5
|
-
"description": "Validate a GitOps environment or preview project contract.",
|
|
6
|
-
"type": "object",
|
|
7
|
-
"properties": {
|
|
8
|
-
"mode": {
|
|
9
|
-
"type": "string",
|
|
10
|
-
"enum": ["environment", "preview"],
|
|
11
|
-
"description": "GitOps project contract to validate."
|
|
12
|
-
},
|
|
13
|
-
"applicationFile": {
|
|
14
|
-
"type": "string",
|
|
15
|
-
"description": "Optional Application manifest relative to the owning Nx project root."
|
|
16
|
-
},
|
|
17
|
-
"applicationSetFile": {
|
|
18
|
-
"type": "string",
|
|
19
|
-
"description": "ApplicationSet manifest relative to the owning Nx project root."
|
|
20
|
-
},
|
|
21
|
-
"artifactsFile": {
|
|
22
|
-
"type": "string",
|
|
23
|
-
"description": "Artifact lock file relative to the owning Nx project root."
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"required": ["mode"],
|
|
27
|
-
"additionalProperties": false
|
|
28
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { PromiseExecutor } from '@nx/devkit';
|
|
2
|
-
import type { ValidateExecutorSchema } from './schema';
|
|
3
|
-
/** Validates the declared Argo CD resources and artifact lock for one project. */
|
|
4
|
-
declare const runExecutor: PromiseExecutor<ValidateExecutorSchema>;
|
|
5
|
-
export default runExecutor;
|