Refactor StackForm and parseDockerComposeFile
This commit is contained in:
parent
5b0a942b42
commit
c99bb4cfd7
@ -3,12 +3,13 @@
|
|||||||
namespace App\Livewire\Project\Service;
|
namespace App\Livewire\Project\Service;
|
||||||
|
|
||||||
use App\Models\Service;
|
use App\Models\Service;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class StackForm extends Component
|
class StackForm extends Component
|
||||||
{
|
{
|
||||||
public Service $service;
|
public Service $service;
|
||||||
public $fields = [];
|
public Collection $fields;
|
||||||
protected $listeners = ["saveCompose"];
|
protected $listeners = ["saveCompose"];
|
||||||
public $rules = [
|
public $rules = [
|
||||||
'service.docker_compose_raw' => 'required',
|
'service.docker_compose_raw' => 'required',
|
||||||
@ -20,6 +21,7 @@ class StackForm extends Component
|
|||||||
public $validationAttributes = [];
|
public $validationAttributes = [];
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
|
$this->fields = collect([]);
|
||||||
$extraFields = $this->service->extraFields();
|
$extraFields = $this->service->extraFields();
|
||||||
foreach ($extraFields as $serviceName => $fields) {
|
foreach ($extraFields as $serviceName => $fields) {
|
||||||
foreach ($fields as $fieldKey => $field) {
|
foreach ($fields as $fieldKey => $field) {
|
||||||
@ -27,18 +29,20 @@ public function mount()
|
|||||||
$value = data_get($field, 'value');
|
$value = data_get($field, 'value');
|
||||||
$rules = data_get($field, 'rules', 'nullable');
|
$rules = data_get($field, 'rules', 'nullable');
|
||||||
$isPassword = data_get($field, 'isPassword');
|
$isPassword = data_get($field, 'isPassword');
|
||||||
$this->fields[$key] = [
|
$this->fields->put($key, [
|
||||||
"serviceName" => $serviceName,
|
"serviceName" => $serviceName,
|
||||||
"key" => $key,
|
"key" => $key,
|
||||||
"name" => $fieldKey,
|
"name" => $fieldKey,
|
||||||
"value" => $value,
|
"value" => $value,
|
||||||
"isPassword" => $isPassword,
|
"isPassword" => $isPassword,
|
||||||
"rules" => $rules
|
"rules" => $rules
|
||||||
];
|
]);
|
||||||
|
|
||||||
$this->rules["fields.$key.value"] = $rules;
|
$this->rules["fields.$key.value"] = $rules;
|
||||||
$this->validationAttributes["fields.$key.value"] = $fieldKey;
|
$this->validationAttributes["fields.$key.value"] = $fieldKey;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->fields = $this->fields->sort();
|
||||||
}
|
}
|
||||||
public function saveCompose($raw)
|
public function saveCompose($raw)
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,6 @@ public function isConfigurationChanged(bool $save = false)
|
|||||||
$domains = implode(',', $domains);
|
$domains = implode(',', $domains);
|
||||||
|
|
||||||
$applicationImages = $this->applications()->get()->pluck('image')->sort();
|
$applicationImages = $this->applications()->get()->pluck('image')->sort();
|
||||||
ray($applicationImages->toArray());
|
|
||||||
$databaseImages = $this->databases()->get()->pluck('image')->sort();
|
$databaseImages = $this->databases()->get()->pluck('image')->sort();
|
||||||
$images = $applicationImages->merge($databaseImages);
|
$images = $applicationImages->merge($databaseImages);
|
||||||
$images = implode(',', $images->toArray());
|
$images = implode(',', $images->toArray());
|
||||||
|
@ -656,6 +656,9 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
if (str(data_get($service, 'image'))->contains('glitchtip')) {
|
if (str(data_get($service, 'image'))->contains('glitchtip')) {
|
||||||
$tempServiceName = 'glitchtip';
|
$tempServiceName = 'glitchtip';
|
||||||
}
|
}
|
||||||
|
if ($serviceName === 'supabase-kong') {
|
||||||
|
$tempServiceName = 'supabase';
|
||||||
|
}
|
||||||
$serviceDefinition = data_get($allServices, $tempServiceName);
|
$serviceDefinition = data_get($allServices, $tempServiceName);
|
||||||
$predefinedPort = data_get($serviceDefinition, 'port');
|
$predefinedPort = data_get($serviceDefinition, 'port');
|
||||||
if ($serviceName === 'plausible') {
|
if ($serviceName === 'plausible') {
|
||||||
@ -977,12 +980,14 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
// Caddy needs exact port in some cases.
|
// Caddy needs exact port in some cases.
|
||||||
|
ray($predefinedPort);
|
||||||
if ($predefinedPort && !$key->endsWith("_{$predefinedPort}")) {
|
if ($predefinedPort && !$key->endsWith("_{$predefinedPort}")) {
|
||||||
if ($resource->server->proxyType() === 'CADDY') {
|
if ($resource->server->proxyType() === 'CADDY') {
|
||||||
$env = EnvironmentVariable::where([
|
$env = EnvironmentVariable::where([
|
||||||
'key' => $key,
|
'key' => $key,
|
||||||
'service_id' => $resource->id,
|
'service_id' => $resource->id,
|
||||||
])->first();
|
])->first();
|
||||||
|
ray($env);
|
||||||
if ($env) {
|
if ($env) {
|
||||||
$env_url = Url::fromString($savedService->fqdn);
|
$env_url = Url::fromString($savedService->fqdn);
|
||||||
$env_port = $env_url->getPort();
|
$env_port = $env_url->getPort();
|
||||||
@ -1482,7 +1487,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
'application_id' => $resource->id,
|
'application_id' => $resource->id,
|
||||||
])->first();
|
])->first();
|
||||||
['command' => $command, 'forService' => $forService, 'generatedValue' => $generatedValue, 'port' => $port] = parseEnvVariable($value);
|
['command' => $command, 'forService' => $forService, 'generatedValue' => $generatedValue, 'port' => $port] = parseEnvVariable($value);
|
||||||
ray($command, $generatedValue);
|
|
||||||
if (!is_null($command)) {
|
if (!is_null($command)) {
|
||||||
if ($command?->value() === 'FQDN' || $command?->value() === 'URL') {
|
if ($command?->value() === 'FQDN' || $command?->value() === 'URL') {
|
||||||
if (Str::lower($forService) === $serviceName) {
|
if (Str::lower($forService) === $serviceName) {
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
<div class="w-full pl-8">
|
<div class="w-full pl-8">
|
||||||
<div x-cloak x-show="activeTab === 'service-stack'">
|
<div x-cloak x-show="activeTab === 'service-stack'">
|
||||||
<livewire:project.service.stack-form :service="$service" />
|
<livewire:project.service.stack-form :service="$service" />
|
||||||
|
<h3>Services</h3>
|
||||||
<div class="grid grid-cols-1 gap-2 pt-4 xl:grid-cols-1">
|
<div class="grid grid-cols-1 gap-2 pt-4 xl:grid-cols-1">
|
||||||
@foreach ($applications as $application)
|
@foreach ($applications as $application)
|
||||||
<div @class([
|
<div @class([
|
||||||
|
Loading…
Reference in New Issue
Block a user