2023-04-19 10:42:15 +00:00
|
|
|
<?php
|
|
|
|
|
2023-04-25 09:01:56 +00:00
|
|
|
namespace App\Http\Livewire\Project\Application;
|
2023-04-19 10:42:15 +00:00
|
|
|
|
|
|
|
use App\Models\Application;
|
2023-05-22 09:21:03 +00:00
|
|
|
use App\Models\InstanceSettings;
|
2023-09-20 13:42:41 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2023-05-16 13:41:23 +00:00
|
|
|
use Illuminate\Support\Str;
|
2023-08-08 09:51:36 +00:00
|
|
|
use Livewire\Component;
|
2023-05-22 09:21:03 +00:00
|
|
|
use Spatie\Url\Url;
|
2023-09-19 13:51:13 +00:00
|
|
|
use Symfony\Component\Yaml\Yaml;
|
2023-04-19 10:42:15 +00:00
|
|
|
|
|
|
|
class General extends Component
|
|
|
|
{
|
|
|
|
public string $applicationId;
|
|
|
|
|
|
|
|
public Application $application;
|
2023-09-20 13:42:41 +00:00
|
|
|
public Collection $services;
|
2023-04-19 10:42:15 +00:00
|
|
|
public string $name;
|
2023-10-09 09:10:04 +00:00
|
|
|
public ?string $fqdn = null;
|
2023-04-19 10:42:15 +00:00
|
|
|
public string $git_repository;
|
|
|
|
public string $git_branch;
|
2023-10-09 09:10:04 +00:00
|
|
|
public ?string $git_commit_sha = null;
|
2023-04-19 10:42:15 +00:00
|
|
|
public string $build_pack;
|
|
|
|
|
2023-04-25 13:48:45 +00:00
|
|
|
public bool $is_static;
|
2023-05-31 09:24:02 +00:00
|
|
|
public bool $is_git_submodules_enabled;
|
|
|
|
public bool $is_git_lfs_enabled;
|
|
|
|
public bool $is_debug_enabled;
|
|
|
|
public bool $is_preview_deployments_enabled;
|
|
|
|
public bool $is_auto_deploy_enabled;
|
|
|
|
public bool $is_force_https_enabled;
|
2023-04-19 12:00:31 +00:00
|
|
|
|
2023-09-19 13:51:13 +00:00
|
|
|
|
2023-04-19 10:42:15 +00:00
|
|
|
protected $rules = [
|
2023-07-06 12:37:14 +00:00
|
|
|
'application.name' => 'required',
|
2023-08-07 16:46:40 +00:00
|
|
|
'application.description' => 'nullable',
|
2023-04-19 10:42:15 +00:00
|
|
|
'application.fqdn' => 'nullable',
|
|
|
|
'application.git_repository' => 'required',
|
|
|
|
'application.git_branch' => 'required',
|
|
|
|
'application.git_commit_sha' => 'nullable',
|
2023-05-05 07:02:50 +00:00
|
|
|
'application.install_command' => 'nullable',
|
|
|
|
'application.build_command' => 'nullable',
|
|
|
|
'application.start_command' => 'nullable',
|
2023-04-19 10:42:15 +00:00
|
|
|
'application.build_pack' => 'required',
|
2023-04-25 13:48:45 +00:00
|
|
|
'application.static_image' => 'required',
|
2023-04-19 10:42:15 +00:00
|
|
|
'application.base_directory' => 'required',
|
|
|
|
'application.publish_directory' => 'nullable',
|
2023-04-25 12:43:35 +00:00
|
|
|
'application.ports_exposes' => 'required',
|
|
|
|
'application.ports_mappings' => 'nullable',
|
2023-08-11 20:41:47 +00:00
|
|
|
'application.dockerfile' => 'nullable',
|
2023-10-10 09:16:38 +00:00
|
|
|
'application.docker_registry_image_name' => 'nullable',
|
|
|
|
'application.docker_registry_image_tag' => 'nullable',
|
2023-10-10 12:02:43 +00:00
|
|
|
'application.dockerfile_location' => 'nullable',
|
2023-04-19 10:42:15 +00:00
|
|
|
];
|
2023-06-16 10:35:40 +00:00
|
|
|
protected $validationAttributes = [
|
|
|
|
'application.name' => 'name',
|
2023-08-07 16:46:40 +00:00
|
|
|
'application.description' => 'description',
|
2023-06-16 10:35:40 +00:00
|
|
|
'application.fqdn' => 'FQDN',
|
|
|
|
'application.git_repository' => 'Git repository',
|
|
|
|
'application.git_branch' => 'Git branch',
|
|
|
|
'application.git_commit_sha' => 'Git commit SHA',
|
|
|
|
'application.install_command' => 'Install command',
|
|
|
|
'application.build_command' => 'Build command',
|
|
|
|
'application.start_command' => 'Start command',
|
|
|
|
'application.build_pack' => 'Build pack',
|
|
|
|
'application.static_image' => 'Static image',
|
|
|
|
'application.base_directory' => 'Base directory',
|
|
|
|
'application.publish_directory' => 'Publish directory',
|
|
|
|
'application.ports_exposes' => 'Ports exposes',
|
|
|
|
'application.ports_mappings' => 'Ports mappings',
|
2023-08-11 20:41:47 +00:00
|
|
|
'application.dockerfile' => 'Dockerfile',
|
2023-10-10 09:16:38 +00:00
|
|
|
'application.docker_registry_image_name' => 'Docker registry image name',
|
|
|
|
'application.docker_registry_image_tag' => 'Docker registry image tag',
|
2023-10-10 12:02:43 +00:00
|
|
|
'application.dockerfile_location' => 'Dockerfile location',
|
2023-09-19 13:51:13 +00:00
|
|
|
|
2023-06-16 10:35:40 +00:00
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-10-11 10:12:25 +00:00
|
|
|
public function updatedApplicationBuildPack(){
|
|
|
|
$this->submit();
|
|
|
|
}
|
2023-04-19 12:00:31 +00:00
|
|
|
public function instantSave()
|
|
|
|
{
|
2023-05-05 07:28:00 +00:00
|
|
|
// @TODO: find another way - if possible
|
2023-04-25 13:48:45 +00:00
|
|
|
$this->application->settings->is_static = $this->is_static;
|
2023-07-06 11:55:30 +00:00
|
|
|
if ($this->is_static) {
|
|
|
|
$this->application->ports_exposes = 80;
|
|
|
|
} else {
|
|
|
|
$this->application->ports_exposes = 3000;
|
|
|
|
}
|
2023-05-31 09:24:02 +00:00
|
|
|
$this->application->settings->is_git_submodules_enabled = $this->is_git_submodules_enabled;
|
|
|
|
$this->application->settings->is_git_lfs_enabled = $this->is_git_lfs_enabled;
|
|
|
|
$this->application->settings->is_debug_enabled = $this->is_debug_enabled;
|
|
|
|
$this->application->settings->is_preview_deployments_enabled = $this->is_preview_deployments_enabled;
|
|
|
|
$this->application->settings->is_auto_deploy_enabled = $this->is_auto_deploy_enabled;
|
|
|
|
$this->application->settings->is_force_https_enabled = $this->is_force_https_enabled;
|
2023-04-19 12:00:31 +00:00
|
|
|
$this->application->settings->save();
|
2023-07-06 11:55:30 +00:00
|
|
|
$this->application->save();
|
2023-04-26 11:01:09 +00:00
|
|
|
$this->application->refresh();
|
2023-09-20 13:42:41 +00:00
|
|
|
$this->emit('success', 'Application settings updated!');
|
2023-05-22 09:21:03 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-09-30 13:39:40 +00:00
|
|
|
public function getWildcardDomain() {
|
|
|
|
$server = data_get($this->application, 'destination.server');
|
|
|
|
if ($server) {
|
|
|
|
$fqdn = generateFqdn($server, $this->application->uuid);
|
|
|
|
ray($fqdn);
|
|
|
|
$this->application->fqdn = $fqdn;
|
|
|
|
$this->application->save();
|
|
|
|
$this->emit('success', 'Application settings updated!');
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-09-30 13:39:40 +00:00
|
|
|
}
|
2023-04-19 10:42:15 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-10-01 15:39:57 +00:00
|
|
|
if (data_get($this->application,'settings')) {
|
|
|
|
$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;
|
|
|
|
$this->is_debug_enabled = $this->application->settings->is_debug_enabled;
|
|
|
|
$this->is_preview_deployments_enabled = $this->application->settings->is_preview_deployments_enabled;
|
|
|
|
$this->is_auto_deploy_enabled = $this->application->settings->is_auto_deploy_enabled;
|
|
|
|
$this->is_force_https_enabled = $this->application->settings->is_force_https_enabled;
|
|
|
|
}
|
2023-04-19 10:42:15 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-04-19 10:42:15 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
2023-05-16 13:27:47 +00:00
|
|
|
try {
|
2023-09-20 13:42:41 +00:00
|
|
|
$this->validate();
|
2023-10-11 10:10:40 +00:00
|
|
|
if (data_get($this->application,'build_pack') === 'dockerimage') {
|
|
|
|
$this->validate([
|
|
|
|
'application.docker_registry_image_name' => 'required',
|
|
|
|
'application.docker_registry_image_tag' => 'required',
|
|
|
|
]);
|
|
|
|
}
|
2023-09-19 13:51:13 +00:00
|
|
|
if (data_get($this->application, 'fqdn')) {
|
2023-08-27 12:55:57 +00:00
|
|
|
$domains = Str::of($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
|
|
|
|
return Str::of($domain)->trim()->lower();
|
|
|
|
});
|
|
|
|
$this->application->fqdn = $domains->implode(',');
|
|
|
|
}
|
2023-09-19 13:51:13 +00:00
|
|
|
if (data_get($this->application, 'dockerfile')) {
|
2023-08-21 16:00:12 +00:00
|
|
|
$port = get_port_from_dockerfile($this->application->dockerfile);
|
2023-10-02 07:08:33 +00:00
|
|
|
if ($port && !$this->application->ports_exposes) {
|
2023-08-21 16:00:12 +00:00
|
|
|
$this->application->ports_exposes = $port;
|
|
|
|
}
|
2023-08-11 20:41:47 +00:00
|
|
|
}
|
2023-07-07 12:56:20 +00:00
|
|
|
if ($this->application->base_directory && $this->application->base_directory !== '/') {
|
|
|
|
$this->application->base_directory = rtrim($this->application->base_directory, '/');
|
|
|
|
}
|
|
|
|
if ($this->application->publish_directory && $this->application->publish_directory !== '/') {
|
|
|
|
$this->application->publish_directory = rtrim($this->application->publish_directory, '/');
|
|
|
|
}
|
2023-05-16 13:27:47 +00:00
|
|
|
$this->application->save();
|
2023-06-22 08:04:39 +00:00
|
|
|
$this->emit('success', 'Application settings updated!');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-05-16 13:27:47 +00:00
|
|
|
}
|
2023-04-19 10:42:15 +00:00
|
|
|
}
|
|
|
|
}
|