feat: initial api endpoints

feat: server resources are now looks better
This commit is contained in:
Andras Bacsai
2024-02-16 21:56:38 +01:00
parent 3539e4dce9
commit b8708f086e
24 changed files with 318 additions and 142 deletions

View File

@@ -26,7 +26,6 @@ class Environment extends Model
{
return $this->hasMany(Application::class);
}
public function postgresqls()
{
return $this->hasMany(StandalonePostgresql::class);

View File

@@ -6,7 +6,10 @@ use Illuminate\Database\Eloquent\Model;
class ProjectSetting extends Model
{
protected $fillable = [
'project_id'
];
protected $guarded = [];
public function project()
{
return $this->belongsTo(Project::class);
}
}

View File

@@ -245,6 +245,8 @@ class Server extends BaseModel
$mysqls = data_get($standaloneDocker, 'mysqls', collect([]));
$mariadbs = data_get($standaloneDocker, 'mariadbs', collect([]));
return $postgresqls->concat($redis)->concat($mongodbs)->concat($mysqls)->concat($mariadbs);
})->filter(function ($item) {
return data_get($item,'name') === 'coolify-db';
})->flatten();
}
public function applications()

View File

@@ -28,6 +28,48 @@ class Service extends BaseModel
{
return $this->morphToMany(Tag::class, 'taggable');
}
public function status() {
$foundRunning = false;
$isDegraded = false;
$foundRestaring = false;
$applications = $this->applications;
$databases = $this->databases;
foreach ($applications as $application) {
if ($application->exclude_from_status) {
continue;
}
if (Str::of($application->status)->startsWith('running')) {
$foundRunning = true;
} else if (Str::of($application->status)->startsWith('restarting')) {
$foundRestaring = true;
} else {
$isDegraded = true;
}
}
foreach ($databases as $database) {
if ($database->exclude_from_status) {
continue;
}
if (Str::of($database->status)->startsWith('running')) {
$foundRunning = true;
} else if (Str::of($database->status)->startsWith('restarting')) {
$foundRestaring = true;
} else {
$isDegraded = true;
}
}
if ($foundRestaring) {
return 'degraded';
}
if ($foundRunning && !$isDegraded) {
return 'running';
} else if ($foundRunning && $isDegraded) {
return 'degraded';
} else if (!$foundRunning && !$isDegraded) {
return 'exited';
}
return 'exited';
}
public function extraFields()
{
$fields = collect([]);

View File

@@ -82,6 +82,9 @@ class StandaloneMariadb extends BaseModel
{
return $this->morphToMany(Tag::class, 'taggable');
}
public function project() {
return data_get($this, 'environment.project');
}
public function team()
{
return data_get($this, 'environment.project.team');

View File

@@ -85,6 +85,9 @@ class StandaloneMongodb extends BaseModel
{
return $this->morphToMany(Tag::class, 'taggable');
}
public function project() {
return data_get($this, 'environment.project');
}
public function team()
{
return data_get($this, 'environment.project.team');

View File

@@ -82,6 +82,9 @@ class StandaloneMysql extends BaseModel
{
return $this->morphToMany(Tag::class, 'taggable');
}
public function project() {
return data_get($this, 'environment.project');
}
public function team()
{
return data_get($this, 'environment.project.team');

View File

@@ -82,6 +82,10 @@ class StandalonePostgresql extends BaseModel
{
return $this->morphToMany(Tag::class, 'taggable');
}
public function project()
{
return data_get($this, 'environment.project');
}
public function link()
{
if (data_get($this, 'environment.project.uuid')) {

View File

@@ -77,6 +77,10 @@ class StandaloneRedis extends BaseModel
{
return $this->morphToMany(Tag::class, 'taggable');
}
public function project()
{
return data_get($this, 'environment.project');
}
public function team()
{
return data_get($this, 'environment.project.team');