UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

28 lines (25 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCloudRunDomainSuffix = void 0; const child_process_promise_1 = require("child-process-promise"); const getSuffixFromService = (service) => { const fullUrl = service.status.url; const name = service.metadata.name; return fullUrl.replace("https://" + name + "-", ""); }; const getCloudRunDomainSuffix = async (config) => { /* google cloud run domains are partially predictable, they have a fixed suffix that depends on the region and project, but we don't know it beforehand So what we do is either: - get one service and extract its suffix - create a dummy project, extract the suffix and save that as a gitlab variable */ const dummyServiceName = "cl-dummy-service-delete-me"; const existingServices = await (0, child_process_promise_1.exec)(`gcloud run services list --format=json --project="${config.projectId}" --region=${config.region} --limit=1`).then((r) => JSON.parse(r.stdout)); if (existingServices.length > 0) { return getSuffixFromService(existingServices[0]); } const result = await (0, child_process_promise_1.exec)(`gcloud run deploy ${dummyServiceName} --region=${config.region} --allow-unauthenticated --project ${config.projectId} --image=us-docker.pkg.dev/cloudrun/container/hello --format=json`).then((r) => JSON.parse(r.stdout)); return await getSuffixFromService(result); }; exports.getCloudRunDomainSuffix = getCloudRunDomainSuffix; //# sourceMappingURL=getCloudRunDomainSuffix.js.map