Skip to content

Commit 285056c

Browse files
authored
Merge pull request #8672 from ProcessMaker/feature/FOUR-27925
FOUR-28753: [TCE] Military V1 - Phase 1: Update Script Executor for Intake
2 parents 72ae527 + bb21d76 commit 285056c

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

ProcessMaker/Console/Commands/BuildScriptExecutors.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ class BuildScriptExecutors extends Command
1818
*
1919
* @var string
2020
*/
21-
protected $signature = 'processmaker:build-script-executor {lang} {user?} {--rebuild}';
21+
protected $signature = 'processmaker:build-script-executor
22+
{lang : The ID or language of the script executor}
23+
{user? : The user ID to send the broadcast event to}
24+
{--rebuild : Rebuild the docker image}
25+
{--build-args= : The build arguments for the docker build command}';
2226

2327
/**
2428
* The console command description.
@@ -159,6 +163,12 @@ public function buildExecutor()
159163
$command = Docker::command() .
160164
" build --build-arg SDK_DIR=./sdk -t {$image} -f {$packagePath}/Dockerfile.custom {$packagePath}";
161165

166+
$buildArgs = $this->getBuildArgs();
167+
168+
foreach ($buildArgs as $buildArg) {
169+
$command .= ' ' . $buildArg;
170+
}
171+
162172
$this->execCommand($command);
163173

164174
$isNayra = $scriptExecutor->language === Base::NAYRA_LANG;
@@ -167,6 +177,29 @@ public function buildExecutor()
167177
}
168178
}
169179

180+
/**
181+
* Get the build arguments for the docker build command.
182+
*
183+
* @return array
184+
* - '--build-arg <key>=<value>'
185+
*/
186+
public function getBuildArgs(): array
187+
{
188+
$args = $this->option('build-args');
189+
190+
if ($args) {
191+
$buildArgs = [];
192+
193+
foreach (explode(',', $args) as $arg) {
194+
$buildArgs[] = '--build-arg ' . $arg;
195+
}
196+
197+
return $buildArgs;
198+
}
199+
200+
return [];
201+
}
202+
170203
public function getDockerfileContent(ScriptExecutor $scriptExecutor): string
171204
{
172205
$lang = $scriptExecutor->language;

ProcessMaker/Models/ScriptDockerNayraTrait.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ trait ScriptDockerNayraTrait
2323
{
2424

2525
private $schema = 'http';
26-
public static $nayraPort = 8080;
2726

2827
/**
2928
* Execute the script task using Nayra Docker.
@@ -82,7 +81,7 @@ public function handleNayraDocker(string $code, array $data, array $config, $tim
8281
private function getNayraInstanceUrl()
8382
{
8483
$servers = self::getNayraAddresses();
85-
return $this->schema . '://' . $servers[0] . ':' . static::$nayraPort;
84+
return $this->schema . '://' . $servers[0] . ':' . $this->getNayraPort();
8685
}
8786

8887
private function getDockerLogs($instanceName)
@@ -131,11 +130,14 @@ private function bringUpNayra($restart = false)
131130
if ($status) {
132131
$this->bringUpNayraContainer();
133132
} else {
134-
133+
$isHost = config('app.nayra_docker_network') === 'host';
134+
$portMapping = $isHost ? '-e PORT=' . $this->getNayraPort() . ' ' : '-p ' . $this->getNayraPort() . ':8080 ';
135135
exec($docker . " stop {$instanceName}_nayra 2>&1 || true");
136136
exec($docker . " rm {$instanceName}_nayra 2>&1 || true");
137137
exec(
138-
$docker . ' run -d --name ' . $instanceName . '_nayra '
138+
$docker . ' run -d '
139+
. ($this->getNayraPort() !== 8080 ? $portMapping : '')
140+
. '--name ' . $instanceName . '_nayra '
139141
. (config('app.nayra_docker_network')
140142
? '--network=' . config('app.nayra_docker_network') . ' '
141143
: '')
@@ -322,4 +324,9 @@ public static function initNayraPhpUnitTest()
322324
}
323325
}
324326
}
327+
328+
private function getNayraPort()
329+
{
330+
return config('app.nayra_port', 8080);
331+
}
325332
}

config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
'force_https' => env('FORCE_HTTPS', true),
258258

259259
'nayra_docker_network' => env('NAYRA_DOCKER_NETWORK', 'host'),
260+
'nayra_port' => env('NAYRA_PORT', 8080),
260261

261262
// Process Request security log rate limit: 1 per day (86400 seconds)
262263
'process_request_errors_rate_limit' => env('PROCESS_REQUEST_ERRORS_RATE_LIMIT', 1),

0 commit comments

Comments
 (0)