Skip to content

Allow for custom builds in core #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdk
24 changes: 8 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
# Bring in from Mono docker image
FROM mcr.microsoft.com/dotnet/core/sdk:2.2

RUN apt update && apt install -y mono-devel
RUN apt update

# Copy over our .NET C# solution skeleton
COPY ./src /opt/executor
WORKDIR /opt/executor

# SDK is not public yet
RUN if [ ! -d "sdk-csharp" ]; then git clone --depth 1 https://github.com/ProcessMaker/package-csharp.git sdk-csharp; fi

RUN mv sdk-csharp ../
WORKDIR /opt/sdk-csharp
RUN chmod 755 build.sh && ./build.sh
WORKDIR /opt/executor
RUN mv ../sdk-csharp/bin . && rm -rf ../sdk-csharp

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

WORKDIR /opt/executor
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# executor-php
# executor-csharp
Script Task Executor Engine with Mono Runtime to support C#

This docker image provides a sandboxed protected environment to run custom C# "scripts" that are written in ProcessMaker BPM.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "processmaker/docker-executor-csharp",
"friendly_name": "CSharp Docker Executor",
"description": "CSharp script executor for processmaker 4",
"version": "0.0.1",
"version": "1.0.0",
"minimum-stability": "dev",
"autoload": {
"psr-4": {
Expand Down
3 changes: 1 addition & 2 deletions src/BaseScript.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Newtonsoft.Json.Linq;
using ProcessMakerSDK.Client;

/**
BaseScript is the base class that a custom script should inherit. It has one single
Expand All @@ -8,5 +7,5 @@ object to populate.
*/
public abstract class BaseScript
{
public abstract void Execute(dynamic data, dynamic config, dynamic output, Configuration apiConfig);
public abstract void Execute(dynamic data, dynamic config, dynamic output);
}
34 changes: 27 additions & 7 deletions src/DockerExecutorCSharpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use ProcessMaker\Traits\PluginServiceProviderTrait;
use ProcessMaker\Package\Packages\Events\PackageEvent;
use ProcessMaker\Package\WebEntry\Listeners\PackageListener;
use ProcessMaker\Models\ScriptExecutor;

class DockerExecutorCSharpServiceProvider extends ServiceProvider
{
use PluginServiceProviderTrait;

const version = '0.0.1'; // Required for PluginServiceProviderTrait
const version = '1.0.0'; // Required for PluginServiceProviderTrait

public function register()
{
Expand All @@ -28,21 +27,42 @@ public function register()
public function boot()
{
\Artisan::command('docker-executor-csharp:install', function () {
// nothing to do here
$scriptExecutor = ScriptExecutor::install([
'language' => 'csharp',
'title' => 'C# Executor',
'description' => 'Default C# 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 csharp');

// Restart the workers so they know about the new supported language
\Artisan::call('horizon:terminate');
});

$config = [
'name' => 'C#',
'runner' => 'CSharpRunner',
'mime_type' => 'text/plain',
'image' => env('SCRIPTS_CSHARP_IMAGE', 'processmaker4/executor-csharp'),
'options' => [
'packageName' => "ProcessMakerSDK",
]
],
'init_dockerfile' => [
"ARG SDK_DIR",
'COPY $SDK_DIR /opt/sdk-csharp',
'WORKDIR /opt/sdk-csharp',
'RUN chmod 755 build.sh',
'# OpenAPI Builder for csharp is broken',
'# RUN ./build.sh',
'WORKDIR /opt/executor',
'# RUN mv ../sdk-csharp/bin . && rm -rf ../sdk-csharp',
],
'package_path' => __DIR__ . '/..',
'package_version' => self::version,
];
config(['script-runners.csharp' => $config]);

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

// Complete the plugin booting
$this->completePluginBoot();
Expand Down
9 changes: 4 additions & 5 deletions src/ScriptRunner.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using Newtonsoft.Json.Linq;
using ProcessMakerSDK.Client;

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

Configuration apiConfig = Configuration.Default;
apiConfig.BasePath = apiHost;
apiConfig.AccessToken = apiToken;
// Configuration apiConfig = Configuration.Default;
// apiConfig.BasePath = apiHost;
// apiConfig.AccessToken = apiToken;

dynamic data = JToken.Parse(File.ReadAllText(@"data.json"));
dynamic config = JToken.Parse(File.ReadAllText(@"config.json"));
dynamic output = new JObject();
Script script = new Script();
script.Execute(data, config, output, apiConfig);
script.Execute(data, config, output);
File.WriteAllText(@"output.json", output.ToString());
}
}
3 changes: 0 additions & 3 deletions src/ScriptRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<Reference Include="ProcessMakerSDK">
<HintPath>bin/ProcessMakerSDK.dll</HintPath>
</Reference>
</ItemGroup>

</Project>