Implement Keystone environment deployments
This commit is contained in:
@@ -3,20 +3,24 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\RepositoryType;
|
||||
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\HasManyThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
class Application extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'repository_type' => RepositoryType::class,
|
||||
'deploy_key_private' => 'encrypted',
|
||||
'deploy_key_installed_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -25,18 +29,13 @@ class Application extends Model
|
||||
return $this->belongsTo(Organisation::class);
|
||||
}
|
||||
|
||||
public function instances(): HasMany
|
||||
public function environments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Instance::class);
|
||||
return $this->hasMany(Environment::class);
|
||||
}
|
||||
|
||||
public function servers(): HasManyThrough
|
||||
public function operations(): MorphMany
|
||||
{
|
||||
return $this->hasManyThrough(Server::class, Instance::class);
|
||||
}
|
||||
|
||||
public function deployments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Deployment::class, 'target');
|
||||
return $this->morphMany(Operation::class, 'target');
|
||||
}
|
||||
}
|
||||
|
||||
35
app/Models/BuildArtifact.php
Normal file
35
app/Models/BuildArtifact.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\BuildArtifactStatus;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class BuildArtifact extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'status' => BuildArtifactStatus::class,
|
||||
'metadata' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function environment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Environment::class);
|
||||
}
|
||||
|
||||
public function builtByOperation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Operation::class, 'built_by_operation_id');
|
||||
}
|
||||
|
||||
public function builtByService(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Service::class, 'built_by_service_id');
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
class Deployment extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function (self $deployment) {
|
||||
$deployment->hash = str()->random(16);
|
||||
});
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'started_at' => 'datetime',
|
||||
'finished_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function steps(): HasMany
|
||||
{
|
||||
return $this->hasMany(Step::class);
|
||||
}
|
||||
|
||||
public function target(): MorphTo
|
||||
{
|
||||
return $this->morphTo('target');
|
||||
}
|
||||
}
|
||||
56
app/Models/Environment.php
Normal file
56
app/Models/Environment.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\SchedulerMode;
|
||||
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 Environment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'scheduler_enabled' => 'boolean',
|
||||
'scheduler_mode' => SchedulerMode::class,
|
||||
'build_config' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function application(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Application::class);
|
||||
}
|
||||
|
||||
public function services(): HasMany
|
||||
{
|
||||
return $this->hasMany(Service::class);
|
||||
}
|
||||
|
||||
public function attachments(): HasMany
|
||||
{
|
||||
return $this->hasMany(EnvironmentAttachment::class);
|
||||
}
|
||||
|
||||
public function variables(): HasMany
|
||||
{
|
||||
return $this->hasMany(EnvironmentVariable::class);
|
||||
}
|
||||
|
||||
public function buildArtifacts(): HasMany
|
||||
{
|
||||
return $this->hasMany(BuildArtifact::class);
|
||||
}
|
||||
|
||||
public function operations(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Operation::class, 'target');
|
||||
}
|
||||
}
|
||||
35
app/Models/EnvironmentAttachment.php
Normal file
35
app/Models/EnvironmentAttachment.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\EnvironmentAttachmentRole;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class EnvironmentAttachment extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_primary' => 'boolean',
|
||||
'role' => EnvironmentAttachmentRole::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function environment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Environment::class);
|
||||
}
|
||||
|
||||
public function service(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
public function serviceSlice(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ServiceSlice::class);
|
||||
}
|
||||
}
|
||||
31
app/Models/EnvironmentVariable.php
Normal file
31
app/Models/EnvironmentVariable.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\EnvironmentVariableSource;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class EnvironmentVariable extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'value' => 'encrypted',
|
||||
'source' => EnvironmentVariableSource::class,
|
||||
'overridable' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function environment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Environment::class);
|
||||
}
|
||||
|
||||
public function serviceSlice(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ServiceSlice::class);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
class Instance extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'config' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function application(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Application::class);
|
||||
}
|
||||
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
public function deployments(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Deployment::class, 'target');
|
||||
}
|
||||
}
|
||||
57
app/Models/Operation.php
Normal file
57
app/Models/Operation.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\OperationKind;
|
||||
use App\Enums\OperationStatus;
|
||||
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\MorphTo;
|
||||
|
||||
class Operation extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function (self $operation) {
|
||||
$operation->hash ??= str()->random(16);
|
||||
});
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'kind' => OperationKind::class,
|
||||
'status' => OperationStatus::class,
|
||||
'started_at' => 'datetime',
|
||||
'finished_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Operation::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(Operation::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function steps(): HasMany
|
||||
{
|
||||
return $this->hasMany(OperationStep::class);
|
||||
}
|
||||
|
||||
public function target(): MorphTo
|
||||
{
|
||||
return $this->morphTo('target');
|
||||
}
|
||||
}
|
||||
85
app/Models/OperationStep.php
Normal file
85
app/Models/OperationStep.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\OperationStatus;
|
||||
use App\Jobs\Services\RunStep;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class OperationStep extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $appends = [
|
||||
'logs_excerpt',
|
||||
'error_logs_excerpt',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'status' => OperationStatus::class,
|
||||
'started_at' => 'datetime',
|
||||
'finished_at' => 'datetime',
|
||||
'secrets' => 'encrypted:array',
|
||||
];
|
||||
}
|
||||
|
||||
public function operation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Operation::class);
|
||||
}
|
||||
|
||||
public function logsExcerpt(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->logs ? Str::afterLast($this->logs, "\n") : null,
|
||||
);
|
||||
}
|
||||
|
||||
public function errorLogsExcerpt(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->error_logs ? Str::afterLast($this->error_logs, "\n") : null,
|
||||
);
|
||||
}
|
||||
|
||||
public function dispatchJob(): void
|
||||
{
|
||||
dispatch(new RunStep($this));
|
||||
}
|
||||
|
||||
public function scriptForExecution(): string
|
||||
{
|
||||
$script = $this->script;
|
||||
|
||||
foreach (($this->secrets ?? []) as $key => $value) {
|
||||
$script = str_replace("[!{$key}!]", $value, $script);
|
||||
}
|
||||
|
||||
return $script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{container_id?: string, health_status?: string}
|
||||
*/
|
||||
public function capturedRuntimeState(): array
|
||||
{
|
||||
$state = [];
|
||||
|
||||
foreach (explode("\n", (string) $this->logs) as $line) {
|
||||
if (str_starts_with($line, 'container_id=')) {
|
||||
$state['container_id'] = trim((string) str($line)->after('container_id='));
|
||||
}
|
||||
|
||||
if (str_starts_with($line, 'health_status=')) {
|
||||
$state['health_status'] = trim((string) str($line)->after('health_status='));
|
||||
}
|
||||
}
|
||||
|
||||
return array_filter($state, fn (string $value): bool => $value !== '');
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,21 @@ class Organisation extends Model
|
||||
return $this->hasMany(Application::class);
|
||||
}
|
||||
|
||||
public function services(): HasMany
|
||||
{
|
||||
return $this->hasMany(Service::class);
|
||||
}
|
||||
|
||||
public function registries(): HasMany
|
||||
{
|
||||
return $this->hasMany(Registry::class);
|
||||
}
|
||||
|
||||
public function sourceProviders(): HasMany
|
||||
{
|
||||
return $this->hasMany(SourceProvider::class);
|
||||
}
|
||||
|
||||
public function providers(): HasMany
|
||||
{
|
||||
return $this->hasMany(Provider::class);
|
||||
|
||||
27
app/Models/Registry.php
Normal file
27
app/Models/Registry.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\RegistryType;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Registry extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $hidden = ['credentials'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'type' => RegistryType::class,
|
||||
'credentials' => 'encrypted:array',
|
||||
];
|
||||
}
|
||||
|
||||
public function organisation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Organisation::class);
|
||||
}
|
||||
}
|
||||
@@ -44,14 +44,9 @@ class Server extends Model
|
||||
return $this->hasMany(Service::class);
|
||||
}
|
||||
|
||||
public function instances(): HasMany
|
||||
public function serviceReplicas(): HasMany
|
||||
{
|
||||
return $this->hasMany(Instance::class);
|
||||
}
|
||||
|
||||
public function applications(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Application::class, Instance::class);
|
||||
return $this->hasMany(ServiceReplica::class);
|
||||
}
|
||||
|
||||
public function firewallRules(): HasMany
|
||||
@@ -64,26 +59,16 @@ class Server extends Model
|
||||
return $this->belongsTo(Provider::class);
|
||||
}
|
||||
|
||||
public function serviceDeployments(): HasManyThrough
|
||||
public function serviceOperations(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
Deployment::class,
|
||||
Operation::class,
|
||||
Service::class,
|
||||
'server_id',
|
||||
'target_id',
|
||||
)->where('target_type', (new Service)->getMorphClass());
|
||||
}
|
||||
|
||||
public function applicationDeployments(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
Deployment::class,
|
||||
Application::class,
|
||||
'server_id',
|
||||
'target_id',
|
||||
)->where('target_type', (new Application)->getMorphClass());
|
||||
}
|
||||
|
||||
public function sshClient(string $user = 'root'): Ssh
|
||||
{
|
||||
return Ssh::create($user, $this->ipv4)
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
29
app/Models/ServiceEndpoint.php
Normal file
29
app/Models/ServiceEndpoint.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ServiceEndpointScope;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ServiceEndpoint extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'scope' => ServiceEndpointScope::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function service(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
public function serviceReplica(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ServiceReplica::class);
|
||||
}
|
||||
}
|
||||
43
app/Models/ServiceReplica.php
Normal file
43
app/Models/ServiceReplica.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
class ServiceReplica extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'cpu_limit' => 'decimal:3',
|
||||
'config' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function service(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
public function operation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Operation::class);
|
||||
}
|
||||
|
||||
public function operations(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Operation::class, 'target');
|
||||
}
|
||||
}
|
||||
44
app/Models/ServiceSlice.php
Normal file
44
app/Models/ServiceSlice.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
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 ServiceSlice extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'config' => 'array',
|
||||
'credentials' => 'encrypted:array',
|
||||
];
|
||||
}
|
||||
|
||||
public function service(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Service::class);
|
||||
}
|
||||
|
||||
public function environment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Environment::class);
|
||||
}
|
||||
|
||||
public function attachments(): HasMany
|
||||
{
|
||||
return $this->hasMany(EnvironmentAttachment::class);
|
||||
}
|
||||
|
||||
public function operations(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Operation::class, 'target');
|
||||
}
|
||||
}
|
||||
25
app/Models/SourceProvider.php
Normal file
25
app/Models/SourceProvider.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\SourceProviderType;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SourceProvider extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'type' => SourceProviderType::class,
|
||||
'config' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function organisation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Organisation::class);
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Jobs\Services\RunStep;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Step extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $appends = [
|
||||
'logs_excerpt',
|
||||
'error_logs_excerpt',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'started_at' => 'datetime',
|
||||
'finished_at' => 'datetime',
|
||||
'secrets' => 'encrypted:array',
|
||||
];
|
||||
}
|
||||
|
||||
public function deployment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Deployment::class);
|
||||
}
|
||||
|
||||
public function logsExcerpt(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->logs ? Str::afterLast($this->logs, "\n"): null,
|
||||
);
|
||||
}
|
||||
|
||||
public function errorLogsExcerpt(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->error_logs ? Str::afterLast($this->error_logs, "\n"): null,
|
||||
);
|
||||
}
|
||||
|
||||
public function dispatchJob(): void
|
||||
{
|
||||
dispatch(new RunStep($this));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user