Implement Keystone environment deployments

This commit is contained in:
2026-05-13 16:11:23 +01:00
parent 65d3142d03
commit aa680b25fd
175 changed files with 10258 additions and 740 deletions

View File

@@ -4,16 +4,21 @@ namespace App\Models;
use App\Drivers\DatabaseDriver;
use App\Drivers\Driver;
use App\Enums\DeployPolicy;
use App\Enums\ServiceCategory;
use App\Enums\ServiceStatus;
use App\Enums\ServiceType;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
class Service extends Model
{
use HasFactory;
protected $guarded = [];
protected $hidden = ['credentials', 'container_name', 'container_id'];
@@ -24,6 +29,10 @@ class Service extends Model
'status' => ServiceStatus::class,
'category' => ServiceCategory::class,
'type' => ServiceType::class,
'deploy_policy' => DeployPolicy::class,
'process_roles' => 'array',
'default_cpu_limit' => 'decimal:3',
'config' => 'array',
'credentials' => 'encrypted:array',
];
}
@@ -31,7 +40,7 @@ class Service extends Model
public function folderName(): Attribute
{
return new Attribute(
get: fn() => $this->name . '-' . $this->id,
get: fn () => $this->name.'-'.$this->id,
);
}
@@ -40,14 +49,41 @@ class Service extends Model
return $this->belongsTo(Server::class);
}
public function deployments(): MorphMany
public function organisation(): BelongsTo
{
return $this->morphMany(Deployment::class, 'target');
return $this->belongsTo(Organisation::class);
}
public function environment(): BelongsTo
{
return $this->belongsTo(Environment::class);
}
public function replicas(): HasMany
{
return $this->hasMany(ServiceReplica::class);
}
public function slices(): HasMany
{
return $this->hasMany(ServiceSlice::class);
}
public function endpoints(): HasMany
{
return $this->hasMany(ServiceEndpoint::class);
}
public function operations(): MorphMany
{
return $this->morphMany(Operation::class, 'target');
}
public function driver(): Driver
{
$class = config("keystone.drivers.{$this->driver_name}");
[$driverType, $versionTrack] = array_pad(explode('.', $this->driver_name, 2), 2, null);
$class = config('keystone.drivers')[$driverType][$versionTrack] ?? null;
if (! class_exists($class)) {
throw new \Exception("Driver class {$class} not found");
}