feat: add container logs in case the container does not start healthy
This commit is contained in:
		@@ -184,6 +184,9 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
 | 
			
		||||
 | 
			
		||||
    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 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
 | 
			
		||||
                    }
 | 
			
		||||
                    if (Str::of($this->saved_outputs->get('health_check'))->replace('"', '')->value() === 'unhealthy') {
 | 
			
		||||
                        $this->newVersionIsHealthy = false;
 | 
			
		||||
                        $this->query_logs();
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                    $counter++;
 | 
			
		||||
@@ -997,9 +1001,25 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
 | 
			
		||||
                        $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') {
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
        ));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user