UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

97 lines (96 loc) 3.89 kB
"use strict"; var __importDefault = this && this.__importDefault || function (mod) { return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.commandPortForward = void 0; const defineCommand_1 = require("../../core/defineCommand"); const kubernetes_1 = require("../../kubernetes"); const log_1 = require("../../utils/log"); const portForward_1 = require("../../kubernetes/portForward"); const projects_1 = require("../../utils/projects"); const ensureCluster_1 = require("../../apps/cli/commands/project/utils/ensureCluster"); const parseChoice_1 = require("../../config/parseChoice"); const getProjectConfig_1 = require("../../config/getProjectConfig"); const pipeline_1 = require("../../../../pipeline/src/index.js"); const portForwards_1 = require("../../utils/portForwards"); const open_1 = __importDefault(require("open")); const autocompletions_1 = require("../../apps/cli/commands/project/utils/autocompletions"); const availability_1 = require("../availability"); exports.commandPortForward = (0, defineCommand_1.defineCommand)({ name: "project port-forward", description: "start port-forwarding", group: "project", isAvailable: (0, availability_1.hasDeployType)("kubernetes", "google-cloudrun"), inputs: { envComponent: { type: "string", message: "environment:component", positional: true, choices: async () => (0, autocompletions_1.envAndComponents)() }, podName: { type: "string", message: "Which pod? 🤔", choices: async ctx => (0, kubernetes_1.getProjectPodNames)(await ctx.get("envComponent")) }, localPort: { type: "number", message: "Local port: " }, remotePort: { type: "number", message: "Remote port: " }, mr: { type: "number", message: "Which mr 🤔 " } }, execute: async ctx => { var _a, _b, _c; const envComponent = await ctx.get("envComponent"); const { env, componentName } = (0, parseChoice_1.parseChoice)(envComponent); const context = await (0, getProjectConfig_1.getPipelineContextByChoice)(env, componentName); if ((0, pipeline_1.isOfDeployType)((_a = context.deploy) === null || _a === void 0 ? void 0 : _a.config, "kubernetes")) { await (0, ensureCluster_1.ensureCluster)(ctx, envComponent); const namespace = await (0, projects_1.getProjectNamespace)(envComponent); const podNames = await (0, kubernetes_1.getProjectPodNames)(envComponent); if (podNames.length === 0) { (0, log_1.logError)(ctx, "sorry, no pods found"); return; } const podName = await ctx.get("podName"); const localPort = await ctx.get("localPort"); const remotePort = await ctx.get("remotePort"); return (0, portForward_1.startKubePortForward)(podName, localPort, remotePort, namespace); } if ((0, pipeline_1.isOfDeployType)((_b = context.deploy) === null || _b === void 0 ? void 0 : _b.config, "google-cloudrun")) { if (!(0, pipeline_1.isOfDeployType)((_c = context.deploy) === null || _c === void 0 ? void 0 : _c.config, "google-cloudrun")) { throw new Error("not cloud run"); } const { fullName } = context.environment; let serviceName = fullName.toString(); if (context.environment.envType === "review") { const mr = await ctx.get("mr"); serviceName = serviceName.toString().replace("-review-", "-review-mr" + mr + "-"); } const { projectId, region } = context.deploy.config; const command = `gcloud beta run services proxy ${serviceName} --project ${projectId} --region ${region}`; await (0, portForwards_1.startPortForwardCommand)(`cloudRun/${serviceName}`, command); (0, open_1.default)("http://localhost:8080"); } } });