@autofleet/cli 2.1.0 → 2.2.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-L4UCN7UP.js +13 -0
- package/dist/e2e.js +1 -1
- package/dist/git-autofleet.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -2
- package/dist/chunk-CR7NP4MD.js +0 -13
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import{parseArgs as $}from"node:util";var x="2.2.1";var E={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 j(e){e.options={...E,...e.options};let t=$(e),{values:r}=t;r.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
|
+
`:"",n=`
|
|
7
|
+
${e.binName} ${s?"[command] ":""}<options>${s}
|
|
8
|
+
Options:
|
|
9
|
+
${Object.entries(e.options).map(([i,{description:l,type:c,short:p}])=>`${(p?`--${i}, -${p}`:`--${i}`).padEnd(30," ")} ${l.padEnd(70," ")} [${c}]`).join(`
|
|
10
|
+
`)}
|
|
11
|
+
`;return r.help&&(console.log(n),process.exit(0)),{...t,help:n}}import{spawn as A}from"node:child_process";var O=()=>{if(Promise.withResolvers)return Promise.withResolvers();let e,t;return{promise:new Promise((s,n)=>{e=n,t=s}),reject:e,resolve:t}},b=async(e,t,{print:r=!0,env:s={}}={})=>{typeof t=="boolean"&&(r=t,t=void 0);let n=new Error,i=n.stack?n.stack.replace(/^.*/," ..."):null,{promise:l,reject:c,resolve:p}=O(),o=A(e,t,{env:Object.assign(s,process.env)});r&&(o.stdout.pipe(process.stdout),o.stderr.pipe(process.stderr));let d="",u="";o.stdout?.on("data",a=>{d+=a}),o.stderr?.on("data",a=>{u+=a});let m=r?"exit":"close";function v(a){o.removeListener(m,P),Object.assign(a,{pid:o.pid,stdout:d,stderr:u,status:null,signal:null}),c(a)}function P(a,g){o.removeListener("error",v);let y={pid:o.pid,stdout:d,stderr:u,status:a,signal:g};if(a!==0){let w=typeof t!="boolean"&&` ${t?.join(" ")}`||"",f=g?new Error(`${e}${w} exited with signal: ${g}`):new Error(`${e}${w} exited with non-zero code: ${a}`);f.stack&&i&&(f.stack+=`
|
|
12
|
+
${i}`),Object.assign(f,y),c(f)}else p(y)}return o.once(m,P),o.once("error",v),l};import T from"node:fs";import{createInterface as S}from"node:readline/promises";var _="SERVICE_HOST",C={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"]},Y=({newFilePath:e,filePath:t,linesToReplace:r})=>{let s=T.readFileSync(t,"utf8");for(let{find:n,replace:i}of r)s=s.replace(n,i);T.writeFileSync(e,s)},L=async e=>{let t=C[e];if(!t)throw new Error(`Cluster name ${e} does not exist!`);let[r,s,n]=t;await b("gcloud",["container","clusters","get-credentials",r,"--region",s,"--project",n||r],{print:!1})},z=async({clusterName:e,variationId:t})=>(await L(e),`--namespace=${t}`),H=e=>{let t=e.split(`
|
|
13
|
+
`).filter(Boolean);t.shift();let r=t.map(s=>{let[n,i,l,c,p,o]=s.split(/(\s+)/).map(m=>m.trim()).filter(Boolean);return`${n.replace(/-/g,"_").toUpperCase()}_${_}=${c}`});return r=r.filter(s=>!s.includes("none")&&!s.includes("undefined")),r},J=(e,t)=>(e instanceof Error||(e=new Error(e)),console.error(e),t&&console.log(t),process.exit(1)),R=async e=>{let t=S({input:process.stdin,output:process.stdout}),r=await t.question(`${e} [Y/n]`);t.close();let s=r.trim().toLowerCase();return["y","yes",""].includes(s)?!0:["n","no",""].includes(s)?!1:(console.log("Please answer with y/yes or n/no"),R(e))};export{j as a,b,Y as c,L as d,z as e,H as f,J as g,R as h};
|
package/dist/e2e.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as
|
|
2
|
+
import{a as m,b as t,c as p,e as d,f as h,g as s}from"./chunk-L4UCN7UP.js";import u from"node:path";import y from"p-retry";var f=["identity-ms","vehicle-ms","ride-ms","vehicle-live-data-ms","pricing-ms","payment-ms","route-plan-ms","task-ms","audit-ms","pgweb","queue-ms","placement-ms","demand-prediction-ms","control-center-ms","setting-ms","api-gateway-ms"],E={start:'--e2eBranch=<branchName> --branches="{\\"ride-ms\\": \\"AUT-7070\\"}"',getIpsForEnv:"--variationId=<yourVariationUuid> --cluster=<dev1/e2eManager>"},_=e=>Object.keys(E).includes(e),{positionals:g,values:i,help:c}=m({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"'},cluster:{type:"string",short:"c",description:"The cluster name. One of dev1, e2eManager, expManager"},variationId:{type:"string",short:"i",description:"The variation id"}},commands:E});g.length||(console.log(c),process.exit(0));var[n]=g;if(!_(n))throw s(new Error(`Command ${n} does not exist`),c);if(n==="start"){let a=(i.branches?.replace("{"," ")||"").replace(/[^a-z0-9]/gi,""),r=`${u.resolve()}/bin/utils/e2e.sh`,l=`${u.resolve()}/e2e.sh`;p({newFilePath:l,filePath:r,linesToReplace:[{find:"$E2E_BRANCH_PLACE_HOLDER$",replace:i.e2eBranch},{find:"$BRANCHES_PLACE_HOLDER$",replace:i.branches},{find:"$NAME_PLACE_HOLDER$",replace:a}]}),await t("chmod",[`+x ${l} && ${l}`]),console.log("finished e2e")}var{cluster:v,variationId:w}=i;if(!v)throw s(new Error("cluster required"),c);if(!w)throw s(new Error("variationId required"),c);var o;try{o=await d({clusterName:v,variationId:w})}catch(e){throw s(e)}n==="getIpsForEnv"&&(await Promise.all(f.map(e=>t("kubectl",["annotate",o,"service",e,"cloud.google.com/load-balancer-type-"],{print:!1}))),await Promise.all(f.map(e=>t("kubectl",["patch","svc",o,e,"-p",'{"spec": {"type": "LoadBalancer"}}'],{print:!1}))),console.log("exposed services successfully. the services are now creating public ips."),await y(async()=>{let{stdout:e}=await t("kubectl",[o,"get","services"],{print:!1}),a=h(e);if(a.some(r=>r.includes("<pending>")))throw new Error("Some services are still pending");a.forEach(r=>console.log(r))},{retries:10,factor:1,maxTimeout:5e3,randomize:!0}),process.exit(0));
|
package/dist/git-autofleet.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as d,b as e,g as s,h as l}from"./chunk-
|
|
2
|
+
import{a as d,b as e,g as s,h as l}from"./chunk-L4UCN7UP.js";import{basename as y}from"node:path";import{randomUUID as $}from"node:crypto";var m=["premajor","preminor","prepatch","prerelease"],h=["major","minor","patch",...m],f={bumpVersion:`[${h.join("|")}]`,openPR:"Opens github UI for creating a PR from the current branch.",releaseBeta:"Bumps version if needed, and publishes a beta release to NPM."},P=t=>Object.keys(f).includes(t),w=async(t,o="")=>{let{stdout:i}=await e("npm",["version",t,"--no-git-tag-version","--preid",o],{print:!1});return await e("git",["add","package*"],{print:!1}),await e("git",["commit","-m",`${t} version: ${i}`],{print:!1}),console.log(`Created commit for version bump: ${t}. Version is now ${i}`),i},{positionals:b,help:a}=d({strict:!0,binName:"git autofleet",allowPositionals:!0,options:{},commands:f});b.length||(console.log(a),process.exit(0));var[p,n]=b;if(!P(p))throw s(new Error(`Command ${p} does not exist`),a);if(p==="bumpVersion"){if(!n)throw s(new Error(`Must explicitly define version type.
|
|
3
3
|
Version type can be one of: ${h.join(", ")}`),a);let{stdout:t}=await e("git",["branch","--show-current"],{print:!1});["main","master"].includes(t.trim())&&(await l("Are you sure you want to bump version on main branch?")||process.exit(0)),await w(n),process.exit(0)}if(p==="openPR"){let[{stdout:t},{stdout:o}]=await Promise.all([e("git",["rev-parse","--show-toplevel"],{print:!1}),e("git",["branch","--show-current"],{print:!1})]),c=`https://github.com/Autofleet/${y(t.trim())}/compare/${o.trim()}?expand=1`;await e("open",[c],{print:!1}),process.exit(0)}if(p==="releaseBeta"){if(n&&!m.includes(n))throw s(new Error(`Invalid version type: ${n}
|
|
4
4
|
Version must be a prerelease type. (${m.join(", ")})`),a);let{stdout:t}=await e("git",["branch","--show-current"],{print:!1});if(["main","master"].includes(t.trim()))throw s(new Error("Cannot release beta from main branch"),a);let{stdout:o}=await e("git",["diff","origin/master..","package.json"],{print:!1}),c=!o.split(`
|
|
5
5
|
`).some(r=>/^\+\s*"version":\s*"\d+\.\d+\.\d+(?:-(?:[\w-]+\.)?\d+)?",/.test(r))||await l("Version already bumped on branch. Should version be re-bumped?"),g=c&&await e("git",["rev-parse","--show-toplevel"],{print:!1}).then(({stdout:r})=>r.trim()).then(r=>import(`${r}/package.json`,{assert:{type:"json"},with:{type:"json"}}).then(({default:v})=>v.version)).then(r=>r.replace(/\d+\.\d+\.\d+(?:-beta-([\w]+)?\.\d+)?/,"$1")),u=c&&await w(n||"prerelease",`beta-${g||$().split("-")[0]}`);await e("npm",["run","build"]);try{await e("npm",["publish","--tag","beta","--@autofleet:registry=https://registry.npmjs.org"])}catch(r){throw console.error(r),s("Failed to publish beta version")}if(u)console.log(`Published beta version with new version: ${u}`);else{let{stdout:r}=await e("npm",["info",".","version"],{print:!1});console.log(`Published beta version with existing version: ${r}`)}process.exit(0)}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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-
|
|
2
|
+
import{a as w,b as t,d as b,e as h,f as v,g as a}from"./chunk-L4UCN7UP.js";import N from"node:path";import{cwd as S}from"node:process";var c="--variationId=<yourVariationUuid> --cluster=<dev1/e2eManager>",$={switchCluster:"--cluster=<dev1/e2eManager>",exposeService:`--service=<driver-ms> ${c}`,forwardDb:c,forwardService:`--service=<driver-ms> ${c} --port=<port> --local-port=<localPort>`,getIps:c,enableSimulator:c,rabbitCreds:c,updateExp:c},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[n]=g;if(!x(n))throw a(new Error(`Command ${n} does not exist`),i);var{cluster:m,variationId:p,service:l}=u;if(!m)throw a(new Error("cluster required"),i);n==="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(n==="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(n==="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
3
|
access the DB at ${o}
|
|
4
4
|
Press ctrl+c to stop.`),t("open",[o],{print:!1}).catch(()=>null),await t("kubectl",[s,"port-forward",`statefulset/p${p}-postgresql`,`${e}:5432`],{print:!1}),process.exit(0)}if(n==="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}"'],{print:!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
5
|
Press ctrl+c to stop.`),await t("kubectl",["port-forward",s,r,`${o}:${e}`],{print:!1}),process.exit(0)}if(n==="getIps"){let{stdout:e}=await t("kubectl",[s,"get","services"],{print:!1});v(e).forEach(r=>console.log(r)),process.exit(0)}if(n==="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(n==="rabbitCreds"){let e=f=>["get","secret","rabbitmq-default-user","-o",`jsonpath="{.data.${f}}"`],[{stdout:o},{stdout:r}]=await Promise.all([t("kubectl",e("username"),{print:!1}),t("kubectl",e("password"),{print:!1})]);console.log(`username: ${Buffer.from(o,"base64").toString("ascii")}`),console.log(`password: ${Buffer.from(r,"base64").toString("ascii")}`),process.exit(0)}if(n==="updateExp"){let e=N.basename(S()),[{stdout:o},{stdout:r}]=await Promise.all([t("git",["branch","--show-current"],{print:!1}),t("uname",["-m"],{print:!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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/cli",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,5 +34,8 @@
|
|
|
34
34
|
},
|
|
35
35
|
"type": "module",
|
|
36
36
|
"author": "Autofleet",
|
|
37
|
-
"license": "ISC"
|
|
37
|
+
"license": "ISC",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"p-retry": "^6.2.0"
|
|
40
|
+
}
|
|
38
41
|
}
|
package/dist/chunk-CR7NP4MD.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import{parseArgs as $}from"node:util";var b="2.1.0";var A={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 j(e){e.options={...A,...e.options};let t=$(e),{values:s}=t;s.version&&(console.log(b),process.exit(0));let n=e.commands?`
|
|
2
|
-
|
|
3
|
-
Commands:
|
|
4
|
-
${Object.entries(e.commands).map(([o,c])=>`${o.padEnd(30," ")} ${c}`).join(`
|
|
5
|
-
`)}
|
|
6
|
-
`:"",r=`
|
|
7
|
-
${e.binName} ${n?"[command] ":""}<options>${n}
|
|
8
|
-
Options:
|
|
9
|
-
${Object.entries(e.options).map(([o,{description:c,type:l,short:p}])=>`${(p?`--${o}, -${p}`:`--${o}`).padEnd(30," ")} ${c.padEnd(70," ")} [${l}]`).join(`
|
|
10
|
-
`)}
|
|
11
|
-
`;return s.help&&(console.log(r),process.exit(0)),{...t,help:r}}import{spawn as S}from"node:child_process";var O=()=>{if(Promise.withResolvers)return Promise.withResolvers();let e,t;return{promise:new Promise((n,r)=>{e=r,t=n}),reject:e,resolve:t}},x=async(e,t,{print:s=!0,env:n={}}={})=>{typeof t=="boolean"&&(s=t,t=void 0);let r=new Error,o=r.stack?r.stack.replace(/^.*/," ..."):null,{promise:c,reject:l,resolve:p}=O(),i=S(e,t,{env:Object.assign(n,process.env)});s&&(i.stdout.pipe(process.stdout),i.stderr.pipe(process.stderr));let u="",m="";i.stdout?.on("data",a=>{u+=a}),i.stderr?.on("data",a=>{m+=a});let P=s?"exit":"close";function v(a){i.removeListener(P,w),Object.assign(a,{pid:i.pid,stdout:u,stderr:m,status:null,signal:null}),l(a)}function w(a,g){i.removeListener("error",v);let y={pid:i.pid,stdout:u,stderr:m,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&&o&&(d.stack+=`
|
|
12
|
-
${o}`),Object.assign(d,y),l(d)}else p(y)}return i.once(P,w),i.once("error",v),c};import T from"node:fs";import{createInterface as C}from"node:readline/promises";var L=0,R=6,_="SERVICE_HOST",I={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"]},z=({newFilePath:e,filePath:t,linesToReplace:s})=>{let n=T.readFileSync(t,"utf8");for(let{find:r,replace:o}of s)n=n.replace(r,o);T.writeFileSync(e,n)},N=async e=>{let t=I[e];if(!t)throw new Error(`Cluster name ${e} does not exist!`);let[s,n,r]=t;await x("gcloud",["container","clusters","get-credentials",s,"--region",n,"--project",r||s],{print:!1})},H=async({clusterName:e,variationId:t})=>(await N(e),`--namespace=${t}`),J=e=>{let t=e.split(`
|
|
13
|
-
`);t.shift();let s=t.map(n=>{let r=n.split(/(\s+)/),o=r[L].replace(/-/g,"_").toUpperCase(),c=r[R];return`${o}_${_}=${c}`});return s=s.filter(n=>!n.includes("none")&&!n.includes("undefined")),s},q=(e,t)=>(e instanceof Error||(e=new Error(e)),console.error(e),t&&console.log(t),process.exit(1)),f=C({input:process.stdin,output:process.stdout}),k=async e=>{let s=(await f.question(`${e} [Y/n]`)).trim().toLowerCase();return["y","yes",""].includes(s)?(f.close(),!0):["n","no",""].includes(s)?(f.close(),!1):(console.log("Please answer with y/yes or n/no"),k(e))};export{j as a,x as b,z as c,N as d,H as e,J as f,q as g,k as h};
|