UNPKG

@storm-software/k8s-tools

Version:

Tools for managing Kubernetes (k8s) infrastructure within a Nx workspace.

137 lines (126 loc) 5.36 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunkJSFRUBG5js = require('./chunk-JSFRUBG5.js'); var _chunkXKOZIQT3js = require('./chunk-XKOZIQT3.js'); var _chunkRECJ3G6Fjs = require('./chunk-RECJ3G6F.js'); // src/utils/client.ts var _child_process = require('child_process'); var HelmClient = class extends _chunkJSFRUBG5js.AbstractHelmClient { /** * Creates an instance of HelmClient */ constructor() { super(); } package(options) { let chartPath = void 0; let output = {}; try { output = this.runCommand([ "helm", "package", options.chartFolder, "-d", options.outputFolder ]); } catch (err) { if (_optionalChain([err, 'optionalAccess', _ => _.stderr, 'access', _2 => _2.length]) > 0 && _optionalChain([err, 'optionalAccess', _3 => _3.exitCode]) !== 0) { throw new Error(`Failed to package chart: ${err.stderr}`); } } if (_optionalChain([output, 'optionalAccess', _4 => _4.stderr, 'access', _5 => _5.length]) > 0 && _optionalChain([output, 'optionalAccess', _6 => _6.exitCode]) !== 0) { throw new Error(`Failed to package chart: ${output.stderr}`); } const match = _optionalChain([output, 'access', _7 => _7.stdout, 'optionalAccess', _8 => _8.match, 'call', _9 => _9( /Successfully packaged chart and saved it to: (.+)/ )]); if (!match || match.length < 2) { throw new Error("Failed to parse chart path from helm output"); } chartPath = _optionalChain([match, 'access', _10 => _10[1], 'optionalAccess', _11 => _11.trim, 'call', _12 => _12()]); return new Promise((resolve) => resolve(chartPath)); } push(options) { try { this.runCommand(["helm", "push", options.chartPath, options.remote]); } catch (err) { if (_optionalChain([err, 'optionalAccess', _13 => _13.stderr, 'access', _14 => _14.length]) > 0 && _optionalChain([err, 'optionalAccess', _15 => _15.exitCode]) !== 0) { throw new Error(`Failed to push chart: ${err.stderr}`); } } } dependencyUpdate(chartFolder) { try { this.runCommand(["helm", "dependency", "update", chartFolder]); } catch (err) { if (_optionalChain([err, 'optionalAccess', _16 => _16.stderr, 'access', _17 => _17.length]) > 0 && _optionalChain([err, 'optionalAccess', _18 => _18.exitCode]) !== 0) { throw new Error(`Failed to update chart dependencies: ${err.stderr}`); } } } dependencyBuild(chartFolder) { try { this.runCommand(["helm", "dependency", "build", chartFolder]); } catch (err) { if (_optionalChain([err, 'optionalAccess', _19 => _19.stderr, 'access', _20 => _20.length]) > 0 && _optionalChain([err, 'optionalAccess', _21 => _21.exitCode]) !== 0) { throw new Error(`Failed to build chart dependencies: ${err.stderr}`); } } } addRepository(name, url) { try { this.runCommand(["helm", "repo", "add", name, url]); } catch (err) { if (_optionalChain([err, 'optionalAccess', _22 => _22.stderr, 'access', _23 => _23.length]) > 0 && _optionalChain([err, 'optionalAccess', _24 => _24.exitCode]) !== 0) { throw new Error(`Failed to add repository: ${err.stderr}`); } } } /** * Initialize Helm * * @returns A promise */ async initialize() { if (this.initialized) { return; } try { this.runCommand(["helm", "version"]); } catch (err) { if (_optionalChain([err, 'optionalAccess', _25 => _25.stderr, 'access', _26 => _26.length]) > 0 && _optionalChain([err, 'optionalAccess', _27 => _27.exitCode]) !== 0) { throw new Error(`Helm is not installed: ${err.stderr}`); } } return new Promise((resolve) => { this.initialized = true; resolve(); }); } runCommand(commands) { return _child_process.execSync.call(void 0, commands.filter(Boolean).join(" "), { encoding: "utf8", windowsHide: true, maxBuffer: 1024 * 1e6, stdio: "pipe" }); } }; _chunkRECJ3G6Fjs.__decorateClass.call(void 0, [ _chunkXKOZIQT3js.ensureInitialized ], HelmClient.prototype, "package", 1); _chunkRECJ3G6Fjs.__decorateClass.call(void 0, [ _chunkXKOZIQT3js.ensureInitialized ], HelmClient.prototype, "push", 1); _chunkRECJ3G6Fjs.__decorateClass.call(void 0, [ _chunkXKOZIQT3js.ensureInitialized ], HelmClient.prototype, "dependencyUpdate", 1); _chunkRECJ3G6Fjs.__decorateClass.call(void 0, [ _chunkXKOZIQT3js.ensureInitialized ], HelmClient.prototype, "dependencyBuild", 1); _chunkRECJ3G6Fjs.__decorateClass.call(void 0, [ _chunkXKOZIQT3js.ensureInitialized ], HelmClient.prototype, "addRepository", 1); var createHelmClient = () => { return new HelmClient(); }; exports.HelmClient = HelmClient; exports.createHelmClient = createHelmClient;