81 lines
1.7 KiB
PHP
81 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\DockerImageBuildFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
#[Fillable([
|
|
'user_id',
|
|
'image_name',
|
|
'image_tag',
|
|
'dockerfile_content',
|
|
'environment',
|
|
'status',
|
|
'build_output',
|
|
'successful',
|
|
'exit_code',
|
|
'queued_at',
|
|
'started_at',
|
|
'finished_at',
|
|
])]
|
|
class DockerImageBuild extends Model
|
|
{
|
|
/** @use HasFactory<DockerImageBuildFactory> */
|
|
use HasFactory;
|
|
|
|
public const STATUS_QUEUED = 'queued';
|
|
|
|
public const STATUS_RUNNING = 'running';
|
|
|
|
public const STATUS_SUCCEEDED = 'succeeded';
|
|
|
|
public const STATUS_FAILED = 'failed';
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'environment' => 'array',
|
|
'successful' => 'boolean',
|
|
'queued_at' => 'datetime',
|
|
'started_at' => 'datetime',
|
|
'finished_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the user that owns the Docker image build.
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Get the full Docker image reference.
|
|
*/
|
|
public function image(): string
|
|
{
|
|
return "{$this->image_name}:{$this->image_tag}";
|
|
}
|
|
|
|
/**
|
|
* Determine if the build has finished running.
|
|
*/
|
|
public function isFinished(): bool
|
|
{
|
|
return in_array($this->status, [
|
|
self::STATUS_SUCCEEDED,
|
|
self::STATUS_FAILED,
|
|
], true);
|
|
}
|
|
}
|