feat: add container logs in case the container does not start healthy

This commit is contained in:
Andras Bacsai 2024-05-24 11:50:31 +02:00
parent 52b339d0b8
commit a01e604443
2 changed files with 20 additions and 6 deletions

View File

@ -184,6 +184,9 @@ public function __construct(int $application_deployment_queue_id)
public function handle(): void
{
$this->application_deployment_queue->update([
'status' => ApplicationDeploymentStatus::IN_PROGRESS->value,
]);
if (!$this->server->isFunctional()) {
$this->application_deployment_queue->addLogEntry("Server is not functional.");
$this->fail("Server is not functional.");
@ -988,6 +991,7 @@ private function health_check()
}
if (Str::of($this->saved_outputs->get('health_check'))->replace('"', '')->value() === 'unhealthy') {
$this->newVersionIsHealthy = false;
$this->query_logs();
break;
}
$counter++;
@ -997,9 +1001,25 @@ private function health_check()
$sleeptime++;
}
}
if (Str::of($this->saved_outputs->get('health_check'))->replace('"', '')->value() === 'starting') {
$this->query_logs();
}
}
}
}
private function query_logs()
{
$this->application_deployment_queue->addLogEntry("----------------------------------------");
$this->application_deployment_queue->addLogEntry("Container logs:");
$this->execute_remote_command(
[
"command" => "docker logs -n 100 {$this->container_name}",
"type" => "stderr",
"ignore_errors" => true,
],
);
$this->application_deployment_queue->addLogEntry("----------------------------------------");
}
private function deploy_pull_request()
{
if ($this->application->build_pack === 'dockercompose') {

View File

@ -43,16 +43,10 @@ function queue_application_deployment(Application $application, string $deployme
]);
if ($no_questions_asked) {
$deployment->update([
'status' => ApplicationDeploymentStatus::IN_PROGRESS->value,
]);
dispatch(new ApplicationDeploymentJob(
application_deployment_queue_id: $deployment->id,
));
} else if (next_queuable($server_id, $application_id)) {
$deployment->update([
'status' => ApplicationDeploymentStatus::IN_PROGRESS->value,
]);
dispatch(new ApplicationDeploymentJob(
application_deployment_queue_id: $deployment->id,
));