fix(docker): Improve Docker compose file validation process
- Increase UUID length for better uniqueness - Add server existence check before validation - Implement cleanup of temporary compose file in finally block
This commit is contained in:
parent
64f44f3f8b
commit
e1c5ace342
1 changed files with 11 additions and 2 deletions
|
|
@ -834,9 +834,12 @@ function generateCustomDockerRunOptionsForDatabases($docker_run_options, $docker
|
||||||
|
|
||||||
function validateComposeFile(string $compose, int $server_id): string|Throwable
|
function validateComposeFile(string $compose, int $server_id): string|Throwable
|
||||||
{
|
{
|
||||||
$uuid = Str::random(10);
|
$uuid = Str::random(18);
|
||||||
|
$server = Server::ownedByCurrentTeam()->find($server_id);
|
||||||
try {
|
try {
|
||||||
$server = Server::ownedByCurrentTeam()->findOrFail($server_id);
|
if (! $server) {
|
||||||
|
throw new \Exception('Server not found');
|
||||||
|
}
|
||||||
$base64_compose = base64_encode($compose);
|
$base64_compose = base64_encode($compose);
|
||||||
instant_remote_process([
|
instant_remote_process([
|
||||||
"echo {$base64_compose} | base64 -d | tee /tmp/{$uuid}.yml > /dev/null",
|
"echo {$base64_compose} | base64 -d | tee /tmp/{$uuid}.yml > /dev/null",
|
||||||
|
|
@ -848,6 +851,12 @@ function validateComposeFile(string $compose, int $server_id): string|Throwable
|
||||||
return 'OK';
|
return 'OK';
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
|
} finally {
|
||||||
|
if (filled($server)) {
|
||||||
|
instant_remote_process([
|
||||||
|
"rm /tmp/{$uuid}.yml",
|
||||||
|
], $server, throwError: false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue