Merge branch 'next' into feat/disable-default-redirect

This commit is contained in:
Kael
2024-11-03 18:58:59 +11:00
committed by GitHub
28 changed files with 612 additions and 2893 deletions

View File

@@ -51,6 +51,8 @@ class StartClickhouse
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'healthcheck' => [
'test' => "clickhouse-client --password {$this->database->clickhouse_admin_password} --query 'SELECT 1'",

View File

@@ -48,6 +48,8 @@ class StartDragonfly
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'healthcheck' => [
'test' => "redis-cli -a {$this->database->dragonfly_password} ping",

View File

@@ -50,6 +50,8 @@ class StartKeydb
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'healthcheck' => [
'test' => "keydb-cli --pass {$this->database->keydb_password} ping",

View File

@@ -45,6 +45,8 @@ class StartMariadb
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'healthcheck' => [
'test' => ['CMD', 'healthcheck.sh', '--connect', '--innodb_initialized'],

View File

@@ -49,6 +49,8 @@ class StartMongodb
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'healthcheck' => [
'test' => [

View File

@@ -45,6 +45,8 @@ class StartMysql
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'healthcheck' => [
'test' => ['CMD', 'mysqladmin', 'ping', '-h', 'localhost', '-u', 'root', "-p{$this->database->mysql_root_password}"],

View File

@@ -49,6 +49,8 @@ class StartPostgresql
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'healthcheck' => [
'test' => [

View File

@@ -50,6 +50,8 @@ class StartRedis
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'healthcheck' => [
'test' => [

View File

@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\DB;
class CleanupDatabase extends Command
{
protected $signature = 'cleanup:database {--yes}';
protected $signature = 'cleanup:database {--yes} {--keep-days=}';
protected $description = 'Cleanup database';
@@ -20,9 +20,9 @@ class CleanupDatabase extends Command
}
if (isCloud()) {
// Later on we can increase this to 180 days or dynamically set
$keep_days = 60;
$keep_days = $this->option('keep-days') ?? 60;
} else {
$keep_days = 60;
$keep_days = $this->option('keep-days') ?? 60;
}
echo "Keep days: $keep_days\n";
// Cleanup failed jobs table

View File

@@ -14,6 +14,7 @@ use App\Jobs\ScheduledTaskJob;
use App\Jobs\ServerCheckJob;
use App\Jobs\ServerCleanupMux;
use App\Jobs\UpdateCoolifyJob;
use App\Models\InstanceSettings;
use App\Models\ScheduledDatabaseBackup;
use App\Models\ScheduledTask;
use App\Models\Server;
@@ -26,10 +27,13 @@ class Kernel extends ConsoleKernel
{
private $allServers;
private InstanceSettings $settings;
protected function schedule(Schedule $schedule): void
{
$this->allServers = Server::all();
$settings = instanceSettings();
$this->allServers = Server::where('ip', '!=', '1.2.3.4')->get();
$this->settings = instanceSettings();
$schedule->job(new CleanupStaleMultiplexedConnections)->hourly();
@@ -43,14 +47,12 @@ class Kernel extends ConsoleKernel
$this->checkScheduledTasks($schedule);
$schedule->command('uploads:clear')->everyTwoMinutes();
$schedule->command('telescope:prune')->daily();
$schedule->job(new CheckHelperImageJob)->everyFiveMinutes()->onOneServer();
} else {
// Instance Jobs
$schedule->command('horizon:snapshot')->everyFiveMinutes();
$schedule->command('cleanup:unreachable-servers')->daily()->onOneServer();
$schedule->job(new PullTemplatesFromCDN)->cron($settings->update_check_frequency)->timezone($settings->instance_timezone)->onOneServer();
$schedule->job(new PullTemplatesFromCDN)->cron($this->settings->update_check_frequency)->timezone($this->settings->instance_timezone)->onOneServer();
$schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer();
$this->scheduleUpdates($schedule);
@@ -67,36 +69,33 @@ class Kernel extends ConsoleKernel
private function pullImages($schedule): void
{
$settings = instanceSettings();
$servers = $this->allServers->where('settings.is_usable', true)->where('settings.is_reachable', true)->where('ip', '!=', '1.2.3.4');
$servers = $this->allServers->whereRelation('settings', 'is_usable', true)->whereRelation('settings', 'is_reachable', true);
foreach ($servers as $server) {
if ($server->isSentinelEnabled()) {
$schedule->job(function () use ($server) {
CheckAndStartSentinelJob::dispatch($server);
})->cron($settings->update_check_frequency)->timezone($settings->instance_timezone)->onOneServer();
})->cron($this->settings->update_check_frequency)->timezone($this->settings->instance_timezone)->onOneServer();
}
}
$schedule->job(new CheckHelperImageJob)
->cron($settings->update_check_frequency)
->timezone($settings->instance_timezone)
->cron($this->settings->update_check_frequency)
->timezone($this->settings->instance_timezone)
->onOneServer();
}
private function scheduleUpdates($schedule): void
{
$settings = instanceSettings();
$updateCheckFrequency = $settings->update_check_frequency;
$updateCheckFrequency = $this->settings->update_check_frequency;
$schedule->job(new CheckForUpdatesJob)
->cron($updateCheckFrequency)
->timezone($settings->instance_timezone)
->timezone($this->settings->instance_timezone)
->onOneServer();
if ($settings->is_auto_update_enabled) {
$autoUpdateFrequency = $settings->auto_update_frequency;
if ($this->settings->is_auto_update_enabled) {
$autoUpdateFrequency = $this->settings->auto_update_frequency;
$schedule->job(new UpdateCoolifyJob)
->cron($autoUpdateFrequency)
->timezone($settings->instance_timezone)
->timezone($this->settings->instance_timezone)
->onOneServer();
}
}
@@ -104,11 +103,11 @@ class Kernel extends ConsoleKernel
private function checkResources($schedule): void
{
if (isCloud()) {
$servers = $this->allServers->whereNotNull('team.subscription')->where('team.subscription.stripe_trial_already_ended', false)->where('ip', '!=', '1.2.3.4');
$servers = $this->allServers->whereNotNull('team.subscription')->where('team.subscription.stripe_trial_already_ended', false);
$own = Team::find(0)->servers;
$servers = $servers->merge($own);
} else {
$servers = $this->allServers->where('ip', '!=', '1.2.3.4');
$servers = $this->allServers;
}
foreach ($servers as $server) {
$lastSentinelUpdate = $server->sentinel_updated_at;

View File

@@ -25,19 +25,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
public $containers;
public $applications;
public $databases;
public $services;
public $previews;
public function backoff(): int
{
return isDev() ? 1 : 3;
}
public function __construct(public Server $server) {}
public function handle()
@@ -47,11 +34,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue
return 'Server is not reachable or not ready.';
}
$this->applications = $this->server->applications();
$this->databases = $this->server->databases();
$this->services = $this->server->services()->get();
$this->previews = $this->server->previews();
if (! $this->server->isSwarmWorker() && ! $this->server->isBuildServer()) {
['containers' => $this->containers, 'containerReplicates' => $containerReplicates] = $this->server->getContainers();
if (is_null($this->containers)) {

View File

@@ -2,6 +2,8 @@
namespace App\Livewire\Server;
use App\Actions\Server\StartSentinel;
use App\Actions\Server\StopSentinel;
use App\Models\Server;
use Livewire\Attributes\Rule;
use Livewire\Component;
@@ -177,6 +179,37 @@ class Show extends Component
}
}
public function restartSentinel()
{
$this->server->restartSentinel();
$this->dispatch('success', 'Sentinel restarted.');
}
public function updatedIsSentinelDebugEnabled($value)
{
$this->submit();
$this->restartSentinel();
}
public function updatedIsMetricsEnabled($value)
{
$this->submit();
$this->restartSentinel();
}
public function updatedIsSentinelEnabled($value)
{
if ($value === true) {
StartSentinel::run($this->server, true);
} else {
$this->isMetricsEnabled = false;
$this->isSentinelDebugEnabled = false;
StopSentinel::dispatch($this->server);
}
$this->submit();
}
public function regenerateSentinelToken()
{
try {
@@ -196,7 +229,7 @@ class Show extends Component
{
try {
$this->syncData(true);
$this->dispatch('success', 'Server updated');
$this->dispatch('success', 'Server updated.');
} catch (\Throwable $e) {
return handleError($e, $this);
}

View File

@@ -5,7 +5,6 @@ namespace App\Models;
use App\Actions\Server\InstallDocker;
use App\Actions\Server\StartSentinel;
use App\Enums\ProxyTypes;
use App\Helpers\SshMultiplexingHelper;
use App\Jobs\CheckAndStartSentinelJob;
use App\Notifications\Server\Reachable;
use App\Notifications\Server\Unreachable;
@@ -875,8 +874,6 @@ $schema://$host {
$standalone_docker = $this->hasMany(StandaloneDocker::class)->get();
$swarm_docker = $this->hasMany(SwarmDocker::class)->get();
// $additional_dockers = $this->belongsToMany(StandaloneDocker::class, 'additional_destinations')->withPivot('server_id')->get();
// return $standalone_docker->concat($swarm_docker)->concat($additional_dockers);
return $standalone_docker->concat($swarm_docker);
}
@@ -1056,8 +1053,6 @@ $schema://$host {
{
config()->set('constants.ssh.mux_enabled', ! $isManualCheck);
SshMultiplexingHelper::removeMuxFile($this);
if ($this->skipServer()) {
return ['uptime' => false, 'error' => 'Server skipped.'];
}

View File

@@ -10,7 +10,12 @@ use Laravel\Sanctum\Sanctum;
class AppServiceProvider extends ServiceProvider
{
public function register(): void {}
public function register(): void
{
if ($this->app->environment('local')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
}
}
public function boot(): void
{