2023-09-19 13:51:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project\New;
|
|
|
|
|
|
|
|
use App\Models\Project;
|
2023-09-20 13:42:41 +00:00
|
|
|
use App\Models\Service;
|
2023-09-19 13:51:13 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
use Illuminate\Support\Str;
|
2023-09-25 10:49:55 +00:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
2023-09-19 13:51:13 +00:00
|
|
|
|
|
|
|
class DockerCompose extends Component
|
|
|
|
{
|
2023-09-25 13:48:43 +00:00
|
|
|
public string $dockerComposeRaw = '';
|
2023-09-19 13:51:13 +00:00
|
|
|
public array $parameters;
|
|
|
|
public array $query;
|
|
|
|
public function mount()
|
|
|
|
{
|
2023-09-25 13:48:43 +00:00
|
|
|
|
2023-09-19 13:51:13 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
|
|
|
$this->query = request()->query();
|
|
|
|
if (isDev()) {
|
2023-09-25 13:48:43 +00:00
|
|
|
$this->dockerComposeRaw = 'services:
|
2023-09-25 10:49:55 +00:00
|
|
|
plausible_events_db:
|
|
|
|
image: clickhouse/clickhouse-server:23.3.7.5-alpine
|
|
|
|
restart: always
|
2023-09-19 13:51:13 +00:00
|
|
|
volumes:
|
2023-09-25 10:49:55 +00:00
|
|
|
- event-data:/var/lib/clickhouse
|
|
|
|
- ./clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
|
|
|
|
- ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
|
|
|
|
ulimits:
|
|
|
|
nofile:
|
|
|
|
soft: 262144
|
|
|
|
hard: 262144
|
2023-09-19 13:51:13 +00:00
|
|
|
';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function submit()
|
|
|
|
{
|
2023-09-25 10:49:55 +00:00
|
|
|
try {
|
|
|
|
$this->validate([
|
2023-09-25 13:48:43 +00:00
|
|
|
'dockerComposeRaw' => 'required'
|
2023-09-25 10:49:55 +00:00
|
|
|
]);
|
2023-09-25 13:48:43 +00:00
|
|
|
$this->dockerComposeRaw = Yaml::dump(Yaml::parse($this->dockerComposeRaw), 10, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);
|
2023-09-25 10:49:55 +00:00
|
|
|
$server_id = $this->query['server_id'];
|
|
|
|
|
|
|
|
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
|
|
|
|
$environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first();
|
2023-09-19 13:51:13 +00:00
|
|
|
|
2023-09-25 10:49:55 +00:00
|
|
|
$service = Service::create([
|
|
|
|
'name' => 'service' . Str::random(10),
|
2023-09-25 13:48:43 +00:00
|
|
|
'docker_compose_raw' => $this->dockerComposeRaw,
|
2023-09-25 10:49:55 +00:00
|
|
|
'environment_id' => $environment->id,
|
|
|
|
'server_id' => (int) $server_id,
|
|
|
|
]);
|
|
|
|
$service->name = "service-$service->uuid";
|
2023-09-21 15:48:31 +00:00
|
|
|
|
2023-09-25 10:49:55 +00:00
|
|
|
$service->parse(isNew: true);
|
2023-09-21 15:48:31 +00:00
|
|
|
|
2023-09-25 10:49:55 +00:00
|
|
|
return redirect()->route('project.service', [
|
|
|
|
'service_uuid' => $service->uuid,
|
|
|
|
'environment_name' => $environment->name,
|
|
|
|
'project_uuid' => $project->uuid,
|
|
|
|
]);
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
2023-09-19 13:51:13 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|