Skip to content

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.

Merge remote-tracking branch 'origin/release/v4.5' into automation/sync-main-to-release-v4.5

Andras Bacsai200af072259d
diff --cc .ai/lessons.md
index 190bbee34e,7b94e29b3b..a1096cebad
--- a/.ai/lessons.md
+++ b/.ai/lessons.md
@@@ -12,8 -12,8 +12,9 @@@
- SSH retries replay the full command batch. Only exit code 255 is an SSH transport failure; other exit codes come from the remote command, so do not retry them. Keep batches safe to run twice (for example `docker rm -f <name> || true` before `docker run --name <name>`).
- Redirect browser test output to a file (`> /tmp/x.log 2>&1`); piping it (`| tail`) hangs because the Playwright server keeps the pipe open.
- Browser `click('Text')` can match a hidden element first (for example inactive modal steps) and wait forever; use `button:visible:has-text("Text")`.
+ - A new worktree has no `vendor/` or `public/build/`. Run `composer install --ignore-platform-req=ext-zip` and copy `public/build` from the main checkout before page-rendering tests; otherwise they fail with a Vite manifest error.
- Never run `php artisan test` inside a dev container (`./scripts/dev exec` or `docker exec coolify-dev-*`). The container sets `DB_CONNECTION=pgsql` as a real environment variable, which wins over `phpunit.xml`, so `RefreshDatabase` runs `migrate:fresh` on the dev database and wipes it. Run tests on the host only.
+- Do not symlink `vendor` into another worktree. Composer resolves the base path from the real `vendor` path, so the tests load the app classes of the other checkout. Run `composer install --ignore-platform-req=ext-zip` in the worktree.
- Call `visit()` directly in each `tests/v4/Browser` test body; Pest does not mark a test that only uses helper-wrapped `visit()` as a browser test, so it fails with `sendText() on null`.
## Verify the complete user flow
diff --cc app/Actions/Server/UpdateCoolify.php
index 7011ec5429,ddfc6578e4..52c37743ec
--- a/app/Actions/Server/UpdateCoolify.php
+++ b/app/Actions/Server/UpdateCoolify.php
@@@ -2,9 -2,9 +2,11 @@@
namespace App\Actions\Server;
+ use App\Jobs\DatabaseBackupJob;
use App\Models\Server;
+ use App\Models\StandalonePostgresql;
+use App\Notifications\Server\UpgradeSkippedLowDiskSpace;
+use App\Services\CoolifyUpgradeDiskSpace;
use App\Services\CoolifyUpgradeStatus;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
@@@ -21,9 -21,10 +23,10 @@@ class UpdateCoolif
public ?string $currentVersion = null;
- public function handle($manual_update = false)
+ public function handle($manual_update = false, bool $skipDiskSpaceCheck = false)
{
if (isDev()) {
+ $this->backupDatabase();
Sleep::for(10)->seconds();
return;
@@@ -112,16 -113,29 +115,33 @@@
);
}
+ if (! $skipDiskSpaceCheck && ! $this->ensureEnoughDiskSpace($manual_update)) {
+ return;
+ }
+
+ $this->backupDatabase();
- $this->update();
+ $this->update($skipDiskSpaceCheck);
$settings->new_version_available = false;
$settings->save();
}
+ private function backupDatabase(): void
+ {
+ $backup = StandalonePostgresql::find(0)?->scheduledBackups()->first();
+ if (! $backup || ! instanceSettings()->is_backup_before_update_enabled) {
+ return;
+ }
+
+ // Runs inline so the update waits for the result. dispatchSync() would go through the job's
+ // WithoutOverlapping middleware, which silently drops the run while the scheduled backup is running.
+ $job = new DatabaseBackupJob($backup);
+ $job->handle();
+ if ($job->backup_log?->status !== 'success') {
+ throw new \Exception('The database backup failed, so the update was not started.');
+ }
+ }
+
- private function update()
+ private function update(bool $skipDiskSpaceCheck)
{
$this->ensureNoUpgradeIsRunning();
diff --cc app/Jobs/DatabaseBackupJob.php
index 99e691af86,eb0959865b..00f3d35a50
--- a/app/Jobs/DatabaseBackupJob.php
+++ b/app/Jobs/DatabaseBackupJob.php
@@@ -889,12 -922,10 +922,10 @@@ class DatabaseBackupJob implements Shou
$resolveOptions = $resolveOptions === '' ? '' : ' '.$resolveOptions;
$commands[] = "docker exec backup-of-{$this->backup_log_uuid} mc alias set{$resolveOptions} temporary {$escapedEndpoint} {$escapedKey} {$escapedSecret}";
- $commands[] = "docker exec backup-of-{$this->backup_log_uuid} mc cp {$escapedBackupLocation} {$escapedS3Destination}";
+ $commands[] = "docker exec backup-of-{$this->backup_log_uuid} mc cp{$resolveOptions} {$escapedBackupLocation} {$escapedS3Destination}";
instant_remote_process($commands, $this->server, true, false, $this->commandTimeout(), disableMultiplexing: true);
- $this->s3_uploaded = true;
} catch (Throwable $e) {
- $this->s3_uploaded = false;
$this->add_to_error_output($e->getMessage());
throw $e;
} finally {
diff --cc bootstrap/helpers/docker.php
index 076d03d40c,2c1025b623..9793336698
--- a/bootstrap/helpers/docker.php
+++ b/bootstrap/helpers/docker.php
@@@ -911,20 -922,7 +926,20 @@@ function dockerComposeServicePorts(?str
->unique()->values()->all();
}
+/**
+ * Traefik matches an IPv6 host without brackets: Host(`[2a01:4f8::1]`) never matches a request,
+ * Host(`2a01:4f8::1`) does. Labels that were saved with brackets get them removed here.
+ */
+function traefikHostRulesWithoutIpv6Brackets(Collection $labels): Collection
+{
+ return $labels->map(fn ($label) => is_string($label) ? preg_replace_callback(
+ '/Host\(`\[([0-9A-Fa-f:.]+)\]`\)/',
+ fn (array $matches): string => filter_var($matches[1], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false ? "Host(`{$matches[1]}`)" : $matches[0],
+ $label,
+ ) : $label);
+}
+
- function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, bool $generate_unique_uuid = false, ?string $image = null, string $redirect_direction = 'both', bool $is_http_basic_auth_enabled = false, ?string $http_basic_auth_username = null, ?string $http_basic_auth_password = null, ?Collection $noindex_domains = null, bool $escape_redirect_replacement_for_compose = true, array $domainPortOverrides = [])
+ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true, ?bool $is_stripprefix_enabled = true, ?string $service_name = null, bool $generate_unique_uuid = false, ?string $image = null, string $redirect_direction = 'both', bool $is_http_basic_auth_enabled = false, ?string $http_basic_auth_username = null, ?string $http_basic_auth_password = null, ?Collection $noindex_domains = null, bool $escape_redirect_replacement_for_compose = true, array $domainPortOverrides = [], ?int $http_basic_auth_bcrypt_cost = null)
{
$labels = collect([]);
$labels->push('traefik.enable=true');
diff --cc tests/Unit/UpdateCoolifyTest.php
index c15a99fcf6,087fc03514..8b604a042f
--- a/tests/Unit/UpdateCoolifyTest.php
+++ b/tests/Unit/UpdateCoolifyTest.php
@@@ -3,10 -3,13 +3,14 @@@
use App\Actions\Server\UpdateCoolify;
use App\Livewire\Settings\Updates;
use App\Models\InstanceSettings;
+ use App\Models\PrivateKey;
+ use App\Models\ScheduledDatabaseBackup;
use App\Models\Server;
+ use App\Models\StandaloneDocker;
+ use App\Models\StandalonePostgresql;
use App\Models\Team;
use App\Models\User;
+use App\Notifications\Server\UpgradeSkippedLowDiskSpace;
use App\Support\RemoteProcessCommand;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Cache;
@@@ -55,48 -59,40 +60,76 @@@ function updateCoolifyTestActionWithSta
};
}
+function updateCoolifyTestActionWithDiskSpace(?float $availableGb): UpdateCoolify
+{
+ return new class($availableGb) extends UpdateCoolify
+ {
+ public function __construct(private ?float $availableGb) {}
+
+ protected function readUpgradeStatus(): ?string
+ {
+ return '';
+ }
+
+ protected function availableDiskSpaceGb(): ?float
+ {
+ return $this->availableGb;
+ }
+ };
+}
+
+ function updateCoolifyTestCreateInstanceBackup(): void
+ {
+ Storage::fake('ssh-keys');
+ Notification::fake();
+ Server::query()->whereKey(0)->update(['private_key_id' => PrivateKey::factory()->create(['team_id' => 0])->id]);
+ Server::flushIdentityMap();
+ StandalonePostgresql::forceCreate([
+ 'id' => 0,
+ 'name' => 'coolify-db',
+ 'postgres_password' => 'password',
+ 'destination_type' => StandaloneDocker::class,
+ 'destination_id' => 0,
+ ]);
+ ScheduledDatabaseBackup::create([
+ 'frequency' => '0 0 * * *',
+ 'database_id' => 0,
+ 'database_type' => StandalonePostgresql::class,
+ 'team_id' => 0,
+ ]);
+ }
+
-function updateCoolifyTestPrepareUpdate(array $settings = []): void
+function updateCoolifyTestPrepareUpgrade(): void
{
Queue::fake();
config([
'app.env' => 'testing',
'constants.coolify.version' => '4.0.9',
+ 'constants.coolify.helper_version' => '1.0.14',
+ 'constants.coolify.upgrade_script_url' => 'https://cdn.example.com/upgrade.sh',
'constants.ssh.mux_enabled' => false,
]);
- Http::fake(['*' => Http::response(['coolify' => ['v4' => ['version' => '4.0.10']]], 200)]);
- updateCoolifyTestCreateRootServerAndSettings($settings);
+
+ updateCoolifyTestCreateRootServerAndSettings([
+ 'is_auto_update_enabled' => true,
+ 'new_version_available' => true,
+ 'docker_registry_url' => 'docker.io',
+ ]);
+
+ Http::fake([
+ '*' => Http::response([
+ 'coolify' => ['v4' => ['version' => '4.0.10']],
+ ], 200),
+ ]);
+}
+
++function updateCoolifyTestPrepareUpdate(array $settings = []): void
++{
++ updateCoolifyTestPrepareUpgrade();
++ InstanceSettings::findOrFail(0)->update($settings);
+ updateCoolifyTestCreateInstanceBackup();
+ }
+
afterEach(function () {
Mockery::close();
});
@@@ -408,49 -404,32 +441,79 @@@ it('starts an upgrade when the previou
->toContain("bash /data/coolify/source/upgrade.sh '4.0.10'");
});
+it('skips an automatic update and notifies the root team when the disk is almost full', function () {
+ updateCoolifyTestPrepareUpgrade();
+ Notification::fake();
+ Team::findOrFail(0)->discordNotificationSettings()->update(['discord_enabled' => true, 'server_disk_usage_discord_notifications' => true]);
+
+ updateCoolifyTestActionWithDiskSpace(3.2)->handle();
+
+ expect(Activity::query()->count())->toBe(0)
+ ->and((bool) InstanceSettings::findOrFail(0)->new_version_available)->toBeTrue();
+ Notification::assertSentTo(
+ Team::findOrFail(0),
+ UpgradeSkippedLowDiskSpace::class,
+ fn (UpgradeSkippedLowDiskSpace $notification) => $notification->version === '4.0.10'
+ && $notification->availableGb === 3.2
+ && str_contains((string) $notification->toMail()->render(), '3.2 GB free'),
+ );
+});
+
+it('fails a manual update when the disk is almost full', function () {
+ updateCoolifyTestPrepareUpgrade();
+ Notification::fake();
+
+ expect(fn () => updateCoolifyTestActionWithDiskSpace(3.2)->handle(manual_update: true))
+ ->toThrow(Exception::class, 'Not enough free disk space to upgrade: 3.2 GB free, 5 GB required.');
+
+ expect(Activity::query()->count())->toBe(0);
+ Notification::assertNothingSent();
+});
+
+it('upgrades when the free disk space cannot be measured', function () {
+ updateCoolifyTestPrepareUpgrade();
+
+ updateCoolifyTestActionWithDiskSpace(null)->handle();
+
+ expect(RemoteProcessCommand::read(Activity::query()->latest('id')->first()))
+ ->toEndWith("bash /data/coolify/source/upgrade.sh '4.0.10' '1.0.14' 'docker.io'");
+});
+
+it('upgrades and tells the upgrade script to skip its disk space check when the user overrides it', function () {
+ updateCoolifyTestPrepareUpgrade();
+
+ updateCoolifyTestActionWithDiskSpace(3.2)->handle(manual_update: true, skipDiskSpaceCheck: true);
+
+ expect(RemoteProcessCommand::read(Activity::query()->latest('id')->first()))
+ ->toEndWith("bash /data/coolify/source/upgrade.sh '4.0.10' '1.0.14' 'docker.io' 'false' 'true'");
+});
++
+ it('backs up the instance database before the update', function () {
+ updateCoolifyTestPrepareUpdate();
+ Process::fake(['*du -b*' => '128', '*' => '']);
+
+ (new UpdateCoolify)->handle(manual_update: true);
+
+ Process::assertRan(fn ($process) => str_contains($process->command, 'pg_dump'));
+ expect(RemoteProcessCommand::read(Activity::query()->latest('id')->first()))
+ ->toContain("bash /data/coolify/source/upgrade.sh '4.0.10'");
+ });
+
+ it('skips the backup before the update when it is disabled', function () {
+ updateCoolifyTestPrepareUpdate(['is_backup_before_update_enabled' => false]);
+ Process::fake();
+
+ (new UpdateCoolify)->handle(manual_update: true);
+
+ Process::assertNotRan(fn ($process) => str_contains($process->command, 'pg_dump'));
+ expect(Activity::query()->count())->toBe(1);
+ });
+
+ it('does not start the update when the instance backup fails', function () {
+ updateCoolifyTestPrepareUpdate();
+ Process::fake(['*pg_dump*' => Process::result(exitCode: 1), '*' => '']);
+
+ expect(fn () => (new UpdateCoolify)->handle(manual_update: true))
+ ->toThrow(Exception::class, 'The database backup failed, so the update was not started.')
+ ->and(Activity::query()->count())->toBe(0);
+ });