@platforma-sdk/bootstrap 2.9.1 → 3.0.0
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/assets/compose-backend.yaml +12 -5
- package/dist/block.d.ts.map +1 -1
- package/dist/cmd-opts.d.ts +5 -2
- package/dist/cmd-opts.d.ts.map +1 -1
- package/dist/commands/start/docker/s3.d.ts.map +1 -1
- package/dist/commands/start/docker.d.ts.map +1 -1
- package/dist/commands/start/local/s3.d.ts +2 -2
- package/dist/commands/start/local/s3.d.ts.map +1 -1
- package/dist/commands/start/local.d.ts.map +1 -1
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/stop.d.ts.map +1 -1
- package/dist/commands/svc/create/docker/s3.d.ts +32 -0
- package/dist/commands/svc/create/docker/s3.d.ts.map +1 -0
- package/dist/commands/svc/create/docker.d.ts +34 -0
- package/dist/commands/svc/create/docker.d.ts.map +1 -0
- package/dist/commands/svc/create/local.d.ts +39 -0
- package/dist/commands/svc/create/local.d.ts.map +1 -0
- package/dist/commands/svc/delete.d.ts +15 -0
- package/dist/commands/svc/delete.d.ts.map +1 -0
- package/dist/commands/svc/down.d.ts +14 -0
- package/dist/commands/svc/down.d.ts.map +1 -0
- package/dist/commands/svc/list.d.ts +8 -0
- package/dist/commands/svc/list.d.ts.map +1 -0
- package/dist/commands/svc/up.d.ts +14 -0
- package/dist/commands/svc/up.d.ts.map +1 -0
- package/dist/core.d.ts +19 -13
- package/dist/core.d.ts.map +1 -1
- package/dist/index.d.ts +18 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1253 -950
- package/dist/index.mjs.map +1 -1
- package/dist/platforma.d.ts.map +1 -1
- package/dist/run.d.ts +11 -5
- package/dist/run.d.ts.map +1 -1
- package/dist/state.d.ts +43 -22
- package/dist/state.d.ts.map +1 -1
- package/dist/templates/compose.d.ts +3 -1
- package/dist/templates/compose.d.ts.map +1 -1
- package/dist/templates/types.d.ts.map +1 -1
- package/dist/util.d.ts +7 -1
- package/dist/util.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var vr=Object.defineProperty;var Pr=(a,e,t)=>e in a?vr(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var l=(a,e,t)=>Pr(a,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@oclif/core"),T=require("node:os"),u=require("node:fs"),h=require("node:path"),ae=require("node:child_process"),le=require("winston"),kr=require("node:crypto"),K=require("readline-sync"),Sr=require("node:fs/promises"),$r=require("node:stream"),D=require("zod"),Ar=require("decompress"),ge=require("yaml"),ue=require("@milaboratories/pl-local"),Lr=require("node:https"),Ir=require("tar");function gr(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const x=gr(Sr),Or=gr(Ir),A={"log-level":d.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"],required:!1})};d.Flags.string({description:"name of instance",required:!1});const fe={image:d.Flags.string({description:"use custom docker image to run platforma"})},q={version:d.Flags.string({description:"use custom platforma release (official docker image or binary package)"})},me={arch:d.Flags.string({description:"override architecture. You can start amd64 linux image on arm-based host (say, Apple M family processor)",options:["amd64","arm64"]})},J={license:d.Flags.string({description:'pass a license code. The license can be got from "https://licensing.milaboratories.com".'}),"license-file":d.Flags.file({exists:!0,description:"specify a path to the file with a license. The license can be got from 'https://licensing.milaboratories.com'."})},H={"grpc-port":d.Flags.integer({description:"port for Platforma Backend gRPC API. Default is 6345",env:"PLATFORMA_GRPC_PORT"}),"grpc-listen":d.Flags.string({description:"full listen addr for Platforma Backend gRPC API. Default is 127.0.0.1:6345",env:"PLATFORMA_GRPC_LISTEN"}),"monitoring-port":d.Flags.integer({description:"port for Platforma Backend monitoring API. Default is 9090",env:"PLATFORMA_MONITORING_PORT"}),"monitoring-listen":d.Flags.string({description:"full listen addr for Platforma Backend monitoring API. Default is 127.0.0.1:9090",env:"PLATFORMA_MONITORING_LISTEN"}),"debug-port":d.Flags.integer({description:"port for Platforma Backend debug API. Default is 9091",env:"PLATFORMA_DEBUG_PORT"}),"debug-listen":d.Flags.string({description:"full listen addr for Platforma Backend debug API. Default is 127.0.0.1:9091",env:"PLATFORMA_DEBUG_LISTEN"})},ur={"s3-port":d.Flags.integer({description:"port that S3 will listen, default is 9000",default:9e3,env:"PLATFORMA_S3_PORT"}),"s3-console-port":d.Flags.integer({description:"port that a console of S3 will listen, default is 9001",default:9001,env:"PLATFORMA_S3_CONSOLE_PORT"})},W={storage:d.Flags.string({description:"specify path on host to be used as storage for all Platforma Backend data"})},fr={"minio-presign-host":d.Flags.boolean({description:"use 'minio' host instead of 'localhost' in presign URLs"})},he={mount:d.Flags.string({multiple:!0,description:"things to be mounted into platforma docker container. Targets will appear inside the container under the same absolute paths"})},De={"pl-log-file":d.Flags.file({description:"specify path for Platforma Backend log file"})},xe={"pl-workdir":d.Flags.file({description:"specify working directory for Platforma Backend process"})},_e={"pl-binary":d.Flags.file({description:"start given Platforma Backend binary instead of automatically downloaded version"})},Ne={"pl-sources":d.Flags.file({description:"path to pl repository root: build Platforma Backend from sources and start the resulting binary"})},Ce={config:d.Flags.string({description:"use custom Platforma Backend config"})};d.Flags.file({description:"specify path on host to be used as 'primary' storage"});const ie={"storage-work":d.Flags.file({description:"specify path on host to be used as 'work' storage"})};d.Flags.file({description:"specify path on host to be used as 'library' storage"});const ce={"storage-primary":d.Flags.string({description:`specify 'primary' storage destination URL.
|
|
2
2
|
file:/path/to/dir for directory on local FS
|
|
3
3
|
s3://<bucket>/?region=<name> for real AWS bucket
|
|
4
4
|
s3e://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via http
|
|
5
|
-
s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},
|
|
5
|
+
s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},oe={"storage-library":d.Flags.string({description:`specify 'library' storage destination URL.
|
|
6
6
|
file:/path/to/dir for directory on local FS
|
|
7
7
|
s3://<bucket>/?region=<name> for real AWS bucket
|
|
8
8
|
s3e://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via http
|
|
9
|
-
s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},
|
|
10
|
-
`).map((
|
|
11
|
-
`);return`${(
|
|
12
|
-
`);return
|
|
13
|
-
env: ${JSON.stringify(
|
|
14
|
-
cmd: ${JSON.stringify([e,...
|
|
15
|
-
wd: ${
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
wd: ${t.cwd}`),t.env={...process.env,...t.env},T.spawnSync(e,r,t)}function Ge(a,e,r){if(!r||r.size==0){l.copyFileSync(a,e);return}const t=l.readFileSync(a,{encoding:"utf-8"}),s=X.parse(t.toString());if(!s.services)throw new Error(`file '${a}' seems to be not a docker-compose file or has unsupported version`);for(const i of Object.keys(s.services))r.has(i)||delete s.services[i];for(const[i,n]of r.entries()){const c=s.services[i];if(!c)throw new Error(`docker compose '${a}' has no declaration of service '${i}'`);if(n.platform&&(c.platform=n.platform),n.envs){c.environment||(c.environment=[]);for(let o=0;o<((c==null?void 0:c.environment.length)??0);){const u=c.environment[o].split("=")[0];if(n.envs[u]){const b=c.environment.pop();b&&c.environment.length!==o&&(c.environment[o]=b)}else o++}for(const[o,m]of Object.entries(n.envs))c.environment.push(`${o}=${m}`)}if(n.mounts){c.volumes||(c.volumes=[]);for(const o of n.mounts)c.volumes.push(`${o.hostPath}:${o.containerPath}`)}}l.writeFileSync(e,X.stringify(s))}function Br(a){return{id:a,type:"S3",indexCachePeriod:"0s",endpoint:"",region:"",presignEndpoint:"",bucketName:"",createBucket:!1,forcePathStyle:!1,key:"",secret:"",keyPrefix:"",accessPrefixes:[],uploadKeyPrefix:""}}function tr(a){return{id:a,type:"FS",indexCachePeriod:"0s",rootPath:""}}function M(a,e,r){a=pr(a);const t=new URL(a,`file:${e}`);switch(t.protocol){case"s3:":var n=t.hostname,s=t.searchParams.get("region");return{...r,type:"S3",bucketName:n,region:s};case"s3e:":var i=t.pathname.split("/").slice(1),n=i[0],c=i.length>1?i[1]:"";return{...r,type:"S3",endpoint:`http://${t.host}/`,bucketName:n,keyPrefix:c,region:t.searchParams.get("region"),key:t.username?`static:${t.username}`:"",secret:t.password?`static:${t.password}`:""};case"s3es:":var i=t.pathname.split("/").slice(1),n=i[0],c=i.length>1?i[1]:"";return{...r,type:"S3",endpoint:`https://${t.host}/`,bucketName:n,keyPrefix:c,region:t.searchParams.get("region"),key:t.username?`static:${t.username}`:"",secret:t.password?`static:${t.password}`:""};case"file:":return{type:"FS",rootPath:t.pathname};default:throw new Error(`storage protocol '${t.protocol}' is not supported`)}}function jr(a,e){var h,y,L,w,k,R,A,S,p,ve,we,ke,Se,pe,Ae,Re,Le,_e,$e,Oe,Fe,Te,Ee,De,Ne,Ie,xe,Me,Ce,Be;const r=(e==null?void 0:e.localRoot)??d.data("local-custom"),t={level:((h=e==null?void 0:e.log)==null?void 0:h.level)??"info",path:((y=e==null?void 0:e.log)==null?void 0:y.path)??`${r}/logs/platforma.log`},s={listen:((L=e==null?void 0:e.grpc)==null?void 0:L.listen)??"localhost:6345",tls:{enable:K((k=(w=e==null?void 0:e.grpc)==null?void 0:w.tls)==null?void 0:k.enable,!1),clientAuthMode:((A=(R=e==null?void 0:e.grpc)==null?void 0:R.tls)==null?void 0:A.clientAuthMode)??"NoAuth",certFile:((p=(S=e==null?void 0:e.grpc)==null?void 0:S.tls)==null?void 0:p.certFile)??`${r}/certs/tls.cert`,keyFile:((we=(ve=e==null?void 0:e.grpc)==null?void 0:ve.tls)==null?void 0:we.keyFile)??`${r}/certs/tls.key`,...(ke=e==null?void 0:e.grpc)==null?void 0:ke.tls}},i={auth:{enabled:((pe=(Se=e==null?void 0:e.core)==null?void 0:Se.auth)==null?void 0:pe.enabled)??!1,drivers:((Re=(Ae=e==null?void 0:e.core)==null?void 0:Ae.auth)==null?void 0:Re.drivers)??[{driver:"jwt",key:a},{driver:"htpasswd",path:`${r}/users.htpasswd`}]},db:{path:`${r}/db`}},n=Ue("main",`${r}/storages/main`,"main-bucket",(Le=e==null?void 0:e.storages)==null?void 0:Le.primary);var c;switch(($e=(_e=e==null?void 0:e.storages)==null?void 0:_e.work)==null?void 0:$e.type){case void 0:case"FS":c=tr("work"),c.rootPath=((Fe=(Oe=e==null?void 0:e.storages)==null?void 0:Oe.work)==null?void 0:Fe.rootPath)??`${r}/storages/work`,c.indexCachePeriod=((Ee=(Te=e==null?void 0:e.storages)==null?void 0:Te.work)==null?void 0:Ee.indexCachePeriod)??"1m";break;default:throw new Error("work storage MUST have 'FS' type as it is used for working directories management")}const m=Ue("library",`${r}/storages/library`,"library-bucket",(De=e==null?void 0:e.storages)==null?void 0:De.library),u={enabled:K((Ne=e==null?void 0:e.monitoring)==null?void 0:Ne.enabled,!0),listen:((Ie=e==null?void 0:e.monitoring)==null?void 0:Ie.listen)??"127.0.0.1:9090"},b={enabled:K((xe=e==null?void 0:e.debug)==null?void 0:xe.enabled,!0),listen:((Me=e==null?void 0:e.debug)==null?void 0:Me.listen)??"127.0.0.1:9091"},v={value:((Ce=e==null?void 0:e.license)==null?void 0:Ce.value)??"",file:((Be=e==null?void 0:e.license)==null?void 0:Be.file)??""};return{localRoot:r,license:v,log:t,grpc:s,core:i,monitoring:u,debug:b,storages:{primary:n,work:c,library:m},hacks:{libraryDownloadable:!0}}}function Ue(a,e,r,t){var s;switch(t==null?void 0:t.type){case void 0:case"FS":s=tr(a),s.rootPath=(t==null?void 0:t.rootPath)??e;break;case"S3":s=Br(a),s.endpoint=(t==null?void 0:t.endpoint)??"http://localhost:9000",s.presignEndpoint=(t==null?void 0:t.presignEndpoint)??"http://localhost:9000",s.bucketName=(t==null?void 0:t.bucketName)??r,s.createBucket=K(t==null?void 0:t.createBucket,!0),s.forcePathStyle=K(t==null?void 0:t.forcePathStyle,!0),s.key=(t==null?void 0:t.key)??"",s.secret=(t==null?void 0:t.secret)??"",s.keyPrefix=(t==null?void 0:t.keyPrefix)??"",s.accessPrefixes=(t==null?void 0:t.accessPrefixes)??[""],s.uploadKeyPrefix=(t==null?void 0:t.uploadKeyPrefix)??"";break;default:throw Y(),new Error("unknown storage type")}return s}function Gr(a){const e=a.monitoring.enabled?"":" disabled",r=a.debug.enabled?"":" disabled",t=a.hacks.libraryDownloadable?"true":"false";var s=a.license.value;return a.license.file!=""&&(s=l.readFileSync(a.license.file).toString().trimEnd()),`
|
|
9
|
+
s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},Fr={"auth-enabled":d.Flags.boolean({description:"enable authorization"})},Er={"auth-htpasswd-file":d.Flags.file({description:"path to .htpasswd file with Platforma users (static user DB auth source)"})},Rr={"auth-ldap-server":d.Flags.string({description:"address of LDAP server to use for auth in Platforma (auth source)"})},Tr={"auth-ldap-default-dn":d.Flags.string({description:"DN to use when checking user with LDAP bind operation: e.g. cn=%u,ou=users,dc=example,dc=com"})},z={...Fr,...Er,...Rr,...Tr};function Dr(a){return K.question(`${a} [y/N] `).toLowerCase()==="y"}function _(a){throw new Error("this should never happen")}function L(a="debug"){return le.createLogger({level:a,format:le.format.printf(({level:e,message:t})=>{const r=" ".repeat(e.length+2);if(typeof t!="string"){const i=JSON.stringify(t);throw Error(`logger message ${i} is not a string`)}const n=t.split(`
|
|
10
|
+
`).map((i,c)=>c===0?i:r+i).join(`
|
|
11
|
+
`);return`${(i=>le.format.colorize().colorize(i,i))(e)}: ${n}`}),transports:[new le.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function xr(a){return kr.randomBytes(Math.ceil(a/2)).toString("hex").slice(0,a)}function _r(a){return a.startsWith("~")?h.join(T.homedir(),a.slice(1)):a}function ye(a,e){u.existsSync(a)||(u.mkdirSync(a,{recursive:!0}),e!=null&&e.mode&&u.chmodSync(a,e.mode))}function Nr(a){try{if(T.platform()!=="win32")return ae.execSync(`ps -p ${a} -o comm=`,{encoding:"utf8"}).trim();const e=`wmic process where processid=${a} get Caption`,t=ae.execSync(e,{encoding:"utf8"}).split(`
|
|
12
|
+
`);return t.length<=1?"":t[1].trim()}catch{return""}}function Cr(a){const e=ae.execSync(`docker compose ls --filter name=${a} --format json`,{encoding:"utf8"}).trim(),t=JSON.parse(e);for(const r of t)if(r.Name===a)return r}const ve=["Python"],mr=["Tengo","Python"],Mr=D.z.union([D.z.literal("Tengo"),D.z.literal("Python")]),jr=D.z.object({npmOrgName:D.z.string().min(1),orgName:D.z.string().min(1),blockName:D.z.string().min(1),softwarePlatforms:D.z.array(Mr).refine(a=>new Set(a).size===a.length,{message:"Must be an array of unique software platforms"})});async function Br(a){const{npmOrgName:e,orgName:t,blockName:r,softwarePlatforms:n}=Gr(),s=h.join(process.cwd(),r);a.info("Downloading boilerplate code..."),await Ur("https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip","platforma-block-boilerplate-main",s);const i=mr.filter(o=>n.indexOf(o)<0),c=ve.length==i.length;a.info(`Keep platforms '${n}', remove: '${i}'. Will remove all platforms? ${c}`);for(const o of i)await qr(s,o);c&&await Jr(s),a.info("Replace everything in the template with provided options..."),Hr(s,[{from:/@platforma-open(?!.*runenv-python-3)/g,to:`@${e}`},{from:/my-org/g,to:t},{from:/block-boilerplate/g,to:r}])}function Gr(){let a=K.question('Write an organization name for npm. Default is "platforma-open": ');a===""&&(a="platforma-open");const e=K.question('Write an organization name, e.g. "my-org": '),t=K.question('Write a name of the block, e.g. "hello-world": '),r=K.keyInYN("Create package for block's software?");let n=["Tengo"];if(r)for(;n.length<mr.length;){const s=K.keyInSelect(ve,"Choose software platform:");if(s<0)break;n.push(ve[s])}return n=Array.from(new Set(n)).sort(),jr.parse({npmOrgName:a,orgName:e,blockName:t,softwarePlatforms:n})}async function Ur(a,e,t){const n=await(await fetch(a)).blob(),s=await x.mkdtemp(h.join(T.tmpdir(),"create-repo")),i=h.join(s,"packed-repo.zip"),c=$r.Writable.toWeb(u.createWriteStream(i));await n.stream().pipeTo(c);const o=h.join(s,"unpacked-repo");await x.mkdir(o),await Ar(i,o),await x.cp(h.join(o,e),t,{recursive:!0})}async function qr(a,e){const t=e.toLowerCase();await Q(h.join(a,"ui","src","pages","MainPage.vue"),new RegExp(`.*${t}Message.*\\n\\n`,"g")),await Q(h.join(a,"model","src","index.ts"),new RegExp(`.*${t}Message.*\\n\\n`,"g")),await Q(h.join(a,"workflow","src","main.tpl.tengo"),new RegExp(`.*${t}.*exec.builder.*[\\s\\S]*?\\n\\n`,"g")),await Q(h.join(a,"workflow","src","main.tpl.tengo"),new RegExp(`.*${t}Message.*\\n`,"g")),await Q(h.join(a,"workflow","src","wf.test.ts"),new RegExp(`.*${t}Message.*\\n.*expect.*\\n\\n`,"g")),await x.rm(h.join(a,"software",`src_${t}`),{recursive:!0}),await Me(h.join(a,"software","package.json"),r=>{const n=JSON.parse(r);return delete n["block-software"].artifacts[`hello-${t}-artifact`],delete n["block-software"].entrypoints[`hello-world-${t}`],JSON.stringify(n,null,2)})}async function Jr(a){await x.rm(h.join(a,"software"),{recursive:!0}),await Me(h.join(a,"workflow","package.json"),e=>{const t=JSON.parse(e);return delete t.dependencies["@platforma-open/my-org.block-boilerplate.software"],JSON.stringify(t,null,2)}),await Q(h.join(a,"pnpm-workspace.yaml"),/.*- software$\n/gm)}async function Hr(a,e){const t=await Wr(a);for(const{from:r,to:n}of e)for(const s of t)await hr(s,r,n)}async function Wr(a){return(await x.readdir(a,{withFileTypes:!0,recursive:!0})).filter(t=>t.isFile()).map(t=>h.join(t.parentPath,t.name))}async function Me(a,e){const t=await x.readFile(a),r=e(t.toString());await x.writeFile(a,r)}async function hr(a,e,t){return await Me(a,r=>r.replaceAll(e,t))}async function Q(a,e){return await hr(a,e,"")}const X=class X extends d.Command{async run(){const{flags:e}=await this.parse(X),t=L(e["log-level"]);await Br(t)}};l(X,"description","Helps to create a new block by downloading a block's template."),l(X,"examples",["<%= name %>"]),l(X,"flags",{...A});let Pe=X;function yr(...a){return h.resolve(__dirname,"..",...a)}function Y(...a){return yr("assets",...a)}function be(...a){return u.readFileSync(yr(...a))}function or(a){return a||(a=ue.getDefaultPlVersion()),`quay.io/milaboratories/platforma:${a}`}const N=class N{constructor(e){l(this,"state",{currentInstance:""});l(this,"filePath");l(this,"dirPath");e=e??h.resolve(T.homedir(),".config","pl-bootstrap");const t=h.join(e,"state.json");this.dirPath=e,this.filePath=t,u.existsSync(e)||u.mkdirSync(e,{recursive:!0}),u.existsSync(t)&&(this.state=JSON.parse(be(t).toString()))}static getStateInstance(){return N.instance||(N.instance=new N),N.instance}path(...e){return h.join(this.dirPath,...e)}instanceDir(e,...t){return e?this.path("data",e,...t):this.path("data")}binaries(...e){return this.path("binaries",...e)}writeState(){u.writeFileSync(this.filePath,JSON.stringify(this.state))}get instanceList(){return u.existsSync(this.instanceDir())?u.readdirSync(this.instanceDir()).filter(t=>this.instanceExists(t)):[]}instanceExists(e){return u.existsSync(this.instanceDir(e,"instance.json"))}getInstanceInfo(e){const t=this.instanceDir(e,"instance.json");if(!u.existsSync(t))throw new Error(`platforma backend instance '${e}' does not exist or is corrupted`);const r=JSON.parse(be(t).toString());return{name:e,...r}}setInstanceInfo(e,t){u.existsSync(this.instanceDir(e))||u.mkdirSync(this.instanceDir(e),{recursive:!0});const r=this.instanceDir(e,"instance.json");let n={};u.existsSync(r)&&(n=JSON.parse(be(r).toString())),u.writeFileSync(r,JSON.stringify({...n,...t}))}isInstanceActive(e){switch(e.type){case"docker":{const r=Cr(`pl-${e.name}`);return r?r.Status.trim().startsWith("running"):!1}case"process":return e.pid?lr(e.pid):!1;default:throw _(),new Error("cli logic error: unknown service type, cannot check its state")}}get isActive(){for(const e of this.instanceList){const t=this.getInstanceInfo(e);if(this.isInstanceActive(t))return!0}return!1}isValidPID(e){return lr(e)}get currentInstance(){const e=this.state.currentInstance;if(e&&this.instanceExists(e))return this.getInstanceInfo(e)}get currentInstanceName(){return this.state.currentInstance}set currentInstanceName(e){this.state.currentInstance=e,this.writeState()}selectInstance(e){if(!this.instanceExists(e))throw new Error(`instance '${e}' does not exist`);this.state.currentInstance=e,this.writeState()}};l(N,"instance");let ke=N;function lr(a){const e=Nr(a);return e==="platforma"||e.endsWith("/platforma")||e.endsWith("\\platforma")}const g=ke.getStateInstance();function pe(a,e,t){const r=[],n=[];for(const s of e)if(t={cwd:s.workdir,env:{...s.envs,...t==null?void 0:t.env},...s.runOpts,...t},s.async){const i=zr(a,s.cmd,s.args,t);n.push(i)}else{const i=Yr(a,s.cmd,s.args,t);if(r.push(i),i.error||i.status!==0)break}return{executed:r,spawned:n}}function zr(a,e,t,r){var c;a.debug(`Running:
|
|
13
|
+
env: ${JSON.stringify(r.env)}
|
|
14
|
+
cmd: ${JSON.stringify([e,...t])}
|
|
15
|
+
wd: ${(c=r.cwd)==null?void 0:c.toString()}`),r.env={...process.env,...r.env},a.debug(" spawning child process");const n=ae.spawn(e,t,r);let s=!1;const i=()=>{n.kill("SIGINT"),s=!0};return a.debug(" setting up signal handler"),process.on("SIGINT",i),n.on("close",o=>{process.removeListener("SIGINT",i),s&&process.exit(o)}),n}function Yr(a,e,t,r){return a.debug(`Running:
|
|
16
|
+
cmd: ${JSON.stringify([e,...t])}
|
|
17
|
+
opts: ${JSON.stringify(r)}`),r.env={...process.env,...r.env},ae.spawnSync(e,t,r)}function we(a,e,t,r,n){const s=u.readFileSync(a,{encoding:"utf-8"}),i=ge.parse(s.toString());if(!i.services)throw new Error(`file '${a}' seems to be not a docker-compose file or has unsupported version`);if(r)for(const c of Object.keys(i.services))r.has(c)||delete i.services[c];i.name=t;for(const[c,o]of(r==null?void 0:r.entries())??[]){const m=i.services[c];if(!m)throw new Error(`docker compose '${a}' has no declaration of service '${c}'`);if(o.platform&&(m.platform=o.platform),o.envs){m.environment||(m.environment=[]);for(let f=0;f<((m==null?void 0:m.environment.length)??0);){const w=m.environment[f].split("=")[0];if(o.envs[w]){const v=m.environment.pop();v&&m.environment.length!==f&&(m.environment[f]=v)}else f++}for(const[f,y]of Object.entries(o.envs))m.environment.push(`${f}=${y}`)}if(o.mounts){m.volumes||(m.volumes=[]);for(const f of o.mounts)m.volumes.push(`${f.hostPath}:${f.containerPath}`)}}n!=null&&n.dropVolumes&&delete i.volumes,u.writeFileSync(e,ge.stringify(i))}function Vr(a){return{id:a,type:"S3",indexCachePeriod:"0s",endpoint:"",region:"",presignEndpoint:"",bucketName:"",createBucket:!1,forcePathStyle:!1,key:"",secret:"",keyPrefix:"",accessPrefixes:[],uploadKeyPrefix:""}}function br(a){return{id:a,type:"FS",indexCachePeriod:"0s",rootPath:""}}function V(a,e,t){a=_r(a);const r=new URL(a,`file:${e}`);switch(r.protocol){case"s3:":var i=r.hostname,n=r.searchParams.get("region");return{...t,type:"S3",bucketName:i,region:n};case"s3e:":var s=r.pathname.split("/").slice(1),i=s[0],c=s.length>1?s[1]:"";return{...t,type:"S3",endpoint:`http://${r.host}/`,bucketName:i,keyPrefix:c,region:r.searchParams.get("region"),key:r.username?`static:${r.username}`:"",secret:r.password?`static:${r.password}`:""};case"s3es:":var s=r.pathname.split("/").slice(1),i=s[0],c=s.length>1?s[1]:"";return{...t,type:"S3",endpoint:`https://${r.host}/`,bucketName:i,keyPrefix:c,region:r.searchParams.get("region"),key:r.username?`static:${r.username}`:"",secret:r.password?`static:${r.password}`:""};case"file:":return{type:"FS",rootPath:r.pathname};default:throw new Error(`storage protocol '${r.protocol}' is not supported`)}}function Kr(a,e){var v,b,P,S,k,p,$,ne,Be,Ge,Ue,qe,Je,He,We,ze,Ye,Ve,Ke,Qe,Xe,Ze,er,rr,tr,ar,nr,sr,ir,cr;const t=(e==null?void 0:e.localRoot)??g.instanceDir("default"),r={level:((v=e==null?void 0:e.log)==null?void 0:v.level)??"info",path:((b=e==null?void 0:e.log)==null?void 0:b.path)??`${t}/logs/platforma.log`},n={listen:((P=e==null?void 0:e.grpc)==null?void 0:P.listen)??"localhost:6345",tls:{enable:se((k=(S=e==null?void 0:e.grpc)==null?void 0:S.tls)==null?void 0:k.enable,!1),clientAuthMode:(($=(p=e==null?void 0:e.grpc)==null?void 0:p.tls)==null?void 0:$.clientAuthMode)??"NoAuth",certFile:((Be=(ne=e==null?void 0:e.grpc)==null?void 0:ne.tls)==null?void 0:Be.certFile)??`${t}/certs/tls.cert`,keyFile:((Ue=(Ge=e==null?void 0:e.grpc)==null?void 0:Ge.tls)==null?void 0:Ue.keyFile)??`${t}/certs/tls.key`,...(qe=e==null?void 0:e.grpc)==null?void 0:qe.tls}},s={auth:{enabled:((He=(Je=e==null?void 0:e.core)==null?void 0:Je.auth)==null?void 0:He.enabled)??!1,drivers:((ze=(We=e==null?void 0:e.core)==null?void 0:We.auth)==null?void 0:ze.drivers)??[{driver:"jwt",key:a},{driver:"htpasswd",path:`${t}/users.htpasswd`}]},db:{path:`${t}/db`}},i=dr("main",`${t}/storages/main`,"main-bucket",(Ye=e==null?void 0:e.storages)==null?void 0:Ye.primary);let c;switch((Ke=(Ve=e==null?void 0:e.storages)==null?void 0:Ve.work)==null?void 0:Ke.type){case void 0:case"FS":c=br("work"),c.rootPath=((Xe=(Qe=e==null?void 0:e.storages)==null?void 0:Qe.work)==null?void 0:Xe.rootPath)??`${t}/storages/work`,c.indexCachePeriod=((er=(Ze=e==null?void 0:e.storages)==null?void 0:Ze.work)==null?void 0:er.indexCachePeriod)??"1m";break;default:throw new Error("work storage MUST have 'FS' type as it is used for working directories management")}const m=dr("library",`${t}/storages/library`,"library-bucket",(rr=e==null?void 0:e.storages)==null?void 0:rr.library),f={enabled:se((tr=e==null?void 0:e.monitoring)==null?void 0:tr.enabled,!0),listen:((ar=e==null?void 0:e.monitoring)==null?void 0:ar.listen)??"127.0.0.1:9090"},y={enabled:se((nr=e==null?void 0:e.debug)==null?void 0:nr.enabled,!0),listen:((sr=e==null?void 0:e.debug)==null?void 0:sr.listen)??"127.0.0.1:9091"},w={value:((ir=e==null?void 0:e.license)==null?void 0:ir.value)??"",file:((cr=e==null?void 0:e.license)==null?void 0:cr.file)??""};return{localRoot:t,license:w,log:r,grpc:n,core:s,monitoring:f,debug:y,storages:{primary:i,work:c,library:m},hacks:{libraryDownloadable:!0}}}function dr(a,e,t,r){let n;switch(r==null?void 0:r.type){case void 0:case"FS":n=br(a),n.rootPath=(r==null?void 0:r.rootPath)??e;break;case"S3":n=Vr(a),n.endpoint=(r==null?void 0:r.endpoint)??"http://localhost:9000",n.presignEndpoint=(r==null?void 0:r.presignEndpoint)??"http://localhost:9000",n.bucketName=(r==null?void 0:r.bucketName)??t,n.createBucket=se(r==null?void 0:r.createBucket,!0),n.forcePathStyle=se(r==null?void 0:r.forcePathStyle,!0),n.key=(r==null?void 0:r.key)??"",n.secret=(r==null?void 0:r.secret)??"",n.keyPrefix=(r==null?void 0:r.keyPrefix)??"",n.accessPrefixes=(r==null?void 0:r.accessPrefixes)??[""],n.uploadKeyPrefix=(r==null?void 0:r.uploadKeyPrefix)??"";break;default:throw _(),new Error("unknown storage type")}return n}function Qr(a){const e=a.monitoring.enabled?"":" disabled",t=a.debug.enabled?"":" disabled",r=a.hacks.libraryDownloadable?"true":"false";let n=a.license.value;return a.license.file!=""&&(n=u.readFileSync(a.license.file).toString().trimEnd()),`
|
|
19
18
|
license:
|
|
20
19
|
value: '${a.license.value}'
|
|
21
20
|
file: '${a.license.file}'
|
|
@@ -32,7 +31,7 @@ logging:
|
|
|
32
31
|
monitoring${e}:
|
|
33
32
|
listen: '${a.monitoring.listen}'
|
|
34
33
|
|
|
35
|
-
debug${
|
|
34
|
+
debug${t}:
|
|
36
35
|
listen: '${a.debug.listen}'
|
|
37
36
|
|
|
38
37
|
core:
|
|
@@ -66,7 +65,7 @@ controllers:
|
|
|
66
65
|
|
|
67
66
|
library:
|
|
68
67
|
mode: passive
|
|
69
|
-
downloadable: ${
|
|
68
|
+
downloadable: ${r}
|
|
70
69
|
|
|
71
70
|
work:
|
|
72
71
|
mode: active
|
|
@@ -83,30 +82,28 @@ controllers:
|
|
|
83
82
|
workdirCacheOnFailure: 1h
|
|
84
83
|
secrets:
|
|
85
84
|
- map:
|
|
86
|
-
MI_LICENSE: ${JSON.stringify(
|
|
85
|
+
MI_LICENSE: ${JSON.stringify(n)}
|
|
87
86
|
|
|
88
87
|
packageLoader:
|
|
89
88
|
packagesRoot: '${a.localRoot}/packages'
|
|
90
89
|
|
|
91
90
|
workflows: {}
|
|
92
|
-
`}function
|
|
93
|
-
URL: ${
|
|
94
|
-
Save to: ${
|
|
95
|
-
Archive: ${
|
|
96
|
-
Target dir: ${
|
|
97
|
-
${c}`),xr(this.logger,r,["-config",t],{cwd:s,stdio:"inherit"},{storagePath:i.localRoot})}startLocalS3(e){var s;this.logger.debug("starting platforma in 'local s3' mode...");const r=(e==null?void 0:e.minioPort)??9e3,t=(s=e==null?void 0:e.configOptions)==null?void 0:s.localRoot;return this.startMinio({minioPort:r,minioConsolePort:e==null?void 0:e.minioConsolePort,storage:t?g.join(t,"minio"):void 0}),this.startLocal({...e,primaryURL:(e==null?void 0:e.primaryURL)??`s3e://testuser:testpassword@localhost:${r}/main-bucket/?region=no-region`,libraryURL:(e==null?void 0:e.libraryURL)??`s3e://testuser:testpassword@localhost:${r}/library-bucket/?region=no-region`})}startMinio(e){this.logger.debug(" starting minio...");const r=O("compose-backend.yaml"),t=e!=null&&e.version?`:${e.version}`:"";this.logger.debug(` minio version: ${t}`);const s=(e==null?void 0:e.image)??`quay.io/minio/minio${t}`;this.logger.debug(` minio image: ${s}`);const i=(e==null?void 0:e.storage)??d.data("minio");Q(i,{mode:"0775"});const n=d.data("stub");Q(n);const c=(e==null?void 0:e.minioPort)??9e3,o=(e==null?void 0:e.minioConsolePort)??9001,m={MINIO_IMAGE:s,MINIO_STORAGE:g.resolve(i),MINIO_PORT:c.toString(),MINIO_CONSOLE_PORT:o.toString(),PL_DATA_DB_ROOT:n,PL_DATA_PRIMARY_ROOT:n,PL_DATA_LIBRARY_ROOT:n,PL_DATA_WORKDIR_ROOT:n,PL_DATA_PACKAGE_ROOT:n,PL_IMAGE:"scratch"};this.logger.debug(" spawning child 'docker' process...");const u=T.spawnSync("docker",["compose",`--file=${r}`,"up","--detach","--remove-orphans","--pull=missing","minio"],{env:{...process.env,...m},stdio:"inherit"});H(u,"failed to start MinIO service in docker")}buildPlatforma(e){const r=g.resolve(e.repoRoot,"cmd","platforma"),t=e.binPath??g.join($.tmpdir(),"platforma-local-build");this.logger.info("Building Platforma Backend binary from sources"),this.logger.info(` sources path: ${e.repoRoot}`),this.logger.info(` binary path: ${t}`);const s=T.spawnSync("go",["build","-o",t,"."],{cwd:r,stdio:"inherit"});return H(s,"failed to build platforma binary from sources using 'go build' command"),t}startDockerS3(e,r){const t=O("compose-backend.yaml"),s=(r==null?void 0:r.image)??ie(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=(...A)=>g.join(e,...A),n=A=>{const S=i(A);return Q(S,{mode:"0775"}),S},c=i("logs","platforma.log");l.existsSync(c)||(l.mkdirSync(g.dirname(c),{recursive:!0}),l.writeFileSync(c,""));const o=(r==null?void 0:r.presignHost)??"localhost",m=M("s3e://testuser:testpassword@minio:9000/main-bucket");if(m.type!=="S3")throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");m.presignEndpoint=`http://${o}:9000`;const u=M("s3e://testuser:testpassword@minio:9000/library-bucket");if(u.type!=="S3")throw new Error(`${u.type} storage type is not supported for library storage`);u.presignEndpoint=`http://${o}:9000`;const b=n("db"),v=n("work"),h=i("users.htpasswd");l.existsSync(h)||l.copyFileSync(O("users.htpasswd"),h);const y=i("compose.yaml");l.existsSync(y)&&this.logger.info(`replacing docker compose file ${y}`);const L=[];for(const A of(r==null?void 0:r.customMounts)??[])L.push({hostPath:A.hostPath,containerPath:A.containerPath??A.hostPath});Ge(t,y,new Map([["minio",{}],["backend",{platform:r==null?void 0:r.platformOverride,mounts:L}]]));const w={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:n("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:h,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:(r==null?void 0:r.logLevel)??"info",PL_LOG_DIR:g.dirname(c),PL_LOG_ROTATION_ENABLED:"true",PL_DATA_DB_ROOT:b,PL_DATA_PRIMARY_ROOT:n("primary"),PL_DATA_LIBRARY_ROOT:n("library"),PL_DATA_WORKDIR_ROOT:v,PL_DATA_PACKAGE_ROOT:n("packages"),...this.configureDockerStorage("primary",m),...this.configureDockerStorage("library",u)};if(r!=null&&r.grpcAddr&&(w.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(w.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(w.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(w.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(w.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(w.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(w.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const A of r.auth.drivers)A.driver==="htpasswd"&&(w.PL_AUTH_HTPASSWD_PATH=g.resolve(A.path),A.path="/etc/platforma/users.htpasswd");w.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}const k=je(this.logger,["compose",`--file=${y}`,"up","--detach","--remove-orphans","--pull=missing","minio","backend"],{env:w,stdio:"inherit"},{plImage:s,composePath:y});H(k,"failed to start Platforma Backend in Docker"),d.isActive=!0;const R=this.renderRunInfo({apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:c,primary:m,work:{type:"FS",rootPath:v},library:u,dbPath:b});this.logger.info(`Started platforma:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
- ${t.join(`
|
|
101
|
-
- `)}`:"",i=`
|
|
102
|
-
You are going to reset the state of platforma service
|
|
103
|
-
Things to be removed:
|
|
104
|
-
- ${e.join(`
|
|
91
|
+
`}function se(a,e){return a===void 0?e:a}const Xr=["linux","macos","windows"];function Zr(a){const e=T.platform();switch(e){case"darwin":return"macos";case"linux":return"linux";case"win32":return"windows";default:throw new Error(`operating system '${e}' is not currently supported by Platforma ecosystem. The list of OSes supported: `+JSON.stringify(Xr))}}const et=["amd64","arm64"];function pr(a){const e=T.arch();switch(e){case"arm64":return"arm64";case"x64":return"amd64";default:throw new Error(`processor architecture '${e}' is not currently supported by Platforma ecosystem. The list of architectures supported: `+JSON.stringify(et))}}function rt(a,e){const t=(e==null?void 0:e.version)??ue.getDefaultPlVersion(),r=(e==null?void 0:e.showProgress)??process.stdout.isTTY,n=`pl-${t}-${pr()}.tgz`,s=(e==null?void 0:e.downloadURL)??`https://cdn.platforma.bio/software/pl/${Zr()}/${n}`,i=(e==null?void 0:e.saveTo)??g.binaries(n);if(u.existsSync(i))return a.info(`Platforma Backend archive download skipped: '${i}' already exists`),Promise.resolve(i);u.mkdirSync(h.dirname(i),{recursive:!0}),a.info(`Downloading Platforma Backend archive:
|
|
92
|
+
URL: ${s}
|
|
93
|
+
Save to: ${i}`);const c=Lr.get(s);return new Promise((o,m)=>{c.on("response",f=>{if(!f.statusCode){const b=new Error("failed to download archive: no HTTP status code in response from server");c.destroy(),m(b);return}if(f.statusCode!==200){const b=new Error(`failed to download archive: ${f.statusCode} ${f.statusMessage}`);c.destroy(),m(b);return}const y=parseInt(f.headers["content-length"]||"0",10);let w=0;const v=u.createWriteStream(i);f.pipe(v),f.on("data",b=>{w+=b.length;const P=w/y*100;r&&process.stdout.write(` downloading: ${P.toFixed(2)}%\r`)}),f.on("error",b=>{u.unlinkSync(i),a.error(`Failed to download Platforma Binary: ${b.message}`),c.destroy(),m(b)}),v.on("finish",()=>{v.close(),a.info(" ... download done."),c.destroy(),o(i)})})})}function tt(a,e){a.debug("extracting archive...");const t=(e==null?void 0:e.version)??ue.getDefaultPlVersion();a.debug(` version: '${t}'`);const r=`${wr({version:t})}.tgz`,n=(e==null?void 0:e.archivePath)??g.binaries(r);a.debug(` archive path: '${n}'`);const s=(e==null?void 0:e.extractTo)??nt(n);if(a.debug(` target dir: '${s}'`),u.existsSync(s))return a.info(`Platforma Backend binaries unpack skipped: '${s}' exists`),s;if(!u.existsSync(n)){const i=`Platforma Backend binary archive not found at '${n}'`;throw a.error(i),new Error(i)}return u.existsSync(s)||(a.debug(` creating target dir '${s}'`),u.mkdirSync(s,{recursive:!0})),a.info(`Unpacking Platforma Backend archive:
|
|
94
|
+
Archive: ${n}
|
|
95
|
+
Target dir: ${s}`),Or.x({file:n,cwd:s,gzip:!0,sync:!0}),a.info(" ... unpack done."),s}function je(a,e){return rt(a,e).then(t=>tt(a,{archivePath:t}))}function wr(a){return`pl-${(a==null?void 0:a.version)??ue.getDefaultPlVersion()}-${pr()}`}function at(a,...e){return g.binaries(wr({version:a}),...e)}function nt(a){const e=a.lastIndexOf(".");return e===-1?a:a.slice(0,e)}class I{constructor(e){this.logger=e}startLast(){const e=g.currentInstance;if(!e)throw this.logger.error("failed to bring back Platforma Backend in the last started configuration: no last configuration found"),new Error("no previous run info found");return this.startInstance(e)}startInstance(e){if(e.runInfo){const r=this.renderRunInfo(e.runInfo);this.logger.info(`Starting platforma backend instance '${e.name}':
|
|
96
|
+
${r}`)}const t=pe(this.logger,e.upCommands);return de(t.executed),t.spawned.length>0&&e.type==="process"&&(e.pid=t.spawned[t.spawned.length-1].pid,g.setInstanceInfo(e.name,e),this.logger.info(`instance '${e.name}' started`)),g.currentInstanceName=e.name,t.spawned}stopInstance(e){if(!g.isInstanceActive(e)){this.logger.info(`instance '${e.name}' is not running`);return}this.logger.info(`stopping platforma backend instance '${e.name}'...`);const t=pe(this.logger,e.downCommands);switch(de(t.executed),e.type){case"docker":return;case"process":{e.pid&&g.isValidPID(e.pid)&&process.kill(e.pid);return}default:_()}}switchInstance(e){for(const t of g.instanceList)if(t!==e.name){const r=g.getInstanceInfo(t);g.isInstanceActive(r)&&this.stopInstance(r)}return this.startInstance(e)}createLocal(e,t){var o,m,f,y,w,v,b,P,S,k;const r=(t==null?void 0:t.binaryPath)??at(t==null?void 0:t.version,"binaries","platforma");let n=t==null?void 0:t.configPath;const s=(t==null?void 0:t.workdir)??(n?process.cwd():g.instanceDir(e));t!=null&&t.primaryURL&&(t.configOptions={...t.configOptions,storages:{...(o=t.configOptions)==null?void 0:o.storages,primary:V(t.primaryURL,s,(f=(m=t.configOptions)==null?void 0:m.storages)==null?void 0:f.primary)}}),t!=null&&t.libraryURL&&(t.configOptions={...t.configOptions,storages:{...(y=t.configOptions)==null?void 0:y.storages,library:V(t.libraryURL,s,(v=(w=t.configOptions)==null?void 0:w.storages)==null?void 0:v.library)}});const i=Kr(this.getLastJwt(),t==null?void 0:t.configOptions);this.logger.debug(" checking license..."),this.checkLicense((P=(b=t==null?void 0:t.configOptions)==null?void 0:b.license)==null?void 0:P.value,(k=(S=t==null?void 0:t.configOptions)==null?void 0:S.license)==null?void 0:k.file);const c=[`${i.localRoot}/packages`,`${i.localRoot}/packages-local`,`${i.localRoot}/blocks-local`];i.storages.primary.type==="FS"&&c.push(i.storages.primary.rootPath),i.storages.library.type==="FS"&&(c.push(i.storages.library.rootPath),i.hacks.libraryDownloadable=!1),i.storages.work.type==="FS"&&c.push(i.storages.work.rootPath),this.logger.debug(" creating pl state directories...");for(const p of c)u.existsSync(p)||(this.logger.debug(` '${p}'`),u.mkdirSync(p,{recursive:!0}));for(const p of i.core.auth.drivers)p.driver==="htpasswd"&&(u.existsSync(p.path)||(this.logger.debug(` installing default 'users.htpasswd' to ${p.path}...`),u.copyFileSync(Y("users.htpasswd"),p.path)));return n||(n=h.join(i.localRoot,"config.yaml"),this.logger.debug(` rendering configuration '${n}'...`),u.writeFileSync(n,Qr(i))),g.setInstanceInfo(e,{type:"process",upCommands:[{async:!0,cmd:r,args:["-config",n],workdir:s,runOpts:{stdio:"inherit"}}],downCommands:[],cleanupCommands:[],runInfo:{configPath:n,dbPath:i.core.db.path,apiAddr:i.grpc.listen,logPath:i.log.path,primary:i.storages.primary,work:i.storages.work,library:i.storages.library}}),g.getInstanceInfo(e)}createLocalS3(e,t){var c;this.logger.debug("creating platforma instance in 'local s3' mode...");const r=(t==null?void 0:t.minioPort)??9e3,n=this.createLocal(e,{...t,primaryURL:(t==null?void 0:t.primaryURL)??`s3e://testuser:testpassword@localhost:${r}/main-bucket/?region=no-region`,libraryURL:(t==null?void 0:t.libraryURL)??`s3e://testuser:testpassword@localhost:${r}/library-bucket/?region=no-region`}),s=(c=t==null?void 0:t.configOptions)==null?void 0:c.localRoot,i=this.createMinio(e,{minioPort:r,minioConsolePort:t==null?void 0:t.minioConsolePort,storage:s?h.join(s,"minio"):void 0});return n.upCommands=[i.start,...n.upCommands],n.downCommands=[i.stop,...n.downCommands],n.cleanupCommands=[i.cleanup,...n.cleanupCommands],g.setInstanceInfo(e,n),n}createMinio(e,t){this.logger.debug(" creating docker compose for minio service...");const r=Y("compose-backend.yaml"),n=g.instanceDir(e,"compose-minio.yaml");we(r,n,`pl-${e}-minio`,new Map([["minio",{}]]),{dropVolumes:!0});const s=t!=null&&t.version?`:${t.version}`:"";this.logger.debug(` minio version: ${s}`);const i=(t==null?void 0:t.image)??`quay.io/minio/minio${s}`;this.logger.debug(` minio image: ${i}`);const c=(t==null?void 0:t.storage)??g.instanceDir(e,"minio");ye(c,{mode:"0775"});const o=(t==null?void 0:t.minioPort)??9e3,m=(t==null?void 0:t.minioConsolePort)??9001,f={MINIO_IMAGE:i,MINIO_STORAGE:h.resolve(c),MINIO_PORT:o.toString(),MINIO_CONSOLE_PORT:m.toString()};return{start:{cmd:"docker",args:["compose",`--file=${n}`,"up","--detach","--remove-orphans","--pull=missing"],envs:f,workdir:g.instanceDir(e),runOpts:{stdio:"inherit"}},stop:{cmd:"docker",args:["compose",`--file=${n}`,"down"],envs:f,workdir:g.instanceDir(e),runOpts:{stdio:"inherit"}},cleanup:{cmd:"docker",args:["compose",`--file=${n}`,"down","--volumes","--remove-orphans"],envs:f,workdir:g.instanceDir(e),runOpts:{stdio:"inherit"}}}}buildPlatforma(e){const t=h.resolve(e.repoRoot,"cmd","platforma"),r=e.binPath??h.join(T.tmpdir(),"platforma-local-build");this.logger.info("Building Platforma Backend binary from sources"),this.logger.info(` sources path: ${e.repoRoot}`),this.logger.info(` binary path: ${r}`);const n=ae.spawnSync("go",["build","-o",r,"."],{cwd:t,stdio:"inherit"});return de([n],"failed to build platforma binary from sources using 'go build' command"),r}createDockerS3(e,t,r){this.logger.debug("creating platforma instance in 'docker s3' mode...");const n=Y("compose-backend.yaml"),s=(r==null?void 0:r.image)??or(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=(...p)=>h.join(t,...p),c=p=>{const $=i(p);return ye($,{mode:"0775"}),$},o=i("logs","platforma.log");u.existsSync(o)||(u.mkdirSync(h.dirname(o),{recursive:!0}),u.writeFileSync(o,""));const m=(r==null?void 0:r.presignHost)??"localhost",f=V("s3e://testuser:testpassword@minio:9000/main-bucket");if(f.type!=="S3")throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");f.presignEndpoint=`http://${m}:9000`;const y=V("s3e://testuser:testpassword@minio:9000/library-bucket");if(y.type!=="S3")throw new Error(`${y.type} storage type is not supported for library storage`);y.presignEndpoint=`http://${m}:9000`;const w=c("db"),v=c("work"),b=i("users.htpasswd");u.existsSync(b)||u.copyFileSync(Y("users.htpasswd"),b);const P=i("compose.yaml");u.existsSync(P)&&this.logger.info(`replacing docker compose file ${P}`);const S=[];for(const p of(r==null?void 0:r.customMounts)??[])S.push({hostPath:p.hostPath,containerPath:p.containerPath??p.hostPath});we(n,P,`pl-${e}`,new Map([["minio",{}],["backend",{platform:r==null?void 0:r.platformOverride,mounts:S}]]));const k={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:b,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:(r==null?void 0:r.logLevel)??"info",PL_LOG_DIR:h.dirname(o),PL_LOG_ROTATION_ENABLED:"true",PL_DATA_DB_ROOT:w,PL_DATA_PRIMARY_ROOT:c("primary"),PL_DATA_LIBRARY_ROOT:c("library"),PL_DATA_WORKDIR_ROOT:v,...this.configureDockerStorage("primary",f),...this.configureDockerStorage("library",y)};if(r!=null&&r.grpcAddr&&(k.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(k.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(k.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(k.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(k.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(k.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(k.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const p of r.auth.drivers)p.driver==="htpasswd"&&(k.PL_AUTH_HTPASSWD_PATH=h.resolve(p.path),p.path="/etc/platforma/users.htpasswd");k.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}return g.setInstanceInfo(e,{type:"docker",upCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"up","--detach","--remove-orphans","--pull=missing"],envs:k,runOpts:{stdio:"inherit"}}],downCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"down"],envs:k,runOpts:{stdio:"inherit"}}],cleanupCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"down","--volumes","--remove-orphans"],envs:k,runOpts:{stdio:"inherit"}}],runInfo:{apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:o,primary:f,work:{type:"FS",rootPath:v},library:y,dbPath:w}}),g.getInstanceInfo(e)}createDocker(e,t,r){this.logger.debug("creating platforma instance in 'docker' mode...");const n=Y("compose-backend.yaml"),s=(r==null?void 0:r.image)??or(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=(...$)=>h.join(t,...$),c=$=>{const ne=i($);return ye(ne,{mode:"0775"}),ne},o=i("logs","platforma.log");u.existsSync(o)||(u.mkdirSync(h.dirname(o),{recursive:!0}),u.writeFileSync(o,""));const m=c("db"),f=c("primary"),y=c("library"),w=c("work"),v=i("users.htpasswd");u.existsSync(v)||u.copyFileSync(Y("users.htpasswd"),v);const b=i("compose.yaml");u.existsSync(b)&&this.logger.info(`replacing docker compose file ${b}`);const P=[];for(const $ of(r==null?void 0:r.customMounts)??[])P.push({hostPath:$.hostPath,containerPath:$.containerPath??$.hostPath});this.logger.debug(`Rendering docker compose file '${b}' using '${n}' as base template`),we(n,b,`pl-${e}`,new Map([["backend",{platform:r==null?void 0:r.platformOverride,mounts:P}]]));const S=V((r==null?void 0:r.primaryStorageURL)??`file:${f}`,"."),k=V((r==null?void 0:r.libraryStorageURL)??`file:${y}`,"."),p={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:v,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:"info",PL_LOG_DIR:h.dirname(o),PL_LOG_ROTATION_ENABLED:"true",PL_DATA_DB_ROOT:m,PL_DATA_PRIMARY_ROOT:f,PL_DATA_LIBRARY_ROOT:y,PL_DATA_WORKDIR_ROOT:w,PL_DATA_PACKAGE_ROOT:c("packages"),...this.configureDockerStorage("primary",S),...this.configureDockerStorage("library",k)};if(r!=null&&r.grpcAddr&&(p.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(p.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(p.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(p.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(p.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(p.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(p.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const $ of r.auth.drivers)$.driver==="htpasswd"&&(p.PL_AUTH_HTPASSWD_PATH=h.resolve($.path),$.path="/etc/platforma/users.htpasswd");p.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}return g.setInstanceInfo(e,{type:"docker",upCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"up","--detach","--remove-orphans","--pull=missing"],envs:p,runOpts:{stdio:"inherit"}}],downCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"down"],envs:p,runOpts:{stdio:"inherit"}}],cleanupCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"down","--volumes","--remove-orphans"],envs:p,runOpts:{stdio:"inherit"}}],runInfo:{apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:o,primary:S,work:{type:"FS",rootPath:w},library:k,dbPath:m}}),g.getInstanceInfo(e)}cleanupInstance(e){const t=[],r=new Map;let n="";if(e){const s=g.getInstanceInfo(e);switch(r.set(e,s),s.type){case"docker":{t.push(`docker service 'pl-${e}', including all its volumes and data in '${g.instanceDir(e)}' will be destroyed`);break}case"process":{t.push(`directory '${g.instanceDir(e)}' would be deleted`),s.downCommands&&t.push("associated docker service, including all volumes and data will be destroyed");break}default:_()}e===g.currentInstanceName&&t.push("last command run cache ('pl-service start' shorthand will stop working until next full start command call)"),n=`
|
|
97
|
+
You are going to reset the state of platforma service '${e}':
|
|
98
|
+
- ${t.join(`
|
|
105
99
|
- `)}
|
|
106
|
-
${
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
`}else{for(const s of g.instanceList)r.set(s,g.getInstanceInfo(s));t.push("last command run cache ('pl-service start' shorthand will stop working until next full start command call)",`all service configurations stored in: ${g.instanceDir()} (including all associated docker containers and volumes)`),n=`
|
|
101
|
+
You are going to reset the state of all platforma services configured with pl-bootstrap package.
|
|
102
|
+
- ${t.join(`
|
|
103
|
+
- `)}
|
|
104
|
+
`}if(this.logger.warn(n),!Dr("Are you sure?")){this.logger.info("Reset action was canceled");return}for(const[s,i]of r.entries()){if(i.cleanupCommands.length){this.logger.info(`Wiping instance ${s} services`);const c=pe(this.logger,i.cleanupCommands);de(c.executed,`failed to wipe instance ${s} services`)}this.logger.info(`Destroying instance '${s}' data directory`),u.rmSync(g.instanceDir(s),{recursive:!0,force:!0})}e||(this.logger.info(`Destroying state dir '${g.path()}'`),u.rmSync(g.path(),{recursive:!0,force:!0})),this.logger.info(`
|
|
105
|
+
If you want to remove all downloaded platforma binaries, delete '${g.binaries()}' dir manually
|
|
106
|
+
`)}mergeLicenseEnvs(e){e.license===void 0&&((process.env.MI_LICENSE??"")!=""?e.license=process.env.MI_LICENSE:(process.env.PL_LICENSE??"")!=""&&(e.license=process.env.PL_LICENSE)),e["license-file"]===void 0&&e.license===void 0&&((process.env.MI_LICENSE_FILE??"")!=""?e["license-file"]=process.env.MI_LICENSE_FILE:(process.env.PL_LICENSE_FILE??"")!=""?e["license-file"]=process.env.PL_LICENSE_FILE:u.existsSync(h.resolve(T.homedir(),".pl.license"))&&(e["license-file"]=h.resolve(T.homedir(),".pl.license")))}initAuthDriversList(e,t){const r=[];if(e["auth-htpasswd-file"]&&r.push({driver:"htpasswd",path:h.resolve(t,e["auth-htpasswd-file"])}),!!e["auth-ldap-server"]!=!!e["auth-ldap-default-dn"])throw new Error("LDAP auth settings require both 'server' and 'default DN' options to be set");if(e["auth-ldap-server"]&&r.push({driver:"ldap",serverUrl:e["auth-ldap-server"],defaultDN:e["auth-ldap-default-dn"]}),r.length!==0)return[{driver:"jwt",key:this.getLastJwt()},...r]}getLastJwt(){const e=g.path("auth.jwt"),t="utf-8";let r="";return u.existsSync(e)&&(r=u.readFileSync(e,{encoding:t})),r==""&&(r=xr(64),u.writeFileSync(e,r,{encoding:t})),r}checkLicense(e,t){if(!(e!==void 0&&e!="")&&!(t!==void 0&&t!=""))throw this.logger.error(`A license for Platforma Backend must be set.
|
|
110
107
|
|
|
111
108
|
You can provide the license directly using the '--license' flag
|
|
112
109
|
or use the '--license-file' flag if the license is stored in a file.
|
|
@@ -116,6 +113,6 @@ Alternatively, you can set it via the environment variables 'MI_LICENSE' or 'PL_
|
|
|
116
113
|
The license file can also be set with the variables 'MI_LICENSE_FILE' or 'PL_LICENSE_FILE',
|
|
117
114
|
or stored in '$HOME/.pl.license'.
|
|
118
115
|
|
|
119
|
-
You can obtain the license from "https://licensing.milaboratories.com".`),new Error("The license was not provided.")}configureDockerStorage(e,
|
|
120
|
-
`)}readComposeFile(e){const r=l.readFileSync(e);return X.parse(r.toString())}writeComposeFile(e,r){l.writeFileSync(e,X.stringify(r))}}function H(a,e){if(a.error)throw a.error;const r=e??"failed to run command";if(a.status!==0)throw new Error(`${r}, process exited with code '${a.status}'`)}const G=class G extends f.Command{async run(){const{flags:e}=await this.parse(G),r=N(e["log-level"]);new x(r).cleanup()}};P(G,"description","Clear service state (forget last run command, destroy docker services, volumes and so on)"),P(G,"examples",["<%= config.bin %> <%= command.id %>"]),P(G,"flags",{...D});let oe=G;const U=class U extends f.Command{async run(){const{flags:e}=await this.parse(U),r=N(e["log-level"]);new x(r).startLast()}};P(U,"description","Start last run service configuraiton"),P(U,"examples",["<%= config.bin %> <%= command.id %>"]),P(U,"flags",{...D});let de=U;const W=class W extends f.Command{async run(){const{flags:e}=await this.parse(W),r=N(e["log-level"]);new x(r).stop()}};P(W,"description","Stop platforma service"),P(W,"examples",["<%= config.bin %> <%= command.id %>"]),P(W,"flags",{...D});let ge=W;const q=class q extends f.Command{async run(){const{flags:e}=await this.parse(q),r=N(e["log-level"]),t=new x(r);t.mergeLicenseEnvs(e);const s=e["auth-enabled"],i=s?{enabled:s,drivers:t.initAuthDriversList(e,".")}:void 0,n=e.storage?g.join(".",e.storage):d.data("docker"),c=[];for(const m of e.mount??[])c.push({hostPath:m});const o=e.arch?`linux/${e.arch}`:void 0;t.startDocker(n,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,platformOverride:o,customMounts:c,license:e.license,licenseFile:e["license-file"],auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]})}};P(q,"description","Run platforma backend service with 'FS' primary storage type"),P(q,"examples",["<%= config.bin %> <%= command.id %>"]),P(q,"flags",{...D,...te,...qe,...ee,...Je,...se,...re,...ze,...ae,...ye,...he,...Pe});let ue=q;const J=class J extends f.Command{async run(){const{flags:e}=await this.parse(J),r=N(e["log-level"]),t=new x(r);t.mergeLicenseEnvs(e);const s=e["pl-workdir"]??".",i=e.storage?g.join(s,e.storage):d.data("local"),n=e["pl-log-file"]?g.join(s,e["pl-log-file"]):void 0,c=t.initAuthDriversList(e,s),o=e["auth-enabled"]??c!==void 0;var m=e["pl-binary"];e["pl-sources"]&&(m=t.buildPlatforma({repoRoot:e["pl-sources"]}));var u="127.0.0.1:6345";e["grpc-listen"]?u=e["grpc-listen"]:e["grpc-port"]&&(u=`127.0.0.1:${e["grpc-port"]}`);var b="127.0.0.1:9090";e["monitoring-listen"]?b=e["monitoring-listen"]:e["monitoring-port"]&&(b=`127.0.0.1:${e["monitoring-port"]}`);var v="127.0.0.1:9091";e["debug-listen"]?v=e["debug-listen"]:e["debug-port"]&&(v=`127.0.0.1:${e["debug-port"]}`);const h={binaryPath:m,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:u},monitoring:{listen:b},debug:{listen:v},license:{value:e.license,file:e["license-file"]},log:{path:n},localRoot:i,core:{auth:{enabled:o,drivers:c}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};h.binaryPath?t.startLocal(h):sr(r,{version:e.version}).then(()=>t.startLocal(h)).catch(function(y){r.error(y.message)})}};P(J,"description","Run Platforma Backend service as local process on current host (no docker container)"),P(J,"examples",["<%= config.bin %> <%= command.id %>"]),P(J,"flags",{...D,...ee,...te,...Ke,...Ve,...Qe,...re,...ae,...ye,...he,...Pe,...He,...Ye,...se});let fe=J;var _;let Kr=(_=class extends f.Command{async run(){const{flags:e}=await this.parse(_),r=N(e["log-level"]),t=new x(r);t.mergeLicenseEnvs(e);const s=e["auth-enabled"],i=s?{enabled:s,drivers:t.initAuthDriversList(e,".")}:void 0,n=e.storage?g.join(".",e.storage):d.data("docker-s3"),c=[];for(const u of e.mount??[])c.push({hostPath:u});const o=e.arch?`linux/${e.arch}`:void 0,m=e["minio-presign-host"]?"minio":"localhost";t.startDockerS3(n,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],platformOverride:o,customMounts:c,auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"],presignHost:m})}},P(_,"description","Run platforma backend service with 'S3' primary storage type"),P(_,"examples",["<%= config.bin %> <%= command.id %>"]),P(_,"flags",{...D,...te,...qe,...ee,...Je,...se,...re,...ze,...ae,...yr}),_);const z=class z extends f.Command{async run(){const{flags:e}=await this.parse(z),r=N(e["log-level"]),t=new x(r);t.mergeLicenseEnvs(e);const s=e["pl-workdir"]??".",i=e.storage?g.join(s,e.storage):d.data("local-s3"),n=e["pl-log-file"]?g.join(s,e["pl-log-file"]):void 0,c=t.initAuthDriversList(e,s),o=e["auth-enabled"]??c!==void 0;var m=e["pl-binary"];e["pl-sources"]&&(m=t.buildPlatforma({repoRoot:e["pl-sources"]}));var u="127.0.0.1:6345";e["grpc-listen"]?u=e["grpc-listen"]:e["grpc-port"]&&(u=`127.0.0.1:${e["grpc-port"]}`);var b="127.0.0.1:9090";e["monitoring-listen"]?b=e["monitoring-listen"]:e["monitoring-port"]&&(b=`127.0.0.1:${e["monitoring-port"]}`);var v="127.0.0.1:9091";e["debug-listen"]?v=e["debug-listen"]:e["debug-port"]&&(v=`127.0.0.1:${e["debug-port"]}`);const h={binaryPath:m,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],minioPort:e["s3-address-port"],minioConsolePort:e["s3-console-address-port"],configOptions:{grpc:{listen:u},monitoring:{listen:b},debug:{listen:v},license:{value:e.license,file:e["license-file"]},log:{path:n},localRoot:i,core:{auth:{enabled:o,drivers:c}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};h.binaryPath?t.startLocalS3(h):sr(r,{version:e.version}).then(()=>t.startLocalS3(h)).catch(function(y){r.error(y.message)})}};P(z,"description","Run Platforma Backend service as local process on current host (no docker container)"),P(z,"examples",["<%= config.bin %> <%= command.id %>"]),P(z,"flags",{...D,...ee,...te,...hr,...Ke,...Ve,...Qe,...re,...ae,...ye,...he,...Pe,...He,...Ye,...se});let me=z;const Vr={"create-block":ce,reset:oe,start:de,stop:ge,"start:docker":ue,"start:local":fe,"start:docker:s3":Kr,"start:local:s3":me};exports.COMMANDS=Vr;
|
|
116
|
+
You can obtain the license from "https://licensing.milaboratories.com".`),new Error("The license was not provided.")}configureDockerStorage(e,t){const r={},n=t.type;switch(e=e.toUpperCase(),n){case"S3":return r[`PL_DATA_${e}_TYPE`]="S3",r[`PL_DATA_${e}_S3_BUCKET`]=t.bucketName,t.endpoint&&(r[`PL_DATA_${e}_S3_ENDPOINT`]=t.endpoint),t.presignEndpoint&&(r[`PL_DATA_${e}_S3_PRESIGN_ENDPOINT`]=t.presignEndpoint),t.region&&(r[`PL_DATA_${e}_S3_REGION`]=t.region),t.key&&(r[`PL_DATA_${e}_S3_KEY`]=t.key),t.secret&&(r[`PL_DATA_${e}_S3_SECRET`]=t.secret),r;case"FS":return r[`PL_DATA_${e}_TYPE`]="FS",r;default:_()}return{}}renderRunInfo(e,t=10){var c,o;const r=[],n=m=>m.padStart(t," ");switch(e.configPath&&r.push(`${n("config")}: ${e.configPath}`),e.apiAddr?r.push(`${n("API")}: ${e.apiAddr}`):e.apiPort?r.push(`${n("API")}: 127.0.0.1:${e.apiPort.toString()}`):r.push(`${n("API")}: 127.0.0.1:6345`),e.logPath&&r.push(`${n("log")}: ${e.logPath}`),(c=e.primary)==null?void 0:c.type){case void 0:break;case"FS":r.push(`${n("primary")}: ${e.primary.rootPath}`);break;case"S3":r.push(`${n("primary")}: S3 at '${e.primary.endpoint??"AWS"}', bucket '${e.primary.bucketName}', prefix: '${e.primary.keyPrefix??""}'`);break;default:_()}switch((o=e.library)==null?void 0:o.type){case void 0:break;case"FS":r.push(`${n("library")}: ${e.library.rootPath}`);break;case"S3":r.push(`${n("library")}: S3 at '${e.library.endpoint??"AWS"}', bucket '${e.library.bucketName}', prefix: '${e.library.keyPrefix??""}'`);break;default:_()}return e.work&&r.push(`${n("workdirs")}: ${e.work.rootPath}`),e.dbPath&&r.push(`${n("db")}: ${e.dbPath}`),r.join(`
|
|
117
|
+
`)}readComposeFile(e){const t=u.readFileSync(e);return ge.parse(t.toString())}writeComposeFile(e,t){u.writeFileSync(e,ge.stringify(t))}}function de(a,e){for(const t of a){if(t.error)throw t.error;const r=e??"failed to run command";if(t.status!==0)throw new Error(`${r}, process exited with code '${t.status}'`)}}const Z=class Z extends d.Command{async run(){const{flags:e}=await this.parse(Z),t=L(e["log-level"]);new I(t).cleanupInstance()}};l(Z,"description","Clear service state (forget last run command, destroy docker services, volumes and so on)"),l(Z,"examples",["<%= config.bin %> <%= command.id %>"]),l(Z,"flags",{...A});let Se=Z;const ee=class ee extends d.Command{async run(){const{flags:e}=await this.parse(ee),t=L(e["log-level"]);new I(t).startLast()}};l(ee,"description","Start last run service configuraiton"),l(ee,"examples",["<%= config.bin %> <%= command.id %>"]),l(ee,"flags",{...A});let $e=ee;const re=class re extends d.Command{async run(){const{flags:e}=await this.parse(re),t=L(e["log-level"]),r=new I(t);g.currentInstance?r.stopInstance(g.currentInstance):t.warn("up/start command was not called for any instance, nothing to stop")}};l(re,"description","Stop platforma service"),l(re,"examples",["<%= config.bin %> <%= command.id %>"]),l(re,"flags",{...A});let Ae=re;var O;let st=(O=class extends d.Command{async run(){const{flags:e}=await this.parse(O),t=L(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="docker",s=e["auth-enabled"],i=s?{enabled:s,drivers:r.initAuthDriversList(e,".")}:void 0,c=e.storage?h.join(".",e.storage):g.instanceDir(n),o=[];for(const y of e.mount??[])o.push({hostPath:y});const m=e.arch?`linux/${e.arch}`:void 0,f=r.createDocker(n,c,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,platformOverride:m,customMounts:o,license:e.license,licenseFile:e["license-file"],auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]});r.switchInstance(f)}},l(O,"description","Run platforma backend service with 'FS' primary storage type"),l(O,"examples",["<%= config.bin %> <%= command.id %>"]),l(O,"flags",{...A,...H,...fe,...q,...me,...z,...J,...he,...W,...ce,...ie,...oe}),O);var F;let it=(F=class extends d.Command{async run(){const{flags:e}=await this.parse(F),t=L(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="local",s=e["pl-workdir"]??".",i=e.storage?h.join(s,e.storage):g.instanceDir(n),c=e["pl-log-file"]?h.join(s,e["pl-log-file"]):void 0,o=r.initAuthDriversList(e,s),m=e["auth-enabled"]??o!==void 0;let f=e["pl-binary"];e["pl-sources"]&&(f=r.buildPlatforma({repoRoot:e["pl-sources"]}));let y="127.0.0.1:6345";e["grpc-listen"]?y=e["grpc-listen"]:e["grpc-port"]&&(y=`127.0.0.1:${e["grpc-port"]}`);let w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);let v="127.0.0.1:9091";e["debug-listen"]?v=e["debug-listen"]:e["debug-port"]&&(v=`127.0.0.1:${e["debug-port"]}`);const b={binaryPath:f,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:y},monitoring:{listen:w},debug:{listen:v},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:m,drivers:o}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}},P=r.createLocal(n,b);b.binaryPath?r.switchInstance(P):je(t,{version:e.version}).then(()=>{const S=r.switchInstance(P);setTimeout(()=>{for(const k of S)k.unref()},1e3)}).catch(function(S){t.error(S.message)})}},l(F,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(F,"examples",["<%= config.bin %> <%= command.id %>"]),l(F,"flags",{...A,...q,...H,..._e,...Ne,...Ce,...J,...W,...ce,...ie,...oe,...De,...xe,...z}),F);const C=class C extends d.Command{async run(){const{flags:e,args:t}=await this.parse(C),r=L(e["log-level"]),n=new I(r),s=t.name;e.all&&(n.cleanupInstance(),process.exit(0)),s||(r.error("Please, specify name of instance to be removed or set '--all' flag instead"),process.exit(1)),n.cleanupInstance(s)}};l(C,"description","List available instances"),l(C,"examples",["<%= config.bin %> <%= command.id %>"]),l(C,"flags",{...A,all:d.Flags.boolean({description:"remove all known instances",required:!1})}),l(C,"args",{name:d.Args.string({required:!1})});let Le=C;const M=class M extends d.Command{async run(){const{flags:e,args:t}=await this.parse(M),r=L(e["log-level"]),n=new I(r),s=t.name??g.currentInstanceName;s||(r.info("no pl service instance selected. No service was stopped"),process.exit(0)),n.stopInstance(g.getInstanceInfo(s))}};l(M,"description","List available instances"),l(M,"examples",["<%= config.bin %> <%= command.id %>"]),l(M,"flags",{...A}),l(M,"args",{name:d.Args.string({required:!1})});let Ie=M;const te=class te extends d.Command{async run(){await this.parse(te);const e=g.instanceList,t=g.currentInstanceName;for(const r of e){const n=[],s=g.getInstanceInfo(r);g.isInstanceActive(s)&&n.push("status:up"),n.push(`type:${s.type}`),console.log(r===t?` * ${r} (${n.join(", ")})`:` ${r} (${n.join(", ")})`)}}};l(te,"description","List available instances"),l(te,"examples",["<%= config.bin %> <%= command.id %>"]),l(te,"flags",{});let Oe=te;const j=class j extends d.Command{async run(){const{flags:e,args:t}=await this.parse(j),r=L(e["log-level"]),n=new I(r),s=t.name??g.currentInstanceName;s||(r.error("no pl service instance is selected. Select instance with 'select' command or provide name to 'up'"),process.exit(1));const i=n.switchInstance(g.getInstanceInfo(s));setTimeout(()=>{for(const c of i)c.unref()},1e3)}};l(j,"description","List available instances"),l(j,"examples",["<%= config.bin %> <%= command.id %>"]),l(j,"flags",{...A}),l(j,"args",{name:d.Args.string({required:!1})});let Fe=j;var E;let ct=(E=class extends d.Command{async run(){const{flags:e}=await this.parse(E),t=L(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="docker-s3",s=e["auth-enabled"],i=s?{enabled:s,drivers:r.initAuthDriversList(e,".")}:void 0,c=e.storage?h.join(".",e.storage):g.instanceDir(n),o=[];for(const w of e.mount??[])o.push({hostPath:w});const m=e.arch?`linux/${e.arch}`:void 0,f=e["minio-presign-host"]?"minio":"localhost",y=r.createDockerS3(n,c,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],platformOverride:m,customMounts:o,auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"],presignHost:f});r.switchInstance(y)}},l(E,"description","Run platforma backend service with 'S3' primary storage type"),l(E,"examples",["<%= config.bin %> <%= command.id %>"]),l(E,"flags",{...A,...H,...fe,...q,...me,...z,...J,...he,...W,...fr}),E);var R;let ot=(R=class extends d.Command{async run(){const{flags:e}=await this.parse(R),t=L(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="local-s3",s=e["pl-workdir"]??".",i=e.storage?h.join(s,e.storage):g.instanceDir(n),c=e["pl-log-file"]?h.join(s,e["pl-log-file"]):void 0,o=r.initAuthDriversList(e,s),m=e["auth-enabled"]??o!==void 0;let f=e["pl-binary"];e["pl-sources"]&&(f=r.buildPlatforma({repoRoot:e["pl-sources"]}));let y="127.0.0.1:6345";e["grpc-listen"]?y=e["grpc-listen"]:e["grpc-port"]&&(y=`127.0.0.1:${e["grpc-port"]}`);let w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);let v="127.0.0.1:9091";e["debug-listen"]?v=e["debug-listen"]:e["debug-port"]&&(v=`127.0.0.1:${e["debug-port"]}`);const b={binaryPath:f,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],minioPort:e["s3-port"],minioConsolePort:e["s3-console-port"],configOptions:{grpc:{listen:y},monitoring:{listen:w},debug:{listen:v},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:m,drivers:o}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}},P=r.createLocalS3(n,b);b.binaryPath?r.switchInstance(P):je(t,{version:e.version}).then(()=>{const S=r.switchInstance(P);setTimeout(()=>{for(const k of S)k.unref()},1e3)}).catch(function(S){t.error(S.message)})}},l(R,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(R,"examples",["<%= config.bin %> <%= command.id %>"]),l(R,"flags",{...A,...q,...H,...ur,..._e,...Ne,...Ce,...J,...W,...ce,...ie,...oe,...De,...xe,...z}),R);const B=class B extends d.Command{async run(){const{flags:e,args:t}=await this.parse(B),r=L(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["auth-enabled"],c=i?{enabled:i,drivers:n.initAuthDriversList(e,".")}:void 0,o=e.storage?h.join(".",e.storage):g.instanceDir(s),m=[];for(const y of e.mount??[])m.push({hostPath:y});const f=e.arch?`linux/${e.arch}`:void 0;n.createDocker(s,o,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,platformOverride:f,customMounts:m,license:e.license,licenseFile:e["license-file"],auth:c,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]}),r.info(`Instance '${s}' was created. To start it run 'up' command`)}};l(B,"description","Run Platforma Backend service as docker container on current host"),l(B,"examples",["<%= config.bin %> <%= command.id %>"]),l(B,"flags",{...A,...H,...fe,...q,...me,...z,...J,...he,...W,...ce,...ie,...oe}),l(B,"args",{name:d.Args.string({required:!0})});let Ee=B;const G=class G extends d.Command{async run(){const{flags:e,args:t}=await this.parse(G),r=L(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["pl-workdir"]??".",c=e.storage?h.join(i,e.storage):g.instanceDir(s),o=e["pl-log-file"]?h.join(i,e["pl-log-file"]):void 0,m=n.initAuthDriversList(e,i),f=e["auth-enabled"]??m!==void 0;let y=e["pl-binary"];e["pl-sources"]&&(y=n.buildPlatforma({repoRoot:e["pl-sources"]}));let w="127.0.0.1:6345";e["grpc-listen"]?w=e["grpc-listen"]:e["grpc-port"]&&(w=`127.0.0.1:${e["grpc-port"]}`);let v="127.0.0.1:9090";e["monitoring-listen"]?v=e["monitoring-listen"]:e["monitoring-port"]&&(v=`127.0.0.1:${e["monitoring-port"]}`);let b="127.0.0.1:9091";e["debug-listen"]?b=e["debug-listen"]:e["debug-port"]&&(b=`127.0.0.1:${e["debug-port"]}`);const P={binaryPath:y,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:w},monitoring:{listen:v},debug:{listen:b},license:{value:e.license,file:e["license-file"]},log:{path:o},localRoot:c,core:{auth:{enabled:f,drivers:m}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};switch(t.mode){case"s3":{r.info("Creating instance configuration, data directory and other stuff..."),n.createLocalS3(s,{...P,minioPort:e["s3-port"],minioConsolePort:e["s3-console-port"]});break}case void 0:{e["s3-port"]&&r.warn("flag 's3-port' is only for 's3' mode"),e["s3-console-port"]&&r.warn("flag 's3-console-port' is only for 's3' mode"),n.createLocal(s,P);break}}if(P.binaryPath){r.info(`Instance '${s}' was created. To start it run 'up' command`);return}je(r,{version:e.version}).then(()=>r.info(`Instance '${s}' was created. To start it run 'pl up' command`)).catch(function(k){r.error(k.message)})}};l(G,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(G,"examples",["<%= config.bin %> <%= command.id %>"]),l(G,"flags",{...A,...q,...ur,...H,..._e,...Ne,...Ce,...J,...W,...ce,...ie,...oe,...De,...xe,...z}),l(G,"args",{name:d.Args.string({required:!0}),mode:d.Args.string({options:["s3"],required:!1})});let Re=G;const U=class U extends d.Command{async run(){const{flags:e,args:t}=await this.parse(U),r=L(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["auth-enabled"],c=i?{enabled:i,drivers:n.initAuthDriversList(e,".")}:void 0,o=e.storage?h.join(".",e.storage):g.instanceDir(s),m=[];for(const w of e.mount??[])m.push({hostPath:w});const f=e.arch?`linux/${e.arch}`:void 0,y=e["minio-presign-host"]?"minio":"localhost";n.createDockerS3(s,o,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],platformOverride:f,customMounts:m,auth:c,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"],presignHost:y}),r.info(`Instance '${s}' was created. To start it run 'up' command`),e["minio-presign-host"]&&r.info(" NOTE: make sure you have 'minio' host in your hosts file as 127.0.0.1 address")}};l(U,"description","Run Platforma Backend service as docker container on current host with MinIO as local S3 storage"),l(U,"examples",["<%= config.bin %> <%= command.id %>"]),l(U,"flags",{...A,...H,...fe,...q,...me,...z,...J,...he,...W,...fr}),l(U,"args",{name:d.Args.string({required:!0})});let Te=U;const lt={"create-block":Pe,reset:Se,start:$e,stop:Ae,"start:docker":st,"start:local":it,"svc:delete":Le,"svc:down":Ie,"svc:list":Oe,"svc:up":Fe,"start:docker:s3":ct,"start:local:s3":ot,"svc:create:docker":Ee,"svc:create:local":Re,"svc:create:docker:s3":Te};exports.COMMANDS=lt;
|
|
121
118
|
//# sourceMappingURL=index.js.map
|