Skip to content

Commit 853dbc8

Browse files
authored
Merge pull request #3 from ProcessMaker/feature/2
Make node its own package and make the docker image a base image
2 parents 3a74037 + c0fa210 commit 853dbc8

7 files changed

Lines changed: 114 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ src/data.json
55
src/config.json
66
src/output.json
77
test.sh
8+
sdk

Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
FROM node:8.15.0
22
COPY /src /opt/executor
33
WORKDIR /opt/executor
4-
RUN if [ ! -d "sdk-node" ]; then git clone --depth 1 https://github.com/ProcessMaker/sdk-node.git; fi
5-
RUN cd /opt/executor/sdk-node; npm install
6-
RUN cd /opt/executor/sdk-node; npm run-script build
74
RUN npm install

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "processmaker/docker-executor-node",
3+
"friendly_name": "Javascript Docker Executor",
4+
"description": "Javascript script executor for processmaker 4",
5+
"version": "1.0.0",
6+
"minimum-stability": "dev",
7+
"autoload": {
8+
"psr-4": {
9+
"ProcessMaker\\Package\\DockerExecutorNode\\": "src",
10+
"ProcessMaker\\ScriptRunners\\": "src/ScriptRunners"
11+
}
12+
},
13+
"extra": {
14+
"laravel": {
15+
"providers": [
16+
"ProcessMaker\\Package\\DockerExecutorNode\\DockerExecutorNodeServiceProvider"
17+
]
18+
}
19+
}
20+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
namespace ProcessMaker\Package\DockerExecutorNode;
3+
4+
use Illuminate\Support\Facades\Route;
5+
use Illuminate\Support\ServiceProvider;
6+
use ProcessMaker\Traits\PluginServiceProviderTrait;
7+
use ProcessMaker\Models\ScriptExecutor;
8+
9+
class DockerExecutorNodeServiceProvider extends ServiceProvider
10+
{
11+
use PluginServiceProviderTrait;
12+
13+
const version = '1.0.0'; // Required for PluginServiceProviderTrait
14+
15+
public function register()
16+
{
17+
}
18+
19+
public function boot()
20+
{
21+
\Artisan::command('docker-executor-node:install', function () {
22+
$scriptExecutor = ScriptExecutor::install([
23+
'language' => 'javascript',
24+
'title' => 'Node Executor',
25+
'description' => 'Default Javascript/Node Executor'
26+
]);
27+
28+
// Build the instance image. This is the same as if you were to build it from the admin UI
29+
\Artisan::call('processmaker:build-script-executor ' . $scriptExecutor->id);
30+
31+
// Restart the workers so they know about the new supported language
32+
\Artisan::call('horizon:terminate');
33+
});
34+
35+
$config = [
36+
'name' => 'JavaScript',
37+
'runner' => 'NodeRunner',
38+
'mime_type' => 'text/javascript',
39+
'options' => ['gitRepoId' => 'sdk-node'],
40+
'init_dockerfile' => [
41+
'ARG SDK_DIR',
42+
'COPY $SDK_DIR /opt/sdk-node',
43+
'WORKDIR /opt/sdk-node',
44+
'RUN npm install',
45+
'RUN npm run build',
46+
'WORKDIR /opt/executor',
47+
'RUN npm install /opt/sdk-node',
48+
],
49+
'package_path' => __DIR__ . '/..',
50+
'package_version' => self::version,
51+
];
52+
config(['script-runners.javascript' => $config]);
53+
54+
$this->completePluginBoot();
55+
}
56+
}

src/ScriptRunners/NodeRunner.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace ProcessMaker\ScriptRunners;
4+
5+
class NodeRunner extends Base
6+
{
7+
/**
8+
* Configure docker with node executor
9+
*
10+
* @param string $code
11+
* @param array $dockerConfig
12+
*
13+
* @return array
14+
*/
15+
public function config($code, array $dockerConfig)
16+
{
17+
$dockerConfig['image'] = config('script-runners.javascript.image');
18+
$dockerConfig['command'] = '/bin/sh /opt/executor/run.sh';
19+
$dockerConfig['inputs']['/opt/executor/script.js'] = $code;
20+
return $dockerConfig;
21+
}
22+
}

src/bootstrap.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
if (process.env['API_SSL_VERIFY'] === '0') {
2+
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
3+
}
4+
15
var fs = require('fs')
26
var script = require('./script_wrapped.js')
3-
var api = require('process_maker_api')
7+
try {
8+
var api = require('process_maker_api');
9+
} catch(err) {
10+
var api = null;
11+
}
412

513
function getFilePromise(file) {
614
return new Promise((resolve, reject) => {
@@ -29,11 +37,13 @@ Promise.all([getConfig, getData]).then(function(values) {
2937
const config = values[0]
3038
const data = values[1]
3139

32-
let client = api.ApiClient.instance
33-
client.basePath = process.env.API_HOST
40+
if (api) {
41+
let client = api.ApiClient.instance
42+
client.basePath = process.env.API_HOST
3443

35-
let auth = client.authentications['pm_api_bearer']
36-
auth.accessToken = process.env.API_TOKEN
44+
let auth = client.authentications['pm_api_bearer']
45+
auth.accessToken = process.env.API_TOKEN
46+
}
3747

3848
const return_value = script.run(data, config, api)
3949

src/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "",
55
"main": "bootstrap.js",
66
"dependencies": {
7-
"process_maker_api": "./sdk-node"
87
},
98
"devDependencies": {},
109
"scripts": {

0 commit comments

Comments
 (0)