@platforma-sdk/bootstrap 2.6.3 → 2.7.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 +7 -6
- package/dist/core.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -47,7 +47,8 @@ services:
|
|
|
47
47
|
|
|
48
48
|
# Logging
|
|
49
49
|
- "PL_LOG_LEVEL=${PL_LOG_LEVEL:-warn}"
|
|
50
|
-
- "PL_LOG_DESTINATION=${
|
|
50
|
+
- "PL_LOG_DESTINATION=${PL_LOG_DIR:+/storage/log/platforma.log}"
|
|
51
|
+
- "PL_LOG_ROTATION_ENABLED=${PL_LOG_ROTATION_ENABLED:-false}"
|
|
51
52
|
- "PL_LOG_COMMIT_SUMMARY=${PL_LOG_COMMIT_SUMMARY:-false}"
|
|
52
53
|
- "PL_LOG_RESOURCE_DATA=${PL_LOG_RESOURCE_DATA:-false}"
|
|
53
54
|
|
|
@@ -81,12 +82,12 @@ services:
|
|
|
81
82
|
volumes:
|
|
82
83
|
- ${PL_AUTH_HTPASSWD_PATH-/dev/null}:/etc/platforma/users.htpasswd
|
|
83
84
|
- ${PL_LICENSE_FILE:-/dev/null}:/storage/mi.license
|
|
84
|
-
- ${
|
|
85
|
+
- ${PL_LOG_DIR:-/dev/null}:/storage/log/
|
|
85
86
|
- ${PL_DATA_DB_ROOT}:/storage/rocksdb
|
|
86
|
-
- ${PL_DATA_PRIMARY_ROOT}:/storage/controllers/data/primary
|
|
87
|
-
- ${PL_DATA_LIBRARY_ROOT}:/storage/controllers/data/library
|
|
88
|
-
- ${PL_DATA_WORKDIR_ROOT}:/storage/controllers/data/work
|
|
89
|
-
- ${PL_DATA_PACKAGE_ROOT}:/storage/controllers/packageLoader
|
|
87
|
+
- ${PL_DATA_PRIMARY_ROOT}:/storage/controllers/data/primary/
|
|
88
|
+
- ${PL_DATA_LIBRARY_ROOT}:/storage/controllers/data/library/
|
|
89
|
+
- ${PL_DATA_WORKDIR_ROOT}:/storage/controllers/data/work/
|
|
90
|
+
- ${PL_DATA_PACKAGE_ROOT}:/storage/controllers/packageLoader/
|
|
90
91
|
|
|
91
92
|
restart: always
|
|
92
93
|
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAoB,MAAM,eAAe,CAAC;AAOjF,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAC/C,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAI3C,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,MAAM,CAAC,OAAO,OAAO,IAAI;IACX,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,OAAO,CAAC,MAAM;IAE5C,SAAS;IAKT,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,YAAY;IA8FrD,YAAY,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,YAAY;IAoBzD,UAAU,CAAC,OAAO,CAAC,EAAE;QAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB;IA+CM,cAAc,CAAC,OAAO,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;IAiBvE,aAAa,CAClB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAElB,IAAI,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC;QAEzB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;QAErB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAElB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,cAAc,CAAC,EAAE,MAAM,CAAC;QAExB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -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}=Rr(),i=o.join(process.cwd(),t);a.info("Downloading boilerplate code..."),await pr("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 Rr(){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 pr(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 Ge(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,R,k,_,J,A,be,we,ve,ke,Se,Ae,Re,pe,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}/logs/platforma.log`},s={listen:((v=e==null?void 0:e.grpc)==null?void 0:v.listen)??"localhost:6345",tls:{enable:V((R=(S=e==null?void 0:e.grpc)==null?void 0:S.tls)==null?void 0:R.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:((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`}},c=je("main",`${r}/storages/main`,"main-bucket",(pe=e==null?void 0:e.storages)==null?void 0:pe.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=je("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 je(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}'
|
|
@@ -89,14 +89,14 @@ controllers:
|
|
|
89
89
|
packagesRoot: '${a.localRoot}/packages'
|
|
90
90
|
|
|
91
91
|
workflows: {}
|
|
92
|
-
`}function V(a,e){return a===void 0?e:a}const Cr=["linux","macos","windows"];function Br(a){const e=L.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(Cr))}}const
|
|
92
|
+
`}function V(a,e){return a===void 0?e:a}const Cr=["linux","macos","windows"];function Br(a){const e=L.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(Cr))}}const Gr=["amd64","arm64"];function er(a){const e=L.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(Gr))}}function jr(a,e){const r=(e==null?void 0:e.version)??X.getDefaultPlVersion(),t=(e==null?void 0:e.showProgress)??process.stdout.isTTY,s=`pl-${r}-${er()}.tgz`,i=(e==null?void 0:e.downloadURL)??`https://cdn.platforma.bio/software/pl/${Br()}/${s}`,c=(e==null?void 0:e.saveTo)??l.binaries(s);if(d.existsSync(c))return a.info(`Platforma Backend archive download skipped: '${c}' already exists`),Promise.resolve(c);d.mkdirSync(o.dirname(c),{recursive:!0}),a.info(`Downloading Platforma Backend archive:
|
|
93
93
|
URL: ${i}
|
|
94
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:
|
|
95
95
|
Archive: ${s}
|
|
96
|
-
Target dir: ${i}`),gr.x({file:s,cwd:i,gzip:!0,sync:!0}),a.info(" ... unpack done."),i}function rr(a,e){return
|
|
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
|
|
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
|
|
99
|
-
${
|
|
96
|
+
Target dir: ${i}`),gr.x({file:s,cwd:i,gzip:!0,sync:!0}),a.info(" ... unpack done."),i}function rr(a,e){return jr(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,R;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,(R=(S=e==null?void 0:e.configOptions)==null?void 0:S.license)==null?void 0:R.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 R=i(S);return Q(R,{mode:"0775"}),R},n=i("logs","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_DIR:o.dirname(n),PL_LOG_ROTATION_ENABLED:"true",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=Ge(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("logs","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_DIR:o.dirname(n),PL_LOG_ROTATION_ENABLED:"true",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=Ge(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 R=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
|
+
${R}`)}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,R,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=(R=l.lastRun)==null?void 0:R.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):
|
|
100
100
|
- ${t.join(`
|
|
101
101
|
- `)}`:"";var i=`
|
|
102
102
|
You are going to reset the state of platforma service
|
|
@@ -117,5 +117,5 @@ The license file can also be set with the variables 'MI_LICENSE_FILE' or 'PL_LIC
|
|
|
117
117
|
or stored in '$HOME/.pl.license'.
|
|
118
118
|
|
|
119
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(`
|
|
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
|
|
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 G=class G extends g.Command{async run(){const{flags:e}=await this.parse(G),r=D(e["log-level"]);new I(r).cleanup()}};y(G,"description","Clear service state (forget last run command, destroy docker services, volumes and so on)"),y(G,"examples",["<%= config.bin %> <%= command.id %>"]),y(G,"flags",{...E});let le=G;const j=class j extends g.Command{async run(){const{flags:e}=await this.parse(j),r=D(e["log-level"]);new I(r).startLast()}};y(j,"description","Start last run service configuraiton"),y(j,"examples",["<%= config.bin %> <%= command.id %>"]),y(j,"flags",{...E});let oe=j;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 p;let zr=(p=class extends g.Command{async run(){const{flags:e}=await this.parse(p),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(p,"description","Run platforma backend service with 'S3' primary storage type"),y(p,"examples",["<%= config.bin %> <%= command.id %>"]),y(p,"flags",{...E,...re,...We,...Z,...te,...ee,...ae}),p);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;
|
|
121
121
|
//# sourceMappingURL=index.js.map
|