An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix: docker cleanup job
Andras Bacsai3f9f197282c9
diff --git a/app/Actions/Server/CleanupDocker.php b/app/Actions/Server/CleanupDocker.phpindex 0009e001d3..0decaf0bcf 100644--- a/app/Actions/Server/CleanupDocker.php+++ b/app/Actions/Server/CleanupDocker.php@@ -9,17 +9,11 @@ class CleanupDocker{use AsAction;- public function handle(Server $server, bool $force = true)+ public function handle(Server $server){// cleanup docker images, containers, and builder caches- if ($force) {- instant_remote_process(['docker image prune -af'], $server, false);- instant_remote_process(['docker container prune -f --filter "label=coolify.managed=true"'], $server, false);- instant_remote_process(['docker builder prune -af'], $server, false);- } else {- instant_remote_process(['docker image prune -f'], $server, false);- instant_remote_process(['docker container prune -f --filter "label=coolify.managed=true"'], $server, false);- instant_remote_process(['docker builder prune -f'], $server, false);- }+ instant_remote_process(['docker image prune -af'], $server, false);+ instant_remote_process(['docker container prune -f --filter "label=coolify.managed=true"'], $server, false);+ instant_remote_process(['docker builder prune -af'], $server, false);}}diff --git a/app/Actions/Server/UpdateCoolify.php b/app/Actions/Server/UpdateCoolify.phpindex 8910d6e972..09d6471e8f 100644--- a/app/Actions/Server/UpdateCoolify.php+++ b/app/Actions/Server/UpdateCoolify.php@@ -26,7 +26,7 @@ class UpdateCoolifyif (! $this->server) {return;}- CleanupDocker::dispatch($this->server, false)->onQueue('high');+ CleanupDocker::dispatch($this->server)->onQueue('high');$response = Http::retry(3, 1000)->get('https://cdn.coollabs.io/coolify/versions.json');if ($response->successful()) {$versions = $response->json();diff --git a/app/Jobs/DockerCleanupJob.php b/app/Jobs/DockerCleanupJob.phpindex 5010263ae2..163b579ebd 100644--- a/app/Jobs/DockerCleanupJob.php+++ b/app/Jobs/DockerCleanupJob.php@@ -19,32 +19,33 @@ class DockerCleanupJob implements ShouldBeEncrypted, ShouldQueuepublic $timeout = 300;- public int|string|null $usageBefore = null;+ public $tries = 2;++ public ?string $usageBefore = null;public function __construct(public Server $server) {}public function handle(): void{- try {- if (! $this->server->isFunctional()) {- return;- }- if ($this->server->settings->is_force_cleanup_enabled) {- Log::info('DockerCleanupJob force cleanup on '.$this->server->name);- CleanupDocker::run(server: $this->server, force: true);-- return;- }+ if (! $this->server->isFunctional()) {+ return;+ }+ if ($this->server->settings->is_force_cleanup_enabled) {+ Log::info('DockerCleanupJob force cleanup on '.$this->server->name);+ CleanupDocker::run(server: $this->server);+ return;+ }+ try {$this->usageBefore = $this->server->getDiskUsage();- if (str($this->usageBefore)->isEmpty() || $this->usageBefore === null || $this->usageBefore === 0) {+ if (str($this->usageBefore)->trim()->isEmpty()) {Log::info('DockerCleanupJob force cleanup on '.$this->server->name);- CleanupDocker::run(server: $this->server, force: true);+ CleanupDocker::run(server: $this->server);return;}if ($this->usageBefore >= $this->server->settings->cleanup_after_percentage) {- CleanupDocker::run(server: $this->server, force: false);+ CleanupDocker::run(server: $this->server);$usageAfter = $this->server->getDiskUsage();if ($usageAfter < $this->usageBefore) {$this->server->team?->notify(new DockerCleanup($this->server, 'Saved '.($this->usageBefore - $usageAfter).'% disk space.'));@@ -56,7 +57,8 @@ class DockerCleanupJob implements ShouldBeEncrypted, ShouldQueueLog::info('No need to clean up '.$this->server->name);}} catch (\Throwable $e) {- ray($e->getMessage());+ CleanupDocker::run(server: $this->server);+ Log::error('DockerCleanupJob failed: '.$e->getMessage());throw $e;}}diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 8a7325bebc..3a1c0eabe8 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -649,7 +649,7 @@ $schema://$host {}}- public function getDiskUsage()+ public function getDiskUsage(): ?string{return instant_remote_process(["df /| tail -1 | awk '{ print $5}' | sed 's/%//g'"], $this, false);}diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.phpindex 918aa74cca..6ba7caeef3 100644--- a/bootstrap/helpers/remoteProcess.php+++ b/bootstrap/helpers/remoteProcess.php@@ -170,7 +170,7 @@ function generateSshCommand(Server $server, string $command)// ray($ssh_command);return $ssh_command;}-function instant_remote_process(Collection|array $command, Server $server, bool $throwError = true, bool $no_sudo = false)+function instant_remote_process(Collection|array $command, Server $server, bool $throwError = true, bool $no_sudo = false): ?string{$timeout = config('constants.ssh.command_timeout');if ($command instanceof Collection) {