wip: services
This commit is contained in:
@@ -34,7 +34,6 @@ class General extends Component
|
||||
public bool $is_auto_deploy_enabled;
|
||||
public bool $is_force_https_enabled;
|
||||
|
||||
public array $service_configurations = [];
|
||||
|
||||
protected $rules = [
|
||||
'application.name' => 'required',
|
||||
@@ -55,9 +54,6 @@ class General extends Component
|
||||
'application.dockerfile' => 'nullable',
|
||||
'application.dockercompose_raw' => 'nullable',
|
||||
'application.dockercompose' => 'nullable',
|
||||
'application.service_configurations.*' => 'nullable',
|
||||
'service_configurations.*.fqdn' => 'nullable|url',
|
||||
'service_configurations.*.port' => 'integer',
|
||||
];
|
||||
protected $validationAttributes = [
|
||||
'application.name' => 'name',
|
||||
@@ -78,8 +74,6 @@ class General extends Component
|
||||
'application.dockerfile' => 'Dockerfile',
|
||||
'application.dockercompose_raw' => 'Docker Compose (raw)',
|
||||
'application.dockercompose' => 'Docker Compose',
|
||||
'service_configurations.*.fqdn' => 'FQDN',
|
||||
'service_configurations.*.port' => 'Port',
|
||||
|
||||
];
|
||||
|
||||
@@ -115,7 +109,6 @@ class General extends Component
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->services = $this->application->services();
|
||||
$this->is_static = $this->application->settings->is_static;
|
||||
$this->is_git_submodules_enabled = $this->application->settings->is_git_submodules_enabled;
|
||||
$this->is_git_lfs_enabled = $this->application->settings->is_git_lfs_enabled;
|
||||
@@ -124,9 +117,6 @@ class General extends Component
|
||||
$this->is_auto_deploy_enabled = $this->application->settings->is_auto_deploy_enabled;
|
||||
$this->is_force_https_enabled = $this->application->settings->is_force_https_enabled;
|
||||
$this->checkWildCardDomain();
|
||||
if (data_get($this->application, 'service_configurations')) {
|
||||
$this->service_configurations = $this->application->service_configurations;
|
||||
}
|
||||
}
|
||||
|
||||
public function generateGlobalRandomDomain()
|
||||
@@ -156,7 +146,6 @@ class General extends Component
|
||||
public function submit()
|
||||
{
|
||||
try {
|
||||
$this->application->service_configurations = $this->service_configurations;
|
||||
$this->validate();
|
||||
if (data_get($this->application, 'fqdn')) {
|
||||
$domains = Str::of($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
|
||||
|
||||
@@ -40,8 +40,6 @@ class DockerCompose extends Component
|
||||
- database__connection__user=$SERVICE_USER_MYSQL
|
||||
- database__connection__password=$SERVICE_PASSWORD_MYSQL
|
||||
- database__connection__database=${MYSQL_DATABASE-ghost}
|
||||
ports:
|
||||
- "2368"
|
||||
depends_on:
|
||||
- mysql
|
||||
mysql:
|
||||
@@ -62,93 +60,25 @@ class DockerCompose extends Component
|
||||
$this->validate([
|
||||
'dockercompose' => 'required'
|
||||
]);
|
||||
$destination_uuid = $this->query['destination'];
|
||||
$destination = StandaloneDocker::where('uuid', $destination_uuid)->first();
|
||||
if (!$destination) {
|
||||
$destination = SwarmDocker::where('uuid', $destination_uuid)->first();
|
||||
}
|
||||
if (!$destination) {
|
||||
throw new \Exception('Destination not found. What?!');
|
||||
}
|
||||
$destination_class = $destination->getMorphClass();
|
||||
$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();
|
||||
$service = new Service();
|
||||
$service->uuid = (string) new Cuid2(7);
|
||||
$service->name = 'service-' . new Cuid2(7);
|
||||
$service->docker_compose_raw = $this->dockercompose;
|
||||
$service->environment_id = $environment->id;
|
||||
$service->destination_id = $destination->id;
|
||||
$service->destination_type = $destination_class;
|
||||
$service->save();
|
||||
$service->parse(saveIt: true);
|
||||
|
||||
$service = Service::create([
|
||||
'name' => 'service' . Str::random(10),
|
||||
'docker_compose_raw' => $this->dockercompose,
|
||||
'environment_id' => $environment->id,
|
||||
'server_id' => (int) $server_id,
|
||||
]);
|
||||
$service->name = "service-$service->uuid";
|
||||
|
||||
$service->parse(isNew: true);
|
||||
|
||||
return redirect()->route('project.service', [
|
||||
'service_uuid' => $service->uuid,
|
||||
'environment_name' => $environment->name,
|
||||
'project_uuid' => $project->uuid,
|
||||
]);
|
||||
// $compose = data_get($parsedService, 'docker_compose');
|
||||
// $service->docker_compose = $compose;
|
||||
// $shouldDefine = data_get($parsedService, 'should_define', collect([]));
|
||||
// if ($shouldDefine->count() > 0) {
|
||||
// $envs = data_get($shouldDefine, 'envs', []);
|
||||
// foreach($envs as $env) {
|
||||
// ray($env);
|
||||
// $variableName = Str::of($env)->before('=');
|
||||
// $variableValue = Str::of($env)->after('=');
|
||||
// ray($variableName, $variableValue);
|
||||
// }
|
||||
// }
|
||||
// foreach ($services as $serviceName => $serviceDetails) {
|
||||
// if (data_get($serviceDetails,'is_database')) {
|
||||
// $serviceDatabase = new ServiceDatabase();
|
||||
// $serviceDatabase->name = $serviceName . '-' . $service->uuid;
|
||||
// $serviceDatabase->service_id = $service->id;
|
||||
// $serviceDatabase->save();
|
||||
// } else {
|
||||
// $serviceApplication = new ServiceApplication();
|
||||
// $serviceApplication->name = $serviceName . '-' . $service->uuid;
|
||||
// $serviceApplication->fqdn =
|
||||
// $serviceApplication->service_id = $service->id;
|
||||
// $serviceApplication->save();
|
||||
// }
|
||||
// }
|
||||
|
||||
// ray($details);
|
||||
// $envs = data_get($details, 'envs', []);
|
||||
// if ($envs->count() > 0) {
|
||||
// foreach ($envs as $env) {
|
||||
// $key = Str::of($env)->before('=');
|
||||
// $value = Str::of($env)->after('=');
|
||||
// EnvironmentVariable::create([
|
||||
// 'key' => $key,
|
||||
// 'value' => $value,
|
||||
// 'is_build_time' => false,
|
||||
// 'service_id' => $service->id,
|
||||
// 'is_preview' => false,
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
// $volumes = data_get($details, 'volumes', []);
|
||||
// if ($volumes->count() > 0) {
|
||||
// foreach ($volumes as $volume => $mount_path) {
|
||||
// LocalPersistentVolume::create([
|
||||
// 'name' => $volume,
|
||||
// 'mount_path' => $mount_path,
|
||||
// 'resource_id' => $service->id,
|
||||
// 'resource_type' => $service->getMorphClass(),
|
||||
// 'is_readonly' => false
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
// $dockercompose_coolified = data_get($details, 'dockercompose', '');
|
||||
// $service->update([
|
||||
// 'docker_compose' => $dockercompose_coolified,
|
||||
// ]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ class Select extends Component
|
||||
'environment_name' => $this->parameters['environment_name'],
|
||||
'type' => $this->type,
|
||||
'destination' => $this->destination_uuid,
|
||||
'server_id' => $this->server_id,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace App\Http\Livewire\Project\Service;
|
||||
|
||||
use App\Actions\Service\StartService;
|
||||
use App\Jobs\ContainerStatusJob;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Component;
|
||||
|
||||
class Index extends Component
|
||||
@@ -11,14 +14,66 @@ class Index extends Component
|
||||
|
||||
public array $parameters;
|
||||
public array $query;
|
||||
public Collection $services;
|
||||
|
||||
public function mount() {
|
||||
protected $rules = [
|
||||
'services.*.fqdn' => 'nullable',
|
||||
];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->services = collect([]);
|
||||
$this->parameters = get_route_parameters();
|
||||
$this->query = request()->query();
|
||||
$this->service = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail();
|
||||
foreach ($this->service->applications as $application) {
|
||||
$this->services->put($application->name, [
|
||||
'fqdn' => $application->fqdn,
|
||||
]);
|
||||
}
|
||||
// foreach ($this->service->databases as $database) {
|
||||
// $this->services->put($database->name, $database->fqdn);
|
||||
// }
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.project.service.index')->layout('layouts.app');
|
||||
}
|
||||
public function check_status()
|
||||
{
|
||||
dispatch_sync(new ContainerStatusJob($this->service->server));
|
||||
$this->service->refresh();
|
||||
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
try {
|
||||
if ($this->services->count() === 0) {
|
||||
return;
|
||||
}
|
||||
foreach ($this->services as $name => $value) {
|
||||
$foundService = $this->service->applications()->whereName($name)->first();
|
||||
if ($foundService) {
|
||||
$foundService->fqdn = data_get($value, 'fqdn');
|
||||
$foundService->save();
|
||||
return;
|
||||
}
|
||||
$foundService = $this->service->databases()->whereName($name)->first();
|
||||
if ($foundService) {
|
||||
// $foundService->save();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
ray($e);
|
||||
} finally {
|
||||
$this->service->parse();
|
||||
}
|
||||
}
|
||||
public function deploy()
|
||||
{
|
||||
$this->service->parse();
|
||||
$activity = StartService::run($this->service);
|
||||
$this->emit('newMonitorActivity', $activity->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Service;
|
||||
|
||||
use App\Models\Service;
|
||||
use Livewire\Component;
|
||||
|
||||
class Index extends Component
|
||||
{
|
||||
public Service $service;
|
||||
|
||||
public array $parameters;
|
||||
public array $query;
|
||||
|
||||
public function mount() {
|
||||
$this->parameters = get_route_parameters();
|
||||
$this->query = request()->query();
|
||||
$this->service = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail();
|
||||
ray($this->service->docker_compose);
|
||||
}
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.project.service.index')->layout('layouts.app');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user