2023-10-12 07:12:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project\Service;
|
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class StackForm extends Component
|
|
|
|
{
|
2023-10-17 08:17:03 +00:00
|
|
|
public $service;
|
2023-11-11 20:32:41 +00:00
|
|
|
public $isConfigurationRequired = false;
|
2023-10-12 07:12:46 +00:00
|
|
|
protected $listeners = ["saveCompose"];
|
|
|
|
protected $rules = [
|
|
|
|
'service.docker_compose_raw' => 'required',
|
|
|
|
'service.docker_compose' => 'required',
|
|
|
|
'service.name' => 'required',
|
|
|
|
'service.description' => 'nullable',
|
|
|
|
];
|
2023-11-11 20:32:41 +00:00
|
|
|
public function mount () {
|
|
|
|
if ($this->service->applications->filter(fn($app) => str($app->image)->contains('minio/minio'))->count() > 0) {
|
|
|
|
$this->isConfigurationRequired = true;
|
|
|
|
}
|
|
|
|
}
|
2023-10-12 07:12:46 +00:00
|
|
|
public function saveCompose($raw)
|
|
|
|
{
|
2023-11-11 20:32:41 +00:00
|
|
|
|
2023-10-12 07:12:46 +00:00
|
|
|
$this->service->docker_compose_raw = $raw;
|
|
|
|
$this->submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->validate();
|
|
|
|
$this->service->save();
|
|
|
|
$this->service->parse();
|
|
|
|
$this->service->refresh();
|
|
|
|
$this->service->saveComposeConfigs();
|
|
|
|
$this->emit('refreshStacks');
|
|
|
|
$this->emit('refreshEnvs');
|
|
|
|
$this->emit('success', 'Service saved successfully.');
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.project.service.stack-form');
|
|
|
|
}
|
|
|
|
}
|