diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5a43536 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +sdk diff --git a/Dockerfile b/Dockerfile index e1c5d1c..eb5837b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 0c8452e..da33488 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/composer.json b/composer.json index 223376b..ddfdbaa 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/BaseScript.cs b/src/BaseScript.cs index 6e6a940..6e3fe66 100644 --- a/src/BaseScript.cs +++ b/src/BaseScript.cs @@ -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 @@ -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); } \ No newline at end of file diff --git a/src/DockerExecutorCSharpServiceProvider.php b/src/DockerExecutorCSharpServiceProvider.php index 680ec78..f052e5b 100644 --- a/src/DockerExecutorCSharpServiceProvider.php +++ b/src/DockerExecutorCSharpServiceProvider.php @@ -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() { @@ -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(); diff --git a/src/ScriptRunner.cs b/src/ScriptRunner.cs index 920ed7f..9b3be99 100644 --- a/src/ScriptRunner.cs +++ b/src/ScriptRunner.cs @@ -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 @@ -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()); } } diff --git a/src/ScriptRunner.csproj b/src/ScriptRunner.csproj index 4cd4983..faef3b1 100644 --- a/src/ScriptRunner.csproj +++ b/src/ScriptRunner.csproj @@ -7,9 +7,6 @@ - - bin/ProcessMakerSDK.dll -