Skip to content

Truncate docker output log and display more info #3203

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 3 commits into from
Jun 18, 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
6 changes: 5 additions & 1 deletion ProcessMaker/Models/ScriptDockerBindingFilesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ private function runContainer($image, $command, $parameters, $bindings, $timeout
);
}
Log::error('Script threw return code ' . $returnCode . 'Message: ' . implode("\n", $output));
throw new ScriptException(implode("\n", $output));

$message = implode("\n", $output);
$message .= "\n\nProcessMaker Stack:\n";
$message .= (new \Exception)->getTraceAsString();
throw new ScriptException($message);
}
$outputs = $this->getOutputFilesContent();
$this->removeTemporalFiles();
Expand Down
8 changes: 6 additions & 2 deletions ProcessMaker/Models/ScriptDockerCopyingFilesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Log;
use RuntimeException;
use ProcessMaker\Exception\ScriptTimeoutException;
use ProcessMaker\Exception\ScriptException;

/**
* Execute a docker container copying files to interchange information.
Expand Down Expand Up @@ -51,7 +52,7 @@ private function createContainer($image, $command, $parameters = '')
{
$cidfile = tempnam(config('app.processmaker_scripts_home'), 'cid');
unlink($cidfile);
$cmd = config('app.processmaker_scripts_docker') . sprintf(' create %s --cidfile %s %s %s 2>&1', $parameters, $cidfile, $image, $command);
$cmd = config('app.processmaker_scripts_docker') . sprintf(' create --network=host %s --cidfile %s %s %s 2>&1', $parameters, $cidfile, $image, $command);
$line = exec($cmd, $output, $returnCode);
if ($returnCode) {
throw new RuntimeException('Unable to create a docker container: ' . implode("\n", $output));
Expand Down Expand Up @@ -150,7 +151,10 @@ private function startContainer($container, $timeout)
throw new ScriptTimeoutException(implode("\n", $output));
}
Log::error('Script threw return code ' . $returnCode);
throw new ScriptException(implode("\n", $output));
$message = implode("\n", $output);
$message .= "\n\nProcessMaker Stack:\n";
$message .= (new \Exception)->getTraceAsString();
throw new ScriptException($message);
}
return compact('line', 'output', 'returnCode');
}
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/ScriptRunners/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function run($code, array $data, array $config, $timeout, ?User $user)
$returnCode = $response['returnCode'];
$stdOutput = $response['output'];
$output = $response['outputs']['response'];
\Log::debug("Docker returned: " . json_encode($response));
\Log::debug("Docker returned: " . substr(json_encode($response), 0, 500));
if ($returnCode || $stdOutput) {
// Has an error code
throw new RuntimeException(implode("\n", $stdOutput));
Expand Down
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@
Artisan::call('migrate:fresh', []);
}

if (count(ScriptExecutor::listOfExecutorImages('php')) === 0) {
if (ScriptExecutor::where('language', 'php')->count() === 0) {
Artisan::call('docker-executor-php:install');
}

if (count(ScriptExecutor::listOfExecutorImages('lua')) === 0) {
if (ScriptExecutor::where('language', 'lua')->count() === 0) {
Artisan::call('docker-executor-lua:install');
}