From e619a55937c91a114a7d0ee466eafbc27817f7af Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Wed, 18 Mar 2020 11:09:27 -0700 Subject: [PATCH 1/4] Allow for custom builds in core --- Dockerfile | 23 +++++++----------- README.md | 2 +- composer.json | 2 +- src/DockerExecutorCSharpServiceProvider.php | 24 ++++++++++++++----- storage/docker-build-config/Dockerfile-csharp | 9 +++++++ 5 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 storage/docker-build-config/Dockerfile-csharp diff --git a/Dockerfile b/Dockerfile index e1c5d1c..ab6c841 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,15 @@ # 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/DockerExecutorCSharpServiceProvider.php b/src/DockerExecutorCSharpServiceProvider.php index 680ec78..3881118 100644 --- a/src/DockerExecutorCSharpServiceProvider.php +++ b/src/DockerExecutorCSharpServiceProvider.php @@ -4,14 +4,12 @@ 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; 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,7 +26,20 @@ public function register() public function boot() { \Artisan::command('docker-executor-csharp:install', function () { - // nothing to do here + // Copy the default custom dockerfile to the storage folder + copy( + __DIR__ . '/../storage/docker-build-config/Dockerfile-csharp', + storage_path("docker-build-config/Dockerfile-csharp") + ); + + // Restart the workers so they know about the new supported language + \Artisan::call('horizon:terminate'); + + // Build the base image that `executor-instance-csharp` inherits from + system("docker build -t processmaker4/executor-csharp:latest " . __DIR__ . '/..'); + + // 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'); }); $config = [ @@ -38,11 +49,12 @@ public function boot() 'image' => env('SCRIPTS_CSHARP_IMAGE', 'processmaker4/executor-csharp'), 'options' => [ 'packageName' => "ProcessMakerSDK", - ] + ], + 'init_dockerfile' => "FROM processmaker4/executor-csharp:latest\nARG SDK_DIR\n", ]; 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/storage/docker-build-config/Dockerfile-csharp b/storage/docker-build-config/Dockerfile-csharp new file mode 100644 index 0000000..610c0ae --- /dev/null +++ b/storage/docker-build-config/Dockerfile-csharp @@ -0,0 +1,9 @@ +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 From 21b0c89a376d93d69394d770d2d9ebe72feda9e4 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Mon, 23 Mar 2020 15:09:05 -0700 Subject: [PATCH 2/4] Temporarily remove the sdk since it won't build --- src/BaseScript.cs | 3 +-- src/ScriptRunner.cs | 9 ++++----- src/ScriptRunner.csproj | 3 --- 3 files changed, 5 insertions(+), 10 deletions(-) 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/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 - From b7d375c5116a0df05cd6b2edb721fd8d4b98f5f6 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Mon, 23 Mar 2020 15:09:29 -0700 Subject: [PATCH 3/4] Make it work with dynamic executors --- .gitignore | 1 + Dockerfile | 1 - src/DockerExecutorCSharpServiceProvider.php | 33 +++++++++++-------- storage/docker-build-config/Dockerfile-csharp | 9 ----- 4 files changed, 21 insertions(+), 23 deletions(-) create mode 100644 .gitignore delete mode 100644 storage/docker-build-config/Dockerfile-csharp 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 ab6c841..eb5837b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -# Bring in from Mono docker image FROM mcr.microsoft.com/dotnet/core/sdk:2.2 RUN apt update diff --git a/src/DockerExecutorCSharpServiceProvider.php b/src/DockerExecutorCSharpServiceProvider.php index 3881118..9b6d9ef 100644 --- a/src/DockerExecutorCSharpServiceProvider.php +++ b/src/DockerExecutorCSharpServiceProvider.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use ProcessMaker\Traits\PluginServiceProviderTrait; +use ProcessMaker\Models\ScriptExecutor; class DockerExecutorCSharpServiceProvider extends ServiceProvider { @@ -26,31 +27,37 @@ public function register() public function boot() { \Artisan::command('docker-executor-csharp:install', function () { - // Copy the default custom dockerfile to the storage folder - copy( - __DIR__ . '/../storage/docker-build-config/Dockerfile-csharp', - storage_path("docker-build-config/Dockerfile-csharp") - ); - - // Restart the workers so they know about the new supported language - \Artisan::call('horizon:terminate'); - - // Build the base image that `executor-instance-csharp` inherits from - system("docker build -t processmaker4/executor-csharp:latest " . __DIR__ . '/..'); + $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' => "FROM processmaker4/executor-csharp:latest\nARG SDK_DIR\n", + '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__ . '/..', ]; config(['script-runners.csharp' => $config]); diff --git a/storage/docker-build-config/Dockerfile-csharp b/storage/docker-build-config/Dockerfile-csharp deleted file mode 100644 index 610c0ae..0000000 --- a/storage/docker-build-config/Dockerfile-csharp +++ /dev/null @@ -1,9 +0,0 @@ -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 From af4883b9a6b5c8e539c36177a010172284c342b3 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Tue, 24 Mar 2020 15:23:00 -0700 Subject: [PATCH 4/4] Add package version to config --- src/DockerExecutorCSharpServiceProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DockerExecutorCSharpServiceProvider.php b/src/DockerExecutorCSharpServiceProvider.php index 9b6d9ef..f052e5b 100644 --- a/src/DockerExecutorCSharpServiceProvider.php +++ b/src/DockerExecutorCSharpServiceProvider.php @@ -58,6 +58,7 @@ public function boot() '# RUN mv ../sdk-csharp/bin . && rm -rf ../sdk-csharp', ], 'package_path' => __DIR__ . '/..', + 'package_version' => self::version, ]; config(['script-runners.csharp' => $config]);