@storm-software/k8s-tools 0.28.2 → 0.29.0
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 +26 -0
- package/README.md +1 -1
- package/package.json +15 -39
- package/.eslintrc.json +0 -35
- package/executors.ts +0 -4
- package/generators.ts +0 -4
- package/index.ts +0 -5
- package/project.json +0 -61
- package/src/executors/container-publish/executor.spec.ts +0 -18
- package/src/executors/container-publish/executor.ts +0 -216
- package/src/executors/helm-package/executor.ts +0 -71
- package/src/generators/helm-chart/files/chart/.helmignore +0 -23
- package/src/generators/helm-chart/generator.ts +0 -69
- package/src/generators/helm-dependency/generator.ts +0 -135
- package/src/plugins/docker/_dockerfile.ts +0 -225
- package/src/plugins/docker/index.ts +0 -1
- package/src/plugins/index.ts +0 -1
- package/src/types.ts +0 -37
- package/src/utils/client.ts +0 -141
- package/src/utils/ensure-init.ts +0 -37
- package/src/utils/index.ts +0 -3
- package/src/utils/prettier.ts +0 -62
- package/tsconfig.json +0 -31
- package/tsup.config.ts +0 -26
- /package/{src → dist/src}/executors/container-publish/schema.d.ts +0 -0
- /package/{src → dist/src}/executors/container-publish/schema.json +0 -0
- /package/{src → dist/src}/executors/helm-package/schema.d.ts +0 -0
- /package/{src → dist/src}/executors/helm-package/schema.json +0 -0
- /package/{src → dist/src}/generators/helm-chart/files/chart/Chart.yaml.template +0 -0
- /package/{src → dist/src}/generators/helm-chart/files/chart/templates/NOTES.txt +0 -0
- /package/{src → dist/src}/generators/helm-chart/files/chart/templates/_helpers.yaml +0 -0
- /package/{src → dist/src}/generators/helm-chart/files/chart/templates/deployment.yaml +0 -0
- /package/{src → dist/src}/generators/helm-chart/files/chart/templates/hpa.yaml +0 -0
- /package/{src → dist/src}/generators/helm-chart/files/chart/templates/ingress.yaml +0 -0
- /package/{src → dist/src}/generators/helm-chart/files/chart/templates/service.yaml +0 -0
- /package/{src → dist/src}/generators/helm-chart/files/chart/templates/serviceaccount.yaml +0 -0
- /package/{src → dist/src}/generators/helm-chart/files/chart/templates/test/test-connection.yaml +0 -0
- /package/{src → dist/src}/generators/helm-chart/files/chart/values.yaml +0 -0
- /package/{src → dist/src}/generators/helm-chart/schema.d.ts +0 -0
- /package/{src → dist/src}/generators/helm-chart/schema.json +0 -0
- /package/{src → dist/src}/generators/helm-dependency/schema.d.ts +0 -0
- /package/{src → dist/src}/generators/helm-dependency/schema.json +0 -0
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatFiles,
|
|
3
|
-
ProjectConfiguration,
|
|
4
|
-
readProjectConfiguration,
|
|
5
|
-
Tree,
|
|
6
|
-
updateProjectConfiguration
|
|
7
|
-
} from "@nx/devkit";
|
|
8
|
-
import { StormWorkspaceConfig } from "@storm-software/config";
|
|
9
|
-
import { writeDebug } from "@storm-software/config-tools";
|
|
10
|
-
import { withRunGenerator } from "@storm-software/workspace-tools/base/base-generator";
|
|
11
|
-
import yaml from "js-yaml";
|
|
12
|
-
import type { HelmDependencyGeneratorSchema } from "./schema";
|
|
13
|
-
|
|
14
|
-
export async function helmDependencyGeneratorFn(
|
|
15
|
-
tree: Tree,
|
|
16
|
-
options: HelmDependencyGeneratorSchema,
|
|
17
|
-
config?: StormWorkspaceConfig
|
|
18
|
-
) {
|
|
19
|
-
writeDebug("📝 Preparing to add Helm Dependency", config);
|
|
20
|
-
|
|
21
|
-
const project = readProjectConfiguration(tree, options.project);
|
|
22
|
-
|
|
23
|
-
if (!project.targets?.["helm-package"]) {
|
|
24
|
-
throw new Error(
|
|
25
|
-
`Project ${options.project} does not have a helm target. Please run the chart generator first.`
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
updateProjectConfiguration(
|
|
30
|
-
tree,
|
|
31
|
-
options.project,
|
|
32
|
-
addDependencyToConfig(project, options.repositoryName, options.repository)
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
updateChartYaml(
|
|
36
|
-
tree,
|
|
37
|
-
project,
|
|
38
|
-
options.chartName!,
|
|
39
|
-
options.chartVersion!,
|
|
40
|
-
options.repository
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
if (options.format) {
|
|
44
|
-
await formatFiles(tree);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
success: true
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export default withRunGenerator<HelmDependencyGeneratorSchema>(
|
|
53
|
-
"Helm Dependency",
|
|
54
|
-
helmDependencyGeneratorFn
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
function addDependencyToConfig(
|
|
58
|
-
project: ProjectConfiguration,
|
|
59
|
-
name: string,
|
|
60
|
-
url: string
|
|
61
|
-
): ProjectConfiguration {
|
|
62
|
-
return {
|
|
63
|
-
...project,
|
|
64
|
-
targets: {
|
|
65
|
-
...project.targets,
|
|
66
|
-
helm: {
|
|
67
|
-
...project.targets?.["helm-package"],
|
|
68
|
-
options: {
|
|
69
|
-
...project.targets?.["helm-package"]?.options,
|
|
70
|
-
dependencies: {
|
|
71
|
-
...project.targets?.["helm-package"]?.options.dependencies,
|
|
72
|
-
repositories: project.targets?.["helm-package"]?.options
|
|
73
|
-
.dependencies.repositories
|
|
74
|
-
? [
|
|
75
|
-
...project.targets["helm-package"].options.dependencies
|
|
76
|
-
.repositories,
|
|
77
|
-
{ name: name, url: url }
|
|
78
|
-
]
|
|
79
|
-
: [{ name: name, url: url }]
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function updateChartYaml(
|
|
88
|
-
tree: Tree,
|
|
89
|
-
project: ProjectConfiguration,
|
|
90
|
-
name: string,
|
|
91
|
-
version: string,
|
|
92
|
-
repository: string
|
|
93
|
-
) {
|
|
94
|
-
const chartFolder = project.targets?.["helm-package"]?.options.chartFolder;
|
|
95
|
-
const chartPath = `${chartFolder}/Chart.yaml`;
|
|
96
|
-
|
|
97
|
-
if (!tree.exists(chartPath)) {
|
|
98
|
-
throw new Error("Chart.yaml not found");
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
const result = tree.read(chartPath, "utf8")?.toString();
|
|
103
|
-
if (!result) {
|
|
104
|
-
throw new Error("Failed to read Chart.yaml");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const chartContents = yaml.load(result) as {
|
|
108
|
-
dependencies: { name: string; version: string; repository: string }[];
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
if (!chartContents.dependencies) {
|
|
112
|
-
chartContents.dependencies = [];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const existingDependency = chartContents.dependencies.find(
|
|
116
|
-
dep => dep.name === name
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
if (existingDependency) {
|
|
120
|
-
existingDependency.version = version;
|
|
121
|
-
existingDependency.repository = repository;
|
|
122
|
-
} else {
|
|
123
|
-
chartContents.dependencies.push({
|
|
124
|
-
name: name,
|
|
125
|
-
version: version,
|
|
126
|
-
repository: repository
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
tree.write(chartPath, yaml.dump(chartContents));
|
|
130
|
-
}
|
|
131
|
-
} catch (error) {
|
|
132
|
-
console.error(error);
|
|
133
|
-
throw new Error("Failed to parse Chart.yaml");
|
|
134
|
-
}
|
|
135
|
-
}
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CreateNodesContext,
|
|
3
|
-
joinPathFragments,
|
|
4
|
-
ProjectGraphExternalNode,
|
|
5
|
-
readJsonFile,
|
|
6
|
-
type CreateDependencies,
|
|
7
|
-
type CreateNodes,
|
|
8
|
-
type ProjectConfiguration,
|
|
9
|
-
} from "@nx/devkit";
|
|
10
|
-
import { getConfig } from "@storm-software/config-tools/get-config";
|
|
11
|
-
import { findWorkspaceRoot } from "@storm-software/config-tools/utilities/find-workspace-root";
|
|
12
|
-
import { getPackageInfo } from "@storm-software/workspace-tools/utils/package-helpers";
|
|
13
|
-
import {
|
|
14
|
-
hasProjectTag,
|
|
15
|
-
isEqualProjectTag,
|
|
16
|
-
ProjectTagConstants,
|
|
17
|
-
setDefaultProjectTags,
|
|
18
|
-
} from "@storm-software/workspace-tools/utils/project-tags";
|
|
19
|
-
import { CargoToml } from "@storm-software/workspace-tools/utils/toml";
|
|
20
|
-
import { existsSync } from "node:fs";
|
|
21
|
-
import type { ExternalContainerExecutorSchema } from "../../executors/container-publish/schema";
|
|
22
|
-
|
|
23
|
-
export const name = "storm-software/docker";
|
|
24
|
-
export const description = "Plugin for parsing Dockerfile files";
|
|
25
|
-
|
|
26
|
-
export interface DockerFilePluginOptions {
|
|
27
|
-
defaultEngine?: ExternalContainerExecutorSchema["engine"];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const createNodes: CreateNodes<DockerFilePluginOptions> = [
|
|
31
|
-
"*/**/{Dockerfile,Dockerfile.*}",
|
|
32
|
-
async (
|
|
33
|
-
dockerFilePath: string,
|
|
34
|
-
opts: DockerFilePluginOptions = {
|
|
35
|
-
defaultEngine: "docker",
|
|
36
|
-
},
|
|
37
|
-
_: CreateNodesContext,
|
|
38
|
-
) => {
|
|
39
|
-
if (!dockerFilePath) {
|
|
40
|
-
return {};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const root = dockerFilePath.substring(dockerFilePath.lastIndexOf("/") + 1);
|
|
44
|
-
const projectJsonPath = joinPathFragments(root, "project.json");
|
|
45
|
-
if (!existsSync(projectJsonPath)) {
|
|
46
|
-
return {};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const projectJson = readJsonFile<ProjectConfiguration>(projectJsonPath);
|
|
50
|
-
if (projectJson?.name) {
|
|
51
|
-
return {};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const workspaceRoot = findWorkspaceRoot();
|
|
55
|
-
const config = await getConfig(workspaceRoot);
|
|
56
|
-
|
|
57
|
-
Object.keys(projectJson).forEach((key) => {
|
|
58
|
-
if (!project[key]) {
|
|
59
|
-
project[key] = projectJson[key];
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const project: ProjectConfiguration = {
|
|
64
|
-
root,
|
|
65
|
-
name: projectJson?.name,
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const engine = opts.defaultEngine ?? "docker";
|
|
69
|
-
const labels = [
|
|
70
|
-
`org.opencontainers.image.ref.name=${project.name}`,
|
|
71
|
-
`org.opencontainers.image.title=${titleCase(project.name)}`,
|
|
72
|
-
`org.opencontainers.image.authors=${config.organization ? titleCase(config.organization) : "Storm Software"}`,
|
|
73
|
-
`org.opencontainers.image.vendor=${config.organization ? titleCase(config.organization) : "Storm Software"}`,
|
|
74
|
-
`org.opencontainers.image.documentation=${config.docs}`,
|
|
75
|
-
`org.opencontainers.image.url=${config.homepage}`,
|
|
76
|
-
`org.opencontainers.image.source=${config.repository}`,
|
|
77
|
-
];
|
|
78
|
-
let tag = "latest";
|
|
79
|
-
|
|
80
|
-
const packageManager = getPackageInfo(project);
|
|
81
|
-
if (packageManager) {
|
|
82
|
-
if (packageManager.type === "Cargo.toml") {
|
|
83
|
-
tag = (packageManager.content as CargoToml).package.version;
|
|
84
|
-
labels.push(
|
|
85
|
-
`org.opencontainers.image.description=${(packageManager.content as CargoToml).package.description}`,
|
|
86
|
-
);
|
|
87
|
-
} else if (packageManager.type === "package.json") {
|
|
88
|
-
tag = packageManager.content.version;
|
|
89
|
-
labels.push(
|
|
90
|
-
`org.opencontainers.image.description=${packageManager.content.description}`,
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
project.targets = {
|
|
96
|
-
...project.targets,
|
|
97
|
-
container: {
|
|
98
|
-
executor: "@nx-tools/nx-container:build",
|
|
99
|
-
options: {
|
|
100
|
-
file: dockerFilePath,
|
|
101
|
-
engine,
|
|
102
|
-
labels,
|
|
103
|
-
push: true,
|
|
104
|
-
platforms: ["linux/amd64"],
|
|
105
|
-
metadata: {
|
|
106
|
-
images: [
|
|
107
|
-
`${config.namespace ? config.namespace : "storm-software"}/${project.name?.replace(`${config.namespace}-`, "")}`,
|
|
108
|
-
`ghcr.io/${config.organization ? config.organization : "storm-software"}/${project.name}`,
|
|
109
|
-
],
|
|
110
|
-
tags: [
|
|
111
|
-
"type=schedule",
|
|
112
|
-
"type=ref,event=branch",
|
|
113
|
-
"type=ref,event=tag",
|
|
114
|
-
"type=ref,event=pr",
|
|
115
|
-
"type=semver,pattern={{version}}",
|
|
116
|
-
"type=semver,pattern={{major}}.{{minor}}",
|
|
117
|
-
"type=semver,pattern={{major}}",
|
|
118
|
-
"type=sha",
|
|
119
|
-
],
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
defaultConfiguration: "production",
|
|
123
|
-
configurations: {
|
|
124
|
-
development: {
|
|
125
|
-
quiet: false,
|
|
126
|
-
"build-args": [
|
|
127
|
-
"ENVIRONMENT=development",
|
|
128
|
-
"DEBUG_IMAGE=true",
|
|
129
|
-
`RELEASE=${tag}`,
|
|
130
|
-
],
|
|
131
|
-
},
|
|
132
|
-
production: {
|
|
133
|
-
quiet: true,
|
|
134
|
-
"build-args": [
|
|
135
|
-
"ENVIRONMENT=production",
|
|
136
|
-
"DEBUG_IMAGE=false",
|
|
137
|
-
`RELEASE=${tag}`,
|
|
138
|
-
],
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
(isEqualProjectTag(
|
|
146
|
-
project,
|
|
147
|
-
ProjectTagConstants.ProjectType.TAG_ID,
|
|
148
|
-
ProjectTagConstants.ProjectType.APPLICATION,
|
|
149
|
-
) ||
|
|
150
|
-
project.projectType === "application") &&
|
|
151
|
-
hasProjectTag(project, ProjectTagConstants.Registry.TAG_ID)
|
|
152
|
-
) {
|
|
153
|
-
if (project.targets["nx-release-publish"]) {
|
|
154
|
-
project.targets["nx-release-publish"] = {
|
|
155
|
-
...project.targets["nx-release-publish"],
|
|
156
|
-
executor: "@storm-software/k8s-tools:container-publish",
|
|
157
|
-
options: {
|
|
158
|
-
packageRoot: project.root,
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
} else {
|
|
162
|
-
project.targets["nx-release-publish"] = {
|
|
163
|
-
cache: true,
|
|
164
|
-
inputs: [
|
|
165
|
-
"linting",
|
|
166
|
-
"testing",
|
|
167
|
-
"documentation",
|
|
168
|
-
"rust",
|
|
169
|
-
"^production",
|
|
170
|
-
],
|
|
171
|
-
dependsOn: ["build", "^nx-release-publish"],
|
|
172
|
-
executor: "@storm-software/k8s-tools:container-publish",
|
|
173
|
-
options: {
|
|
174
|
-
packageRoot: project.root,
|
|
175
|
-
},
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
setDefaultProjectTags(project);
|
|
181
|
-
|
|
182
|
-
const projects: Record<string, ProjectConfiguration> = {};
|
|
183
|
-
const externalNodes: Record<string, ProjectGraphExternalNode> = {};
|
|
184
|
-
|
|
185
|
-
projects[project.root] = {
|
|
186
|
-
...project,
|
|
187
|
-
release: {
|
|
188
|
-
...project.release,
|
|
189
|
-
version: {
|
|
190
|
-
...project.release?.version,
|
|
191
|
-
generator: "@storm-software/workspace-tools:release-version",
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
projects,
|
|
198
|
-
externalNodes,
|
|
199
|
-
};
|
|
200
|
-
},
|
|
201
|
-
];
|
|
202
|
-
|
|
203
|
-
export const createDependencies: CreateDependencies = (_, context) => {
|
|
204
|
-
return [];
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
const titleCase = (input?: string): string | undefined => {
|
|
208
|
-
if (!input) {
|
|
209
|
-
return "";
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return (
|
|
213
|
-
input
|
|
214
|
-
// eslint-disable-next-line no-useless-escape
|
|
215
|
-
.split(/(?=[A-Z])|[\.\-\s_]/)
|
|
216
|
-
.map((s) => s.trim())
|
|
217
|
-
.filter((s) => !!s)
|
|
218
|
-
.map((s) =>
|
|
219
|
-
s
|
|
220
|
-
? s.toLowerCase().charAt(0).toUpperCase() + s.toLowerCase().slice(1)
|
|
221
|
-
: s,
|
|
222
|
-
)
|
|
223
|
-
.join(" ")
|
|
224
|
-
);
|
|
225
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./_dockerfile";
|
package/src/plugins/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./docker";
|
package/src/types.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Options } from "prettier";
|
|
2
|
-
/** Types for the core library */
|
|
3
|
-
|
|
4
|
-
/** Interface for objects that can be initialized */
|
|
5
|
-
export interface Initializable {
|
|
6
|
-
initialized: boolean;
|
|
7
|
-
initialize(): Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/** Options for packaging a chart */
|
|
11
|
-
export interface PackageOptions {
|
|
12
|
-
chartFolder: string;
|
|
13
|
-
outputFolder: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** Options for pushing a chart */
|
|
17
|
-
export interface PushOptions {
|
|
18
|
-
chartPath: string;
|
|
19
|
-
remote: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Abstract class for Helm */
|
|
23
|
-
export abstract class AbstractHelmClient implements Initializable {
|
|
24
|
-
initialized = false;
|
|
25
|
-
|
|
26
|
-
abstract package(options: PackageOptions): Promise<string | undefined>;
|
|
27
|
-
|
|
28
|
-
async initialize(): Promise<void> {
|
|
29
|
-
throw new Error("Method not implemented.");
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Represents an Prettier ignore file. */
|
|
34
|
-
export interface PrettierConfig {
|
|
35
|
-
sourceFilepath: string;
|
|
36
|
-
config: Options;
|
|
37
|
-
}
|
package/src/utils/client.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { execSync } from "node:child_process";
|
|
2
|
-
import type { PackageOptions, PushOptions } from "../types";
|
|
3
|
-
import { AbstractHelmClient } from "../types";
|
|
4
|
-
import { ensureInitialized } from "./ensure-init";
|
|
5
|
-
|
|
6
|
-
/** Helm wrapper class */
|
|
7
|
-
export class HelmClient extends AbstractHelmClient {
|
|
8
|
-
/**
|
|
9
|
-
* Creates an instance of HelmClient
|
|
10
|
-
*/
|
|
11
|
-
public constructor() {
|
|
12
|
-
super();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Package a chart directory into a chart archive
|
|
17
|
-
*
|
|
18
|
-
* @param {PackageOptions} [options]
|
|
19
|
-
*/
|
|
20
|
-
@ensureInitialized
|
|
21
|
-
public package(options: PackageOptions): Promise<string | undefined> {
|
|
22
|
-
let chartPath: string | undefined = undefined;
|
|
23
|
-
|
|
24
|
-
let output = {} as any;
|
|
25
|
-
try {
|
|
26
|
-
output = this.runCommand([
|
|
27
|
-
"helm",
|
|
28
|
-
"package",
|
|
29
|
-
options.chartFolder,
|
|
30
|
-
"-d",
|
|
31
|
-
options.outputFolder,
|
|
32
|
-
]);
|
|
33
|
-
} catch (err) {
|
|
34
|
-
if (err?.stderr.length > 0 && err?.exitCode !== 0) {
|
|
35
|
-
throw new Error(`Failed to package chart: ${err.stderr}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (output?.stderr.length > 0 && output?.exitCode !== 0) {
|
|
40
|
-
throw new Error(`Failed to package chart: ${output.stderr}`);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const match = output.stdout?.match(
|
|
44
|
-
/Successfully packaged chart and saved it to: (.+)/,
|
|
45
|
-
);
|
|
46
|
-
if (!match || match.length < 2) {
|
|
47
|
-
throw new Error("Failed to parse chart path from helm output");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
chartPath = match[1]?.trim();
|
|
51
|
-
|
|
52
|
-
return new Promise((resolve) => resolve(chartPath));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@ensureInitialized
|
|
56
|
-
public push(options: PushOptions) {
|
|
57
|
-
try {
|
|
58
|
-
this.runCommand(["helm", "push", options.chartPath, options.remote]);
|
|
59
|
-
} catch (err) {
|
|
60
|
-
if (err?.stderr.length > 0 && err?.exitCode !== 0) {
|
|
61
|
-
throw new Error(`Failed to push chart: ${err.stderr}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@ensureInitialized
|
|
67
|
-
public dependencyUpdate(chartFolder: string) {
|
|
68
|
-
try {
|
|
69
|
-
this.runCommand(["helm", "dependency", "update", chartFolder]);
|
|
70
|
-
} catch (err) {
|
|
71
|
-
if (err?.stderr.length > 0 && err?.exitCode !== 0) {
|
|
72
|
-
throw new Error(`Failed to update chart dependencies: ${err.stderr}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
@ensureInitialized
|
|
78
|
-
public dependencyBuild(chartFolder: string) {
|
|
79
|
-
try {
|
|
80
|
-
this.runCommand(["helm", "dependency", "build", chartFolder]);
|
|
81
|
-
} catch (err) {
|
|
82
|
-
if (err?.stderr.length > 0 && err?.exitCode !== 0) {
|
|
83
|
-
throw new Error(`Failed to build chart dependencies: ${err.stderr}`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
@ensureInitialized
|
|
89
|
-
public addRepository(name: string, url: string) {
|
|
90
|
-
try {
|
|
91
|
-
this.runCommand(["helm", "repo", "add", name, url]);
|
|
92
|
-
} catch (err) {
|
|
93
|
-
if (err?.stderr.length > 0 && err?.exitCode !== 0) {
|
|
94
|
-
throw new Error(`Failed to add repository: ${err.stderr}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Initialize Helm
|
|
101
|
-
*
|
|
102
|
-
* @returns A promise
|
|
103
|
-
*/
|
|
104
|
-
public override async initialize(): Promise<void> {
|
|
105
|
-
if (this.initialized) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
this.runCommand(["helm", "version"]);
|
|
111
|
-
} catch (err) {
|
|
112
|
-
if (err?.stderr.length > 0 && err?.exitCode !== 0) {
|
|
113
|
-
throw new Error(`Helm is not installed: ${err.stderr}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return new Promise<void>((resolve) => {
|
|
118
|
-
this.initialized = true;
|
|
119
|
-
|
|
120
|
-
resolve();
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private runCommand(commands: string[]): string {
|
|
125
|
-
return execSync(commands.filter(Boolean).join(" "), {
|
|
126
|
-
encoding: "utf8",
|
|
127
|
-
windowsHide: true,
|
|
128
|
-
maxBuffer: 1024 * 1000000,
|
|
129
|
-
stdio: "pipe",
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Create a new Helm client instance
|
|
136
|
-
*
|
|
137
|
-
* @returns {HelmClient}
|
|
138
|
-
*/
|
|
139
|
-
export const createHelmClient = (): HelmClient => {
|
|
140
|
-
return new HelmClient();
|
|
141
|
-
};
|
package/src/utils/ensure-init.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Initializable } from "../types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Decorator to ensure the class is initialized before executing a method
|
|
5
|
-
*
|
|
6
|
-
* @param {any} target
|
|
7
|
-
* @param {string} propertyKey
|
|
8
|
-
* @param {PropertyDescriptor} descriptor
|
|
9
|
-
* @returns {PropertyDescriptor}
|
|
10
|
-
*/
|
|
11
|
-
export const ensureInitialized = (
|
|
12
|
-
target: any,
|
|
13
|
-
propertyKey: string,
|
|
14
|
-
descriptor: PropertyDescriptor,
|
|
15
|
-
): PropertyDescriptor => {
|
|
16
|
-
const originalMethod = descriptor.value;
|
|
17
|
-
descriptor.value = async function (...arguments_: any[]) {
|
|
18
|
-
const self = this as Initializable;
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
self.initialized === undefined ||
|
|
22
|
-
typeof self.initialize !== "function"
|
|
23
|
-
) {
|
|
24
|
-
throw new TypeError(
|
|
25
|
-
`The ensureInitialized decorator can only be applied in classes with an 'initialized' property and 'initialize' method.`,
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!self.initialized) {
|
|
30
|
-
await self.initialize();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return originalMethod.apply(this, arguments_);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return descriptor;
|
|
37
|
-
};
|
package/src/utils/index.ts
DELETED
package/src/utils/prettier.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Tree } from "@nx/devkit";
|
|
2
|
-
import { PrettierConfig } from "../types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Resolves the existing Prettier configuration.
|
|
6
|
-
*
|
|
7
|
-
* @returns The Prettier configuration or undefined if not found.
|
|
8
|
-
*/
|
|
9
|
-
export async function resolveUserExistingPrettierConfig(): Promise<
|
|
10
|
-
PrettierConfig | undefined
|
|
11
|
-
> {
|
|
12
|
-
let prettier: typeof import("prettier");
|
|
13
|
-
try {
|
|
14
|
-
prettier = require("prettier");
|
|
15
|
-
} catch {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (!prettier) {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
try {
|
|
23
|
-
const filepath = await prettier.resolveConfigFile();
|
|
24
|
-
if (!filepath) {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const config = await prettier.resolveConfig(process.cwd(), {
|
|
29
|
-
useCache: false,
|
|
30
|
-
config: filepath,
|
|
31
|
-
});
|
|
32
|
-
if (!config) {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
sourceFilepath: filepath,
|
|
38
|
-
config: config,
|
|
39
|
-
};
|
|
40
|
-
} catch {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function addToPrettierIgnore(tree: Tree, ignore: string[]) {
|
|
46
|
-
const ignorePath = `${tree.root}/.prettierignore`;
|
|
47
|
-
|
|
48
|
-
if (!tree.exists(ignorePath)) {
|
|
49
|
-
tree.write(ignorePath, ignore.join("\n"));
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
const content = tree.read(ignorePath, "utf8") || "";
|
|
55
|
-
const lines = content.split("\n");
|
|
56
|
-
// Remove duplicates
|
|
57
|
-
const newContent = [...new Set([...lines, ...ignore])].join("\n");
|
|
58
|
-
tree.write(ignorePath, newContent);
|
|
59
|
-
} catch (error: unknown) {
|
|
60
|
-
throw new Error(`Failed to update .prettierignore file: ${String(error)}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc",
|
|
5
|
-
"rootDir": "../..",
|
|
6
|
-
"target": "ESNext",
|
|
7
|
-
"module": "ESNext",
|
|
8
|
-
"lib": ["ESNext"],
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"skipDefaultLibCheck": true,
|
|
11
|
-
"moduleResolution": "Bundler",
|
|
12
|
-
"moduleDetection": "force",
|
|
13
|
-
"types": ["node"]
|
|
14
|
-
},
|
|
15
|
-
"include": [
|
|
16
|
-
"executors.ts",
|
|
17
|
-
"generators.ts",
|
|
18
|
-
"index.ts",
|
|
19
|
-
"src/**/*.ts",
|
|
20
|
-
"src/**/*.d.ts",
|
|
21
|
-
"src/**/*.json",
|
|
22
|
-
"tsup.config.ts"
|
|
23
|
-
],
|
|
24
|
-
"exclude": [
|
|
25
|
-
"jest.config.ts",
|
|
26
|
-
"src/generators/**/files/**/*",
|
|
27
|
-
"src/**/untyped.ts",
|
|
28
|
-
"src/**/*.spec.ts",
|
|
29
|
-
"src/**/*.test.ts"
|
|
30
|
-
]
|
|
31
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsup";
|
|
2
|
-
|
|
3
|
-
export default defineConfig([
|
|
4
|
-
{
|
|
5
|
-
name: "k8s-tools",
|
|
6
|
-
target: "node22",
|
|
7
|
-
entryPoints: [
|
|
8
|
-
"./*.ts",
|
|
9
|
-
"./src/types.ts",
|
|
10
|
-
"./src/utils/*.ts",
|
|
11
|
-
"./src/executors/*/executor.ts",
|
|
12
|
-
"./src/generators/*/generator.ts",
|
|
13
|
-
"./src/plugins/docker/index.ts",
|
|
14
|
-
],
|
|
15
|
-
outDir: "dist",
|
|
16
|
-
format: ["cjs", "esm"],
|
|
17
|
-
platform: "node",
|
|
18
|
-
splitting: true,
|
|
19
|
-
clean: true,
|
|
20
|
-
dts: true,
|
|
21
|
-
sourcemap: false,
|
|
22
|
-
shims: true,
|
|
23
|
-
tsconfig: "./tsconfig.json",
|
|
24
|
-
external: ["@storm-software/workspace-tools"],
|
|
25
|
-
},
|
|
26
|
-
]);
|