From d960d4dab80cf40e81b5e2ec8c69df40cc087ebb Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Tue, 10 Mar 2020 13:13:21 -0700 Subject: [PATCH 1/6] Build this docker image as a base image --- Dockerfile | 14 -------------- README.md | 5 +++++ composer.json | 2 +- src/DockerExecutorPhpServiceProvider.php | 16 +++++++--------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index e7467b8..531a13e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,17 +15,3 @@ RUN apt-get update && apt-get install -y git zip unzip RUN composer install -## -## Below is temporary until this is converted to a base image -## - -# Get the sdk repo if it doesn't exist -RUN apt-get update && apt-get install -y git -RUN if [ ! -d "sdk-php" ]; then git clone --depth 1 https://github.com/ProcessMaker/sdk-php.git; fi -RUN mv sdk-php /opt/ -RUN composer config repositories.sdk-php path /opt/sdk-php -RUN composer require ProcessMaker/sdk-php:@dev - -# Get the last AWS-SDK version -RUN apt-get install zip unzip -y -RUN composer require aws/aws-sdk-php \ No newline at end of file diff --git a/README.md b/README.md index 868f27a..e66ce8b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +# Build +``` +docker build -t processmaker4/executor-php:latest . +``` + # executor-php Script Task Executor Engine with PHP Runtime diff --git a/composer.json b/composer.json index d4c0ec8..63b67f5 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "processmaker/docker-executor-php", "friendly_name": "PHP Docker Executor", "description": "PHP script executor for processmaker 4", - "version": "0.0.1", + "version": "1.0.0", "minimum-stability": "dev", "autoload": { "psr-4": { diff --git a/src/DockerExecutorPhpServiceProvider.php b/src/DockerExecutorPhpServiceProvider.php index d3209f9..f542ae4 100644 --- a/src/DockerExecutorPhpServiceProvider.php +++ b/src/DockerExecutorPhpServiceProvider.php @@ -9,7 +9,7 @@ class DockerExecutorPhpServiceProvider extends ServiceProvider { use PluginServiceProviderTrait; - const version = '0.0.1'; // Required for PluginServiceProviderTrait + const version = '1.0.0'; // Required for PluginServiceProviderTrait public function register() { @@ -17,26 +17,24 @@ public function register() public function boot() { - $image = env('SCRIPTS_PHP_IMAGE', 'processmaker4/executor-php'); - $dockerDir = sys_get_temp_dir() . "/pm4-docker-builds/php"; - $sdkDir = $dockerDir . "/sdk"; + // Note: `processmaker4/executor-php` is now the base image that the instance inherits from + $image = env('SCRIPTS_PHP_IMAGE', 'processmaker4/executor-instance-php:v1.0.0'); \Artisan::command('docker-executor-php:install', function () { // Restart the workers so they know about the new supported language \Artisan::call('horizon:terminate'); - }); - \Artisan::command('docker-executor-php:build-base', function () { - system("docker build -t processmaker4/base-php:latest " . __DIR__ . '/..'); + // Build the base image that `executor-instance-php` inherits from + system("docker build -t processmaker4/executor-php:latest " . __DIR__ . '/..'); }); - + $config = [ 'name' => 'PHP', 'runner' => 'PhpRunner', 'mime_type' => 'application/x-php', 'image' => $image, 'options' => ['invokerPackage' => "ProcessMaker\\Client"], - 'init_dockerfile' => "FROM processmaker4/base-php:latest\nCOPY ./sdk /opt/pm4-sdk\nRUN composer config repositories.pm4-sdk path /opt/pm4-sdk\nRUN composer require ProcessMaker/sdk-php:@dev", + 'init_dockerfile' => "FROM processmaker4/executor-php:latest\nARG SDK_DIR\n", ]; config(['script-runners.php' => $config]); From d82bd8c1b1b0a0ae810a8fb1c3a0e5d94d0d5850 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Mon, 23 Mar 2020 09:04:18 -0700 Subject: [PATCH 2/6] Update provider for new executor settings --- .gitignore | 1 + Dockerfile | 4 +--- src/DockerExecutorPhpServiceProvider.php | 26 ++++++++++++++++++------ src/bootstrap.php | 2 +- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index cee46cc..cec3d23 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ src/vendor +sdk diff --git a/Dockerfile b/Dockerfile index 531a13e..0a17e4e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,3 @@ -# Bring in from PHP docker image FROM php:7.2.8-cli-stretch # Copy over our PHP libraries/runtime @@ -13,5 +12,4 @@ RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer RUN apt-get update && apt-get install -y git zip unzip -RUN composer install - +RUN composer install \ No newline at end of file diff --git a/src/DockerExecutorPhpServiceProvider.php b/src/DockerExecutorPhpServiceProvider.php index f542ae4..51c1eb0 100644 --- a/src/DockerExecutorPhpServiceProvider.php +++ b/src/DockerExecutorPhpServiceProvider.php @@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use ProcessMaker\Traits\PluginServiceProviderTrait; +use ProcessMaker\Models\ScriptExecutor; class DockerExecutorPhpServiceProvider extends ServiceProvider { @@ -17,15 +18,22 @@ public function register() public function boot() { - // Note: `processmaker4/executor-php` is now the base image that the instance inherits from - $image = env('SCRIPTS_PHP_IMAGE', 'processmaker4/executor-instance-php:v1.0.0'); + // Docker containers are built for a specific script executor ID `{id}` + // This is replaced on execution. + $image = env('SCRIPTS_PHP_IMAGE', 'processmaker4/executor-php-{id}:latest'); \Artisan::command('docker-executor-php:install', function () { + $scriptExecutor = ScriptExecutor::install([ + 'language' => 'php', + 'title' => 'PHP Executor', + 'description' => 'Default PHP 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 ' . $scriptExecutor->id); + // Restart the workers so they know about the new supported language \Artisan::call('horizon:terminate'); - - // Build the base image that `executor-instance-php` inherits from - system("docker build -t processmaker4/executor-php:latest " . __DIR__ . '/..'); }); $config = [ @@ -34,7 +42,13 @@ public function boot() 'mime_type' => 'application/x-php', 'image' => $image, 'options' => ['invokerPackage' => "ProcessMaker\\Client"], - 'init_dockerfile' => "FROM processmaker4/executor-php:latest\nARG SDK_DIR\n", + 'init_dockerfile' => [ + 'ARG SDK_DIR', + 'COPY $SDK_DIR /opt/sdk-php', + 'RUN composer config repositories.sdk-php path /opt/sdk-php', + 'RUN composer require processmaker/sdk-php:@dev', + ], + 'package_path' => __DIR__ . '/..' ]; config(['script-runners.php' => $config]); diff --git a/src/bootstrap.php b/src/bootstrap.php index 5cbcc0f..0a52816 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -35,7 +35,7 @@ exit(SCRIPT_PATH_INVALID); } -if (getenv('API_TOKEN') && getenv('API_HOST')) { +if (getenv('API_TOKEN') && getenv('API_HOST') && class_exists('ProcessMaker\Client\Configuration')) { $api_config = new ProcessMaker\Client\Configuration(); $api_config->setAccessToken(getenv('API_TOKEN')); $api_config->setHost(getenv('API_HOST')); From 410946580d2916b5891b1812d822354b6532abab Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Mon, 23 Mar 2020 09:18:16 -0700 Subject: [PATCH 3/6] Add the aws sdk in the default executor --- src/DockerExecutorPhpServiceProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DockerExecutorPhpServiceProvider.php b/src/DockerExecutorPhpServiceProvider.php index 51c1eb0..2a21dd4 100644 --- a/src/DockerExecutorPhpServiceProvider.php +++ b/src/DockerExecutorPhpServiceProvider.php @@ -26,7 +26,8 @@ public function boot() $scriptExecutor = ScriptExecutor::install([ 'language' => 'php', 'title' => 'PHP Executor', - 'description' => 'Default PHP Executor' + 'description' => 'Default PHP Executor', + 'config' => 'RUN composer require aws/aws-sdk-php' ]); // Build the instance image. This is the same as if you were to build it from the admin UI From 21800be2dd2c0246091afd625916754a6911e2a3 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Mon, 23 Mar 2020 12:24:26 -0700 Subject: [PATCH 4/6] Let the executor in core determine the image name --- src/DockerExecutorPhpServiceProvider.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/DockerExecutorPhpServiceProvider.php b/src/DockerExecutorPhpServiceProvider.php index 2a21dd4..e5d4d4e 100644 --- a/src/DockerExecutorPhpServiceProvider.php +++ b/src/DockerExecutorPhpServiceProvider.php @@ -18,10 +18,6 @@ public function register() public function boot() { - // Docker containers are built for a specific script executor ID `{id}` - // This is replaced on execution. - $image = env('SCRIPTS_PHP_IMAGE', 'processmaker4/executor-php-{id}:latest'); - \Artisan::command('docker-executor-php:install', function () { $scriptExecutor = ScriptExecutor::install([ 'language' => 'php', @@ -41,7 +37,6 @@ public function boot() 'name' => 'PHP', 'runner' => 'PhpRunner', 'mime_type' => 'application/x-php', - 'image' => $image, 'options' => ['invokerPackage' => "ProcessMaker\\Client"], 'init_dockerfile' => [ 'ARG SDK_DIR', From 1d754a531302b244eac58e4403c551eefa8df84e Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Tue, 24 Mar 2020 15:22:16 -0700 Subject: [PATCH 5/6] Add package version to config --- src/DockerExecutorPhpServiceProvider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DockerExecutorPhpServiceProvider.php b/src/DockerExecutorPhpServiceProvider.php index e5d4d4e..f55b8d8 100644 --- a/src/DockerExecutorPhpServiceProvider.php +++ b/src/DockerExecutorPhpServiceProvider.php @@ -44,7 +44,8 @@ public function boot() 'RUN composer config repositories.sdk-php path /opt/sdk-php', 'RUN composer require processmaker/sdk-php:@dev', ], - 'package_path' => __DIR__ . '/..' + 'package_path' => __DIR__ . '/..', + 'package_version' => self::version, ]; config(['script-runners.php' => $config]); From 0b071553272fc414bd2505bcae990e145d7c1520 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Wed, 25 Mar 2020 07:27:47 -0700 Subject: [PATCH 6/6] Test removing horizon call for circleci --- src/DockerExecutorPhpServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DockerExecutorPhpServiceProvider.php b/src/DockerExecutorPhpServiceProvider.php index f55b8d8..71b2c25 100644 --- a/src/DockerExecutorPhpServiceProvider.php +++ b/src/DockerExecutorPhpServiceProvider.php @@ -30,7 +30,7 @@ public function boot() \Artisan::call('processmaker:build-script-executor ' . $scriptExecutor->id); // Restart the workers so they know about the new supported language - \Artisan::call('horizon:terminate'); + // \Artisan::call('horizon:terminate'); }); $config = [