UNPKG

@storm-software/k8s-tools

Version:

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

203 lines (179 loc) 8.31 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 _chunk5KOGMQTWjs = require('./chunk-5KOGMQTW.js'); var _chunkPJSA4K3Hjs = require('./chunk-PJSA4K3H.js'); var _chunk4AADQIGWjs = require('./chunk-4AADQIGW.js'); // ../workspace-tools/src/base/base-executor.ts var _defu = require('defu'); var withRunExecutor = (name, executorFn, executorOptions = {}) => async (_options, context) => { const stopwatch = _chunkPJSA4K3Hjs.getStopwatch.call(void 0, name); let options = _options; let config = {}; try { if (!_optionalChain([context, 'access', _ => _.projectsConfigurations, 'optionalAccess', _2 => _2.projects]) || !context.projectName || !context.projectsConfigurations.projects[context.projectName]) { throw new Error( "The Build process failed because the context is not valid. Please run this command from a workspace." ); } const workspaceRoot = _chunkPJSA4K3Hjs.findWorkspaceRoot.call(void 0, ); const projectRoot = context.projectsConfigurations.projects[context.projectName].root || workspaceRoot; const sourceRoot = context.projectsConfigurations.projects[context.projectName].sourceRoot || projectRoot || workspaceRoot; const projectName = context.projectName; config.workspaceRoot = workspaceRoot; _chunkPJSA4K3Hjs.writeInfo.call(void 0, `${_chunkPJSA4K3Hjs.brandIcon.call(void 0, config)} Running the ${name} executor for ${projectName} `, config ); if (!executorOptions.skipReadingConfig) { _chunkPJSA4K3Hjs.writeTrace.call(void 0, `Loading the Storm Config from environment variables and storm.config.js file... - workspaceRoot: ${workspaceRoot} - projectRoot: ${projectRoot} - sourceRoot: ${sourceRoot} - projectName: ${projectName} `, config ); config = await _chunkPJSA4K3Hjs.getConfig.call(void 0, workspaceRoot); } if (_optionalChain([executorOptions, 'optionalAccess', _3 => _3.hooks, 'optionalAccess', _4 => _4.applyDefaultOptions])) { _chunkPJSA4K3Hjs.writeDebug.call(void 0, "Running the applyDefaultOptions hook...", config); options = await Promise.resolve( executorOptions.hooks.applyDefaultOptions(options, config) ); _chunkPJSA4K3Hjs.writeDebug.call(void 0, "Completed the applyDefaultOptions hook", config); } _chunkPJSA4K3Hjs.writeTrace.call(void 0, `Executor schema options \u2699\uFE0F ${_chunkPJSA4K3Hjs.formatLogMessage.call(void 0, options)} `, config ); const tokenized = await _chunk5KOGMQTWjs.applyWorkspaceTokens.call(void 0, options, _defu.defu.call(void 0, { workspaceRoot, projectRoot, sourceRoot, projectName, config }, config, context.projectsConfigurations.projects[context.projectName] ), _chunk5KOGMQTWjs.applyWorkspaceProjectTokens ); _chunkPJSA4K3Hjs.writeTrace.call(void 0, `Executor schema tokenized options \u2699\uFE0F ${_chunkPJSA4K3Hjs.formatLogMessage.call(void 0, tokenized)} `, config ); if (_optionalChain([executorOptions, 'optionalAccess', _5 => _5.hooks, 'optionalAccess', _6 => _6.preProcess])) { _chunkPJSA4K3Hjs.writeDebug.call(void 0, "Running the preProcess hook...", config); await Promise.resolve( executorOptions.hooks.preProcess(tokenized, config) ); _chunkPJSA4K3Hjs.writeDebug.call(void 0, "Completed the preProcess hook", config); } const ret = executorFn(tokenized, context, config); if (_isFunction(_optionalChain([ret, 'optionalAccess', _7 => _7.next]))) { const asyncGen = ret; for await (const iter of asyncGen) { void iter; } } const result = await Promise.resolve( ret ); if (result && (!result.success || result.error && _optionalChain([result, 'optionalAccess', _8 => _8.error, 'optionalAccess', _9 => _9.message]) && typeof _optionalChain([result, 'optionalAccess', _10 => _10.error, 'optionalAccess', _11 => _11.message]) === "string" && _optionalChain([result, 'optionalAccess', _12 => _12.error, 'optionalAccess', _13 => _13.name]) && typeof _optionalChain([result, 'optionalAccess', _14 => _14.error, 'optionalAccess', _15 => _15.name]) === "string")) { throw new Error( `Failure determined while running the ${name} executor ${_chunkPJSA4K3Hjs.formatLogMessage.call(void 0, result )}`, { cause: _optionalChain([result, 'optionalAccess', _16 => _16.error]) } ); } if (_optionalChain([executorOptions, 'optionalAccess', _17 => _17.hooks, 'optionalAccess', _18 => _18.postProcess])) { _chunkPJSA4K3Hjs.writeDebug.call(void 0, "Running the postProcess hook...", config); await Promise.resolve(executorOptions.hooks.postProcess(config)); _chunkPJSA4K3Hjs.writeDebug.call(void 0, "Completed the postProcess hook", config); } _chunkPJSA4K3Hjs.writeSuccess.call(void 0, `Completed running the ${name} task executor! `, config); return { success: true }; } catch (error) { _chunkPJSA4K3Hjs.writeFatal.call(void 0, "A fatal error occurred while running the executor - the process was forced to terminate", config ); _chunkPJSA4K3Hjs.writeError.call(void 0, `An exception was thrown in the executor's process - Details: ${error.message} - Stacktrace: ${error.stack}`, config ); return { success: false }; } finally { stopwatch(); } }; var _isFunction = (value) => { try { return value instanceof Function || typeof value === "function" || !!(_optionalChain([value, 'optionalAccess', _19 => _19.constructor]) && _optionalChain([value, 'optionalAccess', _20 => _20.call]) && _optionalChain([value, 'optionalAccess', _21 => _21.apply])); } catch (e) { return false; } }; // src/executors/helm-package/executor.ts async function serveExecutor(options, context, config) { if (!_optionalChain([context, 'optionalAccess', _22 => _22.projectName]) || !_optionalChain([context, 'optionalAccess', _23 => _23.projectsConfigurations, 'optionalAccess', _24 => _24.projects, 'optionalAccess', _25 => _25[context.projectName], 'optionalAccess', _26 => _26.root])) { throw new Error("Nx executor context was invalid"); } const helm = _chunk4AADQIGWjs.createHelmClient.call(void 0, ); if (_optionalChain([options, 'access', _27 => _27.dependencies, 'optionalAccess', _28 => _28.repositories])) { for (const repository of options.dependencies.repositories) { if (repository.name && repository.url) { helm.addRepository(repository.name, repository.url); } else { throw new Error("Repository name and url are required"); } } } if (_optionalChain([options, 'access', _29 => _29.dependencies, 'optionalAccess', _30 => _30.update])) { helm.dependencyUpdate(options.chartFolder); } if (_optionalChain([options, 'access', _31 => _31.dependencies, 'optionalAccess', _32 => _32.build])) { helm.dependencyBuild(options.chartFolder); } const chartPath = await helm.package({ chartFolder: options.chartFolder, outputFolder: options.outputFolder }); if (options.push && chartPath && options.remote) { helm.push({ chartPath, remote: options.remote }); } else { _chunkPJSA4K3Hjs.writeWarning.call(void 0, `Chart packaged at: ${chartPath}`, config); } return { success: true }; } var executor_default = withRunExecutor( "Helm Chart Package executor", serveExecutor, { skipReadingConfig: false, hooks: { applyDefaultOptions: (options) => { options.port ??= 4500; return options; } } } ); exports.serveExecutor = serveExecutor; exports.executor_default = executor_default;