From 4c724b0f733bd95540374a0d6cc66df9f4a0d4d6 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Thu, 12 Mar 2020 13:31:46 -0700 Subject: [PATCH 1/3] Make node its own package and make the docker image a base image --- Dockerfile | 3 -- composer.json | 20 +++++++ src/DockerExecutorNodeServiceProvider.php | 53 +++++++++++++++++++ src/ScriptRunners/NodeRunner.php | 22 ++++++++ src/bootstrap.js | 20 +++++-- src/package.json | 1 - .../docker-build-config/Dockerfile-javascript | 7 +++ 7 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 composer.json create mode 100644 src/DockerExecutorNodeServiceProvider.php create mode 100644 src/ScriptRunners/NodeRunner.php create mode 100644 storage/docker-build-config/Dockerfile-javascript diff --git a/Dockerfile b/Dockerfile index 2dafb50..02ef4bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,4 @@ FROM node:8.15.0 COPY /src /opt/executor WORKDIR /opt/executor -RUN if [ ! -d "sdk-node" ]; then git clone --depth 1 https://github.com/ProcessMaker/sdk-node.git; fi -RUN cd /opt/executor/sdk-node; npm install -RUN cd /opt/executor/sdk-node; npm run-script build RUN npm install diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..85f59a2 --- /dev/null +++ b/composer.json @@ -0,0 +1,20 @@ +{ + "name": "processmaker/docker-executor-node", + "friendly_name": "Javascript Docker Executor", + "description": "Javascript script executor for processmaker 4", + "version": "1.0.0", + "minimum-stability": "dev", + "autoload": { + "psr-4": { + "ProcessMaker\\Package\\DockerExecutorNode\\": "src", + "ProcessMaker\\ScriptRunners\\": "src/ScriptRunners" + } + }, + "extra": { + "laravel": { + "providers": [ + "ProcessMaker\\Package\\DockerExecutorNode\\DockerExecutorNodeServiceProvider" + ] + } + } +} diff --git a/src/DockerExecutorNodeServiceProvider.php b/src/DockerExecutorNodeServiceProvider.php new file mode 100644 index 0000000..0fe8bde --- /dev/null +++ b/src/DockerExecutorNodeServiceProvider.php @@ -0,0 +1,53 @@ + 'JavaScript', + 'runner' => 'NodeRunner', + 'mime_type' => 'text/javascript', + 'image' => $image, + 'options' => ['gitRepoId' => 'sdk-node'], + 'init_dockerfile' => "FROM processmaker4/executor-node:latest\nARG SDK_DIR\n", + ]; + config(['script-runners.javascript' => $config]); + + $this->completePluginBoot(); + } +} diff --git a/src/ScriptRunners/NodeRunner.php b/src/ScriptRunners/NodeRunner.php new file mode 100644 index 0000000..813038a --- /dev/null +++ b/src/ScriptRunners/NodeRunner.php @@ -0,0 +1,22 @@ + { @@ -29,11 +37,13 @@ Promise.all([getConfig, getData]).then(function(values) { const config = values[0] const data = values[1] - let client = api.ApiClient.instance - client.basePath = process.env.API_HOST + if (api) { + let client = api.ApiClient.instance + client.basePath = process.env.API_HOST - let auth = client.authentications['pm_api_bearer'] - auth.accessToken = process.env.API_TOKEN + let auth = client.authentications['pm_api_bearer'] + auth.accessToken = process.env.API_TOKEN + } const return_value = script.run(data, config, api) diff --git a/src/package.json b/src/package.json index 8aefd91..aa60765 100644 --- a/src/package.json +++ b/src/package.json @@ -4,7 +4,6 @@ "description": "", "main": "bootstrap.js", "dependencies": { - "process_maker_api": "./sdk-node" }, "devDependencies": {}, "scripts": { diff --git a/storage/docker-build-config/Dockerfile-javascript b/storage/docker-build-config/Dockerfile-javascript new file mode 100644 index 0000000..5e4033f --- /dev/null +++ b/storage/docker-build-config/Dockerfile-javascript @@ -0,0 +1,7 @@ +# Install the processmaker4 SDK +COPY $SDK_DIR /opt/sdk-node +WORKDIR /opt/sdk-node +RUN npm install +RUN npm run build +WORKDIR /opt/executor +RUN npm install /opt/sdk-node \ No newline at end of file From 2c0e8759446d5b0c5ce5521dacb468f378875fc5 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Mon, 23 Mar 2020 12:47:56 -0700 Subject: [PATCH 2/3] Update to remove specifying the image name --- .gitignore | 1 + src/DockerExecutorNodeServiceProvider.php | 36 ++++++++++--------- .../docker-build-config/Dockerfile-javascript | 7 ---- 3 files changed, 20 insertions(+), 24 deletions(-) delete mode 100644 storage/docker-build-config/Dockerfile-javascript diff --git a/.gitignore b/.gitignore index 579359b..72f3ce3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ src/data.json src/config.json src/output.json test.sh +sdk diff --git a/src/DockerExecutorNodeServiceProvider.php b/src/DockerExecutorNodeServiceProvider.php index 0fe8bde..87b5e00 100644 --- a/src/DockerExecutorNodeServiceProvider.php +++ b/src/DockerExecutorNodeServiceProvider.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use ProcessMaker\Traits\PluginServiceProviderTrait; +use ProcessMaker\Models\ScriptExecutor; class DockerExecutorNodeServiceProvider extends ServiceProvider { @@ -17,34 +18,35 @@ public function register() public function boot() { - // Note: `processmaker4/executor-node` is now the base image that the instance inherits from - $image = env('SCRIPTS_NODE_IMAGE', 'processmaker4/executor-instance-javascript:v1.0.0'); - \Artisan::command('docker-executor-node:install', function () { - - // Copy the default custom dockerfile to the storage folder - copy( - __DIR__ . '/../storage/docker-build-config/Dockerfile-javascript', - storage_path("docker-build-config/Dockerfile-javascript") - ); + $scriptExecutor = ScriptExecutor::install([ + 'language' => 'javascript', + 'title' => 'Node Executor', + 'description' => 'Default Javascript/Node Executor' + ]); + // Build the instance image. This is the same as if you were to build it from the admin UI + \Artisan::call('processmaker:build-script-executor ' . $scriptExecutor->id); + // Restart the workers so they know about the new supported language \Artisan::call('horizon:terminate'); - - // Build the base image that `executor-instance-node` inherits from - system("docker build -t processmaker4/executor-node:latest " . __DIR__ . '/..'); - - // Build the instance image. This is the same as if you were to build it from the admin UI - \Artisan::call('processmaker:build-script-executor javascript'); }); $config = [ 'name' => 'JavaScript', 'runner' => 'NodeRunner', 'mime_type' => 'text/javascript', - 'image' => $image, 'options' => ['gitRepoId' => 'sdk-node'], - 'init_dockerfile' => "FROM processmaker4/executor-node:latest\nARG SDK_DIR\n", + 'init_dockerfile' => [ + 'ARG SDK_DIR', + 'COPY $SDK_DIR /opt/sdk-node', + 'WORKDIR /opt/sdk-node', + 'RUN npm install', + 'RUN npm run build', + 'WORKDIR /opt/executor', + 'RUN npm install /opt/sdk-node', + ], + 'package_path' => __DIR__ . '/..', ]; config(['script-runners.javascript' => $config]); diff --git a/storage/docker-build-config/Dockerfile-javascript b/storage/docker-build-config/Dockerfile-javascript deleted file mode 100644 index 5e4033f..0000000 --- a/storage/docker-build-config/Dockerfile-javascript +++ /dev/null @@ -1,7 +0,0 @@ -# Install the processmaker4 SDK -COPY $SDK_DIR /opt/sdk-node -WORKDIR /opt/sdk-node -RUN npm install -RUN npm run build -WORKDIR /opt/executor -RUN npm install /opt/sdk-node \ No newline at end of file From c0fa210b98bae8368244d8011ef827672821a852 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Tue, 24 Mar 2020 15:22:47 -0700 Subject: [PATCH 3/3] Add package version to config --- src/DockerExecutorNodeServiceProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DockerExecutorNodeServiceProvider.php b/src/DockerExecutorNodeServiceProvider.php index 87b5e00..07c0a89 100644 --- a/src/DockerExecutorNodeServiceProvider.php +++ b/src/DockerExecutorNodeServiceProvider.php @@ -47,6 +47,7 @@ public function boot() 'RUN npm install /opt/sdk-node', ], 'package_path' => __DIR__ . '/..', + 'package_version' => self::version, ]; config(['script-runners.javascript' => $config]);