UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

89 lines 5.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getServiceDeleteScript = exports.getServiceDeployScript = void 0; const getLabels_1 = require("../../../context/getLabels"); const createArgsString_1 = require("../utils/createArgsString"); const getJobOrServiceArgs_1 = require("../utils/getJobOrServiceArgs"); const getServiceName_1 = require("../utils/getServiceName"); const common_1 = require("./common"); const constants_1 = require("./constants"); const healthCheck_1 = require("./healthCheck"); const volumes_1 = require("./volumes"); const getServiceDeployScript = (context, service, nameSuffix) => { var _a, _b, _c, _d, _e, _f; const commonDeployArgs = (0, common_1.getCommonDeployArgs)(context); const serviceName = (0, getServiceName_1.getServiceName)(context); const customConfig = service !== true ? service : undefined; const command = service !== true ? ((_a = service === null || service === void 0 ? void 0 : service.command) !== null && _a !== void 0 ? _a : (context.build.type !== "disabled" ? context.build.config.startCommand : undefined)) : undefined; const commandArray = command ? Array.isArray(command) ? command : command.split(" ") : undefined; const fullServiceName = serviceName.concat(nameSuffix !== null && nameSuffix !== void 0 ? nameSuffix : ""); const argsString = (0, createArgsString_1.createArgsString)({ // command as empty string resets it to default (uses the image's entrypoint) command: commandArray ? '"' + commandArray.join(",") + '"' : '""', args: (0, getJobOrServiceArgs_1.getCloudRunServiceOrJobArgsArg)(customConfig === null || customConfig === void 0 ? void 0 : customConfig.args), ...commonDeployArgs, image: (_b = customConfig === null || customConfig === void 0 ? void 0 : customConfig.image) !== null && _b !== void 0 ? _b : commonDeployArgs.image, labels: (0, common_1.makeLabelString)({ ...(0, getLabels_1.getLabels)(context), "cloud-run-service-name": fullServiceName, }), "env-vars-file": constants_1.ENV_VARS_FILENAME, "min-instances": (_c = customConfig === null || customConfig === void 0 ? void 0 : customConfig.minInstances) !== null && _c !== void 0 ? _c : 0, "max-instances": (_d = customConfig === null || customConfig === void 0 ? void 0 : customConfig.maxInstances) !== null && _d !== void 0 ? _d : 100, "cpu-throttling": (customConfig === null || customConfig === void 0 ? void 0 : customConfig.noCpuThrottling) !== true, cpu: customConfig === null || customConfig === void 0 ? void 0 : customConfig.cpu, memory: customConfig === null || customConfig === void 0 ? void 0 : customConfig.memory, timeout: customConfig === null || customConfig === void 0 ? void 0 : customConfig.timeout, "vpc-connector": customConfig === null || customConfig === void 0 ? void 0 : customConfig.vpcConnector, "vpc-egress": customConfig === null || customConfig === void 0 ? void 0 : customConfig.vpcEgress, network: customConfig === null || customConfig === void 0 ? void 0 : customConfig.network, subnet: customConfig === null || customConfig === void 0 ? void 0 : customConfig.subnet, "use-http2": customConfig === null || customConfig === void 0 ? void 0 : customConfig.http2, "allow-unauthenticated": (_e = customConfig === null || customConfig === void 0 ? void 0 : customConfig.allowUnauthenticated) !== null && _e !== void 0 ? _e : true, ingress: (_f = customConfig === null || customConfig === void 0 ? void 0 : customConfig.ingress) !== null && _f !== void 0 ? _f : "all", "cpu-boost": true, "execution-environment": customConfig === null || customConfig === void 0 ? void 0 : customConfig.executionEnvironment, gpu: customConfig === null || customConfig === void 0 ? void 0 : customConfig.gpu, "gpu-type": customConfig === null || customConfig === void 0 ? void 0 : customConfig.gpuType, ...(0, healthCheck_1.healthCheckCliArgs)(customConfig === null || customConfig === void 0 ? void 0 : customConfig.healthCheck), }, ...(0, volumes_1.createVolumeConfig)(customConfig === null || customConfig === void 0 ? void 0 : customConfig.volumes, "service")); const version = requiresBeta(customConfig) ? "beta" : undefined; return `${(0, common_1.gcloudRunCmd)(version)} deploy ${fullServiceName} ${argsString}`; }; exports.getServiceDeployScript = getServiceDeployScript; const getServiceDeleteScript = (context, serviceSuffix) => { const commonArgs = (0, common_1.getCommonCloudRunArgs)(context); const commonArgsString = (0, createArgsString_1.createArgsString)(commonArgs); const serviceName = (0, getServiceName_1.getServiceName)(context); const fullServiceName = serviceSuffix ? `${serviceName}-${serviceSuffix}` : serviceName; return [ `${(0, common_1.gcloudRunCmd)()} services delete ${fullServiceName} ${commonArgsString}`, ]; }; exports.getServiceDeleteScript = getServiceDeleteScript; const requiresBeta = (config) => { if (!config) { return false; } if (config.gpuType) { return true; } if (config.gpu && config.gpu > 0) { return true; } if (config.healthCheck !== undefined) { return true; } return false; }; //# sourceMappingURL=cloudRunServices.js.map