@runium/plugin-docker 0.0.6 → 0.0.7

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/index.js CHANGED
@@ -1 +1 @@
1
- import{DockerTask as o}from"./tasks/docker-task.js";import{DockerComposeTask as e}from"./tasks/docker-compose-task.js";import{getDockerTaskProjectSchema as r}from"./validation/docker-task-project-schema.js";import{getDockerComposeTaskProjectSchema as c}from"./validation/docker-compose-task-project-schema.js";function p(){return{name:"docker",project:{tasks:{docker:o,"docker-compose":e},validationSchema:{tasks:{Docker_DockerTask:r(),Docker_DockerComposeTask:c()}}}}}export{p as default};
1
+ import{setStartedProjectName as e}from"./state/project.js";import{DockerTask as t}from"./tasks/docker-task.js";import{DockerComposeTask as c}from"./tasks/docker-compose-task.js";import{getDockerTaskProjectSchema as m}from"./validation/docker-task-project-schema.js";import{getDockerComposeTaskProjectSchema as a}from"./validation/docker-compose-task-project-schema.js";function D(){return{name:"docker",hooks:{project:{async beforeStart({path:o,name:r}){e(r||runium.utils.pathToId(o))}}},project:{tasks:{docker:t,"docker-compose":c},validationSchema:{tasks:{Docker_DockerTask:m(),Docker_DockerComposeTask:a()}}}}}export{D as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runium/plugin-docker",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Runium plugin for Docker support",
5
5
  "author": "TheBeastApp",
6
6
  "license": "MIT",
@@ -0,0 +1 @@
1
+ let t="";function r(){return t}function o(e){t=e}export{r as getStartedProjectName,o as setStartedProjectName};
@@ -1 +1 @@
1
- import{spawn as a}from"node:child_process";import{stringify as p}from"yaml";import{DockerTaskBase as c}from"./docker-task-base.js";import{isDockerInstalled as m}from"../utils/is-docker-installed.js";import{isDockerRunning as d}from"../utils/is-docker-running.js";import{pullImage as g}from"../utils/pull-image.js";import{isImagePulled as u}from"../utils/is-image-pulled.js";const{TaskStatus:o}=runium.enum;class x extends c{constructor(r){super(r);this.options=r;this.projectName=`runium-docker-compose-${Date.now()}`,this.composeFile=`docker-compose-${this.projectName}.yml`}projectName;composeFile;version="3.8";correctExitCodes=[130];generateComposeYaml(){const r={version:this.version,services:{}};for(const[s,e]of Object.entries(this.options.services)){const t={image:e.image};e.containerName&&(t.container_name=e.containerName),e.command&&(t.command=e.command),e.ports&&e.ports.length>0&&(t.ports=e.ports),e.volumes&&e.volumes.length>0&&(t.volumes=e.volumes),e.environment&&Object.keys(e.environment).length>0&&(t.environment=e.environment),e.networks&&e.networks.length>0&&(t.networks=e.networks),e.dependsOn&&e.dependsOn.length>0&&(t.depends_on=e.dependsOn),e.restart&&(t.restart=e.restart),e.user&&(t.user=e.user),e.workdir&&(t.working_dir=e.workdir),e.hostname&&(t.hostname=e.hostname),e.entrypoint&&(t.entrypoint=e.entrypoint),e.privileged&&(t.privileged=e.privileged),e.expose&&e.expose.length>0&&(t.expose=e.expose),e.healthcheck&&(t.healthcheck=e.healthcheck),r.services[s]=t}return this.options.networks&&Object.keys(this.options.networks).length>0&&(r.networks=this.options.networks),this.options.volumes&&Object.keys(this.options.volumes).length>0&&(r.volumes=this.options.volumes),p(r)}async pullAllImages(){const r=Object.values(this.options.services).map(e=>e.image),s=[...new Set(r)];for(const e of s){const t=e;await u(t)||(this.updateState({reason:`pull image: ${t}`}),await g(t,{onStdErr:this.onStdErrData.bind(this)}))}}prepareDockerComposeArgs(r){const s=["compose"];return s.push("-p",this.projectName),s.push("-f",runium.storage.getPath(["docker",this.composeFile])),s.push(r),s}async start(){if(this.canStart()){if(this.updateState({status:o.STARTING,iteration:this.state.iteration+1,pid:-1,exitCode:void 0,error:void 0,reason:void 0}),!await m()){this.onError(new Error("Docker is not installed"));return}if(!await d()){this.onError(new Error("Docker is not running"));return}try{const r=this.generateComposeYaml();await runium.storage.ensureDirExists(["docker"]),await runium.storage.write(["docker",this.composeFile],r),await this.initLogStreams(),await this.pullAllImages();const s=this.prepareDockerComposeArgs("up");this.process=a("docker",s,{stdio:["ignore","pipe","pipe"]}),this.addProcessListeners(),this.setTTLTimer(),this.updateState({status:o.STARTED,pid:this.process.pid,reason:void 0})}catch(r){this.onError(r)}}}async stop(r=""){if(this.canStop()){this.updateState({status:o.STOPPING,reason:r});try{const s=this.prepareDockerComposeArgs("down");await new Promise((e,t)=>{const i=a("docker",s);i.on("exit",n=>{n===0?e():t(new Error(`Docker compose down exited with code ${n}`))}),i.on("error",t)})}catch(s){this.onError(s)}}}}export{x as DockerComposeTask};
1
+ import{spawn as a}from"node:child_process";import{stringify as p}from"yaml";import{DockerTaskBase as c}from"./docker-task-base.js";import{getStartedProjectName as m}from"../state/project.js";import{isDockerInstalled as g}from"../utils/is-docker-installed.js";import{isDockerRunning as d}from"../utils/is-docker-running.js";import{pullImage as u}from"../utils/pull-image.js";import{isImagePulled as k}from"../utils/is-image-pulled.js";const{TaskStatus:o}=runium.enum;class E extends c{constructor(r){super(r);this.options=r;this.projectName=`runium-${m()}`,this.composeFile=`docker-compose-${this.projectName}.yml`}projectName;composeFile;version="3.8";correctExitCodes=[130];generateComposeYaml(){const r={version:this.version,services:{}};for(const[s,e]of Object.entries(this.options.services)){const t={image:e.image};e.containerName&&(t.container_name=e.containerName),e.command&&(t.command=e.command),e.ports&&e.ports.length>0&&(t.ports=e.ports),e.volumes&&e.volumes.length>0&&(t.volumes=e.volumes),e.environment&&Object.keys(e.environment).length>0&&(t.environment=e.environment),e.networks&&e.networks.length>0&&(t.networks=e.networks),e.dependsOn&&e.dependsOn.length>0&&(t.depends_on=e.dependsOn),e.restart&&(t.restart=e.restart),e.user&&(t.user=e.user),e.workdir&&(t.working_dir=e.workdir),e.hostname&&(t.hostname=e.hostname),e.entrypoint&&(t.entrypoint=e.entrypoint),e.privileged&&(t.privileged=e.privileged),e.expose&&e.expose.length>0&&(t.expose=e.expose),e.healthcheck&&(t.healthcheck=e.healthcheck),r.services[s]=t}return this.options.networks&&Object.keys(this.options.networks).length>0&&(r.networks=this.options.networks),this.options.volumes&&Object.keys(this.options.volumes).length>0&&(r.volumes=this.options.volumes),p(r)}async pullAllImages(){const r=Object.values(this.options.services).map(e=>e.image),s=[...new Set(r)];for(const e of s){const t=e;await k(t)||(this.updateState({reason:`pull image: ${t}`}),await u(t,{onStdErr:this.onStdErrData.bind(this)}))}}prepareDockerComposeArgs(r){const s=["compose"];return s.push("-p",this.projectName),s.push("-f",runium.storage.getPath(["docker",this.composeFile])),s.push(r),s}async start(){if(this.canStart()){if(this.updateState({status:o.STARTING,iteration:this.state.iteration+1,pid:-1,exitCode:void 0,error:void 0,reason:void 0}),!await g()){this.onError(new Error("Docker is not installed"),1);return}if(!await d()){this.onError(new Error("Docker is not running"),1);return}try{const r=this.generateComposeYaml();await runium.storage.ensureDirExists(["docker"]),await runium.storage.write(["docker",this.composeFile],r),await this.initLogStreams(),await this.pullAllImages();const s=this.prepareDockerComposeArgs("up");this.process=a("docker",s,{stdio:["ignore","pipe","pipe"]}),this.addProcessListeners(),this.setTTLTimer(),this.updateState({status:o.STARTED,pid:this.process.pid,reason:void 0})}catch(r){this.onError(r)}}}async stop(r=""){if(this.canStop()){this.updateState({status:o.STOPPING,reason:r});try{const s=this.prepareDockerComposeArgs("down");await new Promise((e,t)=>{const i=a("docker",s);i.on("exit",n=>{n===0?e():t(new Error(`Docker compose down exited with code ${n}`))}),i.on("error",t)})}catch(s){this.onError(s)}}}}export{E as DockerComposeTask};
@@ -1 +1 @@
1
- import{createWriteStream as o}from"node:fs";import{mkdir as a}from"node:fs/promises";import{dirname as n,resolve as u}from"node:path";import{setTimeout as l}from"node:timers";const d=-1,m=50,{TaskStatus:s,TaskEvent:i}=runium.enum;class P extends runium.class.RuniumTask{constructor(t){super(t);this.options=t;this.setMaxListeners(m)}correctExitCodes=[];state={status:s.IDLE,timestamp:Date.now(),iteration:0,pid:-1};process=null;stdoutStream=null;stderrStream=null;ttlTimer=null;getState(){return{...this.state}}getOptions(){return{...this.options}}canStart(){const{status:t}=this.state;return t!==s.STARTED&&t!==s.STARTING&&t!==s.STOPPING}canStop(){const{status:t}=this.state;return t===s.STARTED||t===s.STARTING}async restart(){await this.stop("restart"),await this.start()}async initLogStreams(){const{stdout:t=null,stderr:e=null}=this.options.log||{};if(t){const r=u(t);await a(n(r),{recursive:!0}),this.stdoutStream=o(t,{flags:"w"})}if(e){const r=u(e);await a(n(r),{recursive:!0}),this.stderrStream=o(e,{flags:"w"})}}setTTLTimer(){const{ttl:t}=this.options;t&&this.process&&(this.ttlTimer=l(()=>{this.stop("ttl")},t))}addProcessListeners(){this.process&&(this.process.stdout?.on("data",t=>this.onStdOutData(t)),this.process.stderr?.on("data",t=>this.onStdErrData(t)),this.process.on("exit",t=>this.onExit(t)),this.process.on("error",t=>this.onError(t)))}onStdOutData(t){const e=t.toString();this.emit(i.STDOUT,e),this.stdoutStream&&this.stdoutStream.write(e)}onStdErrData(t){const e=t.toString();this.emit(i.STDERR,e),this.stderrStream&&this.stderrStream.write(e)}onExit(t){const e=t!==null&&!this.correctExitCodes.includes(t)?t:d;this.updateState({status:e===0?s.COMPLETED:e===d?s.STOPPED:s.FAILED,exitCode:e}),this.cleanup()}onError(t){const e=t?.code??null;this.updateState({status:e===null?s.STOPPED:s.FAILED,reason:t.message||(e??"")}),this.cleanup()}updateState(t){const e={...this.state,...t,timestamp:Date.now()};this.state=Object.fromEntries(Object.entries(e).filter(([r,c])=>c!==void 0)),this.emit(i.STATE_CHANGE,this.getState()),this.emit(this.state.status,this.getState())}cleanup(){this.ttlTimer&&(clearTimeout(this.ttlTimer),this.ttlTimer=null),this.process&&(this.process.removeAllListeners(),this.process.stdout?.removeAllListeners(),this.process.stderr?.removeAllListeners(),this.process=null),this.stdoutStream&&(this.stdoutStream.end(),this.stdoutStream=null),this.stderrStream&&(this.stderrStream.end(),this.stderrStream=null)}}export{P as DockerTaskBase,d as SILENT_EXIT_CODE};
1
+ import{createWriteStream as o}from"node:fs";import{mkdir as a}from"node:fs/promises";import{dirname as n,resolve as u}from"node:path";import{setTimeout as l}from"node:timers";const d=-1,m=50,{TaskStatus:s,TaskEvent:i}=runium.enum;class P extends runium.class.RuniumTask{constructor(t){super(t);this.options=t;this.setMaxListeners(m)}correctExitCodes=[];state={status:s.IDLE,timestamp:Date.now(),iteration:0,pid:-1};process=null;stdoutStream=null;stderrStream=null;ttlTimer=null;getState(){return{...this.state}}getOptions(){return{...this.options}}canStart(){const{status:t}=this.state;return t!==s.STARTED&&t!==s.STARTING&&t!==s.STOPPING}canStop(){const{status:t}=this.state;return t===s.STARTED||t===s.STARTING}async restart(){await this.stop("restart"),await this.start()}async initLogStreams(){const{stdout:t=null,stderr:e=null}=this.options.log||{};if(t){const r=u(t);await a(n(r),{recursive:!0}),this.stdoutStream=o(t,{flags:"w"})}if(e){const r=u(e);await a(n(r),{recursive:!0}),this.stderrStream=o(e,{flags:"w"})}}setTTLTimer(){const{ttl:t}=this.options;t&&this.process&&(this.ttlTimer=l(()=>{this.stop("ttl")},t))}addProcessListeners(){this.process&&(this.process.stdout?.on("data",t=>this.onStdOutData(t)),this.process.stderr?.on("data",t=>this.onStdErrData(t)),this.process.on("exit",t=>this.onExit(t)),this.process.on("error",t=>this.onError(t)))}onStdOutData(t){const e=t.toString();this.emit(i.STDOUT,e),this.stdoutStream&&this.stdoutStream.write(e)}onStdErrData(t){const e=t.toString();this.emit(i.STDERR,e),this.stderrStream&&this.stderrStream.write(e)}onExit(t){const e=t!==null&&!this.correctExitCodes.includes(t)?t:d;this.updateState({status:e===0?s.COMPLETED:e===d?s.STOPPED:s.FAILED,exitCode:e}),this.cleanup()}onError(t,e){const r=e??t?.code??null;this.updateState({status:r===null?s.STOPPED:s.FAILED,reason:t.message||(r??"")}),this.cleanup()}updateState(t){const e={...this.state,...t,timestamp:Date.now()};this.state=Object.fromEntries(Object.entries(e).filter(([r,c])=>c!==void 0)),this.emit(i.STATE_CHANGE,this.getState()),this.emit(this.state.status,this.getState())}cleanup(){this.ttlTimer&&(clearTimeout(this.ttlTimer),this.ttlTimer=null),this.process&&(this.process.removeAllListeners(),this.process.stdout?.removeAllListeners(),this.process.stderr?.removeAllListeners(),this.process=null),this.stdoutStream&&(this.stdoutStream.end(),this.stdoutStream=null),this.stderrStream&&(this.stderrStream.end(),this.stderrStream=null)}}export{P as DockerTaskBase,d as SILENT_EXIT_CODE};
@@ -1 +1 @@
1
- import{spawn as n}from"node:child_process";import{DockerTaskBase as a}from"./docker-task-base.js";import{isDockerInstalled as p}from"../utils/is-docker-installed.js";import{isDockerRunning as h}from"../utils/is-docker-running.js";import{pullImage as c}from"../utils/pull-image.js";import{isImagePulled as u}from"../utils/is-image-pulled.js";const{TaskStatus:o}=runium.enum;class E extends a{constructor(t){super(t);this.options=t;this.options.containerName??=`runium-${this.options.image.replaceAll("/","-").replaceAll(":","-")}-${Date.now()}`}correctExitCodes=[137];prepareDockerArgs(){const t=["run"];return this.options.autoRemove!==!1&&t.push("--rm"),this.options.containerName&&t.push("--name",this.options.containerName),this.options.ports&&this.options.ports.forEach(i=>{t.push("-p",i)}),this.options.volumes&&this.options.volumes.forEach(i=>{t.push("-v",i)}),this.options.env&&Object.entries(this.options.env).forEach(([i,s])=>{t.push("-e",`${i}=${s}`)}),this.options.network&&t.push("--network",this.options.network),this.options.user&&t.push("--user",this.options.user),this.options.workdir&&t.push("--workdir",this.options.workdir),this.options.entrypoint&&t.push("--entrypoint",this.options.entrypoint),this.options.privileged&&t.push("--privileged"),t.push(this.options.image),this.options.command&&t.push(this.options.command),this.options.arguments&&t.push(...this.options.arguments),t}async start(){if(this.canStart()){if(this.updateState({status:o.STARTING,iteration:this.state.iteration+1,pid:-1,containerName:void 0,exitCode:void 0,error:void 0,reason:void 0}),!await p()){this.onError(new Error("Docker is not installed"));return}if(!await h()){this.onError(new Error("Docker is not running"));return}try{await this.initLogStreams();const t=this.options.image;await u(t)||(this.updateState({reason:`pull image: ${t}`}),await c(t,{onStdErr:this.onStdErrData.bind(this)}));const i=this.prepareDockerArgs();this.process=n("docker",i,{stdio:["ignore","pipe","pipe"]}),this.addProcessListeners(),this.setTTLTimer(),this.updateState({status:o.STARTED,containerName:this.options.containerName,pid:this.process.pid,reason:void 0})}catch(t){this.onError(t)}}}async stop(t=""){if(this.canStop()){this.updateState({status:o.STOPPING,reason:t});try{await new Promise((i,s)=>{const e=n("docker",["stop",this.options.containerName]);e.on("exit",r=>{r===0?i():s(new Error(`Docker stop exited with code ${r}`))}),e.on("error",s)})}catch(i){this.onError(i)}finally{await new Promise(i=>{this.process?.kill("SIGTERM"),this.process?.on("exit",()=>{i()})})}}}}export{E as DockerTask};
1
+ import{spawn as n}from"node:child_process";import{DockerTaskBase as a}from"./docker-task-base.js";import{isDockerInstalled as p}from"../utils/is-docker-installed.js";import{isDockerRunning as h}from"../utils/is-docker-running.js";import{pullImage as c}from"../utils/pull-image.js";import{isImagePulled as u}from"../utils/is-image-pulled.js";const{TaskStatus:o}=runium.enum;class E extends a{constructor(t){super(t);this.options=t;this.options.containerName??=`runium-${this.options.image.replaceAll("/","-").replaceAll(":","-")}-${Date.now()}`}correctExitCodes=[137];prepareDockerArgs(){const t=["run"];return this.options.autoRemove!==!1&&t.push("--rm"),this.options.containerName&&t.push("--name",this.options.containerName),this.options.ports&&this.options.ports.forEach(i=>{t.push("-p",i)}),this.options.volumes&&this.options.volumes.forEach(i=>{t.push("-v",i)}),this.options.env&&Object.entries(this.options.env).forEach(([i,s])=>{t.push("-e",`${i}=${s}`)}),this.options.network&&t.push("--network",this.options.network),this.options.user&&t.push("--user",this.options.user),this.options.workdir&&t.push("--workdir",this.options.workdir),this.options.entrypoint&&t.push("--entrypoint",this.options.entrypoint),this.options.privileged&&t.push("--privileged"),t.push(this.options.image),this.options.command&&t.push(this.options.command),this.options.arguments&&t.push(...this.options.arguments),t}async start(){if(this.canStart()){if(this.updateState({status:o.STARTING,iteration:this.state.iteration+1,pid:-1,containerName:void 0,exitCode:void 0,error:void 0,reason:void 0}),!await p()){this.onError(new Error("Docker is not installed"),1);return}if(!await h()){this.onError(new Error("Docker is not running"),1);return}try{await this.initLogStreams();const t=this.options.image;await u(t)||(this.updateState({reason:`pull image: ${t}`}),await c(t,{onStdErr:this.onStdErrData.bind(this)}));const i=this.prepareDockerArgs();this.process=n("docker",i,{stdio:["ignore","pipe","pipe"]}),this.addProcessListeners(),this.setTTLTimer(),this.updateState({status:o.STARTED,containerName:this.options.containerName,pid:this.process.pid,reason:void 0})}catch(t){this.onError(t)}}}async stop(t=""){if(this.canStop()){this.updateState({status:o.STOPPING,reason:t});try{await new Promise((i,s)=>{const e=n("docker",["stop",this.options.containerName]);e.on("exit",r=>{r===0?i():s(new Error(`Docker stop exited with code ${r}`))}),e.on("error",s)})}catch(i){this.onError(i)}finally{await new Promise(i=>{this.process?.kill("SIGTERM"),this.process?.on("exit",()=>{i()})})}}}}export{E as DockerTask};