diff --git a/app/Actions/Server/UpdateCoolify.php b/app/Actions/Server/UpdateCoolify.php index c992ed786..7fb788652 100644 --- a/app/Actions/Server/UpdateCoolify.php +++ b/app/Actions/Server/UpdateCoolify.php @@ -38,9 +38,6 @@ public function handle($manual_update = false) } $this->update(); } catch (\Throwable $e) { - ray('InstanceAutoUpdateJob failed'); - ray($e->getMessage()); - send_internal_notification('InstanceAutoUpdateJob failed: ' . $e->getMessage()); throw $e; } } @@ -57,7 +54,6 @@ private function update() "curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh", "bash /data/coolify/source/upgrade.sh $this->latestVersion" ], $this->server); - send_internal_notification("Instance updated from {$this->currentVersion} -> {$this->latestVersion}"); return; } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index ab8794877..601e1517c 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -6,15 +6,12 @@ use App\Jobs\CleanupInstanceStuffsJob; use App\Jobs\DatabaseBackupJob; use App\Jobs\ScheduledTaskJob; -use App\Jobs\InstanceAutoUpdateJob; use App\Jobs\ContainerStatusJob; +use App\Jobs\PullCoolifyImageJob; use App\Jobs\PullHelperImageJob; use App\Jobs\PullSentinelImageJob; -use App\Jobs\PullTemplatesAndVersions; use App\Jobs\PullTemplatesFromCDN; -use App\Jobs\PullVersionsFromCDN; use App\Jobs\ServerStatusJob; -use App\Models\InstanceSettings; use App\Models\ScheduledDatabaseBackup; use App\Models\ScheduledTask; use App\Models\Server; @@ -32,37 +29,33 @@ protected function schedule(Schedule $schedule): void // Instance Jobs $schedule->command('horizon:snapshot')->everyMinute(); $schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer(); - $schedule->job(new PullVersionsFromCDN)->everyTenMinutes()->onOneServer(); $schedule->job(new PullTemplatesFromCDN)->everyTwoHours()->onOneServer(); - // $schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer(); // Server Jobs $this->check_scheduled_backups($schedule); $this->check_resources($schedule); $this->check_scheduled_backups($schedule); - // $this->pull_helper_image($schedule); $this->check_scheduled_tasks($schedule); $schedule->command('uploads:clear')->everyTwoMinutes(); } else { // Instance Jobs $schedule->command('horizon:snapshot')->everyFiveMinutes(); $schedule->command('cleanup:unreachable-servers')->daily(); - $schedule->job(new PullVersionsFromCDN)->everyTenMinutes()->onOneServer(); - $schedule->job(new PullTemplatesFromCDN)->everyTwoHours()->onOneServer(); + $schedule->job(new PullCoolifyImageJob)->everyTenMinutes()->onOneServer(); + $schedule->job(new PullTemplatesFromCDN)->everyThirtyMinutes()->onOneServer(); $schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer(); // $schedule->job(new CheckResaleLicenseJob)->hourly()->onOneServer(); // Server Jobs - $this->instance_auto_update($schedule); $this->check_scheduled_backups($schedule); $this->check_resources($schedule); - $this->pull_helper_image($schedule); + $this->pull_images($schedule); $this->check_scheduled_tasks($schedule); $schedule->command('cleanup:database --yes')->daily(); $schedule->command('uploads:clear')->everyTwoMinutes(); } } - private function pull_helper_image($schedule) + private function pull_images($schedule) { $servers = $this->all_servers->where('settings.is_usable', true)->where('settings.is_reachable', true)->where('ip', '!=', '1.2.3.4'); foreach ($servers as $server) { @@ -93,16 +86,6 @@ private function check_resources($schedule) $schedule->job(new ServerStatusJob($server))->everyMinute()->onOneServer(); } } - private function instance_auto_update($schedule) - { - if (isDev() || isCloud()) { - return; - } - $settings = InstanceSettings::get(); - if ($settings->is_auto_update_enabled) { - $schedule->job(new InstanceAutoUpdateJob)->everyTenMinutes()->onOneServer(); - } - } private function check_scheduled_backups($schedule) { $scheduled_backups = ScheduledDatabaseBackup::all(); diff --git a/app/Jobs/PullCoolifyImageJob.php b/app/Jobs/PullCoolifyImageJob.php new file mode 100644 index 000000000..3dd48339d --- /dev/null +++ b/app/Jobs/PullCoolifyImageJob.php @@ -0,0 +1,59 @@ +get('https://cdn.coollabs.io/coolify/versions.json'); + if ($response->successful()) { + $versions = $response->json(); + File::put(base_path('versions.json'), json_encode($versions, JSON_PRETTY_PRINT)); + } + $latest_version = get_latest_version_of_coolify(); + instant_remote_process(["docker pull -q ghcr.io/coollabsio/coolify:{$latest_version}"], $server, false); + + $settings = InstanceSettings::get(); + $current_version = config('version'); + if (!$settings->is_auto_update_enabled) { + return; + } + if ($latest_version === $current_version) { + return; + } + if (version_compare($latest_version, $current_version, '<')) { + return; + } + instant_remote_process([ + "curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh", + "bash /data/coolify/source/upgrade.sh $latest_version" + ], $server); + } catch (\Throwable $e) { + throw $e; + } + } +} diff --git a/app/Jobs/PullVersionsFromCDN.php b/app/Jobs/PullVersionsFromCDN.php index 0d4084a30..a5397ef08 100644 --- a/app/Jobs/PullVersionsFromCDN.php +++ b/app/Jobs/PullVersionsFromCDN.php @@ -34,8 +34,7 @@ public function handle(): void } } } catch (\Throwable $e) { - send_internal_notification('PullTemplatesAndVersions failed with: ' . $e->getMessage()); - ray($e->getMessage()); + throw $e; } } } diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh index da5f84c28..b02fe8392 100644 --- a/scripts/upgrade.sh +++ b/scripts/upgrade.sh @@ -1,7 +1,7 @@ #!/bin/bash ## Do not modify this file. You will lose the ability to autoupdate! -VERSION="1.0.4" +VERSION="1.0.5" CDN="https://cdn.coollabs.io/coolify" curl -fsSL $CDN/docker-compose.yml -o /data/coolify/source/docker-compose.yml @@ -30,7 +30,7 @@ docker network create --attachable coolify 2>/dev/null if [ -f /data/coolify/source/docker-compose.custom.yml ]; then echo "docker-compose.custom.yml detected." - docker run -v /data/coolify/source:/data/coolify/source -v /var/run/docker.sock:/var/run/docker.sock --rm ghcr.io/coollabsio/coolify-helper bash -c "LATEST_IMAGE=${1:-} docker compose --env-file /data/coolify/source/.env -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml -f /data/coolify/source/docker-compose.custom.yml up -d --pull always --remove-orphans --force-recreate" + docker run -v /data/coolify/source:/data/coolify/source -v /var/run/docker.sock:/var/run/docker.sock --rm ghcr.io/coollabsio/coolify-helper bash -c "LATEST_IMAGE=${1:-} docker compose --env-file /data/coolify/source/.env -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml -f /data/coolify/source/docker-compose.custom.yml up -d --remove-orphans --force-recreate" else - docker run -v /data/coolify/source:/data/coolify/source -v /var/run/docker.sock:/var/run/docker.sock --rm ghcr.io/coollabsio/coolify-helper bash -c "LATEST_IMAGE=${1:-} docker compose --env-file /data/coolify/source/.env -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml up -d --pull always --remove-orphans --force-recreate" + docker run -v /data/coolify/source:/data/coolify/source -v /var/run/docker.sock:/var/run/docker.sock --rm ghcr.io/coollabsio/coolify-helper bash -c "LATEST_IMAGE=${1:-} docker compose --env-file /data/coolify/source/.env -f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml up -d --remove-orphans --force-recreate" fi