Skip to content

Commit fc5aad6

Browse files
authored
Merge pull request #3 from ProcessMaker/feature/2
Allow for custom builds in core
2 parents 9946aea + af4883b commit fc5aad6

8 files changed

Lines changed: 43 additions & 35 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sdk

Dockerfile

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
1-
# Bring in from Mono docker image
21
FROM mcr.microsoft.com/dotnet/core/sdk:2.2
3-
4-
RUN apt update && apt install -y mono-devel
2+
RUN apt update
53

64
# Copy over our .NET C# solution skeleton
75
COPY ./src /opt/executor
8-
WORKDIR /opt/executor
9-
10-
# SDK is not public yet
11-
RUN if [ ! -d "sdk-csharp" ]; then git clone --depth 1 https://github.com/ProcessMaker/package-csharp.git sdk-csharp; fi
12-
13-
RUN mv sdk-csharp ../
14-
WORKDIR /opt/sdk-csharp
15-
RUN chmod 755 build.sh && ./build.sh
16-
WORKDIR /opt/executor
17-
RUN mv ../sdk-csharp/bin . && rm -rf ../sdk-csharp
186

19-
# Install required
20-
#RUN nuget install Newtonsoft.Json -Version 12.0.1
21-
#dotnet add package Newtonsoft.Json
7+
# Install mono, needed for building the SDK
8+
RUN apt install -y apt-transport-https dirmngr gnupg ca-certificates
9+
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
10+
RUN echo "deb https://download.mono-project.com/repo/debian stable-stretch main" | tee /etc/apt/sources.list.d/mono-official-stable.list
11+
RUN apt update
12+
RUN apt install -y mono-devel
2213

14+
WORKDIR /opt/executor

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# executor-php
1+
# executor-csharp
22
Script Task Executor Engine with Mono Runtime to support C#
33

44
This docker image provides a sandboxed protected environment to run custom C# "scripts" that are written in ProcessMaker BPM.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "processmaker/docker-executor-csharp",
33
"friendly_name": "CSharp Docker Executor",
44
"description": "CSharp script executor for processmaker 4",
5-
"version": "0.0.1",
5+
"version": "1.0.0",
66
"minimum-stability": "dev",
77
"autoload": {
88
"psr-4": {

src/BaseScript.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Newtonsoft.Json.Linq;
2-
using ProcessMakerSDK.Client;
32

43
/**
54
BaseScript is the base class that a custom script should inherit. It has one single
@@ -8,5 +7,5 @@ object to populate.
87
*/
98
public abstract class BaseScript
109
{
11-
public abstract void Execute(dynamic data, dynamic config, dynamic output, Configuration apiConfig);
10+
public abstract void Execute(dynamic data, dynamic config, dynamic output);
1211
}

src/DockerExecutorCSharpServiceProvider.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
use Illuminate\Support\Facades\Route;
55
use Illuminate\Support\ServiceProvider;
66
use ProcessMaker\Traits\PluginServiceProviderTrait;
7-
use ProcessMaker\Package\Packages\Events\PackageEvent;
8-
use ProcessMaker\Package\WebEntry\Listeners\PackageListener;
7+
use ProcessMaker\Models\ScriptExecutor;
98

109
class DockerExecutorCSharpServiceProvider extends ServiceProvider
1110
{
1211
use PluginServiceProviderTrait;
1312

14-
const version = '0.0.1'; // Required for PluginServiceProviderTrait
13+
const version = '1.0.0'; // Required for PluginServiceProviderTrait
1514

1615
public function register()
1716
{
@@ -28,21 +27,42 @@ public function register()
2827
public function boot()
2928
{
3029
\Artisan::command('docker-executor-csharp:install', function () {
31-
// nothing to do here
30+
$scriptExecutor = ScriptExecutor::install([
31+
'language' => 'csharp',
32+
'title' => 'C# Executor',
33+
'description' => 'Default C# Executor',
34+
]);
35+
36+
// Build the instance image. This is the same as if you were to build it from the admin UI
37+
\Artisan::call('processmaker:build-script-executor csharp');
38+
39+
// Restart the workers so they know about the new supported language
40+
\Artisan::call('horizon:terminate');
3241
});
3342

3443
$config = [
3544
'name' => 'C#',
3645
'runner' => 'CSharpRunner',
3746
'mime_type' => 'text/plain',
38-
'image' => env('SCRIPTS_CSHARP_IMAGE', 'processmaker4/executor-csharp'),
3947
'options' => [
4048
'packageName' => "ProcessMakerSDK",
41-
]
49+
],
50+
'init_dockerfile' => [
51+
"ARG SDK_DIR",
52+
'COPY $SDK_DIR /opt/sdk-csharp',
53+
'WORKDIR /opt/sdk-csharp',
54+
'RUN chmod 755 build.sh',
55+
'# OpenAPI Builder for csharp is broken',
56+
'# RUN ./build.sh',
57+
'WORKDIR /opt/executor',
58+
'# RUN mv ../sdk-csharp/bin . && rm -rf ../sdk-csharp',
59+
],
60+
'package_path' => __DIR__ . '/..',
61+
'package_version' => self::version,
4262
];
4363
config(['script-runners.csharp' => $config]);
4464

45-
$this->app['events']->listen(PackageEvent::class, PackageListener::class);
65+
// $this->app['events']->listen(PackageEvent::class, PackageListener::class);
4666

4767
// Complete the plugin booting
4868
$this->completePluginBoot();

src/ScriptRunner.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33
using Newtonsoft.Json.Linq;
4-
using ProcessMakerSDK.Client;
54

65
/*
76
Our quick and simple .net c sharp script runner that prepares reading
@@ -16,15 +15,15 @@ static public void Main ()
1615
string apiHost = Environment.GetEnvironmentVariable("API_HOST");
1716
string apiToken = Environment.GetEnvironmentVariable("API_TOKEN");
1817

19-
Configuration apiConfig = Configuration.Default;
20-
apiConfig.BasePath = apiHost;
21-
apiConfig.AccessToken = apiToken;
18+
// Configuration apiConfig = Configuration.Default;
19+
// apiConfig.BasePath = apiHost;
20+
// apiConfig.AccessToken = apiToken;
2221

2322
dynamic data = JToken.Parse(File.ReadAllText(@"data.json"));
2423
dynamic config = JToken.Parse(File.ReadAllText(@"config.json"));
2524
dynamic output = new JObject();
2625
Script script = new Script();
27-
script.Execute(data, config, output, apiConfig);
26+
script.Execute(data, config, output);
2827
File.WriteAllText(@"output.json", output.ToString());
2928
}
3029
}

src/ScriptRunner.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
<ItemGroup>
99
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
10-
<Reference Include="ProcessMakerSDK">
11-
<HintPath>bin/ProcessMakerSDK.dll</HintPath>
12-
</Reference>
1310
</ItemGroup>
1411

1512
</Project>

0 commit comments

Comments
 (0)