From e8b2d8bf034d19bce0368ad8bc2cd3170c0c2f53 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 1 Aug 2024 08:52:13 +0200 Subject: [PATCH 1/4] chore: Update version to 4.0.0-beta.320 --- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/sentry.php b/config/sentry.php index b2f6ded80..a27a18d30 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.319', + 'release' => '4.0.0-beta.320', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 8b5a5afc6..05acb11ca 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Thu, 1 Aug 2024 08:52:58 +0200 Subject: [PATCH 2/4] refactor: Update CleanupDatabase.php to adjust keep_days based on environment --- app/Console/Commands/CleanupDatabase.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/CleanupDatabase.php b/app/Console/Commands/CleanupDatabase.php index 1e177ca62..bdef780e5 100644 --- a/app/Console/Commands/CleanupDatabase.php +++ b/app/Console/Commands/CleanupDatabase.php @@ -18,7 +18,11 @@ class CleanupDatabase extends Command } else { echo "Running database cleanup in dry-run mode...\n"; } - $keep_days = 60; + if (isCloud()) { + $keep_days = 30; + } else { + $keep_days = 60; + } echo "Keep days: $keep_days\n"; // Cleanup failed jobs table $failed_jobs = DB::table('failed_jobs')->where('failed_at', '<', now()->subDays(1)); From fd855847ff495652c3cb55377dc879d94306f7b1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 1 Aug 2024 09:07:54 +0200 Subject: [PATCH 3/4] refactor: Adjust keep_days in CleanupDatabase.php based on environment --- app/Console/Commands/CleanupDatabase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Commands/CleanupDatabase.php b/app/Console/Commands/CleanupDatabase.php index bdef780e5..07bc4d338 100644 --- a/app/Console/Commands/CleanupDatabase.php +++ b/app/Console/Commands/CleanupDatabase.php @@ -19,7 +19,7 @@ class CleanupDatabase extends Command echo "Running database cleanup in dry-run mode...\n"; } if (isCloud()) { - $keep_days = 30; + $keep_days = 60; } else { $keep_days = 60; } From e6e48c581277ab23d442b7a036d67b04f5836125 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 1 Aug 2024 13:47:58 +0200 Subject: [PATCH 4/4] fix: only append docker network if service/app is running --- app/Models/Application.php | 5 +++++ app/Models/ApplicationPreview.php | 5 +++++ app/Models/Service.php | 5 +++++ bootstrap/helpers/proxy.php | 11 +++++++++-- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/Models/Application.php b/app/Models/Application.php index 538eb89d9..8ee78bb73 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -451,6 +451,11 @@ class Application extends BaseModel ); } + public function isRunning() + { + return (bool) str($this->status)->startsWith('running'); + } + public function isExited() { return (bool) str($this->status)->startsWith('exited'); diff --git a/app/Models/ApplicationPreview.php b/app/Models/ApplicationPreview.php index 2825f984f..57d20e3aa 100644 --- a/app/Models/ApplicationPreview.php +++ b/app/Models/ApplicationPreview.php @@ -35,6 +35,11 @@ class ApplicationPreview extends BaseModel return self::where('application_id', $application_id)->where('pull_request_id', $pull_request_id)->firstOrFail(); } + public function isRunning() + { + return (bool) str($this->status)->startsWith('running'); + } + public function application() { return $this->belongsTo(Application::class); diff --git a/app/Models/Service.php b/app/Models/Service.php index 3ab178046..1aa88c8ec 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -77,6 +77,11 @@ class Service extends BaseModel } } + public function isRunning() + { + return (bool) str($this->status())->contains('running'); + } + public function isExited() { return (bool) str($this->status())->contains('exited'); diff --git a/bootstrap/helpers/proxy.php b/bootstrap/helpers/proxy.php index 23c9a2333..dccfaeb38 100644 --- a/bootstrap/helpers/proxy.php +++ b/bootstrap/helpers/proxy.php @@ -36,16 +36,23 @@ function collectDockerNetworksByServer(Server $server) } // Service networks foreach ($server->services()->get() as $service) { - $networks->push($service->networks()); + if ($service->isRunning()) { + $networks->push($service->networks()); + } } // Docker compose based apps $docker_compose_apps = $server->dockerComposeBasedApplications(); foreach ($docker_compose_apps as $app) { - $networks->push($app->uuid); + if ($app->isRunning()) { + $networks->push($app->uuid); + } } // Docker compose based preview deployments $docker_compose_previews = $server->dockerComposeBasedPreviewDeployments(); foreach ($docker_compose_previews as $preview) { + if (! $preview->isRunning()) { + continue; + } $pullRequestId = $preview->pull_request_id; $applicationId = $preview->application_id; $application = Application::find($applicationId);