wip: services

This commit is contained in:
Andras Bacsai
2023-09-20 15:42:41 +02:00
parent a86e971020
commit b4d69a22df
32 changed files with 964 additions and 222 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Http\Livewire\Project\Application;
use App\Models\Application;
use App\Models\InstanceSettings;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Livewire\Component;
use Spatie\Url\Url;
@@ -14,7 +15,7 @@ class General extends Component
public string $applicationId;
public Application $application;
public ?array $services = null;
public Collection $services;
public string $name;
public string|null $fqdn;
public string $git_repository;
@@ -33,6 +34,7 @@ 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',
@@ -54,6 +56,8 @@ class General extends Component
'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',
@@ -74,6 +78,8 @@ 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',
];
@@ -95,8 +101,8 @@ class General extends Component
$this->application->settings->save();
$this->application->save();
$this->application->refresh();
$this->emit('success', 'Application settings updated!');
$this->checkWildCardDomain();
$this->emit('success', 'Application settings updated!');
}
protected function checkWildCardDomain()
@@ -109,6 +115,7 @@ 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;
@@ -117,8 +124,8 @@ 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, 'dockercompose_raw')) {
$this->services = data_get(Yaml::parse($this->application->dockercompose_raw), 'services');
if (data_get($this->application, 'service_configurations')) {
$this->service_configurations = $this->application->service_configurations;
}
}
@@ -149,8 +156,8 @@ class General extends Component
public function submit()
{
try {
ray($this->application->service_configurations);
// $this->validate();
$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) {
return Str::of($domain)->trim()->lower();
@@ -170,7 +177,7 @@ class General extends Component
$this->application->publish_directory = rtrim($this->application->publish_directory, '/');
}
if (data_get($this->application, 'dockercompose_raw')) {
$details = generateServiceFromTemplate($this->application->dockercompose_raw, $this->application);
$details = generateServiceFromTemplate( $this->application);
$this->application->dockercompose = data_get($details, 'dockercompose');
}
$this->application->save();

View File

@@ -64,7 +64,7 @@ class Heading extends Component
foreach ($containers as $container) {
$containerName = data_get($container, 'Names');
if ($containerName) {
remote_process(
instant_remote_process(
["docker rm -f {$containerName}"],
$this->application->destination->server
);

View File

@@ -7,11 +7,15 @@ use App\Models\EnvironmentVariable;
use App\Models\GithubApp;
use App\Models\LocalPersistentVolume;
use App\Models\Project;
use App\Models\Service;
use App\Models\ServiceApplication;
use App\Models\ServiceDatabase;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
use Illuminate\Support\Str;
use Symfony\Component\Yaml\Yaml;
class DockerCompose extends Component
{
@@ -70,68 +74,81 @@ class DockerCompose extends Component
$project = Project::where('uuid', $this->parameters['project_uuid'])->first();
$environment = $project->load(['environments'])->environments->where('name', $this->parameters['environment_name'])->first();
$application = Application::create([
'name' => 'dockercompose-' . new Cuid2(7),
'repository_project_id' => 0,
'fqdn' => 'https://app.coolify.io',
'git_repository' => "coollabsio/coolify",
'git_branch' => 'main',
'build_pack' => 'dockercompose',
'ports_exposes' => '0',
'dockercompose_raw' => $this->dockercompose,
'environment_id' => $environment->id,
'destination_id' => $destination->id,
'destination_type' => $destination_class,
'source_id' => 0,
'source_type' => GithubApp::class
]);
$fqdn = "http://{$application->uuid}.{$destination->server->ip}.sslip.io";
if (isDev()) {
$fqdn = "http://{$application->uuid}.127.0.0.1.sslip.io";
}
$application->update([
'name' => 'dockercompose-' . $application->uuid,
'fqdn' => $fqdn,
]);
$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);
$details = generateServiceFromTemplate($this->dockercompose, $application);
$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,
'application_id' => $application->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' => $application->id,
'resource_type' => $application->getMorphClass(),
'is_readonly' => false
]);
}
}
$dockercompose_coolified = data_get($details, 'dockercompose', '');
$application->update([
'dockercompose' => $dockercompose_coolified,
'ports_exposes' => data_get($details, 'ports', 0)->implode(','),
]);
redirect()->route('project.application.configuration', [
'application_uuid' => $application->uuid,
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,
// ]);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Livewire\Project\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();
}
public function render()
{
return view('livewire.project.service.index')->layout('layouts.app');
}
}