@otwld/nx-helm 0.0.8 → 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/executors.json +15 -10
- package/generators.json +3 -15
- package/package.json +8 -8
- package/src/executors/commands.d.ts +22 -0
- package/src/executors/commands.js +113 -0
- package/src/executors/commands.js.map +1 -0
- package/src/executors/lint.schema.json +9 -0
- package/src/executors/package.schema.json +7 -0
- package/src/executors/release-publish.schema.json +10 -0
- package/src/executors/template.schema.json +12 -0
- package/src/generators/chart.d.ts +9 -0
- package/src/generators/chart.js +97 -0
- package/src/generators/chart.js.map +1 -0
- package/src/generators/chart.schema.json +17 -0
- package/src/index.d.ts +3 -6
- package/src/index.js +4 -13
- package/src/index.js.map +1 -0
- package/src/plugin.d.ts +7 -0
- package/src/plugin.js +65 -0
- package/src/plugin.js.map +1 -0
- package/src/release/version-actions.d.ts +10 -56
- package/src/release/version-actions.js +32 -101
- package/src/release/version-actions.js.map +1 -0
- package/CHANGELOG.md +0 -48
- package/README.md +0 -131
- package/src/chart-manifest.d.ts +0 -22
- package/src/chart-manifest.js +0 -56
- package/src/executors/package/package.d.ts +0 -10
- package/src/executors/package/package.js +0 -57
- package/src/executors/package/schema.d.ts +0 -7
- package/src/executors/package/schema.json +0 -18
- package/src/executors/project-directory.d.ts +0 -8
- package/src/executors/project-directory.js +0 -23
- package/src/executors/release-publish/release-publish.d.ts +0 -10
- package/src/executors/release-publish/release-publish.js +0 -102
- package/src/executors/release-publish/schema.d.ts +0 -9
- package/src/executors/release-publish/schema.json +0 -22
- package/src/executors/run-helm.d.ts +0 -7
- package/src/executors/run-helm.js +0 -32
- package/src/executors/validate/schema.d.ts +0 -11
- package/src/executors/validate/schema.json +0 -29
- package/src/executors/validate/validate.d.ts +0 -16
- package/src/executors/validate/validate.js +0 -50
- package/src/generators/chart/chart.d.ts +0 -10
- package/src/generators/chart/chart.js +0 -101
- package/src/generators/chart/schema.d.ts +0 -13
- package/src/generators/chart/schema.json +0 -43
- package/src/generators/init/init.d.ts +0 -9
- package/src/generators/init/init.js +0 -37
- package/src/generators/init/schema.d.ts +0 -5
- package/src/generators/init/schema.json +0 -15
- package/src/generators/stack/schema.d.ts +0 -27
- package/src/generators/stack/schema.json +0 -50
- package/src/generators/stack/stack.d.ts +0 -4
- package/src/generators/stack/stack.js +0 -214
- package/src/plugins/plugin.d.ts +0 -38
- package/src/plugins/plugin.js +0 -352
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = stackGenerator;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const yaml_1 = require("yaml");
|
|
6
|
-
/** Creates a generic Helm umbrella chart without repository-specific services. */
|
|
7
|
-
async function stackGenerator(tree, options) {
|
|
8
|
-
const chartName = normalizeName(options.name, 'name');
|
|
9
|
-
const projectRoot = (0, devkit_1.joinPathFragments)(options.directory?.trim() || 'charts', chartName);
|
|
10
|
-
const chartFile = (0, devkit_1.joinPathFragments)(projectRoot, 'Chart.yaml');
|
|
11
|
-
const projectName = options.projectName?.trim() || `helm-${chartName}`;
|
|
12
|
-
if (tree.exists(chartFile)) {
|
|
13
|
-
throw new Error(`[nx-helm] A Helm chart already exists at ${projectRoot}.`);
|
|
14
|
-
}
|
|
15
|
-
const dependencies = normalizeDependencies(options.dependencies);
|
|
16
|
-
tree.write(chartFile, (0, yaml_1.stringify)({
|
|
17
|
-
apiVersion: 'v2',
|
|
18
|
-
name: chartName,
|
|
19
|
-
description: `Umbrella chart for the ${chartName} application stack.`,
|
|
20
|
-
type: 'application',
|
|
21
|
-
version: '0.1.0',
|
|
22
|
-
appVersion: '0.1.0',
|
|
23
|
-
...(dependencies.length ? { dependencies } : {}),
|
|
24
|
-
}, { lineWidth: 0 }));
|
|
25
|
-
tree.write((0, devkit_1.joinPathFragments)(projectRoot, 'values.yaml'), (0, yaml_1.stringify)(createValues(dependencies), { lineWidth: 0 }));
|
|
26
|
-
tree.write((0, devkit_1.joinPathFragments)(projectRoot, 'templates/mongodb-password.yaml'), createMongoPasswordTemplate());
|
|
27
|
-
tree.write((0, devkit_1.joinPathFragments)(projectRoot, 'templates/mongodb.yaml'), createMongoTemplate());
|
|
28
|
-
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(projectRoot, 'project.json'), {
|
|
29
|
-
name: projectName,
|
|
30
|
-
root: projectRoot,
|
|
31
|
-
projectType: 'application',
|
|
32
|
-
tags: options.tags?.length ? options.tags : ['type:chart', 'type:stack'],
|
|
33
|
-
metadata: { helm: { publish: false, releaseName: chartName } },
|
|
34
|
-
});
|
|
35
|
-
if (!options.skipFormat) {
|
|
36
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/** Builds the opinionated stack values contract for dependency toggles and MongoDB. */
|
|
40
|
-
function createValues(dependencies) {
|
|
41
|
-
const values = {
|
|
42
|
-
global: {
|
|
43
|
-
environment: 'local',
|
|
44
|
-
imagePullPolicy: 'IfNotPresent',
|
|
45
|
-
imagePullSecrets: [],
|
|
46
|
-
previewId: '',
|
|
47
|
-
previewDomain: '',
|
|
48
|
-
sourceRevision: '',
|
|
49
|
-
},
|
|
50
|
-
mongodb: {
|
|
51
|
-
enabled: false,
|
|
52
|
-
namespace: '',
|
|
53
|
-
version: '7.0.5',
|
|
54
|
-
storage: '8Gi',
|
|
55
|
-
secret: {
|
|
56
|
-
mode: 'generated',
|
|
57
|
-
encryptedData: { password: '' },
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
for (const dependency of dependencies) {
|
|
62
|
-
values[dependency.name] = { enabled: false };
|
|
63
|
-
}
|
|
64
|
-
return values;
|
|
65
|
-
}
|
|
66
|
-
/** Renders the generated or sealed MongoDB password contract. */
|
|
67
|
-
function createMongoPasswordTemplate() {
|
|
68
|
-
return `{{/* Render the stack's explicit MongoDB credential contract. */}}
|
|
69
|
-
{{- if .Values.mongodb.enabled }}
|
|
70
|
-
{{- $mode := default "generated" .Values.mongodb.secret.mode }}
|
|
71
|
-
{{- if eq $mode "sealed" }}
|
|
72
|
-
apiVersion: bitnami.com/v1alpha1
|
|
73
|
-
kind: SealedSecret
|
|
74
|
-
metadata:
|
|
75
|
-
name: mongodb-app-password
|
|
76
|
-
{{ with .Values.mongodb.namespace }}
|
|
77
|
-
namespace: {{ . | quote }}
|
|
78
|
-
{{ end }}
|
|
79
|
-
annotations:
|
|
80
|
-
{{ with .Values.mongodb.namespace }}
|
|
81
|
-
argocd.argoproj.io/tracking-id: {{ printf "%s:/Secret:%s/mongodb-app-password" . . | quote }}
|
|
82
|
-
{{ end }}
|
|
83
|
-
argocd.argoproj.io/sync-wave: '-10'
|
|
84
|
-
spec:
|
|
85
|
-
encryptedData:
|
|
86
|
-
password: {{ required "mongodb.secret.encryptedData.password is required for sealed credentials" (dig "encryptedData" "password" "" .Values.mongodb.secret) | quote }}
|
|
87
|
-
template:
|
|
88
|
-
metadata:
|
|
89
|
-
name: mongodb-app-password
|
|
90
|
-
{{ with .Values.mongodb.namespace }}
|
|
91
|
-
namespace: {{ . | quote }}
|
|
92
|
-
{{ end }}
|
|
93
|
-
annotations:
|
|
94
|
-
sealedsecrets.bitnami.com/managed: 'true'
|
|
95
|
-
type: Opaque
|
|
96
|
-
{{- else if eq $mode "generated" }}
|
|
97
|
-
apiVersion: v1
|
|
98
|
-
kind: Secret
|
|
99
|
-
metadata:
|
|
100
|
-
name: mongodb-app-password
|
|
101
|
-
{{ with .Values.mongodb.namespace }}
|
|
102
|
-
namespace: {{ . | quote }}
|
|
103
|
-
{{ end }}
|
|
104
|
-
annotations:
|
|
105
|
-
argocd.argoproj.io/sync-wave: '-10'
|
|
106
|
-
delivery.otwld.com/generated-secret: random
|
|
107
|
-
type: Opaque
|
|
108
|
-
data:
|
|
109
|
-
password: {{ randAlphaNum 32 | b64enc | quote }}
|
|
110
|
-
{{- else }}
|
|
111
|
-
{{- fail (printf "mongodb.secret.mode must be sealed or generated, got %q" $mode) }}
|
|
112
|
-
{{- end }}
|
|
113
|
-
{{- end }}
|
|
114
|
-
`;
|
|
115
|
-
}
|
|
116
|
-
/** Renders the opinionated MongoDBCommunity application contract. */
|
|
117
|
-
function createMongoTemplate() {
|
|
118
|
-
return `{{/* Render the opinionated MongoDBCommunity application contract. */}}
|
|
119
|
-
{{- if .Values.mongodb.enabled }}
|
|
120
|
-
apiVersion: mongodbcommunity.mongodb.com/v1
|
|
121
|
-
kind: MongoDBCommunity
|
|
122
|
-
metadata:
|
|
123
|
-
name: mongodb
|
|
124
|
-
{{ with .Values.mongodb.namespace }}
|
|
125
|
-
namespace: {{ . | quote }}
|
|
126
|
-
{{ end }}
|
|
127
|
-
spec:
|
|
128
|
-
members: 1
|
|
129
|
-
type: ReplicaSet
|
|
130
|
-
version: {{ .Values.mongodb.version | quote }}
|
|
131
|
-
security:
|
|
132
|
-
authentication:
|
|
133
|
-
modes:
|
|
134
|
-
- SCRAM
|
|
135
|
-
users:
|
|
136
|
-
- name: app
|
|
137
|
-
db: app
|
|
138
|
-
passwordSecretRef:
|
|
139
|
-
name: mongodb-app-password
|
|
140
|
-
key: password
|
|
141
|
-
roles:
|
|
142
|
-
- name: dbOwner
|
|
143
|
-
db: app
|
|
144
|
-
scramCredentialsSecretName: mongodb-app-scram
|
|
145
|
-
connectionStringSecretName: mongodb-app-connection
|
|
146
|
-
statefulSet:
|
|
147
|
-
spec:
|
|
148
|
-
template:
|
|
149
|
-
spec:
|
|
150
|
-
containers:
|
|
151
|
-
- name: mongod
|
|
152
|
-
resources:
|
|
153
|
-
limits: {}
|
|
154
|
-
requests: {}
|
|
155
|
-
- name: mongodb-agent
|
|
156
|
-
resources:
|
|
157
|
-
limits: {}
|
|
158
|
-
requests: {}
|
|
159
|
-
initContainers:
|
|
160
|
-
- name: mongod-posthook
|
|
161
|
-
resources:
|
|
162
|
-
limits: {}
|
|
163
|
-
requests: {}
|
|
164
|
-
- name: mongodb-agent-readinessprobe
|
|
165
|
-
resources:
|
|
166
|
-
limits: {}
|
|
167
|
-
requests: {}
|
|
168
|
-
volumeClaimTemplates:
|
|
169
|
-
- metadata:
|
|
170
|
-
name: data-volume
|
|
171
|
-
spec:
|
|
172
|
-
accessModes:
|
|
173
|
-
- ReadWriteOnce
|
|
174
|
-
resources:
|
|
175
|
-
requests:
|
|
176
|
-
storage: {{ .Values.mongodb.storage | quote }}
|
|
177
|
-
{{- end }}
|
|
178
|
-
`;
|
|
179
|
-
}
|
|
180
|
-
/** Normalizes dependency values while preserving Helm repository URLs. */
|
|
181
|
-
function normalizeDependencies(dependencies) {
|
|
182
|
-
if (!dependencies)
|
|
183
|
-
return [];
|
|
184
|
-
return dependencies.map((dependency, index) => {
|
|
185
|
-
if (!dependency || typeof dependency !== 'object') {
|
|
186
|
-
throw new Error(`[nx-helm] Dependency ${index} must be an object.`);
|
|
187
|
-
}
|
|
188
|
-
const name = normalizeName(dependency.name, `dependencies[${index}].name`);
|
|
189
|
-
const version = requireValue(dependency.version, `dependencies[${index}].version`);
|
|
190
|
-
const repository = requireValue(dependency.repository, `dependencies[${index}].repository`);
|
|
191
|
-
return {
|
|
192
|
-
name,
|
|
193
|
-
version,
|
|
194
|
-
repository,
|
|
195
|
-
...(dependency.condition?.trim()
|
|
196
|
-
? { condition: dependency.condition.trim() }
|
|
197
|
-
: {}),
|
|
198
|
-
};
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
/** Normalizes an identifier used by the chart and project paths. */
|
|
202
|
-
function normalizeName(value, label) {
|
|
203
|
-
const normalized = (0, devkit_1.names)(requireValue(value, label)).fileName;
|
|
204
|
-
if (!normalized)
|
|
205
|
-
throw new Error(`[nx-helm] A ${label} is required.`);
|
|
206
|
-
return normalized;
|
|
207
|
-
}
|
|
208
|
-
/** Requires a non-empty option. */
|
|
209
|
-
function requireValue(value, label) {
|
|
210
|
-
const normalized = value?.trim();
|
|
211
|
-
if (!normalized)
|
|
212
|
-
throw new Error(`[nx-helm] A ${label} is required.`);
|
|
213
|
-
return normalized;
|
|
214
|
-
}
|
package/src/plugins/plugin.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { type CreateNodes } from '@nx/devkit';
|
|
2
|
-
/** Options for the inferred Helm validation target. */
|
|
3
|
-
export interface HelmValidateTargetOptions {
|
|
4
|
-
/** Target name used for Helm lint and template. */
|
|
5
|
-
target?: string;
|
|
6
|
-
/** Kubernetes version passed to helm template. */
|
|
7
|
-
kubeVersion?: string;
|
|
8
|
-
/** Whether helm lint should fail on warnings. */
|
|
9
|
-
strict?: boolean;
|
|
10
|
-
/** Workspace-wide Helm release name override. */
|
|
11
|
-
releaseName?: string;
|
|
12
|
-
/** Values files passed to helm lint and helm template. */
|
|
13
|
-
validationValues?: string[];
|
|
14
|
-
}
|
|
15
|
-
/** Options for the inferred Helm packaging target. */
|
|
16
|
-
export interface HelmPackageTargetOptions {
|
|
17
|
-
/** Target name used for Helm packaging. */
|
|
18
|
-
target?: string;
|
|
19
|
-
}
|
|
20
|
-
/** Options for inferred Helm publishing. */
|
|
21
|
-
export interface HelmPublishTargetOptions {
|
|
22
|
-
/** OCI registry repository used by inferred Nx Release publishing. */
|
|
23
|
-
registry?: string;
|
|
24
|
-
}
|
|
25
|
-
/** Workspace options for the Helm inferred-target plugin. */
|
|
26
|
-
export interface HelmPluginOptions {
|
|
27
|
-
/** Configuration for the inferred validation target. */
|
|
28
|
-
validate?: HelmValidateTargetOptions;
|
|
29
|
-
/** Configuration for the inferred packaging target. */
|
|
30
|
-
package?: HelmPackageTargetOptions;
|
|
31
|
-
/** Configuration for inferred Nx Release publishing. */
|
|
32
|
-
publish?: HelmPublishTargetOptions;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Infers Helm targets for standalone projects whose root contains Chart.yaml.
|
|
36
|
-
* A sibling project.json identifies the chart as an Nx project.
|
|
37
|
-
*/
|
|
38
|
-
export declare const createNodes: CreateNodes<HelmPluginOptions>;
|
package/src/plugins/plugin.js
DELETED
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = void 0;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const node_fs_1 = require("node:fs");
|
|
6
|
-
const node_path_1 = require("node:path");
|
|
7
|
-
const yaml_1 = require("yaml");
|
|
8
|
-
const chartFilePattern = '**/Chart.yaml';
|
|
9
|
-
const defaultValidateTargetName = 'helm:validate';
|
|
10
|
-
const defaultPackageTargetName = 'helm:package';
|
|
11
|
-
const dependencyBuildTargetName = 'helm:dependency-build';
|
|
12
|
-
const releasePublishTargetName = 'nx-release-publish';
|
|
13
|
-
const defaultKubeVersion = '1.32.0';
|
|
14
|
-
const helmInputs = [
|
|
15
|
-
'{projectRoot}/**/*',
|
|
16
|
-
{ runtime: "helm version --template '{{.Version}}'" },
|
|
17
|
-
];
|
|
18
|
-
/**
|
|
19
|
-
* Infers Helm targets for standalone projects whose root contains Chart.yaml.
|
|
20
|
-
* A sibling project.json identifies the chart as an Nx project.
|
|
21
|
-
*/
|
|
22
|
-
exports.createNodes = [
|
|
23
|
-
chartFilePattern,
|
|
24
|
-
/**
|
|
25
|
-
* Converts matched Chart.yaml files into standalone Helm project targets.
|
|
26
|
-
* @param chartFiles Chart.yaml files matched by Nx.
|
|
27
|
-
* @param options Raw nx.json plugin options.
|
|
28
|
-
* @param context Nx createNodes context.
|
|
29
|
-
* @returns Inferred project configuration contributions.
|
|
30
|
-
*/
|
|
31
|
-
async (chartFiles, options, context) => {
|
|
32
|
-
const normalizedOptions = normalizeOptions(options);
|
|
33
|
-
return (0, devkit_1.createNodesFromFiles)((chartFile, _options, callbackContext) => createNodesInternal(chartFile, normalizedOptions, callbackContext), chartFiles, normalizedOptions, context);
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
/**
|
|
37
|
-
* Builds inferred targets for one Chart.yaml file.
|
|
38
|
-
* @param chartFilePath Chart.yaml path matched by Nx.
|
|
39
|
-
* @param options Normalized plugin options.
|
|
40
|
-
* @param context Nx createNodes context.
|
|
41
|
-
* @returns A project configuration contribution, or an empty result when the
|
|
42
|
-
* chart is not a standalone Nx project.
|
|
43
|
-
*/
|
|
44
|
-
function createNodesInternal(chartFilePath, options, context) {
|
|
45
|
-
const chartRoot = getChartRoot(chartFilePath, context.workspaceRoot);
|
|
46
|
-
if (!chartRoot) {
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
const project = getProject(chartRoot.projectRoot, chartRoot.directory);
|
|
50
|
-
if (!project) {
|
|
51
|
-
return {};
|
|
52
|
-
}
|
|
53
|
-
const validateTargetName = getTargetName(options.validate?.target, defaultValidateTargetName);
|
|
54
|
-
const packageTargetName = getTargetName(options.package?.target, defaultPackageTargetName);
|
|
55
|
-
const outputPath = getPackageOutputPath(chartRoot.projectRoot);
|
|
56
|
-
const dependencies = getChartDependencies(chartRoot.directory, context.workspaceRoot);
|
|
57
|
-
const chartInputs = [...helmInputs, ...dependencies.localInputs];
|
|
58
|
-
const dependencyInputs = [
|
|
59
|
-
'{projectRoot}/Chart.yaml',
|
|
60
|
-
'{projectRoot}/Chart.lock',
|
|
61
|
-
helmInputs[1],
|
|
62
|
-
...dependencies.localInputs,
|
|
63
|
-
];
|
|
64
|
-
const hasDependencies = dependencies.hasDependencies;
|
|
65
|
-
const releaseName = project.metadata.releaseName?.trim() ||
|
|
66
|
-
options.validate?.releaseName?.trim() ||
|
|
67
|
-
project.name;
|
|
68
|
-
const validateOptions = {
|
|
69
|
-
kubeVersion: project.metadata.kubeVersion?.trim() ||
|
|
70
|
-
options.validate?.kubeVersion?.trim() ||
|
|
71
|
-
defaultKubeVersion,
|
|
72
|
-
releaseName,
|
|
73
|
-
strict: project.metadata.strict ?? options.validate?.strict ?? false,
|
|
74
|
-
};
|
|
75
|
-
const validationValues = project.metadata.validationValues ?? options.validate?.validationValues;
|
|
76
|
-
if (validationValues?.length) {
|
|
77
|
-
validateOptions['valuesFiles'] = validationValues;
|
|
78
|
-
}
|
|
79
|
-
const targets = {};
|
|
80
|
-
if (hasDependencies) {
|
|
81
|
-
targets[dependencyBuildTargetName] = {
|
|
82
|
-
executor: 'nx:run-commands',
|
|
83
|
-
cache: true,
|
|
84
|
-
inputs: dependencyInputs,
|
|
85
|
-
outputs: ['{projectRoot}/charts', '{projectRoot}/Chart.lock'],
|
|
86
|
-
options: {
|
|
87
|
-
command: 'helm dependency build --skip-refresh .',
|
|
88
|
-
cwd: chartRoot.projectRoot,
|
|
89
|
-
},
|
|
90
|
-
metadata: {
|
|
91
|
-
technologies: ['helm'],
|
|
92
|
-
description: 'Build local and remote Helm chart dependencies.',
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const dependencyTarget = hasDependencies ? [dependencyBuildTargetName] : [];
|
|
97
|
-
targets[validateTargetName] = {
|
|
98
|
-
executor: '@otwld/nx-helm:validate',
|
|
99
|
-
cache: true,
|
|
100
|
-
...(dependencyTarget.length ? { dependsOn: dependencyTarget } : {}),
|
|
101
|
-
inputs: chartInputs,
|
|
102
|
-
options: validateOptions,
|
|
103
|
-
metadata: {
|
|
104
|
-
technologies: ['helm'],
|
|
105
|
-
description: 'Lint and render the root Helm chart.',
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
targets[packageTargetName] = {
|
|
109
|
-
executor: '@otwld/nx-helm:package',
|
|
110
|
-
cache: true,
|
|
111
|
-
dependsOn: [...dependencyTarget, validateTargetName],
|
|
112
|
-
inputs: chartInputs,
|
|
113
|
-
outputs: [`{workspaceRoot}/${outputPath}`],
|
|
114
|
-
options: {
|
|
115
|
-
outputPath,
|
|
116
|
-
},
|
|
117
|
-
metadata: {
|
|
118
|
-
technologies: ['helm'],
|
|
119
|
-
description: 'Package the root Helm chart.',
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
const registry = normalizeRegistry(project.metadata.registry ?? options.publish?.registry);
|
|
123
|
-
if (registry && project.metadata.publish !== false) {
|
|
124
|
-
targets[releasePublishTargetName] = {
|
|
125
|
-
executor: '@otwld/nx-helm:release-publish',
|
|
126
|
-
dependsOn: [packageTargetName],
|
|
127
|
-
options: { outputPath, registry },
|
|
128
|
-
metadata: {
|
|
129
|
-
technologies: ['helm'],
|
|
130
|
-
description: 'Publish the Helm chart to an OCI registry.',
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
const targetNames = [validateTargetName, packageTargetName];
|
|
135
|
-
if (hasDependencies) {
|
|
136
|
-
targetNames.unshift(dependencyBuildTargetName);
|
|
137
|
-
}
|
|
138
|
-
if (releasePublishTargetName in targets) {
|
|
139
|
-
targetNames.push(releasePublishTargetName);
|
|
140
|
-
}
|
|
141
|
-
assertTargetNamesAreUnique(targetNames);
|
|
142
|
-
return {
|
|
143
|
-
projects: {
|
|
144
|
-
[chartRoot.projectRoot]: {
|
|
145
|
-
root: chartRoot.projectRoot,
|
|
146
|
-
targets,
|
|
147
|
-
metadata: {
|
|
148
|
-
targetGroups: {
|
|
149
|
-
Helm: targetNames,
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Finds declared chart dependencies and workspace-local dependency directories.
|
|
158
|
-
* @param chartDirectory Absolute chart directory.
|
|
159
|
-
* @param workspaceRoot Absolute workspace root.
|
|
160
|
-
* @returns Whether dependencies exist and Nx input globs for local content.
|
|
161
|
-
*/
|
|
162
|
-
function getChartDependencies(chartDirectory, workspaceRoot) {
|
|
163
|
-
const chartFilePath = (0, node_path_1.join)(chartDirectory, 'Chart.yaml');
|
|
164
|
-
const document = (0, yaml_1.parseDocument)((0, node_fs_1.readFileSync)(chartFilePath, 'utf8'), {
|
|
165
|
-
prettyErrors: false,
|
|
166
|
-
});
|
|
167
|
-
if (document.errors.length > 0) {
|
|
168
|
-
throw new Error(`[nx-helm] Chart ${chartFilePath} contains invalid YAML: ${document.errors[0].message}`);
|
|
169
|
-
}
|
|
170
|
-
const manifest = document.toJS();
|
|
171
|
-
const dependencies = manifest.dependencies;
|
|
172
|
-
if (!Array.isArray(dependencies)) {
|
|
173
|
-
return { hasDependencies: false, localInputs: [] };
|
|
174
|
-
}
|
|
175
|
-
const paths = new Set();
|
|
176
|
-
for (const dependency of dependencies) {
|
|
177
|
-
if (!dependency ||
|
|
178
|
-
typeof dependency !== 'object' ||
|
|
179
|
-
Array.isArray(dependency)) {
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
const repository = dependency['repository'];
|
|
183
|
-
if (typeof repository !== 'string' || !repository.startsWith('file://')) {
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
const dependencyPath = (0, node_path_1.resolve)(chartDirectory, decodeURIComponent(repository.slice('file://'.length)));
|
|
187
|
-
const workspacePath = (0, node_path_1.relative)(workspaceRoot, dependencyPath)
|
|
188
|
-
.split(node_path_1.sep)
|
|
189
|
-
.join('/');
|
|
190
|
-
if (!workspacePath ||
|
|
191
|
-
workspacePath === '..' ||
|
|
192
|
-
workspacePath.startsWith('../') ||
|
|
193
|
-
(0, node_path_1.isAbsolute)(workspacePath)) {
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
paths.add(`{workspaceRoot}/${workspacePath}/**/*`);
|
|
197
|
-
}
|
|
198
|
-
return { hasDependencies: dependencies.length > 0, localInputs: [...paths] };
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Resolves a Chart.yaml directory and verifies the standalone project marker.
|
|
202
|
-
* @param chartFilePath Chart.yaml path matched by Nx.
|
|
203
|
-
* @param workspaceRoot Absolute workspace root.
|
|
204
|
-
* @returns Chart root details, or undefined for charts without a sibling
|
|
205
|
-
* project.json.
|
|
206
|
-
*/
|
|
207
|
-
function getChartRoot(chartFilePath, workspaceRoot) {
|
|
208
|
-
const absoluteChartPath = (0, node_path_1.isAbsolute)(chartFilePath)
|
|
209
|
-
? chartFilePath
|
|
210
|
-
: (0, node_path_1.join)(workspaceRoot, chartFilePath);
|
|
211
|
-
const directory = (0, node_path_1.dirname)(absoluteChartPath);
|
|
212
|
-
const projectRoot = toWorkspacePath(directory, workspaceRoot);
|
|
213
|
-
if (!projectRoot || !(0, node_fs_1.existsSync)((0, node_path_1.join)(directory, 'project.json'))) {
|
|
214
|
-
return undefined;
|
|
215
|
-
}
|
|
216
|
-
return { directory, projectRoot };
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Reads project metadata used to configure inferred Helm targets.
|
|
220
|
-
* @param projectRoot Workspace-relative project root.
|
|
221
|
-
* @param projectDirectory Absolute project directory.
|
|
222
|
-
* @returns The project name and Helm metadata, or undefined for invalid input.
|
|
223
|
-
*/
|
|
224
|
-
function getProject(projectRoot, projectDirectory) {
|
|
225
|
-
const projectConfiguration = (0, devkit_1.readJsonFile)((0, node_path_1.join)(projectDirectory, 'project.json'));
|
|
226
|
-
const metadata = readHelmMetadata(projectConfiguration.metadata?.helm);
|
|
227
|
-
if (typeof projectConfiguration.name === 'string') {
|
|
228
|
-
const projectName = projectConfiguration.name.trim();
|
|
229
|
-
if (projectName) {
|
|
230
|
-
return { name: projectName, metadata };
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (projectRoot === '.') {
|
|
234
|
-
return undefined;
|
|
235
|
-
}
|
|
236
|
-
return {
|
|
237
|
-
name: projectRoot.replace(/[\\/\s]+/g, '-').toLowerCase(),
|
|
238
|
-
metadata,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Normalizes optional plugin options while preserving explicit values.
|
|
243
|
-
* @param options Raw nx.json plugin options.
|
|
244
|
-
* @returns Normalized plugin options.
|
|
245
|
-
*/
|
|
246
|
-
function normalizeOptions(options) {
|
|
247
|
-
return {
|
|
248
|
-
validate: {
|
|
249
|
-
...options?.validate,
|
|
250
|
-
target: getTargetName(options?.validate?.target, defaultValidateTargetName),
|
|
251
|
-
},
|
|
252
|
-
package: {
|
|
253
|
-
...options?.package,
|
|
254
|
-
target: getTargetName(options?.package?.target, defaultPackageTargetName),
|
|
255
|
-
},
|
|
256
|
-
publish: { ...options?.publish },
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Resolves a target name while rejecting whitespace-only configuration.
|
|
261
|
-
* @param configuredName Optional configured target name.
|
|
262
|
-
* @param defaultName Fallback target name.
|
|
263
|
-
* @returns A non-empty target name.
|
|
264
|
-
*/
|
|
265
|
-
function getTargetName(configuredName, defaultName) {
|
|
266
|
-
return configuredName?.trim() || defaultName;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Prevents inferred target names from colliding.
|
|
270
|
-
* @param targetNames Inferred target names.
|
|
271
|
-
*/
|
|
272
|
-
function assertTargetNamesAreUnique(targetNames) {
|
|
273
|
-
if (new Set(targetNames).size !== targetNames.length) {
|
|
274
|
-
throw new Error('[nx-helm] Inferred Helm target names must be unique.');
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Reads supported Helm project metadata without exposing arbitrary project data.
|
|
279
|
-
* @param value Potential `metadata.helm` value from project.json.
|
|
280
|
-
* @returns Recognized Helm metadata.
|
|
281
|
-
*/
|
|
282
|
-
function readHelmMetadata(value) {
|
|
283
|
-
if (!isRecord(value)) {
|
|
284
|
-
return {};
|
|
285
|
-
}
|
|
286
|
-
return {
|
|
287
|
-
registry: readString(value['registry']),
|
|
288
|
-
publish: typeof value['publish'] === 'boolean' ? value['publish'] : undefined,
|
|
289
|
-
kubeVersion: readString(value['kubeVersion']),
|
|
290
|
-
strict: typeof value['strict'] === 'boolean' ? value['strict'] : undefined,
|
|
291
|
-
releaseName: readString(value['releaseName']),
|
|
292
|
-
validationValues: readStringArray(value['validationValues']),
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Validates an OCI repository reference for inferred publishing.
|
|
297
|
-
* @param registry Configured registry repository.
|
|
298
|
-
* @returns Normalized OCI repository, or undefined when no valid registry exists.
|
|
299
|
-
*/
|
|
300
|
-
function normalizeRegistry(registry) {
|
|
301
|
-
const normalized = registry?.trim().replace(/\/+$/, '');
|
|
302
|
-
return normalized?.startsWith('oci://') ? normalized : undefined;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Narrows an unknown value to a non-empty string.
|
|
306
|
-
* @param value Value to inspect.
|
|
307
|
-
* @returns Trimmed string, or undefined.
|
|
308
|
-
*/
|
|
309
|
-
function readString(value) {
|
|
310
|
-
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Narrows an unknown value to a string array.
|
|
314
|
-
* @param value Value to inspect.
|
|
315
|
-
* @returns Values array, or undefined for invalid input.
|
|
316
|
-
*/
|
|
317
|
-
function readStringArray(value) {
|
|
318
|
-
return Array.isArray(value) && value.every((item) => typeof item === 'string')
|
|
319
|
-
? value
|
|
320
|
-
: undefined;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Narrows an unknown value to an object record.
|
|
324
|
-
* @param value Value to inspect.
|
|
325
|
-
* @returns Whether the value is a non-null object record.
|
|
326
|
-
*/
|
|
327
|
-
function isRecord(value) {
|
|
328
|
-
return typeof value === 'object' && value !== null;
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Computes the workspace-relative package output directory for a chart.
|
|
332
|
-
* @param projectRoot Workspace-relative chart project root.
|
|
333
|
-
* @returns Workspace-relative package output directory.
|
|
334
|
-
*/
|
|
335
|
-
function getPackageOutputPath(projectRoot) {
|
|
336
|
-
return projectRoot === '.' ? 'dist/helm' : `dist/${projectRoot}/helm`;
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Converts an absolute path to Nx's normalized workspace-relative path.
|
|
340
|
-
* @param directory Absolute directory path.
|
|
341
|
-
* @param workspaceRoot Absolute workspace root.
|
|
342
|
-
* @returns POSIX workspace-relative path.
|
|
343
|
-
*/
|
|
344
|
-
function toWorkspacePath(directory, workspaceRoot) {
|
|
345
|
-
const workspacePath = (0, node_path_1.relative)(workspaceRoot, directory).split(node_path_1.sep).join('/');
|
|
346
|
-
if (workspacePath === '..' ||
|
|
347
|
-
workspacePath.startsWith('../') ||
|
|
348
|
-
workspacePath.length === 0) {
|
|
349
|
-
return workspacePath === '' ? '.' : '';
|
|
350
|
-
}
|
|
351
|
-
return workspacePath;
|
|
352
|
-
}
|