2023-09-30 13:08:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-21 11:44:32 +00:00
|
|
|
namespace App\Livewire\Project\Service;
|
2023-09-30 13:08:40 +00:00
|
|
|
|
2023-12-06 13:57:03 +00:00
|
|
|
use App\Models\Service;
|
2024-03-21 11:44:32 +00:00
|
|
|
use Livewire\Component;
|
2023-09-30 13:08:40 +00:00
|
|
|
|
2024-03-21 11:44:32 +00:00
|
|
|
class EditCompose extends Component
|
2023-09-30 13:08:40 +00:00
|
|
|
{
|
2023-12-06 13:57:03 +00:00
|
|
|
public Service $service;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-12-06 14:50:13 +00:00
|
|
|
public $serviceId;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-10-13 13:38:59 +00:00
|
|
|
public ?string $dockerComposeRaw = null;
|
|
|
|
|
|
|
|
|
|
public ?string $dockerCompose = null;
|
|
|
|
|
|
|
|
|
|
public bool $isContainerLabelEscapeEnabled = false;
|
|
|
|
|
|
2024-08-15 09:23:44 +00:00
|
|
|
protected $listeners = [
|
|
|
|
|
'refreshEnvs',
|
|
|
|
|
'envsUpdated',
|
|
|
|
|
'refresh' => 'envsUpdated',
|
|
|
|
|
];
|
2024-06-22 11:33:22 +00:00
|
|
|
|
2023-12-06 13:57:03 +00:00
|
|
|
protected $rules = [
|
2025-10-13 13:38:59 +00:00
|
|
|
'dockerComposeRaw' => 'required',
|
|
|
|
|
'dockerCompose' => 'required',
|
|
|
|
|
'isContainerLabelEscapeEnabled' => 'required',
|
2023-12-06 13:57:03 +00:00
|
|
|
];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-06-25 08:34:56 +00:00
|
|
|
public function envsUpdated()
|
|
|
|
|
{
|
2025-10-13 13:38:59 +00:00
|
|
|
$this->dispatch('saveCompose', $this->dockerComposeRaw);
|
2024-06-25 08:34:56 +00:00
|
|
|
$this->refreshEnvs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function refreshEnvs()
|
|
|
|
|
{
|
2025-02-27 11:17:23 +00:00
|
|
|
$this->service = Service::ownedByCurrentTeam()->find($this->serviceId);
|
2025-10-13 13:38:59 +00:00
|
|
|
$this->syncData(false);
|
2024-06-25 08:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
2024-04-16 08:44:23 +00:00
|
|
|
public function mount()
|
|
|
|
|
{
|
2025-02-27 11:17:23 +00:00
|
|
|
$this->service = Service::ownedByCurrentTeam()->find($this->serviceId);
|
2025-10-13 13:38:59 +00:00
|
|
|
$this->syncData(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function syncData(bool $toModel = false): void
|
|
|
|
|
{
|
|
|
|
|
if ($toModel) {
|
|
|
|
|
$this->service->docker_compose_raw = $this->dockerComposeRaw;
|
|
|
|
|
$this->service->docker_compose = $this->dockerCompose;
|
|
|
|
|
$this->service->is_container_label_escape_enabled = $this->isContainerLabelEscapeEnabled;
|
|
|
|
|
} else {
|
|
|
|
|
$this->dockerComposeRaw = $this->service->docker_compose_raw;
|
|
|
|
|
$this->dockerCompose = $this->service->docker_compose;
|
|
|
|
|
$this->isContainerLabelEscapeEnabled = $this->service->is_container_label_escape_enabled ?? false;
|
|
|
|
|
}
|
2023-12-06 14:50:13 +00:00
|
|
|
}
|
2024-03-21 11:44:32 +00:00
|
|
|
|
2025-02-27 10:29:04 +00:00
|
|
|
public function validateCompose()
|
|
|
|
|
{
|
2025-10-13 13:38:59 +00:00
|
|
|
$isValid = validateComposeFile($this->dockerComposeRaw, $this->service->server_id);
|
2025-02-27 10:29:04 +00:00
|
|
|
if ($isValid !== 'OK') {
|
|
|
|
|
$this->dispatch('error', "Invalid docker-compose file.\n$isValid");
|
|
|
|
|
} else {
|
|
|
|
|
$this->dispatch('success', 'Docker compose is valid.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-16 08:44:23 +00:00
|
|
|
public function saveEditedCompose()
|
|
|
|
|
{
|
2024-06-10 20:43:34 +00:00
|
|
|
$this->dispatch('info', 'Saving new docker compose...');
|
2025-10-13 13:38:59 +00:00
|
|
|
$this->dispatch('saveCompose', $this->dockerComposeRaw);
|
2024-09-04 12:33:16 +00:00
|
|
|
$this->dispatch('refreshStorages');
|
2024-03-21 11:44:32 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-05-15 15:52:14 +00:00
|
|
|
public function instantSave()
|
|
|
|
|
{
|
|
|
|
|
$this->validate([
|
2025-10-13 13:38:59 +00:00
|
|
|
'isContainerLabelEscapeEnabled' => 'required',
|
2024-05-15 15:52:14 +00:00
|
|
|
]);
|
2025-10-13 13:38:59 +00:00
|
|
|
$this->syncData(true);
|
|
|
|
|
$this->service->save(['is_container_label_escape_enabled' => $this->isContainerLabelEscapeEnabled]);
|
2024-06-10 20:43:34 +00:00
|
|
|
$this->dispatch('success', 'Service updated successfully');
|
2024-05-15 15:52:14 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-21 11:44:32 +00:00
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
return view('livewire.project.service.edit-compose');
|
2023-09-30 13:08:40 +00:00
|
|
|
}
|
|
|
|
|
}
|