Skip to content

Commit a9dfd27

Browse files
committed
Make lua its own package and make the docker image a base image
1 parent 9af010c commit a9dfd27

File tree

4 files changed

+90
-13
lines changed

4 files changed

+90
-13
lines changed

Dockerfile

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ RUN apt-get install -y lua5.3 luarocks liblua5.3-dev build-essential libssl-dev
88
# Copy over our LUA libraries/runtime
99
COPY ./src /opt/executor
1010

11-
# Get the sdk repo if it doesn't exist
11+
# Add dkjson package
1212
WORKDIR /opt/executor
13-
RUN if [ ! -d "sdk-lua" ]; then git clone --depth 1 https://github.com/ProcessMaker/sdk-lua.git; fi
14-
15-
# Build the sdk and save it in luarocks default folder
16-
WORKDIR /opt/executor/sdk-lua
17-
RUN luarocks make --local
18-
19-
# Set working directory to our /opt/executor location
20-
WORKDIR /opt/executor
21-
22-
LABEL maintainer="taylor@processmaker.com"
23-
24-
RUN luarocks install dkjson
13+
RUN luarocks install dkjson

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-lua",
3+
"friendly_name": "Lua Docker Executor",
4+
"description": "Lua script executor for processmaker 4",
5+
"version": "1.0.0",
6+
"minimum-stability": "dev",
7+
"autoload": {
8+
"psr-4": {
9+
"ProcessMaker\\Package\\DockerExecutorLua\\": "src",
10+
"ProcessMaker\\ScriptRunners\\": "src/ScriptRunners"
11+
}
12+
},
13+
"extra": {
14+
"laravel": {
15+
"providers": [
16+
"ProcessMaker\\Package\\DockerExecutorLua\\DockerExecutorLuaServiceProvider"
17+
]
18+
}
19+
}
20+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
namespace ProcessMaker\Package\DockerExecutorLua;
3+
4+
use Illuminate\Support\Facades\Route;
5+
use Illuminate\Support\ServiceProvider;
6+
use ProcessMaker\Traits\PluginServiceProviderTrait;
7+
8+
class DockerExecutorLuaServiceProvider extends ServiceProvider
9+
{
10+
use PluginServiceProviderTrait;
11+
12+
const version = '1.0.0'; // Required for PluginServiceProviderTrait
13+
14+
public function register()
15+
{
16+
}
17+
18+
public function boot()
19+
{
20+
// Note: `processmaker4/executor-lua` is now the base image that the instance inherits from
21+
$image = env('SCRIPTS_LUA_IMAGE', 'processmaker4/executor-instance-lua:v1.0.0');
22+
23+
\Artisan::command('docker-executor-lua:install', function () {
24+
// Restart the workers so they know about the new supported language
25+
\Artisan::call('horizon:terminate');
26+
27+
// Refresh the app cache so script runners config gets updated
28+
\Artisan::call('optimize:clear');
29+
30+
// Build the base image that `executor-instance-lua` inherits from
31+
system("docker build -t processmaker4/executor-lua:latest " . __DIR__ . '/..');
32+
});
33+
34+
$config = [
35+
'name' => 'Lua',
36+
'runner' => 'LuaRunner',
37+
'mime_type' => 'application/x-lua',
38+
'image' => $image,
39+
'options' => ['gitRepoId' => 'sdk-node'],
40+
'init_dockerfile' => "FROM processmaker4/executor-lua:latest\nARG SDK_DIR\n",
41+
];
42+
config(['script-runners.lua' => $config]);
43+
44+
$this->completePluginBoot();
45+
}
46+
}

src/ScriptRunners/LuaRunner.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 LuaRunner extends Base
6+
{
7+
/**
8+
* Configure docker with lua 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.lua.image');
18+
$dockerConfig['command'] = 'lua5.3 /opt/executor/bootstrap.lua';
19+
$dockerConfig['inputs']['/opt/executor/script.lua'] = $code;
20+
return $dockerConfig;
21+
}
22+
}

0 commit comments

Comments
 (0)