Skip to content

Commit

Permalink
Merge branch 'next' into hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai authored Jan 10, 2025
2 parents 3a32193 + d36a179 commit a396d51
Show file tree
Hide file tree
Showing 302 changed files with 57,255 additions and 2,151 deletions.
4 changes: 0 additions & 4 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# Coolify Configuration
APP_ID=
APP_NAME=Coolify
APP_KEY=

# PostgreSQL Database Configuration
DB_USERNAME=coolify
DB_PASSWORD=

# Redis Configuration
REDIS_PASSWORD=

# Pusher Configuration
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
6 changes: 1 addition & 5 deletions app/Actions/Database/StartClickhouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ public function handle(StandaloneClickhouse $database)
'hard' => 262144,
],
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => "clickhouse-client --password {$this->database->clickhouse_admin_password} --query 'SELECT 1'",
'interval' => '5s',
Expand Down
4 changes: 4 additions & 0 deletions app/Actions/Database/StartDatabaseProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|St
$type = \App\Models\StandaloneClickhouse::class;
$containerName = "clickhouse-{$database->service->uuid}";
break;
case 'standalone-supabase/postgres':
$type = \App\Models\StandalonePostgresql::class;
$containerName = "supabase-db-{$database->service->uuid}";
break;
}
}
if ($type === \App\Models\StandaloneRedis::class) {
Expand Down
6 changes: 1 addition & 5 deletions app/Actions/Database/StartDragonfly.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ public function handle(StandaloneDragonfly $database)
'networks' => [
$this->database->destination->network,
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => "redis-cli -a {$this->database->dragonfly_password} ping",
'interval' => '5s',
Expand Down
6 changes: 1 addition & 5 deletions app/Actions/Database/StartKeydb.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ public function handle(StandaloneKeydb $database)
'networks' => [
$this->database->destination->network,
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => "keydb-cli --pass {$this->database->keydb_password} ping",
'interval' => '5s',
Expand Down
6 changes: 1 addition & 5 deletions app/Actions/Database/StartMariadb.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public function handle(StandaloneMariadb $database)
'networks' => [
$this->database->destination->network,
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => ['CMD', 'healthcheck.sh', '--connect', '--innodb_initialized'],
'interval' => '5s',
Expand Down
6 changes: 1 addition & 5 deletions app/Actions/Database/StartMongodb.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ public function handle(StandaloneMongodb $database)
'networks' => [
$this->database->destination->network,
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => [
'CMD',
Expand Down
6 changes: 1 addition & 5 deletions app/Actions/Database/StartMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ public function handle(StandaloneMysql $database)
'networks' => [
$this->database->destination->network,
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => ['CMD', 'mysqladmin', 'ping', '-h', 'localhost', '-u', 'root', "-p{$this->database->mysql_root_password}"],
'interval' => '5s',
Expand Down
29 changes: 18 additions & 11 deletions app/Actions/Database/StartPostgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public function handle(StandalonePostgresql $database)
$this->database = $database;
$container_name = $this->database->uuid;
$this->configuration_dir = database_configuration_dir().'/'.$container_name;
if (isDev()) {
$this->configuration_dir = '/var/lib/docker/volumes/coolify_dev_coolify_data/_data/databases/'.$container_name;
}

$this->commands = [
"echo 'Starting database.'",
Expand All @@ -47,11 +50,7 @@ public function handle(StandalonePostgresql $database)
'networks' => [
$this->database->destination->network,
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => [
'CMD-SHELL',
Expand All @@ -78,7 +77,7 @@ public function handle(StandalonePostgresql $database)
],
],
];
if (! is_null($this->database->limits_cpuset)) {
if (filled($this->database->limits_cpuset)) {
data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset);
}
if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) {
Expand Down Expand Up @@ -108,7 +107,7 @@ public function handle(StandalonePostgresql $database)
];
}
}
if (! is_null($this->database->postgres_conf) && ! empty($this->database->postgres_conf)) {
if (filled($this->database->postgres_conf)) {
$docker_compose['services'][$container_name]['volumes'][] = [
'type' => 'bind',
'source' => $this->configuration_dir.'/custom-postgres.conf',
Expand Down Expand Up @@ -199,9 +198,12 @@ private function generate_environment_variables()

private function generate_init_scripts()
{
if (is_null($this->database->init_scripts) || count($this->database->init_scripts) === 0) {
$this->commands[] = "rm -rf $this->configuration_dir/docker-entrypoint-initdb.d/*";

if (blank($this->database->init_scripts) || count($this->database->init_scripts) === 0) {
return;
}

foreach ($this->database->init_scripts as $init_script) {
$filename = data_get($init_script, 'filename');
$content = data_get($init_script, 'content');
Expand All @@ -213,17 +215,22 @@ private function generate_init_scripts()

private function add_custom_conf()
{
if (is_null($this->database->postgres_conf) || empty($this->database->postgres_conf)) {
$filename = 'custom-postgres.conf';
$config_file_path = "$this->configuration_dir/$filename";

if (blank($this->database->postgres_conf)) {
$this->commands[] = "rm -f $config_file_path";

return;
}
$filename = 'custom-postgres.conf';

$content = $this->database->postgres_conf;
if (! str($content)->contains('listen_addresses')) {
$content .= "\nlisten_addresses = '*'";
$this->database->postgres_conf = $content;
$this->database->save();
}
$content_base64 = base64_encode($content);
$this->commands[] = "echo '{$content_base64}' | base64 -d | tee $this->configuration_dir/{$filename} > /dev/null";
$this->commands[] = "echo '{$content_base64}' | base64 -d | tee $config_file_path > /dev/null";
}
}
6 changes: 1 addition & 5 deletions app/Actions/Database/StartRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ public function handle(StandaloneRedis $database)
'networks' => [
$this->database->destination->network,
],
'labels' => [
'coolify.managed' => 'true',
'coolify.type' => 'database',
'coolify.databaseId' => $this->database->id,
],
'labels' => defaultDatabaseLabels($this->database)->toArray(),
'healthcheck' => [
'test' => [
'CMD-SHELL',
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Docker/GetContainersStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function handle(Server $server, ?Collection $containers = null, ?Collecti
$preview->update(['last_online_at' => now()]);
}
} else {
//Notify user that this container should not be there.
// Notify user that this container should not be there.
}
} else {
$application = $this->applications->where('id', $applicationId)->first();
Expand All @@ -125,7 +125,7 @@ public function handle(Server $server, ?Collection $containers = null, ?Collecti
$application->update(['last_online_at' => now()]);
}
} else {
//Notify user that this container should not be there.
// Notify user that this container should not be there.
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function handle()
'team_id' => 0,
]);
}
//$this->mail = (new BackupSuccess($backup->frequency, $db->name))->toMail();
// $this->mail = (new BackupSuccess($backup->frequency, $db->name))->toMail();
$this->sendEmail();
break;
// case 'invitation-link':
Expand Down
24 changes: 12 additions & 12 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,26 @@ private function checkResources(): void

foreach ($servers as $server) {
$serverTimezone = data_get($server->settings, 'server_timezone', $this->instanceTimezone);
if (validate_timezone($serverTimezone) === false) {
$serverTimezone = config('app.timezone');
}

// Sentinel check
$lastSentinelUpdate = $server->sentinel_updated_at;
if (Carbon::parse($lastSentinelUpdate)->isBefore(now()->subSeconds($server->waitBeforeDoingSshCheck()))) {
// Check container status every minute if Sentinel does not activated
if (validate_timezone($serverTimezone) === false) {
$serverTimezone = config('app.timezone');
}
if (isCloud()) {
$this->scheduleInstance->job(new ServerCheckJob($server))->timezone($serverTimezone)->everyFiveMinutes()->onOneServer();
} else {
$this->scheduleInstance->job(new ServerCheckJob($server))->timezone($serverTimezone)->everyMinute()->onOneServer();
}
// $this->scheduleInstance->job(new \App\Jobs\ServerCheckNewJob($server))->everyFiveMinutes()->onOneServer();

// Check storage usage every 10 minutes if Sentinel does not activated
$this->scheduleInstance->job(new ServerStorageCheckJob($server))->everyTenMinutes()->onOneServer();
}
if ($server->settings->force_docker_cleanup) {
$this->scheduleInstance->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->timezone($serverTimezone)->onOneServer();
} else {
$this->scheduleInstance->job(new DockerCleanupJob($server))->everyTenMinutes()->timezone($serverTimezone)->onOneServer();
$this->scheduleInstance->job(new ServerStorageCheckJob($server))->cron($server->settings->server_disk_usage_check_frequency)->timezone($serverTimezone)->onOneServer();
}

$this->scheduleInstance->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->timezone($serverTimezone)->onOneServer();

// Cleanup multiplexed connections every hour
// $this->scheduleInstance->job(new ServerCleanupMux($server))->hourly()->onOneServer();

Expand Down Expand Up @@ -213,9 +209,13 @@ private function checkScheduledBackups(): void
$serverTimezone = config('app.timezone');
}

if (isset(VALID_CRON_STRINGS[$scheduled_backup->frequency])) {
$scheduled_backup->frequency = VALID_CRON_STRINGS[$scheduled_backup->frequency];
}
$serverTimezone = data_get($server->settings, 'server_timezone', $this->instanceTimezone);
$this->scheduleInstance->job(new DatabaseBackupJob(
backup: $scheduled_backup
))->cron($scheduled_backup->frequency)->timezone($this->instanceTimezone)->onOneServer();
))->cron($scheduled_backup->frequency)->timezone($serverTimezone)->onOneServer();
}
}

Expand Down Expand Up @@ -273,7 +273,7 @@ private function checkScheduledTasks(): void
}
$this->scheduleInstance->job(new ScheduledTaskJob(
task: $scheduled_task
))->cron($scheduled_task->frequency)->timezone($this->instanceTimezone)->onOneServer();
))->cron($scheduled_task->frequency)->timezone($serverTimezone)->onOneServer();
}
}

Expand Down
34 changes: 34 additions & 0 deletions app/Events/RestoreJobFinished.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Events;

use App\Models\Server;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class RestoreJobFinished
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct($data)
{
$scriptPath = data_get($data, 'scriptPath');
$tmpPath = data_get($data, 'tmpPath');
$container = data_get($data, 'container');
$serverId = data_get($data, 'serverId');
if (filled($scriptPath) && filled($tmpPath) && filled($container) && filled($serverId)) {
if (str($tmpPath)->startsWith('/tmp/')
&& str($scriptPath)->startsWith('/tmp/')
&& ! str($tmpPath)->contains('..')
&& ! str($scriptPath)->contains('..')
&& strlen($tmpPath) > 5 // longer than just "/tmp/"
&& strlen($scriptPath) > 5
) {
$commands[] = "docker exec {$container} sh -c 'rm {$scriptPath}'";
$commands[] = "docker exec {$container} sh -c 'rm {$tmpPath}'";
instant_remote_process($commands, Server::find($serverId), throwError: true);
}
}
}
}
Loading

0 comments on commit a396d51

Please sign in to comment.