Skip to content

Commit 57817f4

Browse files
golorodenclaude
andcommitted
fix: Use current directory for temp signing key file with proper cleanup
Changes: - Use current directory (getcwd()) instead of sys_get_temp_dir() for better CI compatibility with Docker mounts - Add cleanup of temp file in stop() method to avoid leaving files behind - Store temp file path in private property for cleanup The mount approach works better than copy methods because the file must be available when the container starts (not after). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 25c67ae commit 57817f4

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/Container.php

Lines changed: 13 additions & 7 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
{
@@ -68,15 +69,14 @@ public function start(): void
6869
->withCommand($command);
6970

7071
if ($this->signingKey instanceof SigningKey) {
71-
// Create a temporary file with the signing key
72-
$tempFile = tempnam(sys_get_temp_dir(), 'esdb_signing_key_');
73-
if ($tempFile === false) {
74-
throw new RuntimeException('Failed to create temporary file for signing key.');
75-
}
76-
file_put_contents($tempFile, $this->signingKey->privateKeyPem);
72+
// Create a temporary file with the signing key in the current directory
73+
// Using current directory instead of sys_get_temp_dir() for better CI compatibility
74+
$this->tempSigningKeyFile = getcwd() . '/.esdb_signing_key_' . uniqid();
75+
file_put_contents($this->tempSigningKeyFile, $this->signingKey->privateKeyPem);
76+
chmod($this->tempSigningKeyFile, 0o644);
7777

7878
// Mount the temp file into the container
79-
$container = $container->withMount($tempFile, '/tmp/signing-key.pem');
79+
$container = $container->withMount($this->tempSigningKeyFile, '/tmp/signing-key.pem');
8080
}
8181

8282
$container = $container->withWait((new WaitForHttp($this->internalPort, 20000))->withPath('/api/v1/ping'));
@@ -142,6 +142,12 @@ public function stop(): void
142142
$this->container->stop();
143143
$this->container = null;
144144
}
145+
146+
// Clean up temporary signing key file
147+
if ($this->tempSigningKeyFile !== null && file_exists($this->tempSigningKeyFile)) {
148+
unlink($this->tempSigningKeyFile);
149+
$this->tempSigningKeyFile = null;
150+
}
145151
}
146152

147153
public function getClient(): Client

0 commit comments

Comments
 (0)