mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-14 06:17:36 +00:00
Merge branch 'next' into feat/healthcheck-cmd
This commit is contained in:
192 files changed
+16780
-10634
No files matched your search
@@ -123,6 +123,12 @@ class EnvironmentVariable extends BaseModel
|
||||
}
|
||||
|
||||
$real_value = $this->get_real_environment_variables($this->value, $resource);
|
||||
|
||||
// Skip escaping for valid JSON objects/arrays to prevent quote corruption (see #6160)
|
||||
if (json_validate($real_value) && (str_starts_with($real_value, '{') || str_starts_with($real_value, '['))) {
|
||||
return $real_value;
|
||||
}
|
||||
|
||||
if ($this->is_literal || $this->is_multiline) {
|
||||
$real_value = '\''.$real_value.'\'';
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Once;
|
||||
use Spatie\Url\Url;
|
||||
|
||||
class InstanceSettings extends Model
|
||||
@@ -35,6 +36,9 @@ class InstanceSettings extends Model
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::updated(function ($settings) {
|
||||
// Clear once() cache so subsequent calls get fresh data
|
||||
Once::flush();
|
||||
|
||||
// Clear trusted hosts cache when FQDN changes
|
||||
if ($settings->wasChanged('fqdn')) {
|
||||
\Cache::forget('instance_settings_fqdn_host');
|
||||
@@ -82,7 +86,7 @@ class InstanceSettings extends Model
|
||||
|
||||
public static function get()
|
||||
{
|
||||
return InstanceSettings::findOrFail(0);
|
||||
return once(fn () => InstanceSettings::findOrFail(0));
|
||||
}
|
||||
|
||||
// public function getRecipients($notification)
|
||||
|
||||
@@ -5,13 +5,35 @@ namespace App\Models;
|
||||
use App\Traits\HasSafeStringAttribute;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
#[OA\Schema(
|
||||
description: 'Scheduled Task model',
|
||||
type: 'object',
|
||||
properties: [
|
||||
'id' => ['type' => 'integer', 'description' => 'The unique identifier of the scheduled task in the database.'],
|
||||
'uuid' => ['type' => 'string', 'description' => 'The unique identifier of the scheduled task.'],
|
||||
'enabled' => ['type' => 'boolean', 'description' => 'The flag to indicate if the scheduled task is enabled.'],
|
||||
'name' => ['type' => 'string', 'description' => 'The name of the scheduled task.'],
|
||||
'command' => ['type' => 'string', 'description' => 'The command to execute.'],
|
||||
'frequency' => ['type' => 'string', 'description' => 'The frequency of the scheduled task.'],
|
||||
'container' => ['type' => 'string', 'nullable' => true, 'description' => 'The container where the command should be executed.'],
|
||||
'timeout' => ['type' => 'integer', 'description' => 'The timeout of the scheduled task in seconds.'],
|
||||
'created_at' => ['type' => 'string', 'format' => 'date-time', 'description' => 'The date and time when the scheduled task was created.'],
|
||||
'updated_at' => ['type' => 'string', 'format' => 'date-time', 'description' => 'The date and time when the scheduled task was last updated.'],
|
||||
],
|
||||
)]
|
||||
class ScheduledTask extends BaseModel
|
||||
{
|
||||
use HasSafeStringAttribute;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public static function ownedByCurrentTeamAPI(int $teamId)
|
||||
{
|
||||
return static::where('team_id', $teamId)->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -3,7 +3,23 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
#[OA\Schema(
|
||||
description: 'Scheduled Task Execution model',
|
||||
type: 'object',
|
||||
properties: [
|
||||
'uuid' => ['type' => 'string', 'description' => 'The unique identifier of the execution.'],
|
||||
'status' => ['type' => 'string', 'enum' => ['success', 'failed', 'running'], 'description' => 'The status of the execution.'],
|
||||
'message' => ['type' => 'string', 'nullable' => true, 'description' => 'The output message of the execution.'],
|
||||
'retry_count' => ['type' => 'integer', 'description' => 'The number of retries.'],
|
||||
'duration' => ['type' => 'number', 'nullable' => true, 'description' => 'Duration in seconds.'],
|
||||
'started_at' => ['type' => 'string', 'format' => 'date-time', 'nullable' => true, 'description' => 'When the execution started.'],
|
||||
'finished_at' => ['type' => 'string', 'format' => 'date-time', 'nullable' => true, 'description' => 'When the execution finished.'],
|
||||
'created_at' => ['type' => 'string', 'format' => 'date-time', 'description' => 'When the record was created.'],
|
||||
'updated_at' => ['type' => 'string', 'format' => 'date-time', 'description' => 'When the record was last updated.'],
|
||||
],
|
||||
)]
|
||||
class ScheduledTaskExecution extends BaseModel
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
@@ -108,6 +108,12 @@ class Server extends BaseModel
|
||||
|
||||
public static $batch_counter = 0;
|
||||
|
||||
/**
|
||||
* Identity map cache for request-scoped Server lookups.
|
||||
* Prevents N+1 queries when the same Server is accessed multiple times.
|
||||
*/
|
||||
private static ?array $identityMapCache = null;
|
||||
|
||||
protected $appends = ['is_coolify_host'];
|
||||
|
||||
protected static function booted()
|
||||
@@ -186,6 +192,40 @@ class Server extends BaseModel
|
||||
$server->settings()->delete();
|
||||
$server->sslCertificates()->delete();
|
||||
});
|
||||
|
||||
static::updated(function () {
|
||||
static::flushIdentityMap();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a Server by ID using the identity map cache.
|
||||
* This prevents N+1 queries when the same Server is accessed multiple times.
|
||||
*/
|
||||
public static function findCached($id): ?static
|
||||
{
|
||||
if ($id === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (static::$identityMapCache === null) {
|
||||
static::$identityMapCache = [];
|
||||
}
|
||||
|
||||
if (! isset(static::$identityMapCache[$id])) {
|
||||
static::$identityMapCache[$id] = static::query()->find($id);
|
||||
}
|
||||
|
||||
return static::$identityMapCache[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the identity map cache.
|
||||
* Called automatically on update, and should be called in tests.
|
||||
*/
|
||||
public static function flushIdentityMap(): void
|
||||
{
|
||||
static::$identityMapCache = null;
|
||||
}
|
||||
|
||||
protected $casts = [
|
||||
|
||||
+35
-1
@@ -881,7 +881,7 @@ class Service extends BaseModel
|
||||
],
|
||||
]);
|
||||
}
|
||||
if ($SERVICE_PASSWORD_LINKDING) {
|
||||
if ($SERVICE_PASSWORD_LINKDING) {
|
||||
$data = $data->merge([
|
||||
'Superuser Password' => [
|
||||
'key' => data_get($SERVICE_PASSWORD_LINKDING, 'key'),
|
||||
@@ -1118,6 +1118,40 @@ class Service extends BaseModel
|
||||
}
|
||||
$fields->put('Sessy', $data->toArray());
|
||||
break;
|
||||
case $image->contains('coollabsio/openclaw'):
|
||||
$data = collect([]);
|
||||
$username = $this->environment_variables()->where('key', 'AUTH_USERNAME')->first();
|
||||
$password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_OPENCLAW')->first();
|
||||
$gateway_token = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_64_GATEWAYTOKEN')->first();
|
||||
if ($username) {
|
||||
$data = $data->merge([
|
||||
'Username' => [
|
||||
'key' => data_get($username, 'key'),
|
||||
'value' => data_get($username, 'value'),
|
||||
'readonly' => true,
|
||||
],
|
||||
]);
|
||||
}
|
||||
if ($password) {
|
||||
$data = $data->merge([
|
||||
'Password' => [
|
||||
'key' => data_get($password, 'key'),
|
||||
'value' => data_get($password, 'value'),
|
||||
'isPassword' => true,
|
||||
],
|
||||
]);
|
||||
}
|
||||
if ($gateway_token) {
|
||||
$data = $data->merge([
|
||||
'Gateway Token' => [
|
||||
'key' => data_get($gateway_token, 'key'),
|
||||
'value' => data_get($gateway_token, 'value'),
|
||||
'isPassword' => true,
|
||||
],
|
||||
]);
|
||||
}
|
||||
$fields->put('Openclaw', $data->toArray());
|
||||
break;
|
||||
default:
|
||||
$data = collect([]);
|
||||
$admin_user = $this->environment_variables()->where('key', 'SERVICE_USER_ADMIN')->first();
|
||||
|
||||
@@ -73,6 +73,28 @@ class StandaloneDocker extends BaseModel
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the server attribute using identity map caching.
|
||||
* This intercepts lazy-loading to use cached Server lookups.
|
||||
*/
|
||||
public function getServerAttribute(): ?Server
|
||||
{
|
||||
// Use eager loaded data if available
|
||||
if ($this->relationLoaded('server')) {
|
||||
return $this->getRelation('server');
|
||||
}
|
||||
|
||||
// Use identity map for lazy loading
|
||||
$server = Server::findCached($this->server_id);
|
||||
|
||||
// Cache in relation for future access on this instance
|
||||
if ($server) {
|
||||
$this->setRelation('server', $server);
|
||||
}
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
||||
public function services()
|
||||
{
|
||||
return $this->morphMany(Service::class, 'destination');
|
||||
|
||||
@@ -28,9 +28,23 @@ class StandalonePostgresql extends BaseModel
|
||||
protected static function booted()
|
||||
{
|
||||
static::created(function ($database) {
|
||||
// This is really stupid and it took me 1h to figure out why the image was not loading properly. This is exactly the reason why we need to use the action pattern because Model events and Accessors are a fragile mess!
|
||||
$image = (string) ($database->getAttributes()['image'] ?? '');
|
||||
$majorVersion = 0;
|
||||
|
||||
if (preg_match('/:(?:pg)?(\d+)/i', $image, $matches)) {
|
||||
$majorVersion = (int) $matches[1];
|
||||
}
|
||||
|
||||
// PostgreSQL 18+ uses /var/lib/postgresql as mount path
|
||||
// Older versions use /var/lib/postgresql/data
|
||||
$mountPath = $majorVersion >= 18
|
||||
? '/var/lib/postgresql'
|
||||
: '/var/lib/postgresql/data';
|
||||
|
||||
LocalPersistentVolume::create([
|
||||
'name' => 'postgres-data-'.$database->uuid,
|
||||
'mount_path' => '/var/lib/postgresql/data',
|
||||
'mount_path' => $mountPath,
|
||||
'host_path' => null,
|
||||
'resource_id' => $database->id,
|
||||
'resource_type' => $database->getMorphClass(),
|
||||
|
||||
@@ -56,6 +56,28 @@ class SwarmDocker extends BaseModel
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the server attribute using identity map caching.
|
||||
* This intercepts lazy-loading to use cached Server lookups.
|
||||
*/
|
||||
public function getServerAttribute(): ?Server
|
||||
{
|
||||
// Use eager loaded data if available
|
||||
if ($this->relationLoaded('server')) {
|
||||
return $this->getRelation('server');
|
||||
}
|
||||
|
||||
// Use identity map for lazy loading
|
||||
$server = Server::findCached($this->server_id);
|
||||
|
||||
// Cache in relation for future access on this instance
|
||||
if ($server) {
|
||||
$this->setRelation('server', $server);
|
||||
}
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
||||
public function services()
|
||||
{
|
||||
return $this->morphMany(Service::class, 'destination');
|
||||
|
||||
Reference in new issue
Block a user