Skip to content

Build this docker image as a base image #6

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 6 commits into from
Mar 31, 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
@@ -1 +1,2 @@
src/vendor
sdk
18 changes: 1 addition & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Bring in from PHP docker image
FROM php:7.2.8-cli-stretch

# Copy over our PHP libraries/runtime
Expand All @@ -13,19 +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

##
## 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
RUN composer install
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Build
```
docker build -t processmaker4/executor-php:latest .
```

# executor-php
Script Task Executor Engine with PHP Runtime

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-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": {
Expand Down
33 changes: 21 additions & 12 deletions src/DockerExecutorPhpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,48 @@
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use ProcessMaker\Traits\PluginServiceProviderTrait;
use ProcessMaker\Models\ScriptExecutor;

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()
{
}

public function boot()
{
$image = env('SCRIPTS_PHP_IMAGE', 'processmaker4/executor-php');
$dockerDir = sys_get_temp_dir() . "/pm4-docker-builds/php";
$sdkDir = $dockerDir . "/sdk";

\Artisan::command('docker-executor-php:install', function () {
$scriptExecutor = ScriptExecutor::install([
'language' => 'php',
'title' => '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
\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');
});

\Artisan::command('docker-executor-php:build-base', function () {
system("docker build -t processmaker4/base-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' => [
'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__ . '/..',
'package_version' => self::version,
];
config(['script-runners.php' => $config]);

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down