diff --git a/composer.json b/composer.json index bce539b..ff838c0 100755 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require": { "php": ">=8.0", - "utopia-php/cli": "0.14.*" + "utopia-php/cli": "0.16.*" }, "require-dev": { "phpunit/phpunit": "^9.3", diff --git a/composer.lock b/composer.lock index 92b7f04..726a142 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "61c6766ea435ba9e95b8efca270d15d4", + "content-hash": "f6f5a9aa8be54983b3488e4d0338c5db", "packages": [ { "name": "utopia-php/cli", - "version": "0.14.0", + "version": "0.16.0", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "c30ef985a4e739758a0d95eb0706b357b6d8c086" + "reference": "5b936638c90c86d1bae83d0dbe81fe14d12ff8ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/c30ef985a4e739758a0d95eb0706b357b6d8c086", - "reference": "c30ef985a4e739758a0d95eb0706b357b6d8c086", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/5b936638c90c86d1bae83d0dbe81fe14d12ff8ff", + "reference": "5b936638c90c86d1bae83d0dbe81fe14d12ff8ff", "shasum": "" }, "require": { @@ -25,8 +25,10 @@ "utopia-php/framework": "0.*.*" }, "require-dev": { + "laravel/pint": "1.2.*", "phpunit/phpunit": "^9.3", - "squizlabs/php_codesniffer": "^3.6" + "squizlabs/php_codesniffer": "^3.6", + "vimeo/psalm": "4.0.1" }, "type": "library", "autoload": { @@ -38,12 +40,6 @@ "license": [ "MIT" ], - "authors": [ - { - "name": "Eldad Fux", - "email": "eldad@appwrite.io" - } - ], "description": "A simple CLI library to manage command line applications", "keywords": [ "cli", @@ -55,22 +51,22 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/0.14.0" + "source": "https://github.com/utopia-php/cli/tree/0.16.0" }, - "time": "2022-10-09T10:19:07+00:00" + "time": "2023-08-05T13:13:08+00:00" }, { "name": "utopia-php/framework", - "version": "0.28.4", + "version": "0.29", "source": { "type": "git", "url": "https://github.com/utopia-php/framework.git", - "reference": "98c5469efe195aeecc63745dbf8e2f357f8cedac" + "reference": "1c8ed95fb73531b0508ad69f85dafc4c78a64414" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/98c5469efe195aeecc63745dbf8e2f357f8cedac", - "reference": "98c5469efe195aeecc63745dbf8e2f357f8cedac", + "url": "https://api.github.com/repos/utopia-php/framework/zipball/1c8ed95fb73531b0508ad69f85dafc4c78a64414", + "reference": "1c8ed95fb73531b0508ad69f85dafc4c78a64414", "shasum": "" }, "require": { @@ -78,9 +74,9 @@ }, "require-dev": { "laravel/pint": "^1.2", - "phpstan/phpstan": "1.9.x-dev", - "phpunit/phpunit": "^9.5.25", - "vimeo/psalm": "4.27.0" + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.5.25" }, "type": "library", "autoload": { @@ -100,9 +96,9 @@ ], "support": { "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.28.4" + "source": "https://github.com/utopia-php/framework/tree/0.29" }, - "time": "2023-06-03T14:09:22+00:00" + "time": "2023-07-30T07:56:23+00:00" } ], "packages-dev": [ @@ -747,16 +743,16 @@ }, { "name": "laravel/pint", - "version": "v1.10.3", + "version": "v1.10.5", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "c472786bca01e4812a9bb7933b23edfc5b6877b7" + "reference": "a458fb057bfa2f5a09888a8aa349610be807b0c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/c472786bca01e4812a9bb7933b23edfc5b6877b7", - "reference": "c472786bca01e4812a9bb7933b23edfc5b6877b7", + "url": "https://api.github.com/repos/laravel/pint/zipball/a458fb057bfa2f5a09888a8aa349610be807b0c3", + "reference": "a458fb057bfa2f5a09888a8aa349610be807b0c3", "shasum": "" }, "require": { @@ -767,9 +763,9 @@ "php": "^8.1.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.18.0", + "friendsofphp/php-cs-fixer": "^3.21.1", "illuminate/view": "^10.5.1", - "laravel-zero/framework": "^10.0.2", + "laravel-zero/framework": "^10.1.1", "mockery/mockery": "^1.5.1", "nunomaduro/larastan": "^2.5.1", "nunomaduro/termwind": "^1.15.1", @@ -809,7 +805,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2023-06-20T15:55:03+00:00" + "time": "2023-07-14T10:26:01+00:00" }, { "name": "myclabs/deep-copy", @@ -923,16 +919,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.15.5", + "version": "v4.16.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e" + "reference": "19526a33fb561ef417e822e85f08a00db4059c17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/11e2663a5bc9db5d714eedb4277ee300403b4a9e", - "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/19526a33fb561ef417e822e85f08a00db4059c17", + "reference": "19526a33fb561ef417e822e85f08a00db4059c17", "shasum": "" }, "require": { @@ -973,9 +969,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.5" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.16.0" }, - "time": "2023-05-19T20:20:00+00:00" + "time": "2023-06-25T14:52:30+00:00" }, { "name": "openlss/lib-array2xml", @@ -1311,16 +1307,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.22.0", + "version": "1.23.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c" + "reference": "846ae76eef31c6d7790fac9bc399ecee45160b26" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/ec58baf7b3c7f1c81b3b00617c953249fb8cf30c", - "reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/846ae76eef31c6d7790fac9bc399ecee45160b26", + "reference": "846ae76eef31c6d7790fac9bc399ecee45160b26", "shasum": "" }, "require": { @@ -1352,22 +1348,22 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.23.1" }, - "time": "2023-06-01T12:35:21+00:00" + "time": "2023-08-03T16:32:59+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.26", + "version": "9.2.27", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1" + "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/443bc6912c9bd5b409254a40f4b0f4ced7c80ea1", - "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/b0a88255cb70d52653d80c890bd7f38740ea50d1", + "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1", "shasum": "" }, "require": { @@ -1423,7 +1419,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.26" + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.27" }, "funding": [ { @@ -1431,7 +1428,7 @@ "type": "github" } ], - "time": "2023-03-06T12:58:08+00:00" + "time": "2023-07-26T13:44:30+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1676,16 +1673,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.9", + "version": "9.6.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a9aceaf20a682aeacf28d582654a1670d8826778" + "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a9aceaf20a682aeacf28d582654a1670d8826778", - "reference": "a9aceaf20a682aeacf28d582654a1670d8826778", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a6d351645c3fe5a30f5e86be6577d946af65a328", + "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328", "shasum": "" }, "require": { @@ -1759,7 +1756,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.9" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.10" }, "funding": [ { @@ -1775,7 +1772,7 @@ "type": "tidelift" } ], - "time": "2023-06-11T06:13:56+00:00" + "time": "2023-07-10T04:04:23+00:00" }, { "name": "psr/container", @@ -2386,16 +2383,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.5", + "version": "5.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" + "reference": "bde739e7565280bda77be70044ac1047bc007e34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", + "reference": "bde739e7565280bda77be70044ac1047bc007e34", "shasum": "" }, "require": { @@ -2438,7 +2435,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" }, "funding": [ { @@ -2446,7 +2443,7 @@ "type": "github" } ], - "time": "2022-02-14T08:28:10+00:00" + "time": "2023-08-02T09:26:13+00:00" }, { "name": "sebastian/lines-of-code", @@ -2846,16 +2843,16 @@ }, { "name": "symfony/console", - "version": "v5.4.24", + "version": "v5.4.26", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8" + "reference": "b504a3d266ad2bb632f196c0936ef2af5ff6e273" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8", - "reference": "560fc3ed7a43e6d30ea94a07d77f9a60b8ed0fb8", + "url": "https://api.github.com/repos/symfony/console/zipball/b504a3d266ad2bb632f196c0936ef2af5ff6e273", + "reference": "b504a3d266ad2bb632f196c0936ef2af5ff6e273", "shasum": "" }, "require": { @@ -2925,7 +2922,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.24" + "source": "https://github.com/symfony/console/tree/v5.4.26" }, "funding": [ { @@ -2941,7 +2938,7 @@ "type": "tidelift" } ], - "time": "2023-05-26T05:13:16+00:00" + "time": "2023-07-19T20:11:33+00:00" }, { "name": "symfony/deprecation-contracts", @@ -3586,16 +3583,16 @@ }, { "name": "symfony/string", - "version": "v6.3.0", + "version": "v6.3.2", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "f2e190ee75ff0f5eced645ec0be5c66fac81f51f" + "reference": "53d1a83225002635bca3482fcbf963001313fb68" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/f2e190ee75ff0f5eced645ec0be5c66fac81f51f", - "reference": "f2e190ee75ff0f5eced645ec0be5c66fac81f51f", + "url": "https://api.github.com/repos/symfony/string/zipball/53d1a83225002635bca3482fcbf963001313fb68", + "reference": "53d1a83225002635bca3482fcbf963001313fb68", "shasum": "" }, "require": { @@ -3652,7 +3649,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.3.0" + "source": "https://github.com/symfony/string/tree/v6.3.2" }, "funding": [ { @@ -3668,7 +3665,7 @@ "type": "tidelift" } ], - "time": "2023-03-21T21:06:29+00:00" + "time": "2023-07-05T08:41:27+00:00" }, { "name": "theseer/tokenizer", diff --git a/src/Orchestration/Adapter.php b/src/Orchestration/Adapter.php index ba26e79..4b394de 100644 --- a/src/Orchestration/Adapter.php +++ b/src/Orchestration/Adapter.php @@ -109,7 +109,7 @@ abstract public function run( * @param string[] $command * @param array $vars */ - abstract public function execute(string $name, array $command, string &$stdout, string &$stderr, array $vars = [], int $timeout = -1): bool; + abstract public function execute(string $name, array $command, string &$output, array $vars = [], int $timeout = -1): bool; /** * Remove Container diff --git a/src/Orchestration/Adapter/DockerAPI.php b/src/Orchestration/Adapter/DockerAPI.php index f434d35..71b1ef4 100644 --- a/src/Orchestration/Adapter/DockerAPI.php +++ b/src/Orchestration/Adapter/DockerAPI.php @@ -486,8 +486,7 @@ public function run( public function execute( string $name, array $command, - string &$stdout, - string &$stderr, + string &$output, array $vars = [], int $timeout = -1 ): bool { @@ -520,8 +519,7 @@ public function execute( $result = $this->streamCall('http://localhost/exec/'.$parsedResponse['Id'].'/start', $timeout); - $stdout = $result['stdout']; - $stderr = $result['stderr']; + $output = $result['stdout'].$result['stderr']; if ($result['code'] !== 200) { throw new Orchestration('Failed to create execute command: '.$result['response'].' Response Code: '.$result['code']); diff --git a/src/Orchestration/Adapter/DockerCLI.php b/src/Orchestration/Adapter/DockerCLI.php index 1ad474a..b5f75a7 100644 --- a/src/Orchestration/Adapter/DockerCLI.php +++ b/src/Orchestration/Adapter/DockerCLI.php @@ -22,11 +22,10 @@ class DockerCLI extends Adapter public function __construct(string $username = null, string $password = null) { if ($username && $password) { - $stdout = ''; - $stderr = ''; + $output = ''; - if (! Console::execute('docker login --username '.$username.' --password-stdin', $password, $stdout, $stderr)) { - throw new Orchestration("Docker Error: {$stderr}"); + if (! Console::execute('docker login --username '.$username.' --password-stdin', $password, $output)) { + throw new Orchestration("Docker Error: {$output}"); } } } @@ -36,10 +35,9 @@ public function __construct(string $username = null, string $password = null) */ public function createNetwork(string $name, bool $internal = false): bool { - $stdout = ''; - $stderr = ''; + $output = ''; - $result = Console::execute('docker network create '.$name.($internal ? '--internal' : ''), '', $stdout, $stderr); + $result = Console::execute('docker network create '.$name.($internal ? '--internal' : ''), '', $output); return $result === 0; } @@ -49,10 +47,9 @@ public function createNetwork(string $name, bool $internal = false): bool */ public function removeNetwork(string $name): bool { - $stdout = ''; - $stderr = ''; + $output = ''; - $result = Console::execute('docker network rm '.$name, '', $stdout, $stderr); + $result = Console::execute('docker network rm '.$name, '', $output); return $result === 0; } @@ -62,10 +59,9 @@ public function removeNetwork(string $name): bool */ public function networkConnect(string $container, string $network): bool { - $stdout = ''; - $stderr = ''; + $output = ''; - $result = Console::execute('docker network connect '.$network.' '.$container, '', $stdout, $stderr); + $result = Console::execute('docker network connect '.$network.' '.$container, '', $output); return $result === 0; } @@ -75,10 +71,9 @@ public function networkConnect(string $container, string $network): bool */ public function networkDisconnect(string $container, string $network, bool $force = false): bool { - $stdout = ''; - $stderr = ''; + $output = ''; - $result = Console::execute('docker network disconnect '.$network.' '.$container.($force ? ' --force' : ''), '', $stdout, $stderr); + $result = Console::execute('docker network disconnect '.$network.' '.$container.($force ? ' --force' : ''), '', $output); return $result === 0; } @@ -102,8 +97,7 @@ public function getStats(string $container = null, array $filters = []): array $containerIds[] = $container; } - $stdout = ''; - $stderr = ''; + $output = ''; if (\count($containerIds) <= 0 && \count($filters) > 0) { return []; // No containers found @@ -117,13 +111,13 @@ public function getStats(string $container = null, array $filters = []): array $containersString .= ' '.$containerId; } - $result = Console::execute('docker stats --no-trunc --format "id={{.ID}}&name={{.Name}}&cpu={{.CPUPerc}}&memory={{.MemPerc}}&diskIO={{.BlockIO}}&memoryIO={{.MemUsage}}&networkIO={{.NetIO}}" --no-stream'.$containersString, '', $stdout, $stderr); + $result = Console::execute('docker stats --no-trunc --format "id={{.ID}}&name={{.Name}}&cpu={{.CPUPerc}}&memory={{.MemPerc}}&diskIO={{.BlockIO}}&memoryIO={{.MemUsage}}&networkIO={{.NetIO}}" --no-stream'.$containersString, '', $output); if ($result !== 0) { - throw new Orchestration("Docker Error: {$stderr}"); + throw new Orchestration("Docker Error: {$output}"); } - $lines = \explode("\n", $stdout); + $lines = \explode("\n", $output); foreach ($lines as $line) { if (empty($line)) { @@ -201,17 +195,16 @@ private function parseIOStats(string $stats) */ public function listNetworks(): array { - $stdout = ''; - $stderr = ''; + $output = ''; - $result = Console::execute('docker network ls --format "id={{.ID}}&name={{.Name}}&driver={{.Driver}}&scope={{.Scope}}"', '', $stdout, $stderr); + $result = Console::execute('docker network ls --format "id={{.ID}}&name={{.Name}}&driver={{.Driver}}&scope={{.Scope}}"', '', $output); if ($result !== 0) { - throw new Orchestration("Docker Error: {$stderr}"); + throw new Orchestration("Docker Error: {$output}"); } $list = []; - $stdoutArray = \explode("\n", $stdout); + $stdoutArray = \explode("\n", $output); foreach ($stdoutArray as $value) { $network = []; @@ -233,10 +226,9 @@ public function listNetworks(): array */ public function pull(string $image): bool { - $stdout = ''; - $stderr = ''; + $output = ''; - $result = Console::execute('docker pull '.$image, '', $stdout, $stderr); + $result = Console::execute('docker pull '.$image, '', $output); return $result === 0; } @@ -249,8 +241,7 @@ public function pull(string $image): bool */ public function list(array $filters = []): array { - $stdout = ''; - $stderr = ''; + $output = ''; $filterString = ''; @@ -258,14 +249,14 @@ public function list(array $filters = []): array $filterString = $filterString.' --filter "'.$key.'='.$value.'"'; } - $result = Console::execute('docker ps --all --no-trunc --format "id={{.ID}}&name={{.Names}}&status={{.Status}}&labels={{.Labels}}"'.$filterString, '', $stdout, $stderr); + $result = Console::execute('docker ps --all --no-trunc --format "id={{.ID}}&name={{.Names}}&status={{.Status}}&labels={{.Labels}}"'.$filterString, '', $output); if ($result !== 0 && $result !== -1) { - throw new Orchestration("Docker Error: {$stderr}"); + throw new Orchestration("Docker Error: {$output}"); } $list = []; - $stdoutArray = \explode("\n", $stdout); + $stdoutArray = \explode("\n", $output); foreach ($stdoutArray as $value) { $container = []; @@ -318,8 +309,7 @@ public function run(string $image, bool $remove = false, string $network = '' ): string { - $stdout = ''; - $stderr = ''; + $output = ''; foreach ($command as $key => $value) { if (str_contains($value, ' ')) { @@ -376,13 +366,13 @@ public function run(string $image, (empty($hostname) ? '' : " --hostname {$hostname}"). (empty($vars) ? '' : ' '.\implode(' ', $vars)). " {$image}". - (empty($command) ? '' : ' '.implode(' ', $command)), '', $stdout, $stderr, 30); + (empty($command) ? '' : ' '.implode(' ', $command)), '', $output, 30); if ($result !== 0) { - throw new Orchestration("Docker Error: {$stderr}"); + throw new Orchestration("Docker Error: {$output}"); } - return rtrim($stdout); + return rtrim($output); } /** @@ -394,8 +384,7 @@ public function run(string $image, public function execute( string $name, array $command, - string &$stdout = '', - string &$stderr = '', + string &$output = '', array $vars = [], int $timeout = -1 ): bool { @@ -416,13 +405,13 @@ public function execute( $vars = $parsedVariables; - $result = Console::execute('docker exec '.\implode(' ', $vars)." {$name} ".implode(' ', $command), '', $stdout, $stderr, $timeout); + $result = Console::execute('docker exec '.\implode(' ', $vars)." {$name} ".implode(' ', $command), '', $output, $timeout); if ($result !== 0) { if ($result == 124) { throw new Timeout('Command timed out'); } else { - throw new Orchestration("Docker Error: {$stderr}"); + throw new Orchestration("Docker Error: {$output}"); } } @@ -434,13 +423,12 @@ public function execute( */ public function remove(string $name, bool $force = false): bool { - $stdout = ''; - $stderr = ''; + $output = ''; - $result = Console::execute('docker rm '.($force ? '--force' : '')." {$name}", '', $stdout, $stderr); + $result = Console::execute('docker rm '.($force ? '--force' : '')." {$name}", '', $output); - if (! str_contains($stdout, $name)) { - throw new Orchestration("Docker Error: {$stderr}"); + if (! \str_starts_with($output, $name) || \str_contains($output, 'No such container')) { + throw new Orchestration("Docker Error: {$output}"); } return ! $result; diff --git a/src/Orchestration/Orchestration.php b/src/Orchestration/Orchestration.php index 33e0445..3de956e 100644 --- a/src/Orchestration/Orchestration.php +++ b/src/Orchestration/Orchestration.php @@ -180,12 +180,11 @@ public function run( public function execute( string $name, array $command, - string &$stdout, - string &$stderr, + string &$output, array $vars = [], int $timeout = -1 ): bool { - return $this->adapter->execute($name, $command, $stdout, $stderr, $vars, $timeout); + return $this->adapter->execute($name, $command, $output, $vars, $timeout); } /** diff --git a/tests/Orchestration/Base.php b/tests/Orchestration/Base.php index d23aca2..2f8e1dd 100644 --- a/tests/Orchestration/Base.php +++ b/tests/Orchestration/Base.php @@ -186,8 +186,7 @@ public function testRemoveNetwork(): void */ public function testExecContainer(): void { - $stdout = ''; - $stderr = ''; + $output = ''; $response = static::getOrchestration()->execute( 'TestContainer', @@ -195,20 +194,18 @@ public function testExecContainer(): void 'php', 'index.php', ], - $stdout, - $stderr, + $output, [ 'test' => 'testEnviromentVariable', ], ); - $this->assertEquals('Hello World! testEnviromentVariable', $stdout); + $this->assertEquals('Hello World! testEnviromentVariable', $output); /** * Test for Failure */ - $stdout = ''; - $stderr = ''; + $output = ''; $this->expectException(\Exception::class); @@ -218,8 +215,7 @@ public function testExecContainer(): void 'php', 'index.php', ], - $stdout, - $stderr + $output ); } @@ -228,8 +224,7 @@ public function testExecContainer(): void */ public function testCheckVolume(): void { - $stdout = ''; - $stderr = ''; + $output = ''; $response = static::getOrchestration()->execute( 'TestContainer', @@ -237,11 +232,10 @@ public function testCheckVolume(): void 'cat', '/test/testfile.txt', ], - $stdout, - $stderr + $output ); - $this->assertEquals('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras dapibus turpis mauris, ac consectetur odio varius ullamcorper.', $stdout); + $this->assertEquals('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras dapibus turpis mauris, ac consectetur odio varius ullamcorper.', $output); } /** @@ -277,8 +271,7 @@ public function testTimeoutContainer(): void /** * Test for Failure */ - $stdout = ''; - $stderr = ''; + $output = ''; $this->expectException(\Exception::class); @@ -288,8 +281,7 @@ public function testTimeoutContainer(): void 'php', 'index.php', ], - $stdout, - $stderr, + $output, [], 1 ); @@ -297,8 +289,7 @@ public function testTimeoutContainer(): void /** * Test for Success */ - $stdout = ''; - $stderr = ''; + $output = ''; $response = static::getOrchestration()->execute( 'TestContainerTimeout', @@ -306,8 +297,7 @@ public function testTimeoutContainer(): void 'php', 'index.php', ], - $stdout, - $stderr, + $output, [], 10 ); @@ -317,8 +307,7 @@ public function testTimeoutContainer(): void /** * Test for Success */ - $stdout = ''; - $stderr = ''; + $output = ''; $response = static::getOrchestration()->execute( 'TestContainerTimeout', @@ -327,13 +316,12 @@ public function testTimeoutContainer(): void '-c', 'echo Hello World!', ], - $stdout, - $stderr, + $output, [], 10 ); - $this->assertEquals('Hello World!', $stdout); + $this->assertEquals('Hello World!', $output); $this->assertEquals(true, $response); } @@ -504,10 +492,9 @@ public function testUsageStats(): void $this->assertNotEmpty($containerId2); // This allows CPU-heavy load check - $stdout = ''; - $stderr = ''; - static::getOrchestration()->execute($containerId1, ['screen', '-d', '-m', "'stress --cpu 1 --timeout 5'"], $stdout, $stderr); // Run in screen so it's background task - static::getOrchestration()->execute($containerId2, ['screen', '-d', '-m', "'stress --cpu 1 --timeout 5'"], $stdout, $stderr); + $output = ''; + static::getOrchestration()->execute($containerId1, ['screen', '-d', '-m', "'stress --cpu 1 --timeout 5'"], $output); // Run in screen so it's background task + static::getOrchestration()->execute($containerId2, ['screen', '-d', '-m', "'stress --cpu 1 --timeout 5'"], $output); // Set CPU stress-test start \sleep(1);