@autofleet/cli 1.0.20 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-74OQ5AHU.js +13 -0
- package/dist/e2e.js +2 -0
- package/dist/git-autofleet.js +3 -0
- package/dist/index.js +5 -0
- package/package.json +22 -18
- package/tsconfig.json +5 -3
- package/tsup.config.ts +9 -0
- package/.nvmrc +0 -1
- package/bin/index.js +0 -88
- package/bin/utils/index.js +0 -54
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{parseArgs as w}from"node:util";var x="2.0.0";var h={help:{type:"boolean",short:"h",default:!1,description:"Show help (prints this message)"},version:{type:"boolean",short:"v",default:!1,description:"Show version number"}};function $(e){e.options={...h,...e.options};let t=w(e),{values:n}=t;n.version&&(console.log(x),process.exit(0));let s=e.commands?`
|
|
2
|
+
|
|
3
|
+
Commands:
|
|
4
|
+
${Object.entries(e.commands).map(([i,l])=>`${i.padEnd(30," ")} ${l}`).join(`
|
|
5
|
+
`)}
|
|
6
|
+
`:"",r=`
|
|
7
|
+
${e.binName} ${s?"[command] ":""}<options>${s}
|
|
8
|
+
Options:
|
|
9
|
+
${Object.entries(e.options).map(([i,{description:l,type:c,short:o}])=>`${(o?`--${i}, -${o}`:`--${i}`).padEnd(30," ")} ${l.padEnd(70," ")} [${c}]`).join(`
|
|
10
|
+
`)}
|
|
11
|
+
`;return n.help&&(console.log(r),process.exit(0)),{...t,help:r}}import{spawn as A}from"node:child_process";var j=()=>{if(Promise.withResolvers)return Promise.withResolvers();let e,t;return{promise:new Promise((s,r)=>{e=r,t=s}),reject:e,resolve:t}},y=async(e,t,n=!0)=>{typeof t=="boolean"&&(n=t,t=void 0);let s=new Error,r=s.stack?s.stack.replace(/^.*/," ..."):null,{promise:i,reject:l,resolve:c}=j(),o=A(e,t);n&&(o.stdout.pipe(process.stdout),o.stderr.pipe(process.stderr));let p="",u="";o.stdout?.on("data",a=>{p+=a}),o.stderr?.on("data",a=>{u+=a});let m=n?"exit":"close";function f(a){o.removeListener(m,P),Object.assign(a,{pid:o.pid,stdout:p,stderr:u,status:null,signal:null}),l(a)}function P(a,g){o.removeListener("error",f);let v={pid:o.pid,stdout:p,stderr:u,status:a,signal:g};if(a!==0){let E=typeof t!="boolean"&&` ${t?.join(" ")}`||"",d=g?new Error(`${e}${E} exited with signal: ${g}`):new Error(`${e}${E} exited with non-zero code: ${a}`);d.stack&&r&&(d.stack+=`
|
|
12
|
+
${r}`),Object.assign(d,v),l(d)}else c(v)}return o.once(m,P),o.once("error",f),i};import T from"node:fs";var S=0,O=6,R="SERVICE_HOST",_={dev1:["dev-cluster-2","europe-west1","dev1-experiment-manager"],e2eManager:["e2e-cluster-2","europe-west1","e2e-project-1"],expManager:["af-experiment-manager","europe-west1"],staging:["autofleet-staging","europe-west1-b"]},X=({newFilePath:e,filePath:t,linesToReplace:n})=>{let s=T.readFileSync(t,"utf8");for(let{find:r,replace:i}of n)s=s.replace(r,i);T.writeFileSync(e,s)},C=async e=>{let t=_[e];if(!t)throw new Error(`Cluster name ${e} does not exist!`);let[n,s,r]=t;await y("gcloud",["container","clusters","get-credentials",n,"--region",s,"--project",r||n],!1)},B=async({clusterName:e,variationId:t})=>(await C(e),`--namespace=${t}`),G=e=>{let t=e.split(`
|
|
13
|
+
`);t.shift();let n=t.map(s=>{let r=s.split(/(\s+)/),i=r[S].replace(/-/g,"_").toUpperCase(),l=r[O];return`${i}_${R}=${l}`});return n=n.filter(s=>!s.includes("none")&&!s.includes("undefined")),n},V=(e,t)=>(e instanceof Error||(e=new Error(e)),console.error(e),t&&console.log(t),process.exit(1));export{$ as a,y as b,X as c,C as d,B as e,G as f,V as g};
|
package/dist/e2e.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as r,b as t,c as a,g as i}from"./chunk-74OQ5AHU.js";import c from"node:path";var l={start:'--e2eBranch=<branchName> --branches="{\\"ride-ms\\": \\"AUT-7070\\"}"'},h=s=>Object.keys(l).includes(s),{positionals:m,values:n,help:p}=r({strict:!0,binName:"autofleet-e2e",allowPositionals:!0,options:{e2eBranch:{type:"string",default:"master",description:"Name of e2e branch"},branches:{type:"string",default:"",description:'"ride-ms": "AUT-7070"'}},commands:l});m.length||(console.log(p),process.exit(0));var[o]=m;if(!h(o))throw i(new Error(`Command ${o} does not exist`),p);if(o==="start"){let E=(n.branches?.replace("{"," ")||"").replace(/[^a-z0-9]/gi,""),d=`${c.resolve()}/bin/utils/e2e.sh`,e=`${c.resolve()}/e2e.sh`;a({newFilePath:e,filePath:d,linesToReplace:[{find:"$E2E_BRANCH_PLACE_HOLDER$",replace:n.e2eBranch},{find:"$BRANCHES_PLACE_HOLDER$",replace:n.branches},{find:"$NAME_PLACE_HOLDER$",replace:E}]}),await t("chmod",[`+x ${e} && ${e}`]),console.log("finished e2e")}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as i,b as o,g as n}from"./chunk-74OQ5AHU.js";import{basename as f}from"node:path";var a=["major","minor","patch","premajor","preminor","prepatch","prerelease"],m={bumpVersion:`[${a.join("|")}]`,openPR:"Opens github UI for creating a PR from the current branch"},u=e=>Object.keys(m).includes(e),{positionals:p,help:s}=i({strict:!0,binName:"git autofleet",allowPositionals:!0,options:{},commands:m});p.length||(console.log(s),process.exit(0));var[r,t]=p;if(!u(r))throw n(new Error(`Command ${r} does not exist`),s);if(r==="bumpVersion"){if(!t)throw n(new Error(`Must explicitly define version type.
|
|
3
|
+
Version type can be one of: ${a.join(", ")}`),s);let{stdout:e}=await o("npm",["version",t,"--no-git-tag-version"],!1);await o("git",["add","package*"],!1),await o("git",["commit","-m",`${t} version: ${e}`],!1),console.log(`Created commit for version bump: ${t}. Version is now ${e}`),process.exit(0)}if(r==="openPR"){let[{stdout:e},{stdout:c}]=await Promise.all([o("git",["rev-parse","--show-toplevel"],!1),o("git",["branch","--show-current"],!1)]),l=`https://github.com/Autofleet/${f(e.trim())}/compare/${c.trim()}?expand=1`;await o("open",[l],!1)}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{a as w,b as t,d as b,e as h,f as v,g as a}from"./chunk-74OQ5AHU.js";import N from"node:path";import{cwd as S}from"node:process";var n="--variationId=<yourVariationUuid> --cluster=<dev1/e2eManager>",$={switchCluster:"--cluster=<dev1/e2eManager>",exposeService:`--service=<driver-ms> ${n}`,forwardDb:n,forwardService:`--service=<driver-ms> ${n} --port=<port> --local-port=<localPort>`,getIps:n,enableSimulator:n,rabbitCreds:n,updateExp:n},x=e=>Object.keys($).includes(e),{positionals:g,values:u,help:i}=w({strict:!0,binName:"autofleet",allowPositionals:!0,options:{cluster:{type:"string",short:"c",description:"The cluster name. One of dev1, e2eManager, expManager"},variationId:{type:"string",short:"i",description:"The variation id"},service:{type:"string",short:"s",description:"The service name"},port:{type:"string",short:"p",description:"The remote port to forward"},"local-port":{type:"string",short:"l",description:"The local port to forward to"}},commands:$});g.length||(console.log(i),process.exit(0));g.length>1&&a("Only one command is allowed",i);var[c]=g;if(!x(c))throw a(new Error(`Command ${c} does not exist`),i);var{cluster:m,variationId:p,service:l}=u;if(!m)throw a(new Error("cluster required"),i);c==="switchCluster"&&(await b(m),console.log(`switched to ${m} successfully`),process.exit(0));if(!p)throw a(new Error("variationId required"),i);var s;try{s=await h({clusterName:m,variationId:p})}catch(e){throw a(e)}if(c==="exposeService"){if(!l)throw a(new Error("service is required for exposeService"),i);await t("kubectl",["annotate",s,"service",l,"cloud.google.com/load-balancer-type-"]),await t("kubectl",["patch","svc",s,l,"-p",'{"spec": {"type": "LoadBalancer"}}']),console.log(`exposed ${l} successfully. the service is now creating a public ip`),process.exit(0)}if(c==="forwardDb"){let e=Number.parseInt(u["local-port"]??"5432",10);if(Number.isNaN(e))throw a(new Error("if defined, local-port must be a number"),i);let o=`postgres://postgres:afpass_${p}@localhost:${e}/postgres?&nickname=var_${p}`;console.log(`Forwarding db to local port ${e}.
|
|
3
|
+
access the DB at ${o}
|
|
4
|
+
Press ctrl+c to stop.`),t("open",[o],!1).catch(()=>null),await t("kubectl",[s,"port-forward",`statefulset/p${p}-postgresql`,`${e}:5432`],!1),process.exit(0)}if(c==="forwardService"){let e=Number.parseInt(u.port??"8080",10),o=Number.parseInt(u["local-port"]??"",10)||e;if(!l)throw a(new Error("service is required for forwardService"),i);if(!e||Number.isNaN(e))throw a(new Error("port is required and must be a numbers"),i);if(o&&Number.isNaN(o))throw a(new Error("local-port must be a number"),i);let{stdout:r}=await t("kubectl",["get","pods",s,"-l",`service=${l}`,"-o",'jsonpath="{.items[0].metadata.name}"'],!1);if(r&&=r.trim(),!r)throw a(new Error(`No pods found for service ${l}`));r.startsWith('"')&&r.endsWith('"')&&(r=r.slice(1,-1)),console.log(`Found pod ${r}, serving locally on port ${o} from remote port ${e}.
|
|
5
|
+
Press ctrl+c to stop.`),await t("kubectl",["port-forward",s,r,`${o}:${e}`],!1),process.exit(0)}if(c==="getIps"){let{stdout:e}=await t("kubectl",[s,"get","services"],!1);v(e).forEach(r=>console.log(r)),process.exit(0)}if(c==="enableSimulator"){let e="simulation-cluster-front";await t("kubectl",["annotate",s,"service",e,"cloud.google.com/load-balancer-type-"]),await t("kubectl",["patch","svc",s,e,"-p",'{"spec": {"type": "LoadBalancer"}}']),await t("kubectl",["create",s,"rolebinding","admin","--clusterrole=cluster-admin",`--serviceaccount=${p}:default`]),console.log(`Successfully exposed ${e} and added role binding to dispatch simulations`),process.exit(0)}if(c==="rabbitCreds"){let e=f=>["get","secret","rabbitmq-default-user","-o",`jsonpath="{.data.${f}}"`],[{stdout:o},{stdout:r}]=await Promise.all([t("kubectl",e("username"),!1),t("kubectl",e("password"),!1)]);console.log(`username: ${Buffer.from(o,"base64").toString("ascii")}`),console.log(`password: ${Buffer.from(r,"base64").toString("ascii")}`),process.exit(0)}if(c==="updateExp"){let e=N.basename(S()),[{stdout:o},{stdout:r}]=await Promise.all([t("git",["branch","--show-current"],!1),t("uname",["-m"],!1)]);r=r.trim(),o=o.trim();let f=`${new Date().getHours().toString().padStart(2,"0")}-${new Date().getMinutes().toString().padStart(2,"0")}-${new Date().getSeconds().toString().padStart(2,"0")}`,d=`gcr.io/autofleetprod/${e}:${o}-${f}`;console.log(`Building and pushing image ${d}`),await t("docker",["build",".",...r==="x86_64"?[]:["--platform","linux/amd64"],"-t",d,"--build-arg",`NPM_TOKEN=${process.env.NPM_TOKEN}`]),await t("docker",["push",d]),await t("kubectl",["patch",`deployment/${e}`,s,"--patch",`{"spec": {"template": {"spec": {"initContainers": [{"name": "init","image": "${d}"}]}}}}`]),await t("kubectl",["set","image",`deployment/${e}`,`worker=${d}`,s]),await t("kubectl",["rollout","status","deployments",e,s]),process.exit(0)}
|
package/package.json
CHANGED
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"start": "
|
|
8
|
-
"
|
|
7
|
+
"start": "tsx bin/index.ts",
|
|
8
|
+
"dev": "tsup --watch",
|
|
9
|
+
"build": "tsup",
|
|
9
10
|
"linter": "./node_modules/.bin/eslint .",
|
|
10
11
|
"test": "jest --forceExit",
|
|
11
|
-
"coverage": "jest --coverage --forceExit && rm -rf ./coverage"
|
|
12
|
-
"dev": "nodemon"
|
|
13
|
-
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"yargs": "^17.4.1"
|
|
12
|
+
"coverage": "jest --coverage --forceExit && rm -rf ./coverage"
|
|
16
13
|
},
|
|
17
14
|
"devDependencies": {
|
|
18
|
-
"@types/jest": "^
|
|
19
|
-
"@
|
|
20
|
-
"eslint": "^7.
|
|
21
|
-
"eslint
|
|
22
|
-
"eslint-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"ts-
|
|
26
|
-
"
|
|
15
|
+
"@types/jest": "^29.5.12",
|
|
16
|
+
"@types/node": "^18.17.19",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
18
|
+
"eslint": "^8.57.0",
|
|
19
|
+
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
20
|
+
"eslint-plugin-import": "^2.29.1",
|
|
21
|
+
"jest": "^29.7.0",
|
|
22
|
+
"ts-jest": "^29.1.2",
|
|
23
|
+
"tsup": "^8.0.2",
|
|
24
|
+
"tsx": "^4.7.1",
|
|
25
|
+
"typescript": "^5.4.2"
|
|
27
26
|
},
|
|
28
27
|
"bin": {
|
|
29
|
-
"autofleet": "./
|
|
28
|
+
"autofleet": "./dist/index.js",
|
|
29
|
+
"autofleet-e2e": "./dist/e2e.js",
|
|
30
|
+
"git-autofleet": "./dist/git-autofleet.js"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": "^16.17.0 || >= 18.3.0"
|
|
30
34
|
},
|
|
31
35
|
"type": "module",
|
|
32
36
|
"author": "Autofleet",
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"module": "
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ES2022",
|
|
5
5
|
"declaration": true,
|
|
6
6
|
"outDir": "./dist",
|
|
7
7
|
"strict": true,
|
|
8
8
|
"esModuleInterop": true,
|
|
9
9
|
"experimentalDecorators": true,
|
|
10
|
-
"emitDecoratorMetadata":
|
|
10
|
+
"emitDecoratorMetadata": false,
|
|
11
|
+
"moduleResolution":"node",
|
|
12
|
+
"resolveJsonModule": true,
|
|
11
13
|
},
|
|
12
14
|
"exclude": ["node_modules", "**/*.test.ts"]
|
|
13
15
|
}
|
package/tsup.config.ts
ADDED
package/.nvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
16.14.2
|
package/bin/index.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import yargs from 'yargs';
|
|
3
|
-
import { hideBin } from 'yargs/helpers';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
import {
|
|
7
|
-
connectAndGetPrefix, parseIps, replaceInFile, terminalCommand,
|
|
8
|
-
} from './utils/index.js';
|
|
9
|
-
|
|
10
|
-
yargs(hideBin(process.argv))
|
|
11
|
-
.command({
|
|
12
|
-
command: 'exposeService',
|
|
13
|
-
describe: '--service=driver-ms --variationId=${yourVariationUuid} --cluster=dev1/e2eManager',
|
|
14
|
-
async handler(argv) {
|
|
15
|
-
const { cluster, variationId, service } = argv;
|
|
16
|
-
const prefix = await connectAndGetPrefix({
|
|
17
|
-
clusterName: cluster,
|
|
18
|
-
variationId,
|
|
19
|
-
});
|
|
20
|
-
await terminalCommand(`kubectl annotate ${prefix} service ${service} cloud.google.com/load-balancer-type-`);
|
|
21
|
-
await terminalCommand(`kubectl patch svc ${prefix} ${service} -p '{"spec": {"type": "LoadBalancer"}}' `);
|
|
22
|
-
console.log(`exposed ${service} successfully. the service is now creating a public ip`);
|
|
23
|
-
},
|
|
24
|
-
})
|
|
25
|
-
.command({
|
|
26
|
-
command: 'getIps',
|
|
27
|
-
describe: '--service=driver-ms --variationId=${yourVariationUuid} --cluster=dev1/e2eManager',
|
|
28
|
-
async handler(argv) {
|
|
29
|
-
const { cluster, variationId } = argv;
|
|
30
|
-
const prefix = await connectAndGetPrefix({
|
|
31
|
-
clusterName: cluster,
|
|
32
|
-
variationId,
|
|
33
|
-
});
|
|
34
|
-
await terminalCommand(`kubectl ${prefix} get services > ips`);
|
|
35
|
-
const ipsFilePath = `${path.resolve()}/ips`;
|
|
36
|
-
const ips = parseIps(ipsFilePath);
|
|
37
|
-
fs.unlinkSync(ipsFilePath);
|
|
38
|
-
ips.forEach((ip) => console.log(ip));
|
|
39
|
-
},
|
|
40
|
-
})
|
|
41
|
-
.command({
|
|
42
|
-
command: 'enableSimulator',
|
|
43
|
-
describe: '--cluster=dev1/e2eManager --variationId=<yourVariationId>',
|
|
44
|
-
async handler(argv) {
|
|
45
|
-
const SIMULATION_CLUSTER_FRONT = 'simulation-cluster-front';
|
|
46
|
-
const { cluster, variationId } = argv;
|
|
47
|
-
const nameSpacePrefix = await connectAndGetPrefix({
|
|
48
|
-
clusterName: cluster,
|
|
49
|
-
variationId,
|
|
50
|
-
});
|
|
51
|
-
await terminalCommand(`kubectl annotate ${nameSpacePrefix} service ${SIMULATION_CLUSTER_FRONT} cloud.google.com/load-balancer-type-`);
|
|
52
|
-
await terminalCommand(`kubectl patch svc ${nameSpacePrefix} ${SIMULATION_CLUSTER_FRONT} -p '{"spec": {"type": "LoadBalancer"}}' `);
|
|
53
|
-
await terminalCommand(`kubectl create ${nameSpacePrefix} rolebinding admin --clusterrole=cluster-admin --serviceaccount=${variationId}:default`);
|
|
54
|
-
console.log(`Successfully exposed ${SIMULATION_CLUSTER_FRONT} and added role binding to dispatch simulations`);
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
.command({
|
|
58
|
-
command: 'e2e',
|
|
59
|
-
describe: '--branches="ride-ms": "AUT-7070" --e2eBranch=your-e2e-branch',
|
|
60
|
-
async handler(argv) {
|
|
61
|
-
const { branches, e2eBranch = 'master' } = argv;
|
|
62
|
-
const name = branches.replace('{', ' ');
|
|
63
|
-
const formattedName = name.replace(/[^a-z0-9]/gi, '');
|
|
64
|
-
const E2E_SCRIPT_TEMPLATE_FILE_PATH = `${path.resolve()}/bin/utils/e2e.sh`;
|
|
65
|
-
const NEW_E2E_SCRIPT_FILE_PATH = `${path.resolve()}/e2e.sh`;
|
|
66
|
-
replaceInFile({
|
|
67
|
-
newFilePath: NEW_E2E_SCRIPT_FILE_PATH,
|
|
68
|
-
filePath: E2E_SCRIPT_TEMPLATE_FILE_PATH,
|
|
69
|
-
linesToReplace: [
|
|
70
|
-
{
|
|
71
|
-
find: '$E2E_BRANCH_PLACE_HOLDER$',
|
|
72
|
-
replace: e2eBranch,
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
find: '$BRANCHES_PLACE_HOLDER$',
|
|
76
|
-
replace: branches,
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
find: '$NAME_PLACE_HOLDER$',
|
|
80
|
-
replace: formattedName,
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
});
|
|
84
|
-
await terminalCommand(`chmod +x ${NEW_E2E_SCRIPT_FILE_PATH} && ${NEW_E2E_SCRIPT_FILE_PATH}`);
|
|
85
|
-
console.log('finished e2e');
|
|
86
|
-
},
|
|
87
|
-
})
|
|
88
|
-
.parse();
|
package/bin/utils/index.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/* eslint-disable guard-for-in */
|
|
3
|
-
/* eslint-disable no-restricted-syntax */
|
|
4
|
-
import { promisify } from 'util';
|
|
5
|
-
import { exec } from 'child_process';
|
|
6
|
-
import fs from 'fs';
|
|
7
|
-
|
|
8
|
-
const asyncExec = promisify(exec);
|
|
9
|
-
const SERVICE_NAME_INDEX = 0;
|
|
10
|
-
const EXTERNAL_IP_INDEX = 6;
|
|
11
|
-
const IP_LINE_SUFFIX = 'SERVICE_HOST';
|
|
12
|
-
const CLUSTER_TO_CMD_MAP = {
|
|
13
|
-
dev1: 'gcloud container clusters get-credentials dev-cluster-2 --region europe-west1 --project dev1-experiment-manager',
|
|
14
|
-
e2eManager: 'gcloud container clusters get-credentials e2e-cluster-2 --region europe-west1 --project e2e-project-1',
|
|
15
|
-
expManager: 'gcloud container clusters get-credentials af-experiment-manager --region europe-west1 --project af-experiment-manager',
|
|
16
|
-
};
|
|
17
|
-
export const terminalCommand = async (command) => {
|
|
18
|
-
const output = await asyncExec(command);
|
|
19
|
-
const formattedOutput = output.stdout.trim();
|
|
20
|
-
console.log(formattedOutput);
|
|
21
|
-
return formattedOutput;
|
|
22
|
-
};
|
|
23
|
-
export const replaceInFile = ({ newFilePath, filePath, linesToReplace }) => {
|
|
24
|
-
let fileAsString = fs.readFileSync(filePath, 'utf8');
|
|
25
|
-
for (const { find, replace } of linesToReplace) {
|
|
26
|
-
fileAsString = fileAsString.replace(find, replace);
|
|
27
|
-
}
|
|
28
|
-
fs.writeFileSync(newFilePath, fileAsString);
|
|
29
|
-
};
|
|
30
|
-
export const connectToCluster = async (clusterName) => {
|
|
31
|
-
const command = CLUSTER_TO_CMD_MAP[clusterName];
|
|
32
|
-
if (!command) {
|
|
33
|
-
throw new Error(`Cluster name ${clusterName} does not exist!`);
|
|
34
|
-
}
|
|
35
|
-
await terminalCommand(command);
|
|
36
|
-
};
|
|
37
|
-
export const connectAndGetPrefix = async ({ clusterName, variationId }) => {
|
|
38
|
-
await connectToCluster(clusterName);
|
|
39
|
-
return `--namespace=${variationId}`;
|
|
40
|
-
};
|
|
41
|
-
export const parseIps = (ipsFilePath) => {
|
|
42
|
-
const ipLines = fs.readFileSync(ipsFilePath, 'utf-8').split('\n');
|
|
43
|
-
ipLines.shift();
|
|
44
|
-
|
|
45
|
-
let formattedIps = ipLines.map((ipLine) => {
|
|
46
|
-
const splittedLine = ipLine.split(/(\s+)/);
|
|
47
|
-
const serviceName = splittedLine[SERVICE_NAME_INDEX].replace(/-/g, '_').toUpperCase();
|
|
48
|
-
const loadBalancerIp = splittedLine[EXTERNAL_IP_INDEX];
|
|
49
|
-
const formattedLine = `${serviceName}_${IP_LINE_SUFFIX}=${loadBalancerIp}`;
|
|
50
|
-
return formattedLine;
|
|
51
|
-
});
|
|
52
|
-
formattedIps = formattedIps.filter((formattedIp) => !formattedIp.includes('none') && !formattedIp.includes('undefined'));
|
|
53
|
-
return formattedIps;
|
|
54
|
-
};
|