-
Notifications
You must be signed in to change notification settings - Fork 0
Implement container reaper and shutdown hook functionality. #19
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "logs": { | ||
| "text": "report/infection/logs/infection-text.log", | ||
| "summary": "report/infection/logs/infection-summary.log" | ||
| }, | ||
| "tmpDir": "report/infection/cache/", | ||
| "minMsi": 100, | ||
| "timeout": 120, | ||
| "source": { | ||
| "directories": [ | ||
| "src" | ||
| ] | ||
| }, | ||
| "phpUnit": { | ||
| "configDir": "", | ||
| "customPath": "./vendor/bin/phpunit" | ||
| }, | ||
| "mutators": { | ||
| "@default": true | ||
| }, | ||
| "minCoveredMsi": 100, | ||
| "testFramework": "phpunit", | ||
| "testFrameworkOptions": "--testsuite=unit" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace TinyBlocks\DockerContainer\Internal\Commands; | ||
|
|
||
| final readonly class DockerReaper implements Command | ||
| { | ||
| private function __construct( | ||
| private string $reaperName, | ||
| private string $containerName, | ||
| private string $testRunnerHostname | ||
| ) { | ||
| } | ||
|
|
||
| public static function from(string $reaperName, string $containerName, string $testRunnerHostname): DockerReaper | ||
| { | ||
| return new DockerReaper( | ||
| reaperName: $reaperName, | ||
| containerName: $containerName, | ||
| testRunnerHostname: $testRunnerHostname | ||
| ); | ||
| } | ||
|
|
||
| public function toCommandLine(): string | ||
| { | ||
| $script = sprintf( | ||
| implode(' ', [ | ||
| 'while docker inspect %s >/dev/null 2>&1; do sleep 2; done;', | ||
| 'docker rm -fv %s 2>/dev/null;', | ||
| 'docker network prune -f --filter label=%s 2>/dev/null' | ||
| ]), | ||
| $this->testRunnerHostname, | ||
| $this->containerName, | ||
| DockerRun::MANAGED_LABEL | ||
| ); | ||
|
|
||
| return sprintf( | ||
| implode(' ', [ | ||
| 'docker run --rm -d --name %s --label %s', | ||
| '-v /var/run/docker.sock:/var/run/docker.sock', | ||
| 'docker:cli sh -c %s' | ||
| ]), | ||
| $this->reaperName, | ||
| DockerRun::MANAGED_LABEL, | ||
| escapeshellarg($script) | ||
| ); | ||
|
Comment on lines
+38
to
+47
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace TinyBlocks\DockerContainer\Internal\Containers; | ||
|
|
||
| use TinyBlocks\DockerContainer\Internal\Client\Client; | ||
| use TinyBlocks\DockerContainer\Internal\Commands\DockerList; | ||
| use TinyBlocks\DockerContainer\Internal\Commands\DockerReaper; | ||
| use TinyBlocks\DockerContainer\Internal\Containers\Models\Name; | ||
|
|
||
| final readonly class ContainerReaper | ||
| { | ||
| public function __construct(private Client $client) | ||
| { | ||
| } | ||
|
|
||
|
|
||
| public function ensureRunningFor(string $containerName): void | ||
| { | ||
|
gustavofreze marked this conversation as resolved.
|
||
| if (!file_exists('/.dockerenv')) { | ||
| return; | ||
| } | ||
|
|
||
| $reaperName = sprintf('tiny-blocks-reaper-%s', $containerName); | ||
| $reaperList = DockerList::from(name: Name::from(value: $reaperName)); | ||
| $reaperExists = !empty(trim($this->client->execute(command: $reaperList)->getOutput())); | ||
|
|
||
| if ($reaperExists) { | ||
| return; | ||
| } | ||
|
|
||
| $this->client->execute( | ||
| command: DockerReaper::from( | ||
| reaperName: $reaperName, | ||
| containerName: $containerName, | ||
| testRunnerHostname: gethostname() | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
mutation-testscript passes--coverage=report/coverage, but PHPUnit’s XML coverage is configured to be written underreport/coverage/coverage-xml(seephpunit.xml). If Infection expects the coverage-XML directory, this path mismatch can cause mutation testing to fail on a clean run. Consider pointing--coverageatreport/coverage/coverage-xml(or adjust PHPUnit’s output directory to match).