@platforma-sdk/bootstrap 2.6.2 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +14 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -1
- package/dist/index.mjs.map +1 -1
- package/dist/templates/pl-config.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ar=Object.defineProperty;var sr=(a,e,r)=>e in a?ar(a,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[e]=r;var y=(a,e,r)=>sr(a,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("@oclif/core"),L=require("node:os"),d=require("node:fs"),o=require("node:path"),F=require("node:child_process"),H=require("winston"),ir=require("node:crypto"),M=require("readline-sync"),cr=require("node:fs/promises"),nr=require("node:stream"),$=require("zod"),lr=require("decompress"),Be=require("yaml"),X=require("@milaboratories/pl-local"),or=require("node:https"),dr=require("tar");function Ue(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const r in a)if(r!=="default"){const t=Object.getOwnPropertyDescriptor(a,r);Object.defineProperty(e,r,t.get?t:{enumerable:!0,get:()=>a[r]})}}return e.default=a,Object.freeze(e)}const T=Ue(cr),gr=Ue(dr),E={"log-level":g.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"],required:!1})},We={image:g.Flags.string({description:"use custom docker image to run platforma"})},Z={version:g.Flags.string({description:"use custom platforma release (official docker image or binary package)"})},ee={license:g.Flags.string({description:'pass a license code. The license can be got from "https://licensing.milaboratories.com".'}),"license-file":g.Flags.file({exists:!0,description:"specify a path to the file with a license. The license can be got from 'https://licensing.milaboratories.com'."})},re={"grpc-port":g.Flags.integer({description:"port for Platforma Backend gRPC API. Default is 6345",env:"PLATFORMA_GRPC_PORT"}),"grpc-listen":g.Flags.string({description:"full listen addr for Platforma Backend gRPC API. Default is 127.0.0.1:6345",env:"PLATFORMA_GRPC_LISTEN"}),"monitoring-port":g.Flags.integer({description:"port for Platforma Backend monitoring API. Default is 9090",env:"PLATFORMA_MONITORING_PORT"}),"monitoring-listen":g.Flags.string({description:"full listen addr for Platforma Backend monitoring API. Default is 127.0.0.1:9090",env:"PLATFORMA_MONITORING_LISTEN"}),"debug-port":g.Flags.integer({description:"port for Platforma Backend debug API. Default is 9091",env:"PLATFORMA_DEBUG_PORT"}),"debug-listen":g.Flags.string({description:"full listen addr for Platforma Backend debug API. Default is 127.0.0.1:9091",env:"PLATFORMA_DEBUG_LISTEN"})},ur={"s3-address-port":g.Flags.integer({description:"port that S3 will listen, default is 9000",default:9e3,env:"PLATFORMA_S3_PORT"}),"s3-console-address-port":g.Flags.integer({description:"port that a console of S3 will listen, default is 9001",default:9001,env:"PLATFORMA_S3_CONSOLE_PORT"})},te={storage:g.Flags.string({description:"specify path on host to be used as storage for all Platforma Backend data"})},qe={"pl-log-file":g.Flags.file({description:"specify path for Platforma Backend log file"})},
|
|
1
|
+
"use strict";var ar=Object.defineProperty;var sr=(a,e,r)=>e in a?ar(a,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[e]=r;var y=(a,e,r)=>sr(a,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("@oclif/core"),L=require("node:os"),d=require("node:fs"),o=require("node:path"),F=require("node:child_process"),H=require("winston"),ir=require("node:crypto"),M=require("readline-sync"),cr=require("node:fs/promises"),nr=require("node:stream"),$=require("zod"),lr=require("decompress"),Be=require("yaml"),X=require("@milaboratories/pl-local"),or=require("node:https"),dr=require("tar");function Ue(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const r in a)if(r!=="default"){const t=Object.getOwnPropertyDescriptor(a,r);Object.defineProperty(e,r,t.get?t:{enumerable:!0,get:()=>a[r]})}}return e.default=a,Object.freeze(e)}const T=Ue(cr),gr=Ue(dr),E={"log-level":g.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"],required:!1})},We={image:g.Flags.string({description:"use custom docker image to run platforma"})},Z={version:g.Flags.string({description:"use custom platforma release (official docker image or binary package)"})},ee={license:g.Flags.string({description:'pass a license code. The license can be got from "https://licensing.milaboratories.com".'}),"license-file":g.Flags.file({exists:!0,description:"specify a path to the file with a license. The license can be got from 'https://licensing.milaboratories.com'."})},re={"grpc-port":g.Flags.integer({description:"port for Platforma Backend gRPC API. Default is 6345",env:"PLATFORMA_GRPC_PORT"}),"grpc-listen":g.Flags.string({description:"full listen addr for Platforma Backend gRPC API. Default is 127.0.0.1:6345",env:"PLATFORMA_GRPC_LISTEN"}),"monitoring-port":g.Flags.integer({description:"port for Platforma Backend monitoring API. Default is 9090",env:"PLATFORMA_MONITORING_PORT"}),"monitoring-listen":g.Flags.string({description:"full listen addr for Platforma Backend monitoring API. Default is 127.0.0.1:9090",env:"PLATFORMA_MONITORING_LISTEN"}),"debug-port":g.Flags.integer({description:"port for Platforma Backend debug API. Default is 9091",env:"PLATFORMA_DEBUG_PORT"}),"debug-listen":g.Flags.string({description:"full listen addr for Platforma Backend debug API. Default is 127.0.0.1:9091",env:"PLATFORMA_DEBUG_LISTEN"})},ur={"s3-address-port":g.Flags.integer({description:"port that S3 will listen, default is 9000",default:9e3,env:"PLATFORMA_S3_PORT"}),"s3-console-address-port":g.Flags.integer({description:"port that a console of S3 will listen, default is 9001",default:9001,env:"PLATFORMA_S3_CONSOLE_PORT"})},te={storage:g.Flags.string({description:"specify path on host to be used as storage for all Platforma Backend data"})},qe={"pl-log-file":g.Flags.file({description:"specify path for Platforma Backend log file"})},ze={"pl-workdir":g.Flags.file({description:"specify working directory for Platforma Backend process"})},Je={"pl-binary":g.Flags.file({description:"start given Platforma Backend binary instead of automatically downloaded version"})},He={"pl-sources":g.Flags.file({description:"path to pl repository root: build Platforma Backend from sources and start the resulting binary"})},Ye={config:g.Flags.string({description:"use custom Platforma Backend config"})};g.Flags.file({description:"specify path on host to be used as 'primary' storage"});const he={"storage-work":g.Flags.file({description:"specify path on host to be used as 'work' storage"})};g.Flags.file({description:"specify path on host to be used as 'library' storage"});const me={"storage-primary":g.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
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},fr={"auth-enabled":g.Flags.boolean({description:"enable authorization"})},hr={"auth-htpasswd-file":g.Flags.file({description:"path to .htpasswd file with Platforma users (static user DB auth source)"})},mr={"auth-ldap-server":g.Flags.string({description:"address of LDAP server to use for auth in Platforma (auth source)"})},yr={"auth-ldap-default-dn":g.Flags.string({description:"DN to use when checking user with LDAP bind operation: e.g. cn=%u,ou=users,dc=example,dc=com"})},ae={...fr,...hr,...mr,...yr};function Pr(a){return M.question(`${a} [y/N] `).toLowerCase()==="y"}function K(a){throw new Error("this should never happen")}function D(a="debug"){return H.createLogger({level:a,format:H.format.combine(H.format.printf(({level:e,message:r})=>{const t=" ".repeat(e.length+2),s=r.split(`
|
|
10
10
|
`).map((c,n)=>n===0?c:t+c).join(`
|
|
11
11
|
`);return`${(c=>H.format.colorize().colorize(c,c))(e)}: ${s}`})),transports:[new H.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function br(a){return ir.randomBytes(Math.ceil(a/2)).toString("hex").slice(0,a)}function wr(a){return a.startsWith("~")?o.join(L.homedir(),a.slice(1)):a}function Q(a,e){d.existsSync(a)||(d.mkdirSync(a,{recursive:!0}),e!=null&&e.mode&&d.chmodSync(a,e.mode))}function vr(a){try{if(L.platform()!=="win32")return F.execSync(`ps -p ${a} -o comm=`,{encoding:"utf8"}).trim();const e=`wmic process where processid=${a} get Caption`,r=F.execSync(e,{encoding:"utf8"}).split(`
|
|
12
|
-
`);return r.length<=1?"":r[1].trim()}catch{return""}}const ie=["Python"],Ke=["Tengo","Python"],kr=$.z.union([$.z.literal("Tengo"),$.z.literal("Python")]),Sr=$.z.object({npmOrgName:$.z.string().min(1),orgName:$.z.string().min(1),blockName:$.z.string().min(1),softwarePlatforms:$.z.array(kr).refine(a=>new Set(a).size===a.length,{message:"Must be an array of unique software platforms"})});async function Ar(a){const{npmOrgName:e,orgName:r,blockName:t,softwarePlatforms:s}=
|
|
12
|
+
`);return r.length<=1?"":r[1].trim()}catch{return""}}const ie=["Python"],Ke=["Tengo","Python"],kr=$.z.union([$.z.literal("Tengo"),$.z.literal("Python")]),Sr=$.z.object({npmOrgName:$.z.string().min(1),orgName:$.z.string().min(1),blockName:$.z.string().min(1),softwarePlatforms:$.z.array(kr).refine(a=>new Set(a).size===a.length,{message:"Must be an array of unique software platforms"})});async function Ar(a){const{npmOrgName:e,orgName:r,blockName:t,softwarePlatforms:s}=pr(),i=o.join(process.cwd(),t);a.info("Downloading boilerplate code..."),await Rr("https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip","platforma-block-boilerplate-main",i);const c=Ke.filter(f=>s.indexOf(f)<0),n=ie.length==c.length;a.info(`Keep platforms '${s}', remove: '${c}'. Will remove all platforms? ${n}`);for(const f of c)await Lr(i,f);n&&await _r(i),a.info("Replace everything in the template with provided options..."),Or(i,[{from:/@platforma-open(?!.*runenv-python-3)/g,to:`@${e}`},{from:/my-org/g,to:r},{from:/block-boilerplate/g,to:t}])}function pr(){let a=M.question('Write an organization name for npm. Default is "platforma-open": ');a===""&&(a="platforma-open");const e=M.question('Write an organization name, e.g. "my-org": '),r=M.question('Write a name of the block, e.g. "hello-world": '),t=M.keyInYN("Create package for block's software?");let s=["Tengo"];if(t)for(;s.length<Ke.length;){const i=M.keyInSelect(ie,"Choose software platform:");if(i<0)break;s.push(ie[i])}return s=Array.from(new Set(s)).sort(),Sr.parse({npmOrgName:a,orgName:e,blockName:r,softwarePlatforms:s})}async function Rr(a,e,r){const s=await(await fetch(a)).blob(),i=await T.mkdtemp(o.join(L.tmpdir(),"create-repo")),c=o.join(i,"packed-repo.zip"),n=nr.Writable.toWeb(d.createWriteStream(c));await s.stream().pipeTo(n);const f=o.join(i,"unpacked-repo");await T.mkdir(f),await lr(c,f),await T.cp(o.join(f,e),r,{recursive:!0})}async function Lr(a,e){const r=e.toLowerCase();await C(o.join(a,"ui","src","pages","MainPage.vue"),new RegExp(`.*${r}Message.*\\n\\n`,"g")),await C(o.join(a,"model","src","index.ts"),new RegExp(`.*${r}Message.*\\n\\n`,"g")),await C(o.join(a,"workflow","src","main.tpl.tengo"),new RegExp(`.*${r}.*exec.builder.*[\\s\\S]*?\\n\\n`,"g")),await C(o.join(a,"workflow","src","main.tpl.tengo"),new RegExp(`.*${r}Message.*\\n`,"g")),await C(o.join(a,"workflow","src","wf.test.ts"),new RegExp(`.*${r}Message.*\\n.*expect.*\\n\\n`,"g")),await T.rm(o.join(a,"software",`src_${r}`),{recursive:!0}),await Pe(o.join(a,"software","package.json"),t=>{const s=JSON.parse(t);return delete s["block-software"].artifacts[`hello-${r}-artifact`],delete s["block-software"].entrypoints[`hello-world-${r}`],JSON.stringify(s,null,2)})}async function _r(a){await T.rm(o.join(a,"software"),{recursive:!0}),await Pe(o.join(a,"workflow","package.json"),e=>{const r=JSON.parse(e);return delete r.dependencies["@platforma-open/my-org.block-boilerplate.software"],JSON.stringify(r,null,2)}),await C(o.join(a,"pnpm-workspace.yaml"),/.*- software$\n/gm)}async function Or(a,e){const r=await $r(a);for(const{from:t,to:s}of e)for(const i of r)await Ve(i,t,s)}async function $r(a){return(await T.readdir(a,{withFileTypes:!0,recursive:!0})).filter(r=>r.isFile()).map(r=>o.join(r.parentPath,r.name))}async function Pe(a,e){const r=await T.readFile(a),t=e(r.toString());await T.writeFile(a,t)}async function Ve(a,e,r){return await Pe(a,t=>t.replaceAll(e,r))}async function C(a,e){return await Ve(a,e,"")}const B=class B extends g.Command{async run(){const{flags:e}=await this.parse(B),r=D(e["log-level"]);await Ar(r)}};y(B,"description","Helps to create a new block by downloading a block's template."),y(B,"examples",["<%= name %>"]),y(B,"flags",{...E});let ce=B;function Qe(...a){return o.resolve(__dirname,"..",...a)}function O(...a){return Qe("assets",...a)}function Fr(){return d.readdirSync(O()).filter(e=>e.startsWith("compose-")&&e.endsWith(".yaml")).map(e=>O(e))}function Tr(...a){return d.readFileSync(Qe(...a))}function se(a){return a||(a=X.getDefaultPlVersion()),`quay.io/milaboratories/platforma:${a}`}const N=class N{constructor(e){y(this,"state",{lastRun:void 0,isActive:!1});y(this,"filePath");y(this,"dirPath");e=e??o.resolve(L.homedir(),".config","pl-bootstrap");const r=o.join(e,"state.json");this.dirPath=e,this.filePath=r,d.existsSync(e)||d.mkdirSync(e,{recursive:!0}),d.existsSync(r)&&(this.state=JSON.parse(Tr(r).toString()))}static getInstance(){return N.instance||(N.instance=new N),N.instance}path(...e){return o.join(this.dirPath,...e)}data(...e){return this.path("data",...e)}binaries(...e){return this.path("binaries",...e)}writeState(){d.writeFileSync(this.filePath,JSON.stringify(this.state))}get isActive(){var e,r;return this.state.isActive?this.state.isActive:(r=(e=this.state.lastRun)==null?void 0:e.process)!=null&&r.pid?this.isValidPID:!1}get isValidPID(){var r,t;if(!((t=(r=this.state.lastRun)==null?void 0:r.process)!=null&&t.pid))return!1;const e=vr(this.state.lastRun.process.pid);return e==="platforma"||e.endsWith("/platforma")||e.endsWith("\\platforma")}set isActive(e){this.state.isActive=e,this.writeState()}get lastRun(){return this.state.lastRun}set lastRun(e){this.state.lastRun=e,this.writeState()}};y(N,"instance");let ne=N;const l=ne.getInstance();function je(a,e,r,t){var s;return l.lastRun={...l.lastRun,mode:"docker",cmd:"docker",args:e,workdir:r.cwd,envs:r.env,docker:{...(s=l.lastRun)==null?void 0:s.docker,...t}},Xe(a,"docker",e,r)}function Er(a,e,r,t,s){var c;l.lastRun={...l.lastRun,mode:"process",cmd:e,args:r,workdir:t.cwd,envs:t.env,process:{...(c=l.lastRun)==null?void 0:c.process,...s}};const i=Nr(a,e,r,t);return l.lastRun.process={...l.lastRun.process,pid:i.pid},i}function Dr(a,e){if(!l.lastRun)throw new Error("no previous run info found: this is the first run after package installation");return e={cwd:l.lastRun.workdir,env:{...l.lastRun.envs,...e.env},...e},Xe(a,l.lastRun.cmd,l.lastRun.args,e)}function Nr(a,e,r,t){a.debug(`Running:
|
|
13
13
|
env: ${JSON.stringify(t.env)}
|
|
14
14
|
cmd: ${JSON.stringify([e,...r])}
|
|
15
15
|
wd: ${t.cwd}`),t.env={...process.env,...t.env},a.debug(" spawning child process");const s=F.spawn(e,r,t);var i=!1;const c=()=>{s.kill("SIGINT"),i=!0};return a.debug(" setting up signal handler"),process.on("SIGINT",c),s.on("close",n=>{process.removeListener("SIGINT",c),i&&process.exit(n)}),s}function Xe(a,e,r,t){return a.debug(`Running:
|
|
16
16
|
env: ${JSON.stringify(t.env)}
|
|
17
17
|
cmd: ${JSON.stringify([e,...r])}
|
|
18
|
-
wd: ${t.cwd}`),t.env={...process.env,...t.env},F.spawnSync(e,r,t)}function Ir(a){return{id:a,type:"S3",indexCachePeriod:"0s",endpoint:"",region:"",presignEndpoint:"",bucketName:"",createBucket:!1,forcePathStyle:!1,key:"",secret:"",keyPrefix:"",accessPrefixes:[],uploadKeyPrefix:""}}function Ze(a){return{id:a,type:"FS",indexCachePeriod:"0s",rootPath:""}}function x(a,e,r){a=wr(a);const t=new URL(a,`file:${e}`);switch(t.protocol){case"s3:":var c=t.hostname,s=t.searchParams.get("region");return{...r,type:"S3",bucketName:c,region:s};case"s3e:":var i=t.pathname.split("/").slice(1),c=i[0],n=i.length>1?i[1]:"";return{...r,type:"S3",endpoint:`http://${t.host}/`,bucketName:c,keyPrefix:n,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),c=i[0],n=i.length>1?i[1]:"";return{...r,type:"S3",endpoint:`https://${t.host}/`,bucketName:c,keyPrefix:n,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 xr(a,e){var u,b,v,S,
|
|
18
|
+
wd: ${t.cwd}`),t.env={...process.env,...t.env},F.spawnSync(e,r,t)}function Ir(a){return{id:a,type:"S3",indexCachePeriod:"0s",endpoint:"",region:"",presignEndpoint:"",bucketName:"",createBucket:!1,forcePathStyle:!1,key:"",secret:"",keyPrefix:"",accessPrefixes:[],uploadKeyPrefix:""}}function Ze(a){return{id:a,type:"FS",indexCachePeriod:"0s",rootPath:""}}function x(a,e,r){a=wr(a);const t=new URL(a,`file:${e}`);switch(t.protocol){case"s3:":var c=t.hostname,s=t.searchParams.get("region");return{...r,type:"S3",bucketName:c,region:s};case"s3e:":var i=t.pathname.split("/").slice(1),c=i[0],n=i.length>1?i[1]:"";return{...r,type:"S3",endpoint:`http://${t.host}/`,bucketName:c,keyPrefix:n,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),c=i[0],n=i.length>1?i[1]:"";return{...r,type:"S3",endpoint:`https://${t.host}/`,bucketName:c,keyPrefix:n,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 xr(a,e){var u,b,v,S,p,k,_,J,A,be,we,ve,ke,Se,Ae,pe,Re,Le,_e,Oe,$e,Fe,Te,Ee,De,Ne,Ie,xe,Me,Ce;const r=(e==null?void 0:e.localRoot)??l.data("local-custom"),t={level:((u=e==null?void 0:e.log)==null?void 0:u.level)??"info",path:((b=e==null?void 0:e.log)==null?void 0:b.path)??`${r}/platforma.log`},s={listen:((v=e==null?void 0:e.grpc)==null?void 0:v.listen)??"localhost:6345",tls:{enable:V((p=(S=e==null?void 0:e.grpc)==null?void 0:S.tls)==null?void 0:p.enable,!1),clientAuthMode:((_=(k=e==null?void 0:e.grpc)==null?void 0:k.tls)==null?void 0:_.clientAuthMode)??"NoAuth",certFile:((A=(J=e==null?void 0:e.grpc)==null?void 0:J.tls)==null?void 0:A.certFile)??`${r}/certs/tls.cert`,keyFile:((we=(be=e==null?void 0:e.grpc)==null?void 0:be.tls)==null?void 0:we.keyFile)??`${r}/certs/tls.key`,...(ve=e==null?void 0:e.grpc)==null?void 0:ve.tls}},i={auth:{enabled:((Se=(ke=e==null?void 0:e.core)==null?void 0:ke.auth)==null?void 0:Se.enabled)??!1,drivers:((pe=(Ae=e==null?void 0:e.core)==null?void 0:Ae.auth)==null?void 0:pe.drivers)??[{driver:"jwt",key:a},{driver:"htpasswd",path:`${r}/users.htpasswd`}]},db:{path:`${r}/db`}},c=Ge("main",`${r}/storages/main`,"main-bucket",(Re=e==null?void 0:e.storages)==null?void 0:Re.primary);var n;switch((_e=(Le=e==null?void 0:e.storages)==null?void 0:Le.work)==null?void 0:_e.type){case void 0:case"FS":n=Ze("work"),n.rootPath=(($e=(Oe=e==null?void 0:e.storages)==null?void 0:Oe.work)==null?void 0:$e.rootPath)??`${r}/storages/work`,n.indexCachePeriod=((Te=(Fe=e==null?void 0:e.storages)==null?void 0:Fe.work)==null?void 0:Te.indexCachePeriod)??"1m";break;default:throw new Error("work storage MUST have 'FS' type as it is used for working directories management")}const m=Ge("library",`${r}/storages/library`,"library-bucket",(Ee=e==null?void 0:e.storages)==null?void 0:Ee.library),h={enabled:V((De=e==null?void 0:e.monitoring)==null?void 0:De.enabled,!0),listen:((Ne=e==null?void 0:e.monitoring)==null?void 0:Ne.listen)??"127.0.0.1:9090"},w={enabled:V((Ie=e==null?void 0:e.debug)==null?void 0:Ie.enabled,!0),listen:((xe=e==null?void 0:e.debug)==null?void 0:xe.listen)??"127.0.0.1:9091"},P={value:((Me=e==null?void 0:e.license)==null?void 0:Me.value)??"",file:((Ce=e==null?void 0:e.license)==null?void 0:Ce.file)??""};return{localRoot:r,license:P,log:t,grpc:s,core:i,monitoring:h,debug:w,storages:{primary:c,work:n,library:m},hacks:{libraryDownloadable:!0}}}function Ge(a,e,r,t){var s;switch(t==null?void 0:t.type){case void 0:case"FS":s=Ze(a),s.rootPath=(t==null?void 0:t.rootPath)??e;break;case"S3":s=Ir(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=V(t==null?void 0:t.createBucket,!0),s.forcePathStyle=V(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 K(),new Error("unknown storage type")}return s}function Mr(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=d.readFileSync(a.license.file).toString().trimEnd()),`
|
|
19
19
|
license:
|
|
20
20
|
value: '${a.license.value}'
|
|
21
21
|
file: '${a.license.file}'
|
|
@@ -24,6 +24,10 @@ logging:
|
|
|
24
24
|
level: '${a.log.level}'
|
|
25
25
|
destinations:
|
|
26
26
|
- path: '${a.log.path}'
|
|
27
|
+
rotation:
|
|
28
|
+
maxSize: 1GiB
|
|
29
|
+
maxBackups: 15
|
|
30
|
+
compress: true
|
|
27
31
|
|
|
28
32
|
monitoring${e}:
|
|
29
33
|
listen: '${a.monitoring.listen}'
|
|
@@ -34,7 +38,7 @@ debug${r}:
|
|
|
34
38
|
core:
|
|
35
39
|
logging:
|
|
36
40
|
extendedInfo: true
|
|
37
|
-
dumpResourceData:
|
|
41
|
+
dumpResourceData: false
|
|
38
42
|
|
|
39
43
|
grpc:
|
|
40
44
|
listen: '${a.grpc.listen}'
|
|
@@ -89,10 +93,10 @@ controllers:
|
|
|
89
93
|
URL: ${i}
|
|
90
94
|
Save to: ${c}`);const n=or.get(i);return new Promise((f,m)=>{n.on("response",h=>{if(!h.statusCode){const b=new Error("failed to download archive: no HTTP status code in response from server");n.destroy(),m(b);return}if(h.statusCode!==200){const b=new Error(`failed to download archive: ${h.statusCode} ${h.statusMessage}`);n.destroy(),m(b);return}const w=parseInt(h.headers["content-length"]||"0",10);let P=0;const u=d.createWriteStream(c);h.pipe(u),h.on("data",b=>{P+=b.length;const v=P/w*100;t&&process.stdout.write(` downloading: ${v.toFixed(2)}%\r`)}),h.on("error",b=>{d.unlinkSync(c),a.error(`Failed to download Platforma Binary: ${b.message}`),n.destroy(),m(b)}),u.on("finish",()=>{u.close(),a.info(" ... download done."),n.destroy(),f(c)})})})}function Ur(a,e){a.debug("extracting archive...");const r=(e==null?void 0:e.version)??X.getDefaultPlVersion();a.debug(` version: '${r}'`);const t=`${tr({version:r})}.tgz`,s=(e==null?void 0:e.archivePath)??l.binaries(t);a.debug(` archive path: '${s}'`);const i=(e==null?void 0:e.extractTo)??qr(s);if(a.debug(` target dir: '${i}'`),d.existsSync(i))return a.info(`Platforma Backend binaries unpack skipped: '${i}' exists`),i;if(!d.existsSync(s)){const c=`Platforma Backend binary archive not found at '${s}'`;throw a.error(c),new Error(c)}return d.existsSync(i)||(a.debug(` creating target dir '${i}'`),d.mkdirSync(i,{recursive:!0})),a.info(`Unpacking Platforma Backend archive:
|
|
91
95
|
Archive: ${s}
|
|
92
|
-
Target dir: ${i}`),gr.x({file:s,cwd:i,gzip:!0,sync:!0}),a.info(" ... unpack done."),i}function rr(a,e){return Gr(a,e).then(r=>Ur(a,{archivePath:r}))}function tr(a){return`pl-${(a==null?void 0:a.version)??X.getDefaultPlVersion()}-${er()}`}function Wr(a,...e){return l.binaries(tr({version:a}),...e)}function qr(a){const e=a.lastIndexOf(".");return e===-1?a:a.slice(0,e)}class I{constructor(e){this.logger=e}startLast(){const e=Dr(this.logger,{stdio:"inherit"});Y(e,"failed to bring back Platforma Backend in the last started configuration")}startLocal(e){var f,m,h,w,P,u,b,v,S,
|
|
93
|
-
${n}`),Er(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?o.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...");var r=O("compose-backend.yaml");const 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)??l.data("minio");Q(i,{mode:"0775"});const c=l.data("stub");Q(c);const n=(e==null?void 0:e.minioPort)??9e3,f=(e==null?void 0:e.minioConsolePort)??9001,m={MINIO_IMAGE:s,MINIO_STORAGE:o.resolve(i),MINIO_PORT:n.toString(),MINIO_CONSOLE_PORT:f.toString(),PL_DATA_DB_ROOT:c,PL_DATA_PRIMARY_ROOT:c,PL_DATA_LIBRARY_ROOT:c,PL_DATA_WORKDIR_ROOT:c,PL_DATA_PACKAGE_ROOT:c,PL_IMAGE:"scratch"};this.logger.debug(" spawning child 'docker' process...");const h=F.spawnSync("docker",["compose",`--file=${r}`,"up","--detach","--remove-orphans","--pull=missing","minio"],{env:{...process.env,...m},stdio:"inherit"});Y(h,"failed to start MinIO service in docker")}buildPlatforma(e){const r=o.resolve(e.repoRoot,"cmd","platforma"),t=e.binPath??o.join(L.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=F.spawnSync("go",["build","-o",t,"."],{cwd:r,stdio:"inherit"});return Y(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)??se(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=S=>o.join(e,S),c=S=>{const
|
|
94
|
-
${v}`)}startDocker(e,r){var t=O("compose-backend.yaml");const s=(r==null?void 0:r.image)??se(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=k=>o.join(e,k),c=k=>{const _=i(k);return Q(_,{mode:"0775"}),_},n=i("platforma.log");d.existsSync(n)||(d.mkdirSync(o.dirname(n),{recursive:!0}),d.writeFileSync(n,""));const f=c("db"),m=c("primary"),h=c("library"),w=c("work"),P=i("users.htpasswd");d.existsSync(P)||d.copyFileSync(O("users.htpasswd"),P);const u=x((r==null?void 0:r.primaryStorageURL)??`file:${m}`,"."),b=x((r==null?void 0:r.libraryStorageURL)??`file:${h}`,"."),v={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:P,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:"info",PL_LOG_FILE:n,PL_DATA_DB_ROOT:f,PL_DATA_PRIMARY_ROOT:m,PL_DATA_LIBRARY_ROOT:h,PL_DATA_WORKDIR_ROOT:w,PL_DATA_PACKAGE_ROOT:c("packages"),...this.configureDockerStorage("primary",u),...this.configureDockerStorage("library",b)};if(r!=null&&r.grpcAddr&&(v.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(v.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(v.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(v.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(v.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(v.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(v.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const k of r.auth.drivers)k.driver==="htpasswd"&&(v.PL_AUTH_HTPASSWD_PATH=o.resolve(k.path),k.path="/etc/platforma/users.htpasswd");v.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}const S=je(this.logger,["compose",`--file=${t}`,"up","--detach","--remove-orphans","--pull=missing","backend"],{env:v,stdio:"inherit"},{plImage:s,composePath:t,primaryPath:m,workPath:w,libraryPath:h});Y(S,"failed to start Platforma Backend in Docker"),l.isActive=!0;const
|
|
95
|
-
${
|
|
96
|
+
Target dir: ${i}`),gr.x({file:s,cwd:i,gzip:!0,sync:!0}),a.info(" ... unpack done."),i}function rr(a,e){return Gr(a,e).then(r=>Ur(a,{archivePath:r}))}function tr(a){return`pl-${(a==null?void 0:a.version)??X.getDefaultPlVersion()}-${er()}`}function Wr(a,...e){return l.binaries(tr({version:a}),...e)}function qr(a){const e=a.lastIndexOf(".");return e===-1?a:a.slice(0,e)}class I{constructor(e){this.logger=e}startLast(){const e=Dr(this.logger,{stdio:"inherit"});Y(e,"failed to bring back Platforma Backend in the last started configuration")}startLocal(e){var f,m,h,w,P,u,b,v,S,p;const r=(e==null?void 0:e.binaryPath)??Wr(e==null?void 0:e.version,"binaries","platforma");var t=e==null?void 0:e.configPath;const s=(e==null?void 0:e.workdir)??(t?process.cwd():l.path());e!=null&&e.primaryURL&&(e.configOptions={...e.configOptions,storages:{...(f=e.configOptions)==null?void 0:f.storages,primary:x(e.primaryURL,s,(h=(m=e.configOptions)==null?void 0:m.storages)==null?void 0:h.primary)}}),e!=null&&e.libraryURL&&(e.configOptions={...e.configOptions,storages:{...(w=e.configOptions)==null?void 0:w.storages,library:x(e.libraryURL,s,(u=(P=e.configOptions)==null?void 0:P.storages)==null?void 0:u.library)}});const i=xr(this.getLastJwt(),e==null?void 0:e.configOptions);this.logger.debug(" checking license..."),this.checkLicense((v=(b=e==null?void 0:e.configOptions)==null?void 0:b.license)==null?void 0:v.value,(p=(S=e==null?void 0:e.configOptions)==null?void 0:S.license)==null?void 0:p.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 k of c)d.existsSync(k)||(this.logger.debug(` '${k}'`),d.mkdirSync(k,{recursive:!0}));for(const k of i.core.auth.drivers)k.driver==="htpasswd"&&(d.existsSync(k.path)||(this.logger.debug(` installing default 'users.htpasswd' to ${k.path}...`),d.copyFileSync(O("users.htpasswd"),k.path)));t||(t=o.join(i.localRoot,"config.yaml"),this.logger.debug(` rendering configuration '${t}'...`),d.writeFileSync(t,Mr(i)));const n=this.renderRunInfo({configPath:t,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});return this.logger.info(`Starting platforma:
|
|
97
|
+
${n}`),Er(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?o.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...");var r=O("compose-backend.yaml");const 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)??l.data("minio");Q(i,{mode:"0775"});const c=l.data("stub");Q(c);const n=(e==null?void 0:e.minioPort)??9e3,f=(e==null?void 0:e.minioConsolePort)??9001,m={MINIO_IMAGE:s,MINIO_STORAGE:o.resolve(i),MINIO_PORT:n.toString(),MINIO_CONSOLE_PORT:f.toString(),PL_DATA_DB_ROOT:c,PL_DATA_PRIMARY_ROOT:c,PL_DATA_LIBRARY_ROOT:c,PL_DATA_WORKDIR_ROOT:c,PL_DATA_PACKAGE_ROOT:c,PL_IMAGE:"scratch"};this.logger.debug(" spawning child 'docker' process...");const h=F.spawnSync("docker",["compose",`--file=${r}`,"up","--detach","--remove-orphans","--pull=missing","minio"],{env:{...process.env,...m},stdio:"inherit"});Y(h,"failed to start MinIO service in docker")}buildPlatforma(e){const r=o.resolve(e.repoRoot,"cmd","platforma"),t=e.binPath??o.join(L.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=F.spawnSync("go",["build","-o",t,"."],{cwd:r,stdio:"inherit"});return Y(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)??se(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=S=>o.join(e,S),c=S=>{const p=i(S);return Q(p,{mode:"0775"}),p},n=i("platforma.log");d.existsSync(n)||(d.mkdirSync(o.dirname(n),{recursive:!0}),d.writeFileSync(n,""));const f=x("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://localhost:9000";const m=x("s3e://testuser:testpassword@minio:9000/library-bucket");if(m.type!=="S3")throw new Error(`${m.type} storage type is not supported for library storage`);m.presignEndpoint="http://localhost:9000";const h=c("db"),w=c("work"),P=i("users.htpasswd");d.existsSync(P)||d.copyFileSync(O("users.htpasswd"),P);const u={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:P,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_FILE:n,PL_DATA_DB_ROOT:h,PL_DATA_PRIMARY_ROOT:c("primary"),PL_DATA_LIBRARY_ROOT:c("library"),PL_DATA_WORKDIR_ROOT:w,PL_DATA_PACKAGE_ROOT:c("packages"),...this.configureDockerStorage("primary",f),...this.configureDockerStorage("library",m)};if(r!=null&&r.grpcAddr&&(u.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(u.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(u.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(u.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(u.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(u.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(u.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const S of r.auth.drivers)S.driver==="htpasswd"&&(u.PL_AUTH_HTPASSWD_PATH=o.resolve(S.path),S.path="/etc/platforma/users.htpasswd");u.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}const b=je(this.logger,["compose",`--file=${t}`,"up","--detach","--remove-orphans","--pull=missing","minio","backend"],{env:u,stdio:"inherit"},{plImage:s,composePath:t});Y(b,"failed to start Platforma Backend in Docker"),l.isActive=!0;const v=this.renderRunInfo({apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:n,primary:f,work:{type:"FS",rootPath:w},library:m,dbPath:h});this.logger.info(`Started platforma:
|
|
98
|
+
${v}`)}startDocker(e,r){var t=O("compose-backend.yaml");const s=(r==null?void 0:r.image)??se(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=k=>o.join(e,k),c=k=>{const _=i(k);return Q(_,{mode:"0775"}),_},n=i("platforma.log");d.existsSync(n)||(d.mkdirSync(o.dirname(n),{recursive:!0}),d.writeFileSync(n,""));const f=c("db"),m=c("primary"),h=c("library"),w=c("work"),P=i("users.htpasswd");d.existsSync(P)||d.copyFileSync(O("users.htpasswd"),P);const u=x((r==null?void 0:r.primaryStorageURL)??`file:${m}`,"."),b=x((r==null?void 0:r.libraryStorageURL)??`file:${h}`,"."),v={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:P,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:"info",PL_LOG_FILE:n,PL_DATA_DB_ROOT:f,PL_DATA_PRIMARY_ROOT:m,PL_DATA_LIBRARY_ROOT:h,PL_DATA_WORKDIR_ROOT:w,PL_DATA_PACKAGE_ROOT:c("packages"),...this.configureDockerStorage("primary",u),...this.configureDockerStorage("library",b)};if(r!=null&&r.grpcAddr&&(v.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(v.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(v.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(v.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(v.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(v.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(v.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const k of r.auth.drivers)k.driver==="htpasswd"&&(v.PL_AUTH_HTPASSWD_PATH=o.resolve(k.path),k.path="/etc/platforma/users.htpasswd");v.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}const S=je(this.logger,["compose",`--file=${t}`,"up","--detach","--remove-orphans","--pull=missing","backend"],{env:v,stdio:"inherit"},{plImage:s,composePath:t,primaryPath:m,workPath:w,libraryPath:h});Y(S,"failed to start Platforma Backend in Docker"),l.isActive=!0;const p=this.renderRunInfo({apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:n,primary:u,work:{type:"FS",rootPath:w},library:b,dbPath:f});this.logger.info(`Started platforma:
|
|
99
|
+
${p}`)}stop(){if(!l.isActive){console.log("no running service detected");return}const e=l.lastRun;switch(e.mode){case"docker":const r=F.spawnSync("docker",["compose","--file",e.docker.composePath,"down"],{env:{...process.env,...e.envs},stdio:"inherit"});l.isActive=!1,r.status!==0&&process.exit(r.status);return;case"process":l.isValidPID&&process.kill(e.process.pid),l.isActive=!1;return;default:K(e.mode)}}cleanup(){var n,f,m,h,w,P,u,b,v,S,p,k,_,J;const e=["last command run cache ('pl-service start' shorthand will stop working until next full start command call)","'platforma' docker compose service containers and volumes"],r=l.data(),t=[r];if((f=(n=l.lastRun)==null?void 0:n.docker)!=null&&f.primaryPath){const A=(h=(m=l.lastRun)==null?void 0:m.docker)==null?void 0:h.primaryPath;A.startsWith(r)||t.push(A)}if((P=(w=l.lastRun)==null?void 0:w.docker)!=null&&P.workPath){const A=(b=(u=l.lastRun)==null?void 0:u.docker)==null?void 0:b.workPath;A.startsWith(r)||t.push(A)}if((S=(v=l.lastRun)==null?void 0:v.process)!=null&&S.storagePath){const A=(k=(p=l.lastRun)==null?void 0:p.process)==null?void 0:k.storagePath;A.startsWith(r)||t.push(A)}const s=t.length>0?` - storages (you'll loose all projects and calculation results stored in service instances):
|
|
96
100
|
- ${t.join(`
|
|
97
101
|
- `)}`:"";var i=`
|
|
98
102
|
You are going to reset the state of platforma service
|
|
@@ -100,7 +104,7 @@ Things to be removed:
|
|
|
100
104
|
- ${e.join(`
|
|
101
105
|
- `)}
|
|
102
106
|
${s}
|
|
103
|
-
`;if(this.logger.warn(i),!Pr("Are you sure?")){this.logger.info("Reset action was canceled");return}const c=new Set(Fr());(
|
|
107
|
+
`;if(this.logger.warn(i),!Pr("Are you sure?")){this.logger.info("Reset action was canceled");return}const c=new Set(Fr());(J=(_=l.lastRun)==null?void 0:_.docker)!=null&&J.composePath&&c.add(l.lastRun.docker.composePath);for(const A of c)this.logger.info(`Destroying docker compose '${A}'`),this.destroyDocker(A,se());for(const A of t)this.logger.info(`Destroying '${A}'`),d.rmSync(A,{recursive:!0,force:!0});this.logger.info(`Destroying state dir '${l.path()}'`),d.rmSync(l.path(),{recursive:!0,force:!0}),this.logger.info(`
|
|
104
108
|
If you want to remove all downloaded platforma binaries, delete '${l.binaries()}' dir manually
|
|
105
109
|
`)}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:d.existsSync(o.resolve(L.homedir(),".pl.license"))&&(e["license-file"]=o.resolve(L.homedir(),".pl.license")))}initAuthDriversList(e,r){var t=[];if(e["auth-htpasswd-file"]&&t.push({driver:"htpasswd",path:o.resolve(r,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"]&&t.push({driver:"ldap",serverUrl:e["auth-ldap-server"],defaultDN:e["auth-ldap-default-dn"]}),t.length!==0)return[{driver:"jwt",key:this.getLastJwt()},...t]}getLastJwt(){const e=l.path("auth.jwt"),r="utf-8";let t="";try{t=d.readFileSync(e,{encoding:r})}catch{}return t==""&&(t=br(64),d.writeFileSync(e,t,{encoding:r})),t}destroyDocker(e,r){const t=l.data("stub"),s=F.spawnSync("docker",["compose","--file",e,"down","--volumes","--remove-orphans"],{env:{...process.env,PL_IMAGE:"scratch",PL_DATA_DB_ROOT:t,PL_DATA_PRIMARY_ROOT:t,PL_DATA_LIBRARY_ROOT:t,PL_DATA_WORKDIR_ROOT:t,PL_DATA_PACKAGE_ROOT:t,MINIO_IMAGE:"scratch",MINIO_STORAGE:t},stdio:"inherit"});s.status!==0&&process.exit(s.status)}checkLicense(e,r){if(!(e!==void 0&&e!="")&&!(r!==void 0&&r!=""))throw this.logger.error(`A license for Platforma Backend must be set.
|
|
106
110
|
|
|
@@ -113,5 +117,5 @@ The license file can also be set with the variables 'MI_LICENSE_FILE' or 'PL_LIC
|
|
|
113
117
|
or stored in '$HOME/.pl.license'.
|
|
114
118
|
|
|
115
119
|
You can obtain the license from "https://licensing.milaboratories.com".`),new Error("The license was not provided.")}configureDockerStorage(e,r){const t={},s=r.type;switch(e=e.toUpperCase(),s){case"S3":return t[`PL_DATA_${e}_TYPE`]="S3",t[`PL_DATA_${e}_S3_BUCKET`]=r.bucketName,r.endpoint&&(t[`PL_DATA_${e}_S3_ENDPOINT`]=r.endpoint),r.presignEndpoint&&(t[`PL_DATA_${e}_S3_PRESIGN_ENDPOINT`]=r.presignEndpoint),r.region&&(t[`PL_DATA_${e}_S3_REGION`]=r.region),r.key&&(t[`PL_DATA_${e}_S3_KEY`]=r.key),r.secret&&(t[`PL_DATA_${e}_S3_SECRET`]=r.secret),t;case"FS":return t[`PL_DATA_${e}_TYPE`]="FS",t;default:K()}return{}}renderRunInfo(e,r=10){var n,f;const t=[],s=m=>m.padStart(r," ");switch(e.configPath&&t.push(`${s("config")}: ${e.configPath}`),e.apiAddr?t.push(`${s("API")}: ${e.apiAddr}`):e.apiPort?t.push(`${s("API")}: 127.0.0.1:${e.apiPort.toString()}`):t.push(`${s("API")}: 127.0.0.1:6345`),e.logPath&&t.push(`${s("log")}: ${e.logPath}`),(n=e.primary)==null?void 0:n.type){case void 0:break;case"FS":t.push(`${s("primary")}: ${e.primary.rootPath}`);break;case"S3":t.push(`${s("primary")}: S3 at '${e.primary.endpoint??"AWS"}', bucket '${e.primary.bucketName}', prefix: '${e.primary.keyPrefix??""}'`);break;default:K()}switch((f=e.library)==null?void 0:f.type){case void 0:break;case"FS":t.push(`${s("library")}: ${e.library.rootPath}`);break;case"S3":t.push(`${s("library")}: S3 at '${e.library.endpoint??"AWS"}', bucket '${e.library.bucketName}', prefix: '${e.library.keyPrefix??""}'`);break;default:K()}return e.work&&t.push(`${s("workdirs")}: ${e.work.rootPath}`),e.dbPath&&t.push(`${s("db")}: ${e.dbPath}`),t.join(`
|
|
116
|
-
`)}readComposeFile(e){const r=d.readFileSync(e);return Be.parse(r.toString())}writeComposeFile(e,r){d.writeFileSync(e,Be.stringify(r))}}function Y(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 j=class j extends g.Command{async run(){const{flags:e}=await this.parse(j),r=D(e["log-level"]);new I(r).cleanup()}};y(j,"description","Clear service state (forget last run command, destroy docker services, volumes and so on)"),y(j,"examples",["<%= config.bin %> <%= command.id %>"]),y(j,"flags",{...E});let le=j;const G=class G extends g.Command{async run(){const{flags:e}=await this.parse(G),r=D(e["log-level"]);new I(r).startLast()}};y(G,"description","Start last run service configuraiton"),y(G,"examples",["<%= config.bin %> <%= command.id %>"]),y(G,"flags",{...E});let oe=G;const U=class U extends g.Command{async run(){const{flags:e}=await this.parse(U),r=D(e["log-level"]);new I(r).stop()}};y(U,"description","Stop platforma service"),y(U,"examples",["<%= config.bin %> <%= command.id %>"]),y(U,"flags",{...E});let de=U;const W=class W extends g.Command{async run(){const{flags:e}=await this.parse(W),r=D(e["log-level"]),t=new I(r);t.mergeLicenseEnvs(e);const s=e["auth-enabled"],i=s?{enabled:s,drivers:t.initAuthDriversList(e,".")}:void 0,c=e.storage?o.join(".",e.storage):l.data("docker");t.startDocker(c,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,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"]})}};y(W,"description","Run platforma backend service with 'FS' primary storage type"),y(W,"examples",["<%= config.bin %> <%= command.id %>"]),y(W,"flags",{...E,...re,...We,...Z,...ae,...ee,...te,...me,...he,...ye});let ge=W;const q=class q extends g.Command{async run(){const{flags:e}=await this.parse(q),r=D(e["log-level"]),t=new I(r);t.mergeLicenseEnvs(e);const s=e["pl-workdir"]??".",i=e.storage?o.join(s,e.storage):l.data("local"),c=e["pl-log-file"]?o.join(s,e["pl-log-file"]):void 0,n=t.initAuthDriversList(e,s),f=e["auth-enabled"]??n!==void 0;var m=e["pl-binary"];e["pl-sources"]&&(m=t.buildPlatforma({repoRoot:e["pl-sources"]}));var h="127.0.0.1:6345";e["grpc-listen"]?h=e["grpc-listen"]:e["grpc-port"]&&(h=`127.0.0.1:${e["grpc-port"]}`);var w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);var P="127.0.0.1:9091";e["debug-listen"]?P=e["debug-listen"]:e["debug-port"]&&(P=`127.0.0.1:${e["debug-port"]}`);const u={binaryPath:m,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:h},monitoring:{listen:w},debug:{listen:P},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:f,drivers:n}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};u.binaryPath?t.startLocal(u):rr(r,{version:e.version}).then(()=>t.startLocal(u)).catch(function(b){r.error(b.message)})}};y(q,"description","Run Platforma Backend service as local process on current host (no docker container)"),y(q,"examples",["<%= config.bin %> <%= command.id %>"]),y(q,"flags",{...E,...Z,...re,...
|
|
120
|
+
`)}readComposeFile(e){const r=d.readFileSync(e);return Be.parse(r.toString())}writeComposeFile(e,r){d.writeFileSync(e,Be.stringify(r))}}function Y(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 j=class j extends g.Command{async run(){const{flags:e}=await this.parse(j),r=D(e["log-level"]);new I(r).cleanup()}};y(j,"description","Clear service state (forget last run command, destroy docker services, volumes and so on)"),y(j,"examples",["<%= config.bin %> <%= command.id %>"]),y(j,"flags",{...E});let le=j;const G=class G extends g.Command{async run(){const{flags:e}=await this.parse(G),r=D(e["log-level"]);new I(r).startLast()}};y(G,"description","Start last run service configuraiton"),y(G,"examples",["<%= config.bin %> <%= command.id %>"]),y(G,"flags",{...E});let oe=G;const U=class U extends g.Command{async run(){const{flags:e}=await this.parse(U),r=D(e["log-level"]);new I(r).stop()}};y(U,"description","Stop platforma service"),y(U,"examples",["<%= config.bin %> <%= command.id %>"]),y(U,"flags",{...E});let de=U;const W=class W extends g.Command{async run(){const{flags:e}=await this.parse(W),r=D(e["log-level"]),t=new I(r);t.mergeLicenseEnvs(e);const s=e["auth-enabled"],i=s?{enabled:s,drivers:t.initAuthDriversList(e,".")}:void 0,c=e.storage?o.join(".",e.storage):l.data("docker");t.startDocker(c,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,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"]})}};y(W,"description","Run platforma backend service with 'FS' primary storage type"),y(W,"examples",["<%= config.bin %> <%= command.id %>"]),y(W,"flags",{...E,...re,...We,...Z,...ae,...ee,...te,...me,...he,...ye});let ge=W;const q=class q extends g.Command{async run(){const{flags:e}=await this.parse(q),r=D(e["log-level"]),t=new I(r);t.mergeLicenseEnvs(e);const s=e["pl-workdir"]??".",i=e.storage?o.join(s,e.storage):l.data("local"),c=e["pl-log-file"]?o.join(s,e["pl-log-file"]):void 0,n=t.initAuthDriversList(e,s),f=e["auth-enabled"]??n!==void 0;var m=e["pl-binary"];e["pl-sources"]&&(m=t.buildPlatforma({repoRoot:e["pl-sources"]}));var h="127.0.0.1:6345";e["grpc-listen"]?h=e["grpc-listen"]:e["grpc-port"]&&(h=`127.0.0.1:${e["grpc-port"]}`);var w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);var P="127.0.0.1:9091";e["debug-listen"]?P=e["debug-listen"]:e["debug-port"]&&(P=`127.0.0.1:${e["debug-port"]}`);const u={binaryPath:m,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:h},monitoring:{listen:w},debug:{listen:P},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:f,drivers:n}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};u.binaryPath?t.startLocal(u):rr(r,{version:e.version}).then(()=>t.startLocal(u)).catch(function(b){r.error(b.message)})}};y(q,"description","Run Platforma Backend service as local process on current host (no docker container)"),y(q,"examples",["<%= config.bin %> <%= command.id %>"]),y(q,"flags",{...E,...Z,...re,...Je,...He,...Ye,...ee,...te,...me,...he,...ye,...qe,...ze,...ae});let ue=q;var R;let zr=(R=class extends g.Command{async run(){const{flags:e}=await this.parse(R),r=D(e["log-level"]),t=new I(r);t.mergeLicenseEnvs(e);const s=e["auth-enabled"],i=s?{enabled:s,drivers:t.initAuthDriversList(e,".")}:void 0,c=e.storage?o.join(".",e.storage):l.data("docker-s3");t.startDockerS3(c,{image:e.image,version:e.version,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"]})}},y(R,"description","Run platforma backend service with 'S3' primary storage type"),y(R,"examples",["<%= config.bin %> <%= command.id %>"]),y(R,"flags",{...E,...re,...We,...Z,...te,...ee,...ae}),R);const z=class z extends g.Command{async run(){const{flags:e}=await this.parse(z),r=D(e["log-level"]),t=new I(r);t.mergeLicenseEnvs(e);const s=e["pl-workdir"]??".",i=e.storage?o.join(s,e.storage):l.data("local-s3"),c=e["pl-log-file"]?o.join(s,e["pl-log-file"]):void 0,n=t.initAuthDriversList(e,s),f=e["auth-enabled"]??n!==void 0;var m=e["pl-binary"];e["pl-sources"]&&(m=t.buildPlatforma({repoRoot:e["pl-sources"]}));var h="127.0.0.1:6345";e["grpc-listen"]?h=e["grpc-listen"]:e["grpc-port"]&&(h=`127.0.0.1:${e["grpc-port"]}`);var w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);var P="127.0.0.1:9091";e["debug-listen"]?P=e["debug-listen"]:e["debug-port"]&&(P=`127.0.0.1:${e["debug-port"]}`);const u={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:h},monitoring:{listen:w},debug:{listen:P},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:f,drivers:n}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};u.binaryPath?t.startLocalS3(u):rr(r,{version:e.version}).then(()=>t.startLocalS3(u)).catch(function(b){r.error(b.message)})}};y(z,"description","Run Platforma Backend service as local process on current host (no docker container)"),y(z,"examples",["<%= config.bin %> <%= command.id %>"]),y(z,"flags",{...E,...Z,...re,...ur,...Je,...He,...Ye,...ee,...te,...me,...he,...ye,...qe,...ze,...ae});let fe=z;const Jr={"create-block":ce,reset:le,start:oe,stop:de,"start:docker":ge,"start:local":ue,"start:docker:s3":zr,"start:local:s3":fe};exports.COMMANDS=Jr;
|
|
117
121
|
//# sourceMappingURL=index.js.map
|