From 16281248ac7bb762cefcc29c748b4b1d55bfe6a5 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 17 Nov 2023 12:22:45 +0100 Subject: [PATCH] Refactor Dockerfile deployment logic and server validation --- app/Jobs/ApplicationDeploymentJob.php | 12 +++++-- app/Jobs/ContainerStatusJob.php | 2 +- app/Models/Server.php | 45 ++++++++++++++------------- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 25c6c879c..4c0450920 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1078,9 +1078,15 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); ); } else { // Pure Dockerfile based deployment - $this->execute_remote_command([ - executeInDocker($this->deployment_uuid, "docker build --pull $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->production_image_name {$this->workdir}"), "hidden" => true - ]); + if ($this->application->dockerfile) { + $this->execute_remote_command([ + executeInDocker($this->deployment_uuid, "docker build --pull $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->production_image_name {$this->workdir}"), "hidden" => true + ]); + } else { + $this->execute_remote_command([ + executeInDocker($this->deployment_uuid, "docker build $this->buildTarget $this->addHosts --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t $this->production_image_name {$this->workdir}"), "hidden" => true + ]); + } } } diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index 74d300c38..250156831 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -23,7 +23,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted public function __construct(public Server $server) { - $this->handle(); + // $this->handle(); } public function middleware(): array { diff --git a/app/Models/Server.php b/app/Models/Server.php index 788808430..a86800403 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -169,23 +169,6 @@ class Server extends BaseModel Sleep::for(5)->seconds(); return; } - $this->update([ - 'unreachable_count' => 0, - ]); - if (data_get($this, 'unreachable_notification_sent') === true) { - ray('Server is reachable again, sending notification...'); - $this->team->notify(new Revived($this)); - $this->update(['unreachable_notification_sent' => false]); - } - if ( - data_get($this, 'settings.is_reachable') === false || - data_get($this, 'settings.is_usable') === false - ) { - $this->settings()->update([ - 'is_reachable' => true, - 'is_usable' => true - ]); - } break; } } @@ -308,19 +291,37 @@ class Server extends BaseModel { return $this->settings->is_reachable && $this->settings->is_usable; } - public function isDrainLogActivated() { + public function isDrainLogActivated() + { return $this->settings->is_logdrain_newrelic_enabled || $this->settings->is_logdrain_highlight_enabled || $this->settings->is_logdrain_axiom_enabled; } public function validateConnection() { $uptime = instant_remote_process(['uptime'], $this, false); if (!$uptime) { - $this->settings->is_reachable = false; - $this->settings->save(); + $this->settings()->update([ + 'is_reachable' => false, + 'is_usable' => false + ]); return false; } - $this->settings->is_reachable = true; - $this->settings->save(); + + if (data_get($this, 'unreachable_notification_sent') === true) { + $this->team->notify(new Revived($this)); + $this->update(['unreachable_notification_sent' => false]); + } + if ( + data_get($this, 'settings.is_reachable') === false || + data_get($this, 'settings.is_usable') === false + ) { + $this->settings()->update([ + 'is_reachable' => true, + 'is_usable' => true + ]); + } + $this->update([ + 'unreachable_count' => 0, + ]); return true; } public function validateDockerEngine($throwError = false)