Skip to content

Commit f1e1b24

Browse files
bwaidelichgolorodenclaude
authored
fix: test container setup with SigningKey (#64)
Co-authored-by: Golo Roden <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent f6fa24a commit f1e1b24

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/Container.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class Container
1818
private string $apiToken = 'secret';
1919
private ?SigningKey $signingKey = null;
2020
private ?StartedGenericContainer $container = null;
21+
private ?string $tempSigningKeyFile = null;
2122

2223
public function withImageTag(string $tag): self
2324
{
@@ -57,26 +58,25 @@ public function start(): void
5758
'--http-enabled',
5859
'--https-enabled=false',
5960
];
60-
$content = [];
6161

6262
if ($this->signingKey instanceof SigningKey) {
6363
$command[] = '--signing-key-file';
6464
$command[] = '/etc/esdb/signing-key.pem';
65+
}
66+
67+
$container = (new GenericContainer("{$this->imageName}:{$this->imageTag}"))
68+
->withExposedPorts($this->internalPort)
69+
->withCommand($command);
70+
71+
if ($this->signingKey instanceof SigningKey) {
72+
$this->tempSigningKeyFile = getcwd() . '/.esdb_signing_key_' . uniqid();
73+
file_put_contents($this->tempSigningKeyFile, $this->signingKey->privateKeyPem);
74+
chmod($this->tempSigningKeyFile, 0o644);
6575

66-
$content[] = [
67-
'content' => $this->signingKey->privateKeyPem,
68-
'target' => '/etc/esdb/signing-key.pem',
69-
'mode' => 0o777,
70-
];
76+
$container = $container->withMount($this->tempSigningKeyFile, '/etc/esdb/signing-key.pem');
7177
}
7278

73-
$container =
74-
(new GenericContainer("{$this->imageName}:{$this->imageTag}"))
75-
->withExposedPorts($this->internalPort)
76-
->withCommand($command)
77-
->withCopyContentToContainer($content)
78-
->withWait((new WaitForHttp($this->internalPort, 20000))->withPath('/api/v1/ping'))
79-
;
79+
$container = $container->withWait((new WaitForHttp($this->internalPort, 20000))->withPath('/api/v1/ping'));
8080

8181
try {
8282
$this->container = $container->start();
@@ -139,6 +139,11 @@ public function stop(): void
139139
$this->container->stop();
140140
$this->container = null;
141141
}
142+
143+
if ($this->tempSigningKeyFile !== null && file_exists($this->tempSigningKeyFile)) {
144+
unlink($this->tempSigningKeyFile);
145+
$this->tempSigningKeyFile = null;
146+
}
142147
}
143148

144149
public function getClient(): Client

0 commit comments

Comments
 (0)