UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

51 lines 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDeleteUnusedRevisionsCommands = void 0; const types_1 = require("../types"); const createArgsString_1 = require("./utils/createArgsString"); const getServiceName_1 = require("./utils/getServiceName"); const removeFirstLinesFromCommandOutput_1 = require("./utils/removeFirstLinesFromCommandOutput"); const getListRevisionsCommand = (context, args) => { var _a; const serviceName = (0, getServiceName_1.getServiceName)(context); const deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config; if (!deployConfig || !(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) { // should not happen throw new Error("deploy config is wrong"); } const filterRevisionArgs = { project: deployConfig.projectId, region: deployConfig.region, // only show inactive revisions service: serviceName, limit: "unlimited", // is actualy the default "sort-by": "metadata.creationTimestamp", ...args, }; // this prints out all inactive images of the given app return `gcloud run revisions list ${(0, createArgsString_1.createArgsString)(filterRevisionArgs)}`; }; const getDeleteUnusedRevisionsCommands = (context, keep) => { var _a; const deployConfig = (_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config; if (!(0, types_1.isOfDeployType)(deployConfig, "google-cloudrun")) { // should not happen throw new Error("deploy config is wrong"); } // this prints out all inactive images of the given app const listAllInactiveRevisionsCmd = getListRevisionsCommand(context, { format: `"value(name)"`, filter: `'(status.conditions.status=False OR status.conditions.status=Unknown)'`, }); // this removes the newest `revisionsToKeep` images const listRevisionsToDeleteCmd = (0, removeFirstLinesFromCommandOutput_1.removeFirstLinesFromCommandOutput)(listAllInactiveRevisionsCmd, keep); const deleteRevisionCmd = `gcloud run revisions delete ${(0, createArgsString_1.createArgsString)({ project: deployConfig.projectId, region: deployConfig.region, quiet: true, })} $revisionname `; const deleteRevisionsCmd = `${listRevisionsToDeleteCmd} | while read -r revisionname; do ${deleteRevisionCmd}; done`; return [deleteRevisionsCmd]; }; exports.getDeleteUnusedRevisionsCommands = getDeleteUnusedRevisionsCommands; //# sourceMappingURL=cloudRunRevisions.js.map