-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerReaper.php
More file actions
41 lines (32 loc) · 1.12 KB
/
ContainerReaper.php
File metadata and controls
41 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
{
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()
)
);
}
}