@platforma-sdk/bootstrap 3.3.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/local/s3.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAQtC,MAAM,CAAC,OAAO,OAAO,EAAG,SAAQ,OAAO;IACrC,OAAgB,WAAW,SAA0F;IAErH,OAAgB,QAAQ,WAA2C;IAEnE,OAAgB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;MAqBnB;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA8ElC"}
1
+ {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/commands/start/local/s3.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAQtC,MAAM,CAAC,OAAO,OAAO,EAAG,SAAQ,OAAO;IACrC,OAAgB,WAAW,SAA0F;IAErH,OAAgB,QAAQ,WAA2C;IAEnE,OAAgB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;MAqBnB;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAyFlC"}
package/dist/index.js CHANGED
@@ -93,7 +93,7 @@ controllers:
93
93
  Save to: ${i}`);const c=Ir.get(s);return new Promise((o,g)=>{c.on("response",d=>{if(!d.statusCode){const b=new Error("failed to download archive: no HTTP status code in response from server");c.destroy(),g(b);return}if(d.statusCode!==200){const b=new Error(`failed to download archive: ${d.statusCode} ${d.statusMessage}`);c.destroy(),g(b);return}const y=parseInt(d.headers["content-length"]||"0",10);let w=0;const p=m.createWriteStream(i);d.pipe(p),d.on("data",b=>{w+=b.length;const P=w/y*100;r&&process.stdout.write(` downloading: ${P.toFixed(2)}%\r`)}),d.on("error",b=>{m.unlinkSync(i),a.error(`Failed to download Platforma Binary: ${b.message}`),c.destroy(),g(b)}),p.on("finish",()=>{p.close(),a.info(" ... download done."),c.destroy(),o(i)})})})}function at(a,e){a.debug("extracting archive...");const t=(e==null?void 0:e.version)??ge.getDefaultPlVersion();a.debug(` version: '${t}'`);const r=`${vr({version:t})}.tgz`,n=(e==null?void 0:e.archivePath)??f.binaries(r);a.debug(` archive path: '${n}'`);const s=(e==null?void 0:e.extractTo)??st(n);if(a.debug(` target dir: '${s}'`),m.existsSync(s))return a.info(`Platforma Backend binaries unpack skipped: '${s}' exists`),s;if(!m.existsSync(n)){const i=`Platforma Backend binary archive not found at '${n}'`;throw a.error(i),new Error(i)}return m.existsSync(s)||(a.debug(` creating target dir '${s}'`),m.mkdirSync(s,{recursive:!0})),a.info(`Unpacking Platforma Backend archive:
94
94
  Archive: ${n}
95
95
  Target dir: ${s}`),Fr.x({file:n,cwd:s,gzip:!0,sync:!0}),a.info(" ... unpack done."),s}function ve(a,e){return tt(a,e).then(t=>at(a,{archivePath:t}))}function vr(a){return`pl-${(a==null?void 0:a.version)??ge.getDefaultPlVersion()}-${pr()}`}function nt(a,...e){return f.binaries(vr({version:a}),...e)}function st(a){const e=a.lastIndexOf(".");return e===-1?a:a.slice(0,e)}class I{constructor(e){this.logger=e}startLast(){const e=f.currentInstance;if(!e)throw this.logger.error("failed to bring back Platforma Backend in the last started configuration: no last configuration found"),new Error("no previous run info found");return this.startInstance(e)}startInstance(e){if(e.runInfo){const r=this.renderRunInfo(e.runInfo);this.logger.info(`Starting platforma backend instance '${e.name}':
96
- ${r}`)}const t=Se(this.logger,e.upCommands);return Le(t.executed),t.spawned.length>0&&e.type==="process"&&(e.pid=t.spawned[t.spawned.length-1].pid,f.setInstanceInfo(e.name,e),this.logger.info(`instance '${e.name}' started`)),f.currentInstanceName=e.name,t.spawned}stopInstance(e){this.logger.info(`stopping platforma backend instance '${e.name}'...`);const t=Se(this.logger,e.downCommands);switch(Le(t.executed),e.type){case"docker":return;case"process":{e.pid&&f.isInstanceActive(e)&&process.kill(e.pid);return}default:U()}}switchInstance(e){for(const t of f.instanceList)if(t!==e.name){const r=f.getInstanceInfo(t);f.isInstanceActive(r)&&this.stopInstance(r)}return this.startInstance(e)}createLocal(e,t){var g,d,y,w,p,b,P,$,S,v;let r=nt(t==null?void 0:t.version,"binaries","platforma");t!=null&&t.sourcesPath&&(r=h.join(D.tmpdir(),"platforma-custom-build")),t!=null&&t.binaryPath&&(r=t.binaryPath);let n=t==null?void 0:t.configPath;const s=(t==null?void 0:t.workdir)??(n?process.cwd():f.instanceDir(e));t!=null&&t.primaryURL&&(t.configOptions={...t.configOptions,storages:{...(g=t.configOptions)==null?void 0:g.storages,primary:K(t.primaryURL,s,(y=(d=t.configOptions)==null?void 0:d.storages)==null?void 0:y.primary)}}),t!=null&&t.libraryURL&&(t.configOptions={...t.configOptions,storages:{...(w=t.configOptions)==null?void 0:w.storages,library:K(t.libraryURL,s,(b=(p=t.configOptions)==null?void 0:p.storages)==null?void 0:b.library)}});const i=Qr(this.getLastJwt(),t==null?void 0:t.configOptions);this.logger.debug(" checking license..."),this.checkLicense(($=(P=t==null?void 0:t.configOptions)==null?void 0:P.license)==null?void 0:$.value,(v=(S=t==null?void 0:t.configOptions)==null?void 0:S.license)==null?void 0:v.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)m.existsSync(k)||(this.logger.debug(` '${k}'`),m.mkdirSync(k,{recursive:!0}));for(const k of i.core.auth.drivers)k.driver==="htpasswd"&&(m.existsSync(k.path)||(this.logger.debug(` installing default 'users.htpasswd' to ${k.path}...`),m.copyFileSync(V("users.htpasswd"),k.path)));n||(n=h.join(i.localRoot,"config.yaml"),this.logger.debug(` rendering configuration '${n}'...`),m.writeFileSync(n,Xr(i)));const o=[];return t!=null&&t.sourcesPath&&o.push({cmd:"go",args:["build","-o",r,"."],workdir:h.resolve(t.sourcesPath,"cmd","platforma"),runOpts:{stdio:"inherit"}}),o.push({async:!0,cmd:r,args:["--config",n],workdir:s,runOpts:{stdio:"inherit"}}),f.setInstanceInfo(e,{type:"process",upCommands:o,downCommands:[],cleanupCommands:[],runInfo:{configPath:n,dbPath:i.core.db.path,apiAddr:i.grpc.listen,logPath:i.log.path,primary:i.storages.primary,work:i.storages.work,library:i.storages.library}}),f.getInstanceInfo(e)}createLocalS3(e,t){var c;this.logger.debug("creating platforma instance in 'local s3' mode...");const r=(t==null?void 0:t.minioPort)??9e3,n=this.createLocal(e,{...t,primaryURL:(t==null?void 0:t.primaryURL)??`s3e://testuser:testpassword@localhost:${r}/main-bucket/?region=no-region`,libraryURL:(t==null?void 0:t.libraryURL)??`s3e://testuser:testpassword@localhost:${r}/library-bucket/?region=no-region`}),s=(c=t==null?void 0:t.configOptions)==null?void 0:c.localRoot,i=this.createMinio(e,{minioPort:r,minioConsolePort:t==null?void 0:t.minioConsolePort,storage:s?h.join(s,"minio"):void 0});return n.upCommands=[i.start,...n.upCommands],n.downCommands=[i.stop,...n.downCommands],n.cleanupCommands=[i.cleanup,...n.cleanupCommands],f.setInstanceInfo(e,n),n}createMinio(e,t){this.logger.debug(" creating docker compose for minio service...");const r=V("compose-backend.yaml"),n=f.instanceDir(e,"compose-minio.yaml");$e(r,n,`pl-${e}-minio`,new Map([["minio",{}]]),{dropVolumes:!0});const s=t!=null&&t.version?`:${t.version}`:"";this.logger.debug(` minio version: ${s}`);const i=(t==null?void 0:t.image)??`quay.io/minio/minio${s}`;this.logger.debug(` minio image: ${i}`);const c=(t==null?void 0:t.storage)??f.instanceDir(e,"minio");Pe(c,{mode:"0775"});const o=(t==null?void 0:t.minioPort)??9e3,g=(t==null?void 0:t.minioConsolePort)??9001,d={MINIO_IMAGE:i,MINIO_STORAGE:h.resolve(c),MINIO_PORT:o.toString(),MINIO_CONSOLE_PORT:g.toString()};return{start:{cmd:"docker",args:["compose",`--file=${n}`,"up","--detach","--remove-orphans","--pull=missing"],envs:d,workdir:f.instanceDir(e),runOpts:{stdio:"inherit"}},stop:{cmd:"docker",args:["compose",`--file=${n}`,"down"],envs:d,workdir:f.instanceDir(e),runOpts:{stdio:"inherit"}},cleanup:{cmd:"docker",args:["compose",`--file=${n}`,"down","--volumes","--remove-orphans"],envs:d,workdir:f.instanceDir(e),runOpts:{stdio:"inherit"}}}}createDockerS3(e,t,r){this.logger.debug("creating platforma instance in 'docker s3' mode...");const n=V("compose-backend.yaml"),s=(r==null?void 0:r.image)??lr(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=(...v)=>h.join(t,...v),c=v=>{const k=i(v);return Pe(k,{mode:"0775"}),k},o=i("logs","platforma.log");m.existsSync(o)||(m.mkdirSync(h.dirname(o),{recursive:!0}),m.writeFileSync(o,""));const g=(r==null?void 0:r.presignHost)??"localhost",d=K("s3e://testuser:testpassword@minio:9000/main-bucket");if(d.type!=="S3")throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");d.presignEndpoint=`http://${g}:9000`;const y=K("s3e://testuser:testpassword@minio:9000/library-bucket");if(y.type!=="S3")throw new Error(`${y.type} storage type is not supported for library storage`);y.presignEndpoint=`http://${g}:9000`;const w=c("db"),p=c("work"),b=i("users.htpasswd");m.existsSync(b)||m.copyFileSync(V("users.htpasswd"),b);const P=i("compose.yaml");m.existsSync(P)&&this.logger.info(`replacing docker compose file ${P}`);const $=[];for(const v of(r==null?void 0:r.customMounts)??[])$.push({hostPath:v.hostPath,containerPath:v.containerPath??v.hostPath});$e(n,P,`pl-${e}`,new Map([["minio",{}],["backend",{platform:r==null?void 0:r.platformOverride,mounts:$}]]));const S={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:b,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:(r==null?void 0:r.logLevel)??"info",PL_LOG_DIR:h.dirname(o),PL_LOG_ROTATION_ENABLED:"true",PL_RUNNER_WD_CACHE_ON_FAILURE:"1h",PL_DATA_DB_ROOT:w,PL_DATA_PRIMARY_ROOT:c("primary"),PL_DATA_LIBRARY_ROOT:c("library"),PL_DATA_WORKDIR_ROOT:p,...this.configureDockerStorage("primary",d),...this.configureDockerStorage("library",y)};if(r!=null&&r.grpcAddr&&(S.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(S.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(S.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(S.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(S.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(S.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(S.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const v of r.auth.drivers)v.driver==="htpasswd"&&(S.PL_AUTH_HTPASSWD_PATH=h.resolve(v.path),v.path="/etc/platforma/users.htpasswd");S.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}return f.setInstanceInfo(e,{type:"docker",upCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"up","--detach","--remove-orphans","--pull=missing"],envs:S,runOpts:{stdio:"inherit"}}],downCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"down"],envs:S,runOpts:{stdio:"inherit"}}],cleanupCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"down","--volumes","--remove-orphans"],envs:S,runOpts:{stdio:"inherit"}}],runInfo:{apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:o,primary:d,work:{type:"FS",rootPath:p},library:y,dbPath:w}}),f.getInstanceInfo(e)}createDocker(e,t,r){this.logger.debug("creating platforma instance in 'docker' mode...");const n=V("compose-backend.yaml"),s=(r==null?void 0:r.image)??lr(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=(...k)=>h.join(t,...k),c=k=>{const ce=i(k);return Pe(ce,{mode:"0775"}),ce},o=i("logs","platforma.log");m.existsSync(o)||(m.mkdirSync(h.dirname(o),{recursive:!0}),m.writeFileSync(o,""));const g=c("db"),d=c("primary"),y=c("library"),w=c("work"),p=i("users.htpasswd");m.existsSync(p)||m.copyFileSync(V("users.htpasswd"),p);const b=i("compose.yaml");m.existsSync(b)&&this.logger.info(`replacing docker compose file ${b}`);const P=[];for(const k of(r==null?void 0:r.customMounts)??[])P.push({hostPath:k.hostPath,containerPath:k.containerPath??k.hostPath});this.logger.debug(`Rendering docker compose file '${b}' using '${n}' as base template`),$e(n,b,`pl-${e}`,new Map([["backend",{platform:r==null?void 0:r.platformOverride,mounts:P}]]));const $=K((r==null?void 0:r.primaryStorageURL)??`file:${d}`,"."),S=K((r==null?void 0:r.libraryStorageURL)??`file:${y}`,"."),v={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:h.dirname(o),PL_LOG_ROTATION_ENABLED:"true",PL_RUNNER_WD_CACHE_ON_FAILURE:"1h",PL_DATA_DB_ROOT:g,PL_DATA_PRIMARY_ROOT:d,PL_DATA_LIBRARY_ROOT:y,PL_DATA_WORKDIR_ROOT:w,PL_DATA_PACKAGE_ROOT:c("packages"),...this.configureDockerStorage("primary",$),...this.configureDockerStorage("library",S)};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=h.resolve(k.path),k.path="/etc/platforma/users.htpasswd");v.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}return f.setInstanceInfo(e,{type:"docker",upCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"up","--detach","--remove-orphans","--pull=missing"],envs:v,runOpts:{stdio:"inherit"}}],downCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"down"],envs:v,runOpts:{stdio:"inherit"}}],cleanupCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"down","--volumes","--remove-orphans"],envs:v,runOpts:{stdio:"inherit"}}],runInfo:{apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:o,primary:$,work:{type:"FS",rootPath:w},library:S,dbPath:g}}),f.getInstanceInfo(e)}cleanupInstance(e){const t=[],r=new Map;let n="";if(e){const s=f.getInstanceInfo(e);switch(r.set(e,s),s.type){case"docker":{t.push(`docker service 'pl-${e}', including all its volumes and data in '${f.instanceDir(e)}' will be destroyed`);break}case"process":{t.push(`directory '${f.instanceDir(e)}' would be deleted`),s.downCommands&&t.push("associated docker service, including all volumes and data will be destroyed");break}default:U()}e===f.currentInstanceName&&t.push("last command run cache ('pl-dev start' shorthand will stop working until next full start command call)"),n=`
96
+ ${r}`)}const t=Se(this.logger,e.upCommands);return Le(t.executed),t.spawned.length>0&&e.type==="process"&&(e.pid=t.spawned[t.spawned.length-1].pid,f.setInstanceInfo(e.name,e),this.logger.info(`instance '${e.name}' started`)),f.currentInstanceName=e.name,t.spawned}stopInstance(e){this.logger.info(`stopping platforma backend instance '${e.name}'...`);const t=Se(this.logger,e.downCommands);switch(Le(t.executed),e.type){case"docker":return;case"process":{e.pid&&f.isInstanceActive(e)&&process.kill(e.pid);return}default:U()}}switchInstance(e){for(const t of f.instanceList)if(t!==e.name){const r=f.getInstanceInfo(t);f.isInstanceActive(r)&&this.stopInstance(r)}return this.startInstance(e)}createLocal(e,t){var g,d,y,w,p,b,P,$,S,v;let r=nt(t==null?void 0:t.version,"binaries","platforma");t!=null&&t.sourcesPath&&(r=h.join(D.tmpdir(),"platforma-custom-build")),t!=null&&t.binaryPath&&(r=t.binaryPath);let n=t==null?void 0:t.configPath;const s=(t==null?void 0:t.workdir)??(n?process.cwd():f.instanceDir(e));t!=null&&t.primaryURL&&(t.configOptions={...t.configOptions,storages:{...(g=t.configOptions)==null?void 0:g.storages,primary:K(t.primaryURL,s,(y=(d=t.configOptions)==null?void 0:d.storages)==null?void 0:y.primary)}}),t!=null&&t.libraryURL&&(t.configOptions={...t.configOptions,storages:{...(w=t.configOptions)==null?void 0:w.storages,library:K(t.libraryURL,s,(b=(p=t.configOptions)==null?void 0:p.storages)==null?void 0:b.library)}});const i=Qr(this.getLastJwt(),t==null?void 0:t.configOptions);this.logger.debug(" checking license..."),this.checkLicense(($=(P=t==null?void 0:t.configOptions)==null?void 0:P.license)==null?void 0:$.value,(v=(S=t==null?void 0:t.configOptions)==null?void 0:S.license)==null?void 0:v.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)m.existsSync(k)||(this.logger.debug(` '${k}'`),m.mkdirSync(k,{recursive:!0}));for(const k of i.core.auth.drivers)k.driver==="htpasswd"&&(m.existsSync(k.path)||(this.logger.debug(` installing default 'users.htpasswd' to ${k.path}...`),m.copyFileSync(V("users.htpasswd"),k.path)));n||(n=h.join(i.localRoot,"config.yaml"),this.logger.debug(` rendering configuration '${n}'...`),m.writeFileSync(n,Xr(i)));const o=[];return t!=null&&t.sourcesPath&&o.push({cmd:"go",args:["build","-o",r,"."],workdir:h.resolve(t.sourcesPath,"cmd","platforma"),runOpts:{stdio:"inherit"}}),o.push({async:!0,cmd:r,args:["--quiet","--config",n],workdir:s,runOpts:{stdio:"inherit"}}),f.setInstanceInfo(e,{type:"process",upCommands:o,downCommands:[],cleanupCommands:[],runInfo:{configPath:n,dbPath:i.core.db.path,apiAddr:i.grpc.listen,logPath:i.log.path,primary:i.storages.primary,work:i.storages.work,library:i.storages.library}}),f.getInstanceInfo(e)}createLocalS3(e,t){var c;this.logger.debug("creating platforma instance in 'local s3' mode...");const r=(t==null?void 0:t.minioPort)??9e3,n=this.createLocal(e,{...t,primaryURL:(t==null?void 0:t.primaryURL)??`s3e://testuser:testpassword@localhost:${r}/main-bucket/?region=no-region`,libraryURL:(t==null?void 0:t.libraryURL)??`s3e://testuser:testpassword@localhost:${r}/library-bucket/?region=no-region`}),s=(c=t==null?void 0:t.configOptions)==null?void 0:c.localRoot,i=this.createMinio(e,{minioPort:r,minioConsolePort:t==null?void 0:t.minioConsolePort,storage:s?h.join(s,"minio"):void 0});return n.upCommands=[i.start,...n.upCommands],n.downCommands=[i.stop,...n.downCommands],n.cleanupCommands=[i.cleanup,...n.cleanupCommands],f.setInstanceInfo(e,n),n}createMinio(e,t){this.logger.debug(" creating docker compose for minio service...");const r=V("compose-backend.yaml"),n=f.instanceDir(e,"compose-minio.yaml");$e(r,n,`pl-${e}-minio`,new Map([["minio",{}]]),{dropVolumes:!0});const s=t!=null&&t.version?`:${t.version}`:"";this.logger.debug(` minio version: ${s}`);const i=(t==null?void 0:t.image)??`quay.io/minio/minio${s}`;this.logger.debug(` minio image: ${i}`);const c=(t==null?void 0:t.storage)??f.instanceDir(e,"minio");Pe(c,{mode:"0775"});const o=(t==null?void 0:t.minioPort)??9e3,g=(t==null?void 0:t.minioConsolePort)??9001,d={MINIO_IMAGE:i,MINIO_STORAGE:h.resolve(c),MINIO_PORT:o.toString(),MINIO_CONSOLE_PORT:g.toString()};return{start:{cmd:"docker",args:["compose",`--file=${n}`,"up","--detach","--remove-orphans","--pull=missing"],envs:d,workdir:f.instanceDir(e),runOpts:{stdio:"inherit"}},stop:{cmd:"docker",args:["compose",`--file=${n}`,"down"],envs:d,workdir:f.instanceDir(e),runOpts:{stdio:"inherit"}},cleanup:{cmd:"docker",args:["compose",`--file=${n}`,"down","--volumes","--remove-orphans"],envs:d,workdir:f.instanceDir(e),runOpts:{stdio:"inherit"}}}}createDockerS3(e,t,r){this.logger.debug("creating platforma instance in 'docker s3' mode...");const n=V("compose-backend.yaml"),s=(r==null?void 0:r.image)??lr(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=(...v)=>h.join(t,...v),c=v=>{const k=i(v);return Pe(k,{mode:"0775"}),k},o=i("logs","platforma.log");m.existsSync(o)||(m.mkdirSync(h.dirname(o),{recursive:!0}),m.writeFileSync(o,""));const g=(r==null?void 0:r.presignHost)??"localhost",d=K("s3e://testuser:testpassword@minio:9000/main-bucket");if(d.type!=="S3")throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");d.presignEndpoint=`http://${g}:9000`;const y=K("s3e://testuser:testpassword@minio:9000/library-bucket");if(y.type!=="S3")throw new Error(`${y.type} storage type is not supported for library storage`);y.presignEndpoint=`http://${g}:9000`;const w=c("db"),p=c("work"),b=i("users.htpasswd");m.existsSync(b)||m.copyFileSync(V("users.htpasswd"),b);const P=i("compose.yaml");m.existsSync(P)&&this.logger.info(`replacing docker compose file ${P}`);const $=[];for(const v of(r==null?void 0:r.customMounts)??[])$.push({hostPath:v.hostPath,containerPath:v.containerPath??v.hostPath});$e(n,P,`pl-${e}`,new Map([["minio",{}],["backend",{platform:r==null?void 0:r.platformOverride,mounts:$}]]));const S={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:b,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:(r==null?void 0:r.logLevel)??"info",PL_LOG_DIR:h.dirname(o),PL_LOG_ROTATION_ENABLED:"true",PL_RUNNER_WD_CACHE_ON_FAILURE:"1h",PL_DATA_DB_ROOT:w,PL_DATA_PRIMARY_ROOT:c("primary"),PL_DATA_LIBRARY_ROOT:c("library"),PL_DATA_WORKDIR_ROOT:p,...this.configureDockerStorage("primary",d),...this.configureDockerStorage("library",y)};if(r!=null&&r.grpcAddr&&(S.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(S.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(S.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(S.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(S.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(S.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(S.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const v of r.auth.drivers)v.driver==="htpasswd"&&(S.PL_AUTH_HTPASSWD_PATH=h.resolve(v.path),v.path="/etc/platforma/users.htpasswd");S.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}return f.setInstanceInfo(e,{type:"docker",upCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"up","--detach","--remove-orphans","--pull=missing"],envs:S,runOpts:{stdio:"inherit"}}],downCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"down"],envs:S,runOpts:{stdio:"inherit"}}],cleanupCommands:[{cmd:"docker",args:["compose",`--file=${P}`,"down","--volumes","--remove-orphans"],envs:S,runOpts:{stdio:"inherit"}}],runInfo:{apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:o,primary:d,work:{type:"FS",rootPath:p},library:y,dbPath:w}}),f.getInstanceInfo(e)}createDocker(e,t,r){this.logger.debug("creating platforma instance in 'docker' mode...");const n=V("compose-backend.yaml"),s=(r==null?void 0:r.image)??lr(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=(...k)=>h.join(t,...k),c=k=>{const ce=i(k);return Pe(ce,{mode:"0775"}),ce},o=i("logs","platforma.log");m.existsSync(o)||(m.mkdirSync(h.dirname(o),{recursive:!0}),m.writeFileSync(o,""));const g=c("db"),d=c("primary"),y=c("library"),w=c("work"),p=i("users.htpasswd");m.existsSync(p)||m.copyFileSync(V("users.htpasswd"),p);const b=i("compose.yaml");m.existsSync(b)&&this.logger.info(`replacing docker compose file ${b}`);const P=[];for(const k of(r==null?void 0:r.customMounts)??[])P.push({hostPath:k.hostPath,containerPath:k.containerPath??k.hostPath});this.logger.debug(`Rendering docker compose file '${b}' using '${n}' as base template`),$e(n,b,`pl-${e}`,new Map([["backend",{platform:r==null?void 0:r.platformOverride,mounts:P}]]));const $=K((r==null?void 0:r.primaryStorageURL)??`file:${d}`,"."),S=K((r==null?void 0:r.libraryStorageURL)??`file:${y}`,"."),v={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:h.dirname(o),PL_LOG_ROTATION_ENABLED:"true",PL_RUNNER_WD_CACHE_ON_FAILURE:"1h",PL_DATA_DB_ROOT:g,PL_DATA_PRIMARY_ROOT:d,PL_DATA_LIBRARY_ROOT:y,PL_DATA_WORKDIR_ROOT:w,PL_DATA_PACKAGE_ROOT:c("packages"),...this.configureDockerStorage("primary",$),...this.configureDockerStorage("library",S)};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=h.resolve(k.path),k.path="/etc/platforma/users.htpasswd");v.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}return f.setInstanceInfo(e,{type:"docker",upCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"up","--detach","--remove-orphans","--pull=missing"],envs:v,runOpts:{stdio:"inherit"}}],downCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"down"],envs:v,runOpts:{stdio:"inherit"}}],cleanupCommands:[{cmd:"docker",args:["compose",`--file=${b}`,"down","--volumes","--remove-orphans"],envs:v,runOpts:{stdio:"inherit"}}],runInfo:{apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:o,primary:$,work:{type:"FS",rootPath:w},library:S,dbPath:g}}),f.getInstanceInfo(e)}cleanupInstance(e){const t=[],r=new Map;let n="";if(e){const s=f.getInstanceInfo(e);switch(r.set(e,s),s.type){case"docker":{t.push(`docker service 'pl-${e}', including all its volumes and data in '${f.instanceDir(e)}' will be destroyed`);break}case"process":{t.push(`directory '${f.instanceDir(e)}' would be deleted`),s.downCommands&&t.push("associated docker service, including all volumes and data will be destroyed");break}default:U()}e===f.currentInstanceName&&t.push("last command run cache ('pl-dev start' shorthand will stop working until next full start command call)"),n=`
97
97
  You are going to reset the state of platforma service '${e}':
98
98
  - ${t.join(`
99
99
  - `)}
@@ -114,5 +114,5 @@ The license file can also be set with the variables 'MI_LICENSE_FILE' or 'PL_LIC
114
114
  or stored in '$HOME/.pl.license'.
115
115
 
116
116
  You can obtain the license from "https://licensing.milaboratories.com".`),new Error("The license was not provided.")}configureDockerStorage(e,t){const r={},n=t.type;switch(e=e.toUpperCase(),n){case"S3":return r[`PL_DATA_${e}_TYPE`]="S3",r[`PL_DATA_${e}_S3_BUCKET`]=t.bucketName,t.endpoint&&(r[`PL_DATA_${e}_S3_ENDPOINT`]=t.endpoint),t.presignEndpoint&&(r[`PL_DATA_${e}_S3_PRESIGN_ENDPOINT`]=t.presignEndpoint),t.region&&(r[`PL_DATA_${e}_S3_REGION`]=t.region),t.key&&(r[`PL_DATA_${e}_S3_KEY`]=t.key),t.secret&&(r[`PL_DATA_${e}_S3_SECRET`]=t.secret),r;case"FS":return r[`PL_DATA_${e}_TYPE`]="FS",r;default:U()}return{}}renderRunInfo(e,t=10){var c,o;const r=[],n=g=>g.padStart(t," ");switch(e.configPath&&r.push(`${n("config")}: ${e.configPath}`),e.apiAddr?r.push(`${n("API")}: ${e.apiAddr}`):e.apiPort?r.push(`${n("API")}: 127.0.0.1:${e.apiPort.toString()}`):r.push(`${n("API")}: 127.0.0.1:6345`),e.logPath&&r.push(`${n("log")}: ${e.logPath}`),(c=e.primary)==null?void 0:c.type){case void 0:break;case"FS":r.push(`${n("primary")}: ${e.primary.rootPath}`);break;case"S3":r.push(`${n("primary")}: S3 at '${e.primary.endpoint??"AWS"}', bucket '${e.primary.bucketName}', prefix: '${e.primary.keyPrefix??""}'`);break;default:U()}switch((o=e.library)==null?void 0:o.type){case void 0:break;case"FS":r.push(`${n("library")}: ${e.library.rootPath}`);break;case"S3":r.push(`${n("library")}: S3 at '${e.library.endpoint??"AWS"}', bucket '${e.library.bucketName}', prefix: '${e.library.keyPrefix??""}'`);break;default:U()}return e.work&&r.push(`${n("workdirs")}: ${e.work.rootPath}`),e.dbPath&&r.push(`${n("db")}: ${e.dbPath}`),r.join(`
117
- `)}}function Le(a,e){for(const t of a){if(t.error)throw t.error;const r=e??"failed to run command";if(t.status!==0)throw new Error(`${r}, process exited with code '${t.status}'`)}}const ee=class ee extends u.Command{async run(){const{flags:e}=await this.parse(ee),t=A(e["log-level"]);new I(t).cleanupInstance()}};l(ee,"description","Clear service state (forget last run command, destroy docker services, volumes and so on)"),l(ee,"examples",["<%= config.bin %> <%= command.id %>"]),l(ee,"flags",{...L});let Fe=ee;const re=class re extends u.Command{async run(){const{flags:e}=await this.parse(re),t=A(e["log-level"]);new I(t).startLast()}};l(re,"description","Start last run service configuraiton"),l(re,"examples",["<%= config.bin %> <%= command.id %>"]),l(re,"flags",{...L});let Ee=re;const te=class te extends u.Command{async run(){const{flags:e}=await this.parse(te),t=A(e["log-level"]),r=new I(t);f.currentInstance?r.stopInstance(f.currentInstance):t.warn("up/start command was not called for any instance, nothing to stop")}};l(te,"description","Stop platforma service"),l(te,"examples",["<%= config.bin %> <%= command.id %>"]),l(te,"flags",{...L});let Re=te;var F;let it=(F=class extends u.Command{async run(){const{flags:e}=await this.parse(F),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="docker",s=e["auth-enabled"],i=s?{enabled:s,drivers:r.initAuthDriversList(e,".")}:void 0,c=e.storage?h.join(".",e.storage):f.instanceDir(n),o=[];for(const y of e.mount??[])o.push({hostPath:y});const g=e.arch?`linux/${e.arch}`:void 0,d=r.createDocker(n,c,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,platformOverride:g,customMounts:o,license:e.license,licenseFile:e["license-file"],auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]});r.switchInstance(d)}},l(F,"description","Run platforma backend service with 'FS' primary storage type"),l(F,"examples",["<%= config.bin %> <%= command.id %>"]),l(F,"flags",{...L,...M,...ue,...N,...fe,...B,...C,...me,...j,...se,...ne,...ie}),F);var E;let ct=(E=class extends u.Command{async run(){const{flags:e}=await this.parse(E),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="local",s=e["pl-workdir"]??".",i=e.storage?h.join(s,e.storage):f.instanceDir(n),c=e["pl-log-file"]?h.join(s,e["pl-log-file"]):void 0,o=r.initAuthDriversList(e,s),g=e["auth-enabled"]??o!==void 0;let d="127.0.0.1:6345";e["grpc-listen"]?d=e["grpc-listen"]:e["grpc-port"]&&(d=`127.0.0.1:${e["grpc-port"]}`);let y="127.0.0.1:9090";e["monitoring-listen"]?y=e["monitoring-listen"]:e["monitoring-port"]&&(y=`127.0.0.1:${e["monitoring-port"]}`);let w="127.0.0.1:9091";e["debug-listen"]?w=e["debug-listen"]:e["debug-port"]&&(w=`127.0.0.1:${e["debug-port"]}`);const p={sourcesPath:e["pl-sources"],binaryPath:e["pl-binary"],version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:d},monitoring:{listen:y},debug:{listen:w},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:g,drivers:o}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}},b=r.createLocal(n,p);p.binaryPath||p.sourcesPath?r.switchInstance(b):ve(t,{version:e.version}).then(()=>{const P=r.switchInstance(b);setTimeout(()=>{for(const $ of P)$.unref()},1e3)}).catch(function(P){t.error(P.message)})}},l(E,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(E,"examples",["<%= config.bin %> <%= command.id %>"]),l(E,"flags",{...L,...N,...M,...be,...we,...pe,...C,...j,...se,...ne,...ie,...he,...ye,...B}),E);const q=class q extends u.Command{async run(){const{flags:e,args:t}=await this.parse(q),r=A(e["log-level"]),n=new I(r),s=t.name;e.all&&(n.cleanupInstance(),process.exit(0)),s||(r.error("Please, specify name of instance to be removed or set '--all' flag instead"),process.exit(1)),n.cleanupInstance(s)}};l(q,"description","List available instances"),l(q,"examples",["<%= config.bin %> <%= command.id %>"]),l(q,"flags",{...L,all:u.Flags.boolean({description:"remove all known instances",required:!1})}),l(q,"args",{name:u.Args.string({required:!1})});let Te=q;const J=class J extends u.Command{async run(){const{flags:e,args:t}=await this.parse(J),r=A(e["log-level"]),n=new I(r),s=t.name??f.currentInstanceName;s||(r.info("no pl service instance selected. No service was stopped"),process.exit(0)),n.stopInstance(f.getInstanceInfo(s))}};l(J,"description","List available instances"),l(J,"examples",["<%= config.bin %> <%= command.id %>"]),l(J,"flags",{...L}),l(J,"args",{name:u.Args.string({required:!1})});let De=J;const ae=class ae extends u.Command{async run(){await this.parse(ae);const e=f.instanceList,t=f.currentInstanceName;for(const r of e){const n=[],s=f.getInstanceInfo(r);f.isInstanceActive(s)&&n.push("status:up"),n.push(`type:${s.type}`),console.log(r===t?` * ${r} (${n.join(", ")})`:` ${r} (${n.join(", ")})`)}}};l(ae,"description","List available instances"),l(ae,"examples",["<%= config.bin %> <%= command.id %>"]),l(ae,"flags",{});let xe=ae;const H=class H extends u.Command{async run(){const{flags:e,args:t}=await this.parse(H),r=A(e["log-level"]),n=new I(r),s=t.name??f.currentInstanceName;s||(r.error("no pl service instance is selected. Select instance with 'select' command or provide name to 'up'"),process.exit(1));const i=n.switchInstance(f.getInstanceInfo(s)),c=[];for(const o of i)c.push(new Promise((g,d)=>{o.on("close",g),o.on("error",d)}));await Promise.all(c)}};l(H,"description","List available instances"),l(H,"examples",["<%= config.bin %> <%= command.id %>"]),l(H,"flags",{...L}),l(H,"args",{name:u.Args.string({required:!1})});let _e=H;var R;let ot=(R=class extends u.Command{async run(){const{flags:e}=await this.parse(R),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="docker-s3",s=e["auth-enabled"],i=s?{enabled:s,drivers:r.initAuthDriversList(e,".")}:void 0,c=e.storage?h.join(".",e.storage):f.instanceDir(n),o=[];for(const w of e.mount??[])o.push({hostPath:w});const g=e.arch?`linux/${e.arch}`:void 0,d=e["minio-presign-host"]?"minio":"localhost",y=r.createDockerS3(n,c,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],platformOverride:g,customMounts:o,auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"],presignHost:d});r.switchInstance(y)}},l(R,"description","Run platforma backend service with 'S3' primary storage type"),l(R,"examples",["<%= config.bin %> <%= command.id %>"]),l(R,"flags",{...L,...M,...ue,...N,...fe,...B,...C,...me,...j,...mr}),R);var T;let lt=(T=class extends u.Command{async run(){const{flags:e}=await this.parse(T),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="local-s3",s=e["pl-workdir"]??".",i=e.storage?h.join(s,e.storage):f.instanceDir(n),c=e["pl-log-file"]?h.join(s,e["pl-log-file"]):void 0,o=r.initAuthDriversList(e,s),g=e["auth-enabled"]??o!==void 0;let d="127.0.0.1:6345";e["grpc-listen"]?d=e["grpc-listen"]:e["grpc-port"]&&(d=`127.0.0.1:${e["grpc-port"]}`);let y="127.0.0.1:9090";e["monitoring-listen"]?y=e["monitoring-listen"]:e["monitoring-port"]&&(y=`127.0.0.1:${e["monitoring-port"]}`);let w="127.0.0.1:9091";e["debug-listen"]?w=e["debug-listen"]:e["debug-port"]&&(w=`127.0.0.1:${e["debug-port"]}`);const p={sourcesPath:e["pl-sources"],binaryPath:e["pl-binary"],version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],minioPort:e["s3-port"],minioConsolePort:e["s3-console-port"],configOptions:{grpc:{listen:d},monitoring:{listen:y},debug:{listen:w},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:g,drivers:o}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}},b=r.createLocalS3(n,p);p.binaryPath||p.sourcesPath?r.switchInstance(b):ve(t,{version:e.version}).then(()=>{const P=r.switchInstance(b);setTimeout(()=>{for(const $ of P)$.unref()},1e3)}).catch(function(P){t.error(P.message)})}},l(T,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(T,"examples",["<%= config.bin %> <%= command.id %>"]),l(T,"flags",{...L,...N,...M,...fr,...be,...we,...pe,...C,...j,...se,...ne,...ie,...he,...ye,...B}),T);const W=class W extends u.Command{async run(){const{flags:e,args:t}=await this.parse(W),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["auth-enabled"],c=i?{enabled:i,drivers:n.initAuthDriversList(e,".")}:void 0,o=e.storage?h.join(".",e.storage):f.instanceDir(s),g=[];for(const y of e.mount??[])g.push({hostPath:y});const d=e.arch?`linux/${e.arch}`:void 0;n.createDocker(s,o,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,platformOverride:d,customMounts:g,license:e.license,licenseFile:e["license-file"],auth:c,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]}),r.info(`Instance '${s}' was created. To start it run 'up' command`)}};l(W,"description","Run Platforma Backend service as docker container on current host"),l(W,"examples",["<%= config.bin %> <%= command.id %>"]),l(W,"flags",{...L,...M,...ue,...N,...fe,...B,...C,...me,...j,...se,...ne,...ie}),l(W,"args",{name:u.Args.string({required:!0})});let Ne=W;var O;let dt=(O=class extends u.Command{async run(){const{flags:e,args:t}=await this.parse(O),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["pl-workdir"]??".",c=e.storage?h.join(i,e.storage):f.instanceDir(s),o=e["pl-log-file"]?h.join(i,e["pl-log-file"]):void 0,g=n.initAuthDriversList(e,i),d=e["auth-enabled"]??g!==void 0;let y="127.0.0.1:6345";e["grpc-listen"]?y=e["grpc-listen"]:e["grpc-port"]&&(y=`127.0.0.1:${e["grpc-port"]}`);let w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);let 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 b={sourcesPath:e["pl-sources"],binaryPath:e["pl-binary"],version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:y},monitoring:{listen:w},debug:{listen:p},license:{value:e.license,file:e["license-file"]},log:{path:o},localRoot:c,core:{auth:{enabled:d,drivers:g}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};if(n.createLocal(s,b),b.binaryPath||b.sourcesPath){r.info(`Instance '${s}' was created. To start it run 'up' command`);return}ve(r,{version:e.version}).then(()=>r.info(`Instance '${s}' was created. To start it run 'svc up' command`)).catch(function(P){r.error(P.message)})}},l(O,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(O,"examples",["<%= config.bin %> <%= command.id %>"]),l(O,"flags",{...L,...N,...M,...be,...we,...pe,...C,...j,...se,...ne,...ie,...he,...ye,...B}),l(O,"args",{name:u.Args.string({required:!0})}),O);const z=class z extends u.Command{async run(){const{flags:e,args:t}=await this.parse(z),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["auth-enabled"],c=i?{enabled:i,drivers:n.initAuthDriversList(e,".")}:void 0,o=e.storage?h.join(".",e.storage):f.instanceDir(s),g=[];for(const w of e.mount??[])g.push({hostPath:w});const d=e.arch?`linux/${e.arch}`:void 0,y=e["minio-presign-host"]?"minio":"localhost";n.createDockerS3(s,o,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],platformOverride:d,customMounts:g,auth:c,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"],presignHost:y}),r.info(`Instance '${s}' was created. To start it run 'up' command`),e["minio-presign-host"]&&r.info(" NOTE: make sure you have 'minio' host in your hosts file as 127.0.0.1 address")}};l(z,"description","Run Platforma Backend service as docker container on current host with MinIO as local S3 storage"),l(z,"examples",["<%= config.bin %> <%= command.id %>"]),l(z,"flags",{...L,...M,...ue,...N,...fe,...B,...C,...me,...j,...mr}),l(z,"args",{name:u.Args.string({required:!0})});let Ce=z;const Y=class Y extends u.Command{async run(){const{flags:e,args:t}=await this.parse(Y),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["pl-workdir"]??".",c=e.storage?h.join(i,e.storage):f.instanceDir(s),o=e["pl-log-file"]?h.join(i,e["pl-log-file"]):void 0,g=n.initAuthDriversList(e,i),d=e["auth-enabled"]??g!==void 0;let y="127.0.0.1:6345";e["grpc-listen"]?y=e["grpc-listen"]:e["grpc-port"]&&(y=`127.0.0.1:${e["grpc-port"]}`);let w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);let 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 b={sourcesPath:e["pl-sources"],binaryPath:e["pl-binary"],version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],minioPort:e["s3-port"],minioConsolePort:e["s3-console-port"],configOptions:{grpc:{listen:y},monitoring:{listen:w},debug:{listen:p},license:{value:e.license,file:e["license-file"]},log:{path:o},localRoot:c,core:{auth:{enabled:d,drivers:g}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};if(r.info("Creating instance configuration, data directory and other stuff..."),n.createLocalS3(s,b),b.binaryPath||b.sourcesPath){r.info(`Instance '${s}' was created. To start it run 'up' command`);return}ve(r,{version:e.version}).then(()=>r.info(`Instance '${s}' was created. To start it run 'svc up' command`)).catch(function(P){r.error(P.message)})}};l(Y,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(Y,"examples",["<%= config.bin %> <%= command.id %>"]),l(Y,"flags",{...L,...N,...fr,...M,...be,...we,...pe,...C,...j,...se,...ne,...ie,...he,...ye,...B}),l(Y,"args",{name:u.Args.string({required:!0})});let Me=Y;const gt={"create-block":Ie,reset:Fe,start:Ee,stop:Re,"start:docker":it,"start:local":ct,"svc:delete":Te,"svc:down":De,"svc:list":xe,"svc:up":_e,"start:docker:s3":ot,"start:local:s3":lt,"svc:create:docker":Ne,"svc:create:local":dt,"svc:create:docker:s3":Ce,"svc:create:local:s3":Me};exports.COMMANDS=gt;
117
+ `)}}function Le(a,e){for(const t of a){if(t.error)throw t.error;const r=e??"failed to run command";if(t.status!==0)throw new Error(`${r}, process exited with code '${t.status}'`)}}const ee=class ee extends u.Command{async run(){const{flags:e}=await this.parse(ee),t=A(e["log-level"]);new I(t).cleanupInstance()}};l(ee,"description","Clear service state (forget last run command, destroy docker services, volumes and so on)"),l(ee,"examples",["<%= config.bin %> <%= command.id %>"]),l(ee,"flags",{...L});let Fe=ee;const re=class re extends u.Command{async run(){const{flags:e}=await this.parse(re),t=A(e["log-level"]);new I(t).startLast()}};l(re,"description","Start last run service configuraiton"),l(re,"examples",["<%= config.bin %> <%= command.id %>"]),l(re,"flags",{...L});let Ee=re;const te=class te extends u.Command{async run(){const{flags:e}=await this.parse(te),t=A(e["log-level"]),r=new I(t);f.currentInstance?r.stopInstance(f.currentInstance):t.warn("up/start command was not called for any instance, nothing to stop")}};l(te,"description","Stop platforma service"),l(te,"examples",["<%= config.bin %> <%= command.id %>"]),l(te,"flags",{...L});let Re=te;var F;let it=(F=class extends u.Command{async run(){const{flags:e}=await this.parse(F),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="docker",s=e["auth-enabled"],i=s?{enabled:s,drivers:r.initAuthDriversList(e,".")}:void 0,c=e.storage?h.join(".",e.storage):f.instanceDir(n),o=[];for(const y of e.mount??[])o.push({hostPath:y});const g=e.arch?`linux/${e.arch}`:void 0,d=r.createDocker(n,c,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,platformOverride:g,customMounts:o,license:e.license,licenseFile:e["license-file"],auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]});r.switchInstance(d)}},l(F,"description","Run platforma backend service with 'FS' primary storage type"),l(F,"examples",["<%= config.bin %> <%= command.id %>"]),l(F,"flags",{...L,...M,...ue,...N,...fe,...B,...C,...me,...j,...se,...ne,...ie}),F);var E;let ct=(E=class extends u.Command{async run(){const{flags:e}=await this.parse(E),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="local",s=e["pl-workdir"]??".",i=e.storage?h.join(s,e.storage):f.instanceDir(n),c=e["pl-log-file"]?h.join(s,e["pl-log-file"]):void 0,o=r.initAuthDriversList(e,s),g=e["auth-enabled"]??o!==void 0;let d="127.0.0.1:6345";e["grpc-listen"]?d=e["grpc-listen"]:e["grpc-port"]&&(d=`127.0.0.1:${e["grpc-port"]}`);let y="127.0.0.1:9090";e["monitoring-listen"]?y=e["monitoring-listen"]:e["monitoring-port"]&&(y=`127.0.0.1:${e["monitoring-port"]}`);let w="127.0.0.1:9091";e["debug-listen"]?w=e["debug-listen"]:e["debug-port"]&&(w=`127.0.0.1:${e["debug-port"]}`);const p={sourcesPath:e["pl-sources"],binaryPath:e["pl-binary"],version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:d},monitoring:{listen:y},debug:{listen:w},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:g,drivers:o}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}},b=r.createLocal(n,p);p.binaryPath||p.sourcesPath?r.switchInstance(b):ve(t,{version:e.version}).then(()=>{const P=r.switchInstance(b);setTimeout(()=>{for(const $ of P)$.unref()},1e3)}).catch(function(P){t.error(P.message)})}},l(E,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(E,"examples",["<%= config.bin %> <%= command.id %>"]),l(E,"flags",{...L,...N,...M,...be,...we,...pe,...C,...j,...se,...ne,...ie,...he,...ye,...B}),E);const q=class q extends u.Command{async run(){const{flags:e,args:t}=await this.parse(q),r=A(e["log-level"]),n=new I(r),s=t.name;e.all&&(n.cleanupInstance(),process.exit(0)),s||(r.error("Please, specify name of instance to be removed or set '--all' flag instead"),process.exit(1)),n.cleanupInstance(s)}};l(q,"description","List available instances"),l(q,"examples",["<%= config.bin %> <%= command.id %>"]),l(q,"flags",{...L,all:u.Flags.boolean({description:"remove all known instances",required:!1})}),l(q,"args",{name:u.Args.string({required:!1})});let Te=q;const J=class J extends u.Command{async run(){const{flags:e,args:t}=await this.parse(J),r=A(e["log-level"]),n=new I(r),s=t.name??f.currentInstanceName;s||(r.info("no pl service instance selected. No service was stopped"),process.exit(0)),n.stopInstance(f.getInstanceInfo(s))}};l(J,"description","List available instances"),l(J,"examples",["<%= config.bin %> <%= command.id %>"]),l(J,"flags",{...L}),l(J,"args",{name:u.Args.string({required:!1})});let De=J;const ae=class ae extends u.Command{async run(){await this.parse(ae);const e=f.instanceList,t=f.currentInstanceName;for(const r of e){const n=[],s=f.getInstanceInfo(r);f.isInstanceActive(s)&&n.push("status:up"),n.push(`type:${s.type}`),console.log(r===t?` * ${r} (${n.join(", ")})`:` ${r} (${n.join(", ")})`)}}};l(ae,"description","List available instances"),l(ae,"examples",["<%= config.bin %> <%= command.id %>"]),l(ae,"flags",{});let xe=ae;const H=class H extends u.Command{async run(){const{flags:e,args:t}=await this.parse(H),r=A(e["log-level"]),n=new I(r),s=t.name??f.currentInstanceName;s||(r.error("no pl service instance is selected. Select instance with 'select' command or provide name to 'up'"),process.exit(1));const i=n.switchInstance(f.getInstanceInfo(s)),c=[];for(const o of i)c.push(new Promise((g,d)=>{o.on("close",g),o.on("error",d)}));await Promise.all(c)}};l(H,"description","List available instances"),l(H,"examples",["<%= config.bin %> <%= command.id %>"]),l(H,"flags",{...L}),l(H,"args",{name:u.Args.string({required:!1})});let _e=H;var R;let ot=(R=class extends u.Command{async run(){const{flags:e}=await this.parse(R),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="docker-s3",s=e["auth-enabled"],i=s?{enabled:s,drivers:r.initAuthDriversList(e,".")}:void 0,c=e.storage?h.join(".",e.storage):f.instanceDir(n),o=[];for(const w of e.mount??[])o.push({hostPath:w});const g=e.arch?`linux/${e.arch}`:void 0,d=e["minio-presign-host"]?"minio":"localhost",y=r.createDockerS3(n,c,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],platformOverride:g,customMounts:o,auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"],presignHost:d});r.switchInstance(y)}},l(R,"description","Run platforma backend service with 'S3' primary storage type"),l(R,"examples",["<%= config.bin %> <%= command.id %>"]),l(R,"flags",{...L,...M,...ue,...N,...fe,...B,...C,...me,...j,...mr}),R);var T;let lt=(T=class extends u.Command{async run(){const{flags:e}=await this.parse(T),t=A(e["log-level"]),r=new I(t);r.mergeLicenseEnvs(e);const n="local-s3",s=e["pl-workdir"]??".",i=e.storage?h.join(s,e.storage):f.instanceDir(n),c=e["pl-log-file"]?h.join(s,e["pl-log-file"]):void 0,o=r.initAuthDriversList(e,s),g=e["auth-enabled"]??o!==void 0;let d="127.0.0.1:6345";e["grpc-listen"]?d=e["grpc-listen"]:e["grpc-port"]&&(d=`127.0.0.1:${e["grpc-port"]}`);let y="127.0.0.1:9090";e["monitoring-listen"]?y=e["monitoring-listen"]:e["monitoring-port"]&&(y=`127.0.0.1:${e["monitoring-port"]}`);let w="127.0.0.1:9091";e["debug-listen"]?w=e["debug-listen"]:e["debug-port"]&&(w=`127.0.0.1:${e["debug-port"]}`);const p={sourcesPath:e["pl-sources"],binaryPath:e["pl-binary"],version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],minioPort:e["s3-port"],minioConsolePort:e["s3-console-port"],configOptions:{grpc:{listen:d},monitoring:{listen:y},debug:{listen:w},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:g,drivers:o}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}},b=r.createLocalS3(n,p);p.binaryPath||p.sourcesPath?r.switchInstance(b):await ve(t,{version:e.version}).then(()=>{const P=r.switchInstance(b),$=[];for(const S of P)$.push(new Promise((v,k)=>{S.on("close",v),S.on("error",k)}));return Promise.all($)}).catch(function(P){t.error(P.message)})}},l(T,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(T,"examples",["<%= config.bin %> <%= command.id %>"]),l(T,"flags",{...L,...N,...M,...fr,...be,...we,...pe,...C,...j,...se,...ne,...ie,...he,...ye,...B}),T);const W=class W extends u.Command{async run(){const{flags:e,args:t}=await this.parse(W),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["auth-enabled"],c=i?{enabled:i,drivers:n.initAuthDriversList(e,".")}:void 0,o=e.storage?h.join(".",e.storage):f.instanceDir(s),g=[];for(const y of e.mount??[])g.push({hostPath:y});const d=e.arch?`linux/${e.arch}`:void 0;n.createDocker(s,o,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,platformOverride:d,customMounts:g,license:e.license,licenseFile:e["license-file"],auth:c,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]}),r.info(`Instance '${s}' was created. To start it run 'up' command`)}};l(W,"description","Run Platforma Backend service as docker container on current host"),l(W,"examples",["<%= config.bin %> <%= command.id %>"]),l(W,"flags",{...L,...M,...ue,...N,...fe,...B,...C,...me,...j,...se,...ne,...ie}),l(W,"args",{name:u.Args.string({required:!0})});let Ne=W;var O;let dt=(O=class extends u.Command{async run(){const{flags:e,args:t}=await this.parse(O),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["pl-workdir"]??".",c=e.storage?h.join(i,e.storage):f.instanceDir(s),o=e["pl-log-file"]?h.join(i,e["pl-log-file"]):void 0,g=n.initAuthDriversList(e,i),d=e["auth-enabled"]??g!==void 0;let y="127.0.0.1:6345";e["grpc-listen"]?y=e["grpc-listen"]:e["grpc-port"]&&(y=`127.0.0.1:${e["grpc-port"]}`);let w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);let 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 b={sourcesPath:e["pl-sources"],binaryPath:e["pl-binary"],version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:y},monitoring:{listen:w},debug:{listen:p},license:{value:e.license,file:e["license-file"]},log:{path:o},localRoot:c,core:{auth:{enabled:d,drivers:g}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};if(n.createLocal(s,b),b.binaryPath||b.sourcesPath){r.info(`Instance '${s}' was created. To start it run 'up' command`);return}ve(r,{version:e.version}).then(()=>r.info(`Instance '${s}' was created. To start it run 'svc up' command`)).catch(function(P){r.error(P.message)})}},l(O,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(O,"examples",["<%= config.bin %> <%= command.id %>"]),l(O,"flags",{...L,...N,...M,...be,...we,...pe,...C,...j,...se,...ne,...ie,...he,...ye,...B}),l(O,"args",{name:u.Args.string({required:!0})}),O);const z=class z extends u.Command{async run(){const{flags:e,args:t}=await this.parse(z),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["auth-enabled"],c=i?{enabled:i,drivers:n.initAuthDriversList(e,".")}:void 0,o=e.storage?h.join(".",e.storage):f.instanceDir(s),g=[];for(const w of e.mount??[])g.push({hostPath:w});const d=e.arch?`linux/${e.arch}`:void 0,y=e["minio-presign-host"]?"minio":"localhost";n.createDockerS3(s,o,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],platformOverride:d,customMounts:g,auth:c,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"],presignHost:y}),r.info(`Instance '${s}' was created. To start it run 'up' command`),e["minio-presign-host"]&&r.info(" NOTE: make sure you have 'minio' host in your hosts file as 127.0.0.1 address")}};l(z,"description","Run Platforma Backend service as docker container on current host with MinIO as local S3 storage"),l(z,"examples",["<%= config.bin %> <%= command.id %>"]),l(z,"flags",{...L,...M,...ue,...N,...fe,...B,...C,...me,...j,...mr}),l(z,"args",{name:u.Args.string({required:!0})});let Ce=z;const Y=class Y extends u.Command{async run(){const{flags:e,args:t}=await this.parse(Y),r=A(e["log-level"]),n=new I(r);n.mergeLicenseEnvs(e);const s=t.name,i=e["pl-workdir"]??".",c=e.storage?h.join(i,e.storage):f.instanceDir(s),o=e["pl-log-file"]?h.join(i,e["pl-log-file"]):void 0,g=n.initAuthDriversList(e,i),d=e["auth-enabled"]??g!==void 0;let y="127.0.0.1:6345";e["grpc-listen"]?y=e["grpc-listen"]:e["grpc-port"]&&(y=`127.0.0.1:${e["grpc-port"]}`);let w="127.0.0.1:9090";e["monitoring-listen"]?w=e["monitoring-listen"]:e["monitoring-port"]&&(w=`127.0.0.1:${e["monitoring-port"]}`);let 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 b={sourcesPath:e["pl-sources"],binaryPath:e["pl-binary"],version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],minioPort:e["s3-port"],minioConsolePort:e["s3-console-port"],configOptions:{grpc:{listen:y},monitoring:{listen:w},debug:{listen:p},license:{value:e.license,file:e["license-file"]},log:{path:o},localRoot:c,core:{auth:{enabled:d,drivers:g}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};if(r.info("Creating instance configuration, data directory and other stuff..."),n.createLocalS3(s,b),b.binaryPath||b.sourcesPath){r.info(`Instance '${s}' was created. To start it run 'up' command`);return}ve(r,{version:e.version}).then(()=>r.info(`Instance '${s}' was created. To start it run 'svc up' command`)).catch(function(P){r.error(P.message)})}};l(Y,"description","Run Platforma Backend service as local process on current host (no docker container)"),l(Y,"examples",["<%= config.bin %> <%= command.id %>"]),l(Y,"flags",{...L,...N,...fr,...M,...be,...we,...pe,...C,...j,...se,...ne,...ie,...he,...ye,...B}),l(Y,"args",{name:u.Args.string({required:!0})});let Me=Y;const gt={"create-block":Ie,reset:Fe,start:Ee,stop:Re,"start:docker":it,"start:local":ct,"svc:delete":Te,"svc:down":De,"svc:list":xe,"svc:up":_e,"start:docker:s3":ot,"start:local:s3":lt,"svc:create:docker":Ne,"svc:create:local":dt,"svc:create:docker:s3":Ce,"svc:create:local:s3":Me};exports.COMMANDS=gt;
118
118
  //# sourceMappingURL=index.js.map