2023-09-20 13:42:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2023-12-08 17:32:08 +00:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2023-09-20 13:42:41 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2024-06-14 12:23:40 +00:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
2023-09-20 13:42:41 +00:00
|
|
|
|
|
|
|
class Service extends BaseModel
|
|
|
|
{
|
2023-12-08 17:32:08 +00:00
|
|
|
use HasFactory, SoftDeletes;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-20 13:42:41 +00:00
|
|
|
protected $guarded = [];
|
2024-04-12 10:44:49 +00:00
|
|
|
|
|
|
|
public function isConfigurationChanged(bool $save = false)
|
|
|
|
{
|
2024-04-15 13:45:50 +00:00
|
|
|
$domains = $this->applications()->get()->pluck('fqdn')->sort()->toArray();
|
2024-04-12 10:44:49 +00:00
|
|
|
$domains = implode(',', $domains);
|
|
|
|
|
2024-04-15 13:45:50 +00:00
|
|
|
$applicationImages = $this->applications()->get()->pluck('image')->sort();
|
|
|
|
$databaseImages = $this->databases()->get()->pluck('image')->sort();
|
2024-04-12 10:44:49 +00:00
|
|
|
$images = $applicationImages->merge($databaseImages);
|
|
|
|
$images = implode(',', $images->toArray());
|
|
|
|
|
2024-04-15 13:45:50 +00:00
|
|
|
$applicationStorages = $this->applications()->get()->pluck('persistentStorages')->flatten()->sortBy('id');
|
|
|
|
$databaseStorages = $this->databases()->get()->pluck('persistentStorages')->flatten()->sortBy('id');
|
2024-04-12 10:44:49 +00:00
|
|
|
$storages = $applicationStorages->merge($databaseStorages)->implode('updated_at');
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
$newConfigHash = $images.$domains.$images.$storages;
|
2024-04-15 13:45:50 +00:00
|
|
|
$newConfigHash .= json_encode($this->environment_variables()->get('value')->sort());
|
2024-04-12 10:44:49 +00:00
|
|
|
$newConfigHash = md5($newConfigHash);
|
|
|
|
$oldConfigHash = data_get($this, 'config_hash');
|
|
|
|
if ($oldConfigHash === null) {
|
|
|
|
if ($save) {
|
|
|
|
$this->config_hash = $newConfigHash;
|
|
|
|
$this->save();
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-12 10:44:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ($oldConfigHash === $newConfigHash) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if ($save) {
|
|
|
|
$this->config_hash = $newConfigHash;
|
|
|
|
$this->save();
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-12 10:44:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-12 10:44:49 +00:00
|
|
|
public function isExited()
|
|
|
|
{
|
|
|
|
return (bool) str($this->status())->contains('exited');
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-22 09:23:49 +00:00
|
|
|
public function type()
|
2023-09-20 13:42:41 +00:00
|
|
|
{
|
2023-09-22 09:23:49 +00:00
|
|
|
return 'service';
|
2023-09-20 13:42:41 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-03 11:39:07 +00:00
|
|
|
public function project()
|
|
|
|
{
|
|
|
|
return data_get($this, 'environment.project');
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-23 16:13:23 +00:00
|
|
|
public function team()
|
|
|
|
{
|
|
|
|
return data_get($this, 'environment.project.team');
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-02 10:50:28 +00:00
|
|
|
public function tags()
|
|
|
|
{
|
|
|
|
return $this->morphToMany(Tag::class, 'taggable');
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-12 08:54:25 +00:00
|
|
|
public function delete_configurations()
|
|
|
|
{
|
|
|
|
$server = data_get($this, 'server');
|
|
|
|
$workdir = $this->workdir();
|
|
|
|
if (str($workdir)->endsWith($this->uuid)) {
|
2024-06-10 20:43:34 +00:00
|
|
|
instant_remote_process(['rm -rf '.$this->workdir()], $server, false);
|
2024-04-12 08:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-23 09:09:42 +00:00
|
|
|
public function status()
|
|
|
|
{
|
2024-02-16 20:56:38 +00:00
|
|
|
$applications = $this->applications;
|
|
|
|
$databases = $this->databases;
|
2024-02-23 09:09:42 +00:00
|
|
|
|
|
|
|
$complexStatus = null;
|
|
|
|
$complexHealth = null;
|
|
|
|
|
2024-02-16 20:56:38 +00:00
|
|
|
foreach ($applications as $application) {
|
|
|
|
if ($application->exclude_from_status) {
|
|
|
|
continue;
|
|
|
|
}
|
2024-02-23 09:09:42 +00:00
|
|
|
$status = str($application->status)->before('(')->trim();
|
|
|
|
$health = str($application->status)->between('(', ')')->trim();
|
|
|
|
if ($complexStatus === 'degraded') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($status->startsWith('running')) {
|
|
|
|
if ($complexStatus === 'exited') {
|
|
|
|
$complexStatus = 'degraded';
|
|
|
|
} else {
|
|
|
|
$complexStatus = 'running';
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
} elseif ($status->startsWith('restarting')) {
|
2024-02-23 09:09:42 +00:00
|
|
|
$complexStatus = 'degraded';
|
2024-06-10 20:43:34 +00:00
|
|
|
} elseif ($status->startsWith('exited')) {
|
2024-02-23 09:09:42 +00:00
|
|
|
$complexStatus = 'exited';
|
|
|
|
}
|
|
|
|
if ($health->value() === 'healthy') {
|
|
|
|
if ($complexHealth === 'unhealthy') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$complexHealth = 'healthy';
|
2024-02-16 20:56:38 +00:00
|
|
|
} else {
|
2024-02-23 09:09:42 +00:00
|
|
|
$complexHealth = 'unhealthy';
|
2024-02-16 20:56:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($databases as $database) {
|
|
|
|
if ($database->exclude_from_status) {
|
|
|
|
continue;
|
|
|
|
}
|
2024-02-23 09:09:42 +00:00
|
|
|
$status = str($database->status)->before('(')->trim();
|
|
|
|
$health = str($database->status)->between('(', ')')->trim();
|
|
|
|
if ($complexStatus === 'degraded') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($status->startsWith('running')) {
|
|
|
|
if ($complexStatus === 'exited') {
|
|
|
|
$complexStatus = 'degraded';
|
|
|
|
} else {
|
|
|
|
$complexStatus = 'running';
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
} elseif ($status->startsWith('restarting')) {
|
2024-02-23 09:09:42 +00:00
|
|
|
$complexStatus = 'degraded';
|
2024-06-10 20:43:34 +00:00
|
|
|
} elseif ($status->startsWith('exited')) {
|
2024-02-23 09:09:42 +00:00
|
|
|
$complexStatus = 'exited';
|
|
|
|
}
|
|
|
|
if ($health->value() === 'healthy') {
|
|
|
|
if ($complexHealth === 'unhealthy') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$complexHealth = 'healthy';
|
2024-02-16 20:56:38 +00:00
|
|
|
} else {
|
2024-02-23 09:09:42 +00:00
|
|
|
$complexHealth = 'unhealthy';
|
2024-02-16 20:56:38 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-23 09:09:42 +00:00
|
|
|
return "{$complexStatus}:{$complexHealth}";
|
2024-02-16 20:56:38 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-11-13 10:09:21 +00:00
|
|
|
public function extraFields()
|
|
|
|
{
|
|
|
|
$fields = collect([]);
|
|
|
|
$applications = $this->applications()->get();
|
|
|
|
foreach ($applications as $application) {
|
|
|
|
$image = str($application->image)->before(':')->value();
|
|
|
|
switch ($image) {
|
2024-04-17 10:48:04 +00:00
|
|
|
case str($image)?->contains('tolgee'):
|
|
|
|
$data = collect([]);
|
|
|
|
$admin_password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_TOLGEE')->first();
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin User' => [
|
|
|
|
'key' => 'TOLGEE_AUTHENTICATION_INITIAL_USERNAME',
|
|
|
|
'value' => 'admin',
|
|
|
|
'readonly' => true,
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
if ($admin_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin Password' => [
|
|
|
|
'key' => 'SERVICE_PASSWORD_TOLGEE',
|
|
|
|
'value' => data_get($admin_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
2024-05-07 08:22:02 +00:00
|
|
|
$fields->put('Tolgee', $data->toArray());
|
2024-04-17 10:48:04 +00:00
|
|
|
break;
|
2024-04-16 12:08:11 +00:00
|
|
|
case str($image)?->contains('logto'):
|
|
|
|
$data = collect([]);
|
|
|
|
$logto_endpoint = $this->environment_variables()->where('key', 'LOGTO_ENDPOINT')->first();
|
|
|
|
$logto_admin_endpoint = $this->environment_variables()->where('key', 'LOGTO_ADMIN_ENDPOINT')->first();
|
|
|
|
if ($logto_endpoint) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Endpoint' => [
|
|
|
|
'key' => data_get($logto_endpoint, 'key'),
|
|
|
|
'value' => data_get($logto_endpoint, 'value'),
|
|
|
|
'rules' => 'required|url',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($logto_admin_endpoint) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin Endpoint' => [
|
|
|
|
'key' => data_get($logto_admin_endpoint, 'key'),
|
|
|
|
'value' => data_get($logto_admin_endpoint, 'value'),
|
|
|
|
'rules' => 'required|url',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
2024-05-07 08:22:02 +00:00
|
|
|
$fields->put('Logto', $data->toArray());
|
2024-04-16 12:08:11 +00:00
|
|
|
break;
|
2024-04-16 10:41:28 +00:00
|
|
|
case str($image)?->contains('unleash-server'):
|
|
|
|
$data = collect([]);
|
|
|
|
$admin_password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_UNLEASH')->first();
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin User' => [
|
|
|
|
'key' => 'SERVICE_USER_UNLEASH',
|
|
|
|
'value' => 'admin',
|
|
|
|
'readonly' => true,
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
if ($admin_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin Password' => [
|
|
|
|
'key' => 'SERVICE_PASSWORD_UNLEASH',
|
|
|
|
'value' => data_get($admin_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
2024-05-07 08:22:02 +00:00
|
|
|
$fields->put('Unleash', $data->toArray());
|
2024-04-16 10:41:28 +00:00
|
|
|
break;
|
2024-03-12 16:43:00 +00:00
|
|
|
case str($image)?->contains('grafana'):
|
|
|
|
$data = collect([]);
|
|
|
|
$admin_password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_GRAFANA')->first();
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin User' => [
|
|
|
|
'key' => 'GF_SECURITY_ADMIN_USER',
|
|
|
|
'value' => 'admin',
|
|
|
|
'readonly' => true,
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
if ($admin_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin Password' => [
|
|
|
|
'key' => 'GF_SECURITY_ADMIN_PASSWORD',
|
|
|
|
'value' => data_get($admin_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
2024-05-07 08:22:02 +00:00
|
|
|
$fields->put('Grafana', $data->toArray());
|
2024-03-12 16:43:00 +00:00
|
|
|
break;
|
2024-03-04 11:46:33 +00:00
|
|
|
case str($image)?->contains('directus'):
|
|
|
|
$data = collect([]);
|
|
|
|
$admin_email = $this->environment_variables()->where('key', 'ADMIN_EMAIL')->first();
|
|
|
|
$admin_password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_ADMIN')->first();
|
|
|
|
|
|
|
|
if ($admin_email) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin Email' => [
|
|
|
|
'key' => data_get($admin_email, 'key'),
|
|
|
|
'value' => data_get($admin_email, 'value'),
|
|
|
|
'rules' => 'required|email',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($admin_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin Password' => [
|
|
|
|
'key' => data_get($admin_password, 'key'),
|
|
|
|
'value' => data_get($admin_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
2024-05-07 08:22:02 +00:00
|
|
|
$fields->put('Directus', $data->toArray());
|
2024-03-04 11:46:33 +00:00
|
|
|
break;
|
2024-02-28 12:48:39 +00:00
|
|
|
case str($image)?->contains('kong'):
|
|
|
|
$data = collect([]);
|
|
|
|
$dashboard_user = $this->environment_variables()->where('key', 'SERVICE_USER_ADMIN')->first();
|
|
|
|
$dashboard_password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_ADMIN')->first();
|
|
|
|
if ($dashboard_user) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Dashboard User' => [
|
|
|
|
'key' => data_get($dashboard_user, 'key'),
|
|
|
|
'value' => data_get($dashboard_user, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($dashboard_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Dashboard Password' => [
|
|
|
|
'key' => data_get($dashboard_password, 'key'),
|
|
|
|
'value' => data_get($dashboard_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$fields->put('Supabase', $data->toArray());
|
2023-11-24 20:04:15 +00:00
|
|
|
case str($image)?->contains('minio'):
|
2023-11-20 14:01:35 +00:00
|
|
|
$data = collect([]);
|
2023-11-13 10:09:21 +00:00
|
|
|
$console_url = $this->environment_variables()->where('key', 'MINIO_BROWSER_REDIRECT_URL')->first();
|
|
|
|
$s3_api_url = $this->environment_variables()->where('key', 'MINIO_SERVER_URL')->first();
|
|
|
|
$admin_user = $this->environment_variables()->where('key', 'SERVICE_USER_MINIO')->first();
|
2023-11-20 14:01:35 +00:00
|
|
|
if (is_null($admin_user)) {
|
|
|
|
$admin_user = $this->environment_variables()->where('key', 'MINIO_ROOT_USER')->first();
|
|
|
|
}
|
2023-11-13 10:09:21 +00:00
|
|
|
$admin_password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_MINIO')->first();
|
2023-11-20 14:01:35 +00:00
|
|
|
if (is_null($admin_password)) {
|
|
|
|
$admin_password = $this->environment_variables()->where('key', 'MINIO_ROOT_PASSWORD')->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($console_url) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Console URL' => [
|
|
|
|
'key' => data_get($console_url, 'key'),
|
|
|
|
'value' => data_get($console_url, 'value'),
|
|
|
|
'rules' => 'required|url',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($s3_api_url) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'S3 API URL' => [
|
|
|
|
'key' => data_get($s3_api_url, 'key'),
|
|
|
|
'value' => data_get($s3_api_url, 'value'),
|
|
|
|
'rules' => 'required|url',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($admin_user) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin User' => [
|
|
|
|
'key' => data_get($admin_user, 'key'),
|
|
|
|
'value' => data_get($admin_user, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($admin_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin Password' => [
|
|
|
|
'key' => data_get($admin_password, 'key'),
|
|
|
|
'value' => data_get($admin_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$fields->put('MinIO', $data->toArray());
|
2023-11-13 10:09:21 +00:00
|
|
|
break;
|
2023-11-24 20:04:15 +00:00
|
|
|
case str($image)?->contains('weblate'):
|
2023-11-20 14:01:35 +00:00
|
|
|
$data = collect([]);
|
2023-11-13 14:19:49 +00:00
|
|
|
$admin_email = $this->environment_variables()->where('key', 'WEBLATE_ADMIN_EMAIL')->first();
|
|
|
|
$admin_password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_WEBLATE')->first();
|
2023-11-20 14:01:35 +00:00
|
|
|
|
|
|
|
if ($admin_email) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin Email' => [
|
|
|
|
'key' => data_get($admin_email, 'key'),
|
|
|
|
'value' => data_get($admin_email, 'value'),
|
|
|
|
'rules' => 'required|email',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($admin_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin Password' => [
|
|
|
|
'key' => data_get($admin_password, 'key'),
|
|
|
|
'value' => data_get($admin_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
2024-05-07 08:22:02 +00:00
|
|
|
$fields->put('Weblate', $data->toArray());
|
2023-11-24 20:04:15 +00:00
|
|
|
break;
|
2023-12-03 11:16:33 +00:00
|
|
|
case str($image)?->contains('meilisearch'):
|
|
|
|
$data = collect([]);
|
|
|
|
$SERVICE_PASSWORD_MEILISEARCH = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_MEILISEARCH')->first();
|
|
|
|
if ($SERVICE_PASSWORD_MEILISEARCH) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'API Key' => [
|
|
|
|
'key' => data_get($SERVICE_PASSWORD_MEILISEARCH, 'key'),
|
|
|
|
'value' => data_get($SERVICE_PASSWORD_MEILISEARCH, 'value'),
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
2024-05-07 08:22:02 +00:00
|
|
|
$fields->put('Meilisearch', $data->toArray());
|
2023-12-03 11:16:33 +00:00
|
|
|
break;
|
2023-11-24 20:04:15 +00:00
|
|
|
case str($image)?->contains('ghost'):
|
|
|
|
$data = collect([]);
|
|
|
|
$MAIL_OPTIONS_AUTH_PASS = $this->environment_variables()->where('key', 'MAIL_OPTIONS_AUTH_PASS')->first();
|
|
|
|
$MAIL_OPTIONS_AUTH_USER = $this->environment_variables()->where('key', 'MAIL_OPTIONS_AUTH_USER')->first();
|
|
|
|
$MAIL_OPTIONS_SECURE = $this->environment_variables()->where('key', 'MAIL_OPTIONS_SECURE')->first();
|
|
|
|
$MAIL_OPTIONS_PORT = $this->environment_variables()->where('key', 'MAIL_OPTIONS_PORT')->first();
|
|
|
|
$MAIL_OPTIONS_SERVICE = $this->environment_variables()->where('key', 'MAIL_OPTIONS_SERVICE')->first();
|
|
|
|
$MAIL_OPTIONS_HOST = $this->environment_variables()->where('key', 'MAIL_OPTIONS_HOST')->first();
|
|
|
|
if ($MAIL_OPTIONS_AUTH_PASS) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Mail Password' => [
|
|
|
|
'key' => data_get($MAIL_OPTIONS_AUTH_PASS, 'key'),
|
|
|
|
'value' => data_get($MAIL_OPTIONS_AUTH_PASS, 'value'),
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($MAIL_OPTIONS_AUTH_USER) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Mail User' => [
|
|
|
|
'key' => data_get($MAIL_OPTIONS_AUTH_USER, 'key'),
|
|
|
|
'value' => data_get($MAIL_OPTIONS_AUTH_USER, 'value'),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($MAIL_OPTIONS_SECURE) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Mail Secure' => [
|
|
|
|
'key' => data_get($MAIL_OPTIONS_SECURE, 'key'),
|
|
|
|
'value' => data_get($MAIL_OPTIONS_SECURE, 'value'),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($MAIL_OPTIONS_PORT) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Mail Port' => [
|
|
|
|
'key' => data_get($MAIL_OPTIONS_PORT, 'key'),
|
|
|
|
'value' => data_get($MAIL_OPTIONS_PORT, 'value'),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($MAIL_OPTIONS_SERVICE) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Mail Service' => [
|
|
|
|
'key' => data_get($MAIL_OPTIONS_SERVICE, 'key'),
|
|
|
|
'value' => data_get($MAIL_OPTIONS_SERVICE, 'value'),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($MAIL_OPTIONS_HOST) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Mail Host' => [
|
|
|
|
'key' => data_get($MAIL_OPTIONS_HOST, 'key'),
|
|
|
|
'value' => data_get($MAIL_OPTIONS_HOST, 'value'),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-05-07 08:22:02 +00:00
|
|
|
$fields->put('Ghost', $data->toArray());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$data = collect([]);
|
|
|
|
$admin_user = $this->environment_variables()->where('key', 'SERVICE_USER_ADMIN')->first();
|
|
|
|
$admin_password = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_ADMIN')->first();
|
2024-05-15 07:46:28 +00:00
|
|
|
if ($admin_user) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'User' => [
|
|
|
|
'key' => 'SERVICE_USER_ADMIN',
|
|
|
|
'value' => data_get($admin_user, 'value', 'admin'),
|
|
|
|
'readonly' => true,
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
2024-05-07 08:22:02 +00:00
|
|
|
if ($admin_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Password' => [
|
|
|
|
'key' => 'SERVICE_PASSWORD_ADMIN',
|
|
|
|
'value' => data_get($admin_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$fields->put('Admin', $data->toArray());
|
2023-11-24 20:04:15 +00:00
|
|
|
break;
|
2024-05-27 07:51:32 +00:00
|
|
|
case str($image)?->contains('vaultwarden'):
|
|
|
|
$data = collect([]);
|
|
|
|
|
|
|
|
$DATABASE_URL = $this->environment_variables()->where('key', 'DATABASE_URL')->first();
|
|
|
|
$ADMIN_TOKEN = $this->environment_variables()->where('key', 'SERVICE_PASSWORD_64_ADMIN')->first();
|
2024-05-31 10:55:14 +00:00
|
|
|
$SIGNUP_ALLOWED = $this->environment_variables()->where('key', 'SIGNUP_ALLOWED')->first();
|
2024-05-27 22:40:35 +00:00
|
|
|
$PUSH_ENABLED = $this->environment_variables()->where('key', 'PUSH_ENABLED')->first();
|
|
|
|
$PUSH_INSTALLATION_ID = $this->environment_variables()->where('key', 'PUSH_SERVICE_ID')->first();
|
|
|
|
$PUSH_INSTALLATION_KEY = $this->environment_variables()->where('key', 'PUSH_SERVICE_KEY')->first();
|
|
|
|
|
2024-05-27 07:51:32 +00:00
|
|
|
if ($DATABASE_URL) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Database URL' => [
|
|
|
|
'key' => data_get($DATABASE_URL, 'key'),
|
|
|
|
'value' => data_get($DATABASE_URL, 'value'),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($ADMIN_TOKEN) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Admin Password' => [
|
|
|
|
'key' => data_get($ADMIN_TOKEN, 'key'),
|
|
|
|
'value' => data_get($ADMIN_TOKEN, 'value'),
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
2024-05-31 10:55:14 +00:00
|
|
|
if ($SIGNUP_ALLOWED) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Signup Allowed' => [
|
|
|
|
'key' => data_get($SIGNUP_ALLOWED, 'key'),
|
|
|
|
'value' => data_get($SIGNUP_ALLOWED, 'value'),
|
|
|
|
'rules' => 'required|string|in:true,false',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
2024-05-27 07:51:32 +00:00
|
|
|
|
2024-05-27 22:40:35 +00:00
|
|
|
if ($PUSH_ENABLED) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Push Enabled' => [
|
|
|
|
'key' => data_get($PUSH_ENABLED, 'key'),
|
|
|
|
'value' => data_get($PUSH_ENABLED, 'value'),
|
|
|
|
'rules' => 'required|string|in:true,false',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($PUSH_INSTALLATION_ID) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Push Installation ID' => [
|
|
|
|
'key' => data_get($PUSH_INSTALLATION_ID, 'key'),
|
|
|
|
'value' => data_get($PUSH_INSTALLATION_ID, 'value'),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($PUSH_INSTALLATION_KEY) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Push Installation Key' => [
|
|
|
|
'key' => data_get($PUSH_INSTALLATION_KEY, 'key'),
|
|
|
|
'value' => data_get($PUSH_INSTALLATION_KEY, 'value'),
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-05-27 07:51:32 +00:00
|
|
|
$fields->put('Vaultwarden', $data);
|
|
|
|
break;
|
2023-11-13 10:09:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$databases = $this->databases()->get();
|
|
|
|
|
|
|
|
foreach ($databases as $database) {
|
|
|
|
$image = str($database->image)->before(':')->value();
|
|
|
|
switch ($image) {
|
|
|
|
case str($image)->contains('postgres'):
|
|
|
|
$userVariables = ['SERVICE_USER_POSTGRES', 'SERVICE_USER_POSTGRESQL'];
|
|
|
|
$passwordVariables = ['SERVICE_PASSWORD_POSTGRES', 'SERVICE_PASSWORD_POSTGRESQL'];
|
|
|
|
$dbNameVariables = ['POSTGRESQL_DATABASE', 'POSTGRES_DB'];
|
|
|
|
$postgres_user = $this->environment_variables()->whereIn('key', $userVariables)->first();
|
|
|
|
$postgres_password = $this->environment_variables()->whereIn('key', $passwordVariables)->first();
|
|
|
|
$postgres_db_name = $this->environment_variables()->whereIn('key', $dbNameVariables)->first();
|
2023-11-13 16:06:43 +00:00
|
|
|
$data = collect([]);
|
|
|
|
if ($postgres_user) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'User' => [
|
|
|
|
'key' => data_get($postgres_user, 'key'),
|
|
|
|
'value' => data_get($postgres_user, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($postgres_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Password' => [
|
|
|
|
'key' => data_get($postgres_password, 'key'),
|
|
|
|
'value' => data_get($postgres_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($postgres_db_name) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Database Name' => [
|
|
|
|
'key' => data_get($postgres_db_name, 'key'),
|
|
|
|
'value' => data_get($postgres_db_name, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$fields->put('PostgreSQL', $data->toArray());
|
2023-11-13 10:09:21 +00:00
|
|
|
break;
|
|
|
|
case str($image)->contains('mysql'):
|
|
|
|
$userVariables = ['SERVICE_USER_MYSQL', 'SERVICE_USER_WORDPRESS'];
|
|
|
|
$passwordVariables = ['SERVICE_PASSWORD_MYSQL', 'SERVICE_PASSWORD_WORDPRESS'];
|
|
|
|
$rootPasswordVariables = ['SERVICE_PASSWORD_MYSQLROOT', 'SERVICE_PASSWORD_ROOT'];
|
|
|
|
$dbNameVariables = ['MYSQL_DATABASE'];
|
|
|
|
$mysql_user = $this->environment_variables()->whereIn('key', $userVariables)->first();
|
|
|
|
$mysql_password = $this->environment_variables()->whereIn('key', $passwordVariables)->first();
|
|
|
|
$mysql_root_password = $this->environment_variables()->whereIn('key', $rootPasswordVariables)->first();
|
|
|
|
$mysql_db_name = $this->environment_variables()->whereIn('key', $dbNameVariables)->first();
|
2023-11-13 16:06:43 +00:00
|
|
|
$data = collect([]);
|
|
|
|
if ($mysql_user) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'User' => [
|
|
|
|
'key' => data_get($mysql_user, 'key'),
|
|
|
|
'value' => data_get($mysql_user, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($mysql_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Password' => [
|
|
|
|
'key' => data_get($mysql_password, 'key'),
|
|
|
|
'value' => data_get($mysql_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($mysql_root_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Root Password' => [
|
|
|
|
'key' => data_get($mysql_root_password, 'key'),
|
|
|
|
'value' => data_get($mysql_root_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($mysql_db_name) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Database Name' => [
|
|
|
|
'key' => data_get($mysql_db_name, 'key'),
|
|
|
|
'value' => data_get($mysql_db_name, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$fields->put('MySQL', $data->toArray());
|
2023-11-13 10:09:21 +00:00
|
|
|
break;
|
|
|
|
case str($image)->contains('mariadb'):
|
|
|
|
$userVariables = ['SERVICE_USER_MARIADB', 'SERVICE_USER_WORDPRESS', '_APP_DB_USER'];
|
|
|
|
$passwordVariables = ['SERVICE_PASSWORD_MARIADB', 'SERVICE_PASSWORD_WORDPRESS', '_APP_DB_PASS'];
|
|
|
|
$rootPasswordVariables = ['SERVICE_PASSWORD_MARIADBROOT', 'SERVICE_PASSWORD_ROOT', '_APP_DB_ROOT_PASS'];
|
|
|
|
$dbNameVariables = ['SERVICE_DATABASE_MARIADB', 'SERVICE_DATABASE_WORDPRESS', '_APP_DB_SCHEMA'];
|
|
|
|
$mariadb_user = $this->environment_variables()->whereIn('key', $userVariables)->first();
|
|
|
|
$mariadb_password = $this->environment_variables()->whereIn('key', $passwordVariables)->first();
|
|
|
|
$mariadb_root_password = $this->environment_variables()->whereIn('key', $rootPasswordVariables)->first();
|
|
|
|
$mariadb_db_name = $this->environment_variables()->whereIn('key', $dbNameVariables)->first();
|
2023-11-13 16:06:43 +00:00
|
|
|
$data = collect([]);
|
2023-09-22 09:23:49 +00:00
|
|
|
|
2023-11-13 16:06:43 +00:00
|
|
|
if ($mariadb_user) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'User' => [
|
|
|
|
'key' => data_get($mariadb_user, 'key'),
|
|
|
|
'value' => data_get($mariadb_user, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($mariadb_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Password' => [
|
|
|
|
'key' => data_get($mariadb_password, 'key'),
|
|
|
|
'value' => data_get($mariadb_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($mariadb_root_password) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Root Password' => [
|
|
|
|
'key' => data_get($mariadb_root_password, 'key'),
|
|
|
|
'value' => data_get($mariadb_root_password, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
'isPassword' => true,
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
if ($mariadb_db_name) {
|
|
|
|
$data = $data->merge([
|
|
|
|
'Database Name' => [
|
|
|
|
'key' => data_get($mariadb_db_name, 'key'),
|
|
|
|
'value' => data_get($mariadb_db_name, 'value'),
|
|
|
|
'rules' => 'required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$fields->put('MariaDB', $data->toArray());
|
2023-11-13 10:09:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-11-13 10:09:21 +00:00
|
|
|
return $fields;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-11-13 10:09:21 +00:00
|
|
|
public function saveExtraFields($fields)
|
|
|
|
{
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
$key = data_get($field, 'key');
|
|
|
|
$value = data_get($field, 'value');
|
|
|
|
$found = $this->environment_variables()->where('key', $key)->first();
|
|
|
|
if ($found) {
|
|
|
|
$found->value = $value;
|
|
|
|
$found->save();
|
|
|
|
} else {
|
|
|
|
$this->environment_variables()->create([
|
|
|
|
'key' => $key,
|
|
|
|
'value' => $value,
|
|
|
|
'is_build_time' => false,
|
|
|
|
'service_id' => $this->id,
|
|
|
|
'is_preview' => false,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-11-27 08:39:43 +00:00
|
|
|
public function link()
|
|
|
|
{
|
2023-11-30 11:21:53 +00:00
|
|
|
if (data_get($this, 'environment.project.uuid')) {
|
|
|
|
return route('project.service.configuration', [
|
|
|
|
'project_uuid' => data_get($this, 'environment.project.uuid'),
|
|
|
|
'environment_name' => data_get($this, 'environment.name'),
|
2024-06-10 20:43:34 +00:00
|
|
|
'service_uuid' => data_get($this, 'uuid'),
|
2023-11-30 11:21:53 +00:00
|
|
|
]);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-11-30 11:21:53 +00:00
|
|
|
return null;
|
2023-11-27 08:39:43 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-21 13:36:26 +00:00
|
|
|
public function failedTaskLink($task_uuid)
|
|
|
|
{
|
|
|
|
if (data_get($this, 'environment.project.uuid')) {
|
|
|
|
return route('project.service.scheduled-tasks', [
|
|
|
|
'project_uuid' => data_get($this, 'environment.project.uuid'),
|
|
|
|
'environment_name' => data_get($this, 'environment.name'),
|
2024-05-24 15:05:18 +00:00
|
|
|
'service_uuid' => data_get($this, 'uuid'),
|
2024-06-10 20:43:34 +00:00
|
|
|
'task_uuid' => $task_uuid,
|
2024-05-21 13:36:26 +00:00
|
|
|
]);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-21 13:36:26 +00:00
|
|
|
return null;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-26 13:07:33 +00:00
|
|
|
public function documentation()
|
|
|
|
{
|
2024-05-22 07:23:17 +00:00
|
|
|
$services = get_service_templates();
|
2024-02-23 09:09:42 +00:00
|
|
|
$service = data_get($services, str($this->name)->beforeLast('-')->value, []);
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-28 09:01:00 +00:00
|
|
|
return data_get($service, 'documentation', config('constants.docs.base_url'));
|
2023-09-26 13:07:33 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-20 13:42:41 +00:00
|
|
|
public function applications()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ServiceApplication::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-20 13:42:41 +00:00
|
|
|
public function databases()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ServiceDatabase::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-10-02 13:51:06 +00:00
|
|
|
public function destination()
|
|
|
|
{
|
|
|
|
return $this->morphTo();
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-21 15:48:31 +00:00
|
|
|
public function environment()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Environment::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-22 09:23:49 +00:00
|
|
|
public function server()
|
|
|
|
{
|
2023-09-21 15:48:31 +00:00
|
|
|
return $this->belongsTo(Server::class);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
|
|
|
public function byUuid(string $uuid)
|
|
|
|
{
|
2024-05-14 13:19:28 +00:00
|
|
|
$app = $this->applications()->whereUuid($uuid)->first();
|
|
|
|
if ($app) {
|
|
|
|
return $app;
|
|
|
|
}
|
|
|
|
$db = $this->databases()->whereUuid($uuid)->first();
|
|
|
|
if ($db) {
|
|
|
|
return $db;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-14 13:19:28 +00:00
|
|
|
return null;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-21 15:48:31 +00:00
|
|
|
public function byName(string $name)
|
|
|
|
{
|
|
|
|
$app = $this->applications()->whereName($name)->first();
|
|
|
|
if ($app) {
|
|
|
|
return $app;
|
|
|
|
}
|
|
|
|
$db = $this->databases()->whereName($name)->first();
|
|
|
|
if ($db) {
|
|
|
|
return $db;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-21 15:48:31 +00:00
|
|
|
return null;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-05 05:06:36 +00:00
|
|
|
public function scheduled_tasks(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(ScheduledTask::class)->orderBy('name', 'asc');
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-20 13:42:41 +00:00
|
|
|
public function environment_variables(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(EnvironmentVariable::class)->orderBy('key', 'asc');
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-11-02 13:03:02 +00:00
|
|
|
public function environment_variables_preview(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(EnvironmentVariable::class)->where('is_preview', true)->orderBy('key', 'asc');
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-25 13:48:43 +00:00
|
|
|
public function workdir()
|
|
|
|
{
|
2024-06-10 20:43:34 +00:00
|
|
|
return service_configuration_dir()."/{$this->uuid}";
|
2023-09-25 10:49:55 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-25 10:49:55 +00:00
|
|
|
public function saveComposeConfigs()
|
|
|
|
{
|
|
|
|
$workdir = $this->workdir();
|
|
|
|
$commands[] = "mkdir -p $workdir";
|
|
|
|
$commands[] = "cd $workdir";
|
|
|
|
|
2024-06-14 12:23:40 +00:00
|
|
|
$json = Yaml::parse($this->docker_compose);
|
2024-06-22 11:32:45 +00:00
|
|
|
$this->docker_compose = Yaml::dump($json, 10, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
|
2023-09-25 10:49:55 +00:00
|
|
|
$docker_compose_base64 = base64_encode($this->docker_compose);
|
2024-06-22 10:55:26 +00:00
|
|
|
|
2024-04-17 08:49:34 +00:00
|
|
|
$commands[] = "echo $docker_compose_base64 | base64 -d | tee docker-compose.yml > /dev/null";
|
2024-06-10 20:43:34 +00:00
|
|
|
$commands[] = 'rm -f .env || true';
|
2024-06-22 10:55:26 +00:00
|
|
|
|
2024-06-25 08:34:56 +00:00
|
|
|
$envs_from_coolify = $this->environment_variables()->get();
|
2024-06-22 10:55:26 +00:00
|
|
|
foreach ($envs_from_coolify as $env) {
|
2024-01-23 16:13:23 +00:00
|
|
|
$commands[] = "echo '{$env->key}={$env->real_value}' >> .env";
|
2023-09-25 10:49:55 +00:00
|
|
|
}
|
2024-06-22 10:55:26 +00:00
|
|
|
if ($envs_from_coolify->count() === 0) {
|
2024-06-10 20:43:34 +00:00
|
|
|
$commands[] = 'touch .env';
|
2023-09-26 12:45:52 +00:00
|
|
|
}
|
2023-09-25 10:49:55 +00:00
|
|
|
instant_remote_process($commands, $this->server);
|
|
|
|
}
|
2023-09-28 08:53:00 +00:00
|
|
|
|
2023-09-27 10:45:53 +00:00
|
|
|
public function parse(bool $isNew = false): Collection
|
2023-09-20 13:42:41 +00:00
|
|
|
{
|
2023-11-24 14:48:23 +00:00
|
|
|
return parseDockerComposeFile($this, $isNew);
|
2023-09-20 13:42:41 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-11-27 08:58:31 +00:00
|
|
|
public function networks()
|
|
|
|
{
|
|
|
|
$networks = getTopLevelNetworks($this);
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-11-27 08:58:31 +00:00
|
|
|
return $networks;
|
|
|
|
}
|
2023-09-20 13:42:41 +00:00
|
|
|
}
|