@autofleet/cli 2.5.1 → 2.5.2
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var x=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t);var L=(t,e,s)=>{if(e!=null){if(typeof e!="object"&&typeof e!="function")throw TypeError("Object expected");var n;if(s&&(n=e[x("asyncDispose")]),n===void 0&&(n=e[x("dispose")]),typeof n!="function")throw TypeError("Object not disposable");t.push([s,n,e])}else s&&t.push([s]);return e},I=(t,e,s)=>{var n=typeof SuppressedError=="function"?SuppressedError:function(o,p,l,r){return r=Error(l),r.name="SuppressedError",r.error=o,r.suppressed=p,r},i=o=>e=s?new n(o,e,"An error was suppressed during disposal"):(s=!0,o),a=o=>{for(;o=t.pop();)try{var p=o[1]&&o[1].call(o[2]);if(o[0])return Promise.resolve(p).then(a,l=>(i(l),a()))}catch(l){i(l)}if(s)throw e};return a()};import{parseArgs as j}from"node:util";var b="2.5.
|
|
1
|
+
var x=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t);var L=(t,e,s)=>{if(e!=null){if(typeof e!="object"&&typeof e!="function")throw TypeError("Object expected");var n;if(s&&(n=e[x("asyncDispose")]),n===void 0&&(n=e[x("dispose")]),typeof n!="function")throw TypeError("Object not disposable");t.push([s,n,e])}else s&&t.push([s]);return e},I=(t,e,s)=>{var n=typeof SuppressedError=="function"?SuppressedError:function(o,p,l,r){return r=Error(l),r.name="SuppressedError",r.error=o,r.suppressed=p,r},i=o=>e=s?new n(o,e,"An error was suppressed during disposal"):(s=!0,o),a=o=>{for(;o=t.pop();)try{var p=o[1]&&o[1].call(o[2]);if(o[0])return Promise.resolve(p).then(a,l=>(i(l),a()))}catch(l){i(l)}if(s)throw e};return a()};import{parseArgs as j}from"node:util";var b="2.5.2";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 S(t){t.options={...A,...t.options};let e=j(t),{values:s}=e;s.version&&(console.log(b),process.exit(0));let n=t.commands?`
|
|
2
2
|
|
|
3
3
|
Commands:
|
|
4
4
|
${Object.entries(t.commands).map(([a,o])=>`${a.padEnd(30," ")} ${o}`).join(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as d,b as m,d as s,e as y,j as u}from"./chunk-
|
|
1
|
+
import{a as d,b as m,d as s,e as y,j as u}from"./chunk-2WXH7AN2.js";import{confirm as h,input as l,select as P}from"@inquirer/prompts";Symbol.dispose??=Symbol.for("nodejs.dispose");Symbol.asyncDispose??=Symbol.for("nodejs.asyncDispose");var f,g=()=>f?.();function b(){return process.once("beforeExit",g),{[Symbol.dispose](){process.off("beforeExit",g),f=void 0}}}async function n(e,...r){try{var t=[];try{let a=d(t,b());let p=e(...r);f=p.cancel;return await p}catch(o){var c=o,i=!0}finally{m(t,c,i)}}catch(a){throw a instanceof Error&&["CancelPromptError","ExitPromptError"].includes(a.constructor.name)?u("Cancelled! \u{1F44B}"):u(a)}}function w(...e){return n(P,...e)}var v=e=>e.charAt(0).toUpperCase()+e.slice(1).split(/(?=[A-Z])/).join(" ");function x(){return w({message:"Which environment do you want to use?",choices:y.map(e=>({name:v(e),value:e})),default:"expManager"})}function S(){return n(l,{message:"Enter the service name:"})}function V(){return n(l,{message:"Enter your simulator id:"})}async function E(e="8080",r=!1){return n(l,{message:`Enter the ${r?"local ":""}port:`,default:e,validate(t){return/^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/.test(t)?!0:"Please enter a valid port number"}})}async function C(e="5432"){return E(e,!0)}var T={cluster:x,variationId:V,service:S,port:(e="8080")=>E(e),"local-port":C};async function L(e,r){for(let t of r){let o=typeof t=="object"?t.option:t,c=typeof t=="object"?t.defaultVal:void 0;if(typeof o!="string")throw new Error(`Invalid option ${String(o)}`);let i=T[o];if(!i)throw new Error(`No value getter for ${String(o)}`);e[o]??=await i(c)}return e}async function R(e,r=!0){return n(h,{message:e,default:r})}var q=async()=>{let{stdout:e}=await s("git",["branch","--show-current"],{print:!1});return e.trim()},M=async()=>{let{stdout:e}=await s("git",["rev-parse","--show-toplevel"],{print:!1});return e.trim()},D=async e=>{let{stdout:r}=await s("git",["diff","origin/master..",e],{print:!1});return r};export{w as a,V as b,C as c,L as d,R as e,q as f,M as g,D as h};
|
package/dist/e2e.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{c as m,d as t,f as p,h as d,i as h,j as s}from"./chunk-
|
|
2
|
+
import{c as m,d as t,f as p,h as d,i as h,j as s}from"./chunk-2WXH7AN2.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 w,e as u,f as m,g as d,h as b}from"./chunk-
|
|
2
|
+
import{a as w,e as u,f as m,g as d,h as b}from"./chunk-OHRXFR2L.js";import{c as g,d as n,j as r}from"./chunk-2WXH7AN2.js";import{basename as P}from"node:path";import{randomUUID as V}from"node:crypto";var l=["premajor","preminor","prepatch","prerelease"],h=["major","minor","patch",...l],v={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."},j=e=>Object.keys(v).includes(e),y=async(e,t="")=>{let{stdout:o}=await n("npm",["version",e,"--no-git-tag-version","--preid",t],{print:!1});return await n("git",["add","package*"],{print:!1}),await n("git",["commit","-m",`${e} version: ${o}`],{print:!1}),console.log(`Created commit for version bump: ${e}. Version is now ${o}`),o},x=async()=>{let e=await d(),{default:{version:t}}=await import(`${e}/package.json`,{assert:{type:"json"},with:{type:"json"}});return t.replace(/\d+\.\d+\.\d+(?:-beta-([\w]+)?\.\d+)?/,"$1")},{positionals:$,help:p}=g({strict:!0,binName:"git autofleet",allowPositionals:!0,options:{},commands:v});$.length||(console.log(p),process.exit(0));var[s,i]=$;if(!j(s))throw r(new Error(`Command ${s} does not exist`),p);if(s==="openPR"){let[e,t]=await Promise.all([d(),m()]),c=`https://github.com/Autofleet/${P(e)}/compare/${t}?expand=1`;await n("open",[c],{print:!1}),process.exit(0)}if(s==="bumpVersion"){let e=i||await w({message:"Which version type do you want to bump?",choices:(s==="bumpVersion"?h:l).map(o=>({name:o,value:o}))});if(!e)throw r(new Error(`Must explicitly define version type.
|
|
3
3
|
Version type can be one of: ${h.join(", ")}`),p);let t=await m();["main","master"].includes(t)&&(await u("Are you sure you want to bump version on main branch?")||process.exit(0)),await y(e),process.exit(0)}if(s==="releaseBeta"){if(i&&!l.includes(i))throw r(new Error(`Invalid version type: ${i}
|
|
4
4
|
Version must be a prerelease type. (${l.join(", ")})`),p);let e=await m();if(["main","master"].includes(e))throw r(new Error("Cannot release beta from main branch"),p);let c=!(await b("package.json")).split(`
|
|
5
5
|
`).some(a=>/^\+\s*"version":\s*"\d+\.\d+\.\d+(?:-(?:[\w-]+\.)?\d+)?",/.test(a))||await u("Version already bumped on branch. Should version be re-bumped?"),C=c&&await x(),f=c&&await y(i||"prerelease",`beta-${C||V().split("-")[0]}`);await n("npm",["run","build"]);try{await n("npm",["publish","--tag","beta","--@autofleet:registry=https://registry.npmjs.org"])}catch(a){throw console.error(a),r("Failed to publish beta version")}if(f)console.log(`Published beta version with new version: ${f}`);else{let{stdout:a}=await n("npm",["info",".","version"],{print:!1});console.log(`Published beta version with existing version: ${a}`)}process.exit(0)}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as I,b as N,c as C,d as T,f as k,g as D}from"./chunk-
|
|
3
|
-
https://www.telepresence.io/docs/latest/quick-start/`)}}function R(){return I({message:"Do you want to leave the connection or create a new one?",choices:[{name:"Leave the current connection",value:"leave"},{name:"Create a new connection",value:"connect"}],default:"connect"})}async function v(e){await L();let{cluster:r="",service:o=""}=e;await g(r);let i=await R();if(!["leave","connect"].includes(i))throw a("Invalid action, how did you get here? \u{1F914}");if(i==="leave"){await t("telepresence",["leave",o]),console.log("Disconnected! \u{1F44B}");return}let
|
|
2
|
+
import{a as I,b as N,c as C,d as T,f as k,g as D}from"./chunk-OHRXFR2L.js";import{c as S,d as t,e as E,g,h as P,i as x,j as a}from"./chunk-2WXH7AN2.js";import{cwd as U}from"node:process";import{basename as O}from"node:path";async function L(){try{await t("telepresence",["version"],{print:!1})}catch{throw a(`Telepresence is not installed. Please install it from:
|
|
3
|
+
https://www.telepresence.io/docs/latest/quick-start/`)}}function R(){return I({message:"Do you want to leave the connection or create a new one?",choices:[{name:"Leave the current connection",value:"leave"},{name:"Create a new connection",value:"connect"}],default:"connect"})}async function v(e){await L();let{cluster:r="",service:o=""}=e;await g(r);let i=await R();if(!["leave","connect"].includes(i))throw a("Invalid action, how did you get here? \u{1F914}");if(i==="leave"){await t("telepresence",["leave",o]),console.log("Disconnected! \u{1F44B}");return}let w=e.variationId||await N(),n=e["local-port"]&&Number.parseInt(e["local-port"],10)||Number.parseInt(await C(),10);await t("telepresence",["connect",`--namespace=${w}`]),await t("telepresence",["intercept",o,"--port",n.toString(),"--env-file=./.env"]),console.log("Everything is set up! \u{1F680}"),console.log(`You can now access the service at localhost:${n}`),console.log("You can only have one connection at a time. If you want to connect to a different service, you need to leave the current connection first.")}import{EOL as _}from"node:os";import{resolve as q}from"node:path";import{readFile as F,writeFile as B}from"node:fs/promises";async function M(e,r,o){let i=q(e,".env"),n=(await F(i,"utf8")).split(_),$=`(?<!#\\s*)${r}(?==)`,m=n.find(W=>W.match($));if(m?.split("=").at(-1)===o){console.log("env file already up to date!");return}let y=m?n.indexOf(m):-1;return y!==-1?n.splice(y,1,`${r}=${o}`):n.push(`${r}=${o}`),B(i,n.join(_))}var A=E.join("/"),p=`--variationId=<yourVariationUuid> --cluster=<${A}>`,V={switchCluster:`--cluster=<${A}>`,exposeService:`--service=<driver-ms> ${p}`,forwardDb:`${p} --local-port=<localPort>`,forwardService:`--service=<driver-ms> ${p} --port=<port> --local-port=<localPort>`,getIps:p,enableSimulator:p,rabbitCreds:p,updateExp:p,telepresenceWizard:`--service=<driver-ms> ${p} --local-port=<localPort>`,localDev:p},j=e=>Object.keys(V).includes(e),{positionals:b,values:f,help:l}=S({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:V}),z={switchCluster:["cluster"],exposeService:["cluster","variationId","service"],forwardDb:["cluster","variationId",{option:"local-port",defaultVal:"5432"}],forwardService:["cluster","variationId","service","port"],telepresenceWizard:["cluster","service"]};b.length||(console.log(l),process.exit(0));b.length>1&&a("Only one command is allowed",l);var[c]=b;if(!j(c))throw a(new Error(`Command ${c} does not exist`),l);await T(f,z[c]??["cluster","variationId"]);var{cluster:h,variationId:d,service:u}=f;if(!h)throw a(new Error("cluster required"),l);c==="telepresenceWizard"&&(await v(f),process.exit(0));c==="switchCluster"&&(await g(h),console.log(`switched to ${h} successfully`),process.exit(0));if(!d)throw a(new Error("variationId required"),l);var s;try{s=await P({clusterName:h,variationId:d})}catch(e){throw a(e)}if(c==="exposeService"){if(!u)throw a(new Error("service is required for exposeService"),l);await t("kubectl",["patch","svc",s,u,"-p",'{"spec": {"type": "LoadBalancer"}}']),console.log(`exposed ${u} successfully. the service is now creating an internal load balancer ip to use with vpn`),process.exit(0)}if(c==="forwardDb"){let e=Number.parseInt(f["local-port"]??"5432",10);if(Number.isNaN(e))throw a(new Error("if defined, local-port must be a number"),l);let r=`postgres://postgres:afpass_${d}@localhost:${e}/postgres?&nickname=var_${d}`;console.log(`Forwarding db to local port ${e}.
|
|
4
4
|
access the DB at ${r}
|
|
5
|
-
Press ctrl+c to stop.`),t("open",[r],{print:!1}).catch(()=>null),await t("kubectl",[s,"port-forward",`statefulset/p${
|
|
6
|
-
Press ctrl+c to stop.`),await t("kubectl",["port-forward",s,o,`${r}:${e}`],{print:!1}),process.exit(0)}if(c==="getIps"){let{stdout:e}=await t("kubectl",[s,"get","services"],{print:!1});x(e).forEach(o=>console.log(o)),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=${
|
|
5
|
+
Press ctrl+c to stop.`),t("open",[r],{print:!1}).catch(()=>null),await t("kubectl",[s,"port-forward",`statefulset/p${d}-postgresql`,`${e}:5432`],{print:!1}),process.exit(0)}if(c==="forwardService"){let e=Number.parseInt(f.port??"8080",10),r=Number.parseInt(f["local-port"]??"",10)||e;if(!u)throw a(new Error("service is required for forwardService"),l);if(!e||Number.isNaN(e))throw a(new Error("port is required and must be a numbers"),l);if(r&&Number.isNaN(r))throw a(new Error("local-port must be a number"),l);let{stdout:o}=await t("kubectl",["get","pods",s,"-l",`service=${u}`,"-o",'jsonpath="{.items[0].metadata.name}"'],{print:!1});if(o&&=o.trim(),!o)throw a(new Error(`No pods found for service ${u}`));o.startsWith('"')&&o.endsWith('"')&&(o=o.slice(1,-1)),console.log(`Found pod ${o}, serving locally on port ${r} from remote port ${e}.
|
|
6
|
+
Press ctrl+c to stop.`),await t("kubectl",["port-forward",s,o,`${r}:${e}`],{print:!1}),process.exit(0)}if(c==="getIps"){let{stdout:e}=await t("kubectl",[s,"get","services"],{print:!1});x(e).forEach(o=>console.log(o)),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=${d}:default`]),console.log(`Successfully exposed ${e} and added role binding to dispatch simulations`),process.exit(0)}if(c==="rabbitCreds"){let e=i=>["get","secret","rabbitmq-default-user","-o",`jsonpath="{.data.${i}}"`],[{stdout:r},{stdout:o}]=await Promise.all([t("kubectl",e("username"),{print:!1}),t("kubectl",e("password"),{print:!1})]);console.log(`username: ${Buffer.from(r,"base64").toString("ascii")}`),console.log(`password: ${Buffer.from(o,"base64").toString("ascii")}`),process.exit(0)}if(c==="updateExp"){let e=O(U()),[r,o]=await Promise.all([k(),t("uname",["-m"],{print:!1})]),i=o.stdout.trim(),w=`${new Date().getHours().toString().padStart(2,"0")}-${new Date().getMinutes().toString().padStart(2,"0")}-${new Date().getSeconds().toString().padStart(2,"0")}`,n=`gcr.io/autofleetprod/${e}:${r}-${w}`;console.log(`Building and pushing image ${n}`),await t("docker",["build",".",...i==="x86_64"?[]:["--platform","linux/amd64"],"-t",n,"--build-arg",`NPM_TOKEN=${process.env.NPM_TOKEN}`]),await t("docker",["push",n]);let{stdout:m}=await t("kubectl",["describe","pod",s,"-l",`service=${e}`],{print:!1});m.includes("Init Containers:")&&await t("kubectl",["patch",`deployment/${e}`,s,"--patch",`{"spec": {"template": {"spec": {"initContainers": [{"name": "init","image": "${n}"}]}}}}`]),await t("kubectl",["set","image",`deployment/${e}`,`worker=${n}`,s]),await t("kubectl",["rollout","status","deployments",e,s]),process.exit(0)}if(c==="localDev"){let e="api-gateway-ms",r="control-center-ms",o=await D();O(o)!=="control-center"&&a(new Error("The `localDev` command must be run from the control-center repository"));let{stdout:i}=await t("kubectl",["get","ingress",`${e}-ingress`,s,"-o",'jsonpath="{.status.loadBalancer.ingress[0].ip}"'],{print:!1});i||a(new Error(`The IP of the Load balancer for ${e} was not found`)),await M(o,"API_GATEWAY_MS_SERVICE_HOST",i.replace(/"/g,"")),console.log(`Updated .env file to use ${e} IP (${i}). Will now start port-forwarding ${r} to port 8085.
|
|
7
7
|
Press ctrl+c to stop.`),await t("kubectl",["port-forward",s,`svc/${r}`,"8085:80"],{print:!1}),process.exit(0)}
|