From 370c9b63cf5383522196a73cadb86254539ee190 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 6 Jun 2024 15:13:21 +0200 Subject: [PATCH] fix: post deployment command could fail, but won't make the deployment fail anymore feat: better error for post deployment command --- app/Jobs/ApplicationDeploymentJob.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 8a949da5a..6517aae0a 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -289,7 +289,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted } private function post_deployment() { - if ($this->server->isProxyShouldRun()) { GetContainersStatus::dispatch($this->server); // dispatch(new ContainerStatusJob($this->server)); @@ -1992,7 +1991,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); if ($containers->count() == 0) { return; } - $this->application_deployment_queue->addLogEntry("Executing pre-deployment command (see debug log for output)."); + $this->application_deployment_queue->addLogEntry("Executing pre-deployment command (see debug log for output/errors)."); foreach ($containers as $container) { $containerName = data_get($container, 'Names'); @@ -2015,6 +2014,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); if (empty($this->application->post_deployment_command)) { return; } + $this->application_deployment_queue->addLogEntry("----------------------------------------"); $this->application_deployment_queue->addLogEntry("Executing post-deployment command (see debug log for output)."); $containers = getCurrentApplicationContainerStatus($this->server, $this->application->id, $this->pull_request_id); @@ -2023,11 +2023,20 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); if ($containers->count() == 1 || str_starts_with($containerName, $this->application->post_deployment_command_container . '-' . $this->application->uuid)) { $cmd = "sh -c '" . str_replace("'", "'\''", $this->application->post_deployment_command) . "'"; $exec = "docker exec {$containerName} {$cmd}"; - $this->execute_remote_command( - [ - 'command' => $exec, 'hidden' => true - ], - ); + try { + $this->execute_remote_command( + [ + 'command' => $exec, 'hidden' => true, 'save' => 'post-deployment-command-output' + ], + ); + } catch (Exception $e) { + $post_deployment_command_output = $this->saved_outputs->get('post-deployment-command-output'); + if ($post_deployment_command_output) { + $this->application_deployment_queue->addLogEntry("Post-deployment command failed."); + $this->application_deployment_queue->addLogEntry($post_deployment_command_output, 'stderr'); + } + } + return; } }