From f4210e39f27914e15241a533ef9d5fc3323536df Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 26 Apr 2023 13:01:09 +0200 Subject: [PATCH] static hosting --- .../Livewire/Project/Application/General.php | 1 + .../Project/New/PublicGitRepository.php | 20 +++++++++++++++++-- app/Jobs/DeployApplicationJob.php | 5 +++-- app/Models/Application.php | 14 +++++++++++++ app/Models/ApplicationSetting.php | 15 ++++++++++++++ app/View/Components/FormInput.php | 1 + .../components/applications/layout.blade.php | 7 ------- .../views/components/form-input.blade.php | 4 ++-- .../project/application/deploy.blade.php | 8 ++++---- .../project/application/general.blade.php | 17 +++++++++++++--- .../new/public-git-repository.blade.php | 8 ++++++-- .../application/configuration.blade.php | 6 ++++-- .../project/application/deployment.blade.php | 6 ++++-- .../project/application/deployments.blade.php | 6 ++++-- 14 files changed, 90 insertions(+), 28 deletions(-) delete mode 100644 resources/views/components/applications/layout.blade.php diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php index 2edfab88d..2d903862e 100644 --- a/app/Http/Livewire/Project/Application/General.php +++ b/app/Http/Livewire/Project/Application/General.php @@ -55,6 +55,7 @@ class General extends Component $this->application->settings->is_auto_deploy = $this->is_auto_deploy; $this->application->settings->is_dual_cert = $this->is_dual_cert; $this->application->settings->save(); + $this->application->refresh(); } public function mount() { diff --git a/app/Http/Livewire/Project/New/PublicGitRepository.php b/app/Http/Livewire/Project/New/PublicGitRepository.php index d7ac933e8..3fd272c01 100644 --- a/app/Http/Livewire/Project/New/PublicGitRepository.php +++ b/app/Http/Livewire/Project/New/PublicGitRepository.php @@ -24,14 +24,17 @@ class PublicGitRepository extends Component public $swarm_docker; public $chosenServer; public $chosenDestination; - public $is_static = false; public $github_apps; public $gitlab_apps; + public bool $is_static = false; + public string $publish_directory = ''; + protected $rules = [ 'public_repository_url' => 'required|url', 'port' => 'required|numeric', 'is_static' => 'required|boolean', + 'publish_directory' => 'string', ]; public function mount() { @@ -54,10 +57,20 @@ class PublicGitRepository extends Component $this->chosenDestination = $instance::where('uuid', $destination_uuid)->first(); } + public function instantSave() + { + if ($this->is_static) { + $this->port = 80; + $this->publish_directory = '/dist'; + } else { + $this->port = 3000; + $this->publish_directory = null; + } + } + public function submit() { $this->validate(); - $url = Url::fromString($this->public_repository_url); $git_host = $url->getHost(); $git_repository = $url->getSegment(1) . '/' . $url->getSegment(2); @@ -75,6 +88,7 @@ class PublicGitRepository extends Component 'git_branch' => $git_branch, 'build_pack' => 'nixpacks', 'ports_exposes' => $this->port, + 'publish_directory' => $this->publish_directory, 'environment_id' => $environment->id, 'destination_id' => $this->chosenDestination->id, 'destination_type' => $this->chosenDestination->getMorphClass(), @@ -88,6 +102,8 @@ class PublicGitRepository extends Component } elseif ($git_host == 'bitbucket.org') { } $application = Application::create($application_init); + $application->settings->is_static = $this->is_static; + $application->settings->save(); return redirect()->route('project.application.configuration', [ 'project_uuid' => $project->uuid, diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php index 511e3b5e8..fa40f0e36 100644 --- a/app/Jobs/DeployApplicationJob.php +++ b/app/Jobs/DeployApplicationJob.php @@ -222,6 +222,7 @@ COPY --from={$this->application->uuid}:{$this->git_commit}-build /app/{$this->ap { $persistentStorages = $this->generate_local_persistent_volumes(); $volume_names = $this->generate_local_persistent_volumes_only_volume_names(); + $ports = $this->application->settings->is_static ? [80] : $this->application->ports_exposes_array; $docker_compose = [ 'version' => '3.8', 'services' => [ @@ -230,10 +231,10 @@ COPY --from={$this->application->uuid}:{$this->git_commit}-build /app/{$this->ap 'container_name' => $this->application->uuid, 'restart' => 'always', 'environment' => [ - 'PORT' => $this->application->ports_exposes_array[0] + 'PORT' => $ports[0] ], 'labels' => $this->set_labels_for_applications(), - 'expose' => $this->application->ports_exposes_array, + 'expose' => $ports, 'networks' => [ $this->destination->network, ], diff --git a/app/Models/Application.php b/app/Models/Application.php index 5f402e163..05d185aac 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -33,7 +33,9 @@ class Application extends BaseModel 'source_type', 'ports_mappings', 'ports_exposes', + 'publish_directory', ]; + public function environment() { return $this->belongsTo(Environment::class); @@ -55,6 +57,18 @@ class Application extends BaseModel return $this->morphMany(LocalPersistentVolume::class, 'resource'); } + public function publishDirectory(): Attribute + { + return Attribute::make( + set: fn ($value) => $value ? '/' . ltrim($value, '/') : null, + ); + } + public function baseDirectory(): Attribute + { + return Attribute::make( + set: fn ($value) => '/' . ltrim($value, '/'), + ); + } public function portsMappingsArray(): Attribute { return Attribute::make( diff --git a/app/Models/ApplicationSetting.php b/app/Models/ApplicationSetting.php index 61d9f6ed8..b447cf948 100644 --- a/app/Models/ApplicationSetting.php +++ b/app/Models/ApplicationSetting.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; class ApplicationSetting extends Model @@ -11,6 +12,20 @@ class ApplicationSetting extends Model 'is_git_submodules_allowed', 'is_git_lfs_allowed', ]; + public function isStatic(): Attribute + { + return Attribute::make( + set: function ($value) { + if ($value) { + $this->application->ports_exposes = '80'; + } else { + $this->application->ports_exposes = '3000'; + } + $this->application->save(); + return $value; + } + ); + } public function application() { return $this->belongsTo(Application::class); diff --git a/app/View/Components/FormInput.php b/app/View/Components/FormInput.php index 5b346b11d..a96dc3b6c 100644 --- a/app/View/Components/FormInput.php +++ b/app/View/Components/FormInput.php @@ -18,6 +18,7 @@ class FormInput extends Component public string|null $label = null, public string|null $type = 'text', public bool $instantSave = false, + public bool $disabled = false, ) { } diff --git a/resources/views/components/applications/layout.blade.php b/resources/views/components/applications/layout.blade.php deleted file mode 100644 index 24de20df5..000000000 --- a/resources/views/components/applications/layout.blade.php +++ /dev/null @@ -1,7 +0,0 @@ - -

{{ $title ?? 'NOT SET' }}

- -
- {{ $slot }} -
-
diff --git a/resources/views/components/form-input.blade.php b/resources/views/components/form-input.blade.php index 86515f143..9fb1a030c 100644 --- a/resources/views/components/form-input.blade.php +++ b/resources/views/components/form-input.blade.php @@ -26,8 +26,8 @@ @endif + @if ($required) required @endif @if ($disabled) disabled @endif + @if ($readonly) readOnly disabled @endif /> @error($id)
{{ $message }}
@enderror diff --git a/resources/views/livewire/project/application/deploy.blade.php b/resources/views/livewire/project/application/deploy.blade.php index a01660a54..c278f615c 100644 --- a/resources/views/livewire/project/application/deploy.blade.php +++ b/resources/views/livewire/project/application/deploy.blade.php @@ -17,11 +17,11 @@ Open URL @endif - @if (data_get($application, 'ports_exposes_array')) - @foreach ($application->ports_exposes_array as $port) + @if (data_get($application, 'ports_mappings_array')) + @foreach ($application->ports_mappings_array as $port) @if (env('APP_ENV') === 'local') - Open - {{ $port }} + Open + {{ explode(':', $port)[0] }} @else Open diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.php index 7d5c95ea6..0aee12182 100644 --- a/resources/views/livewire/project/application/general.blade.php +++ b/resources/views/livewire/project/application/general.blade.php @@ -11,15 +11,26 @@ @if ($application->settings->is_static) - + @endif
+ - + @if ($application->settings->is_static) + + @else + + @endif +
- + @if ($application->settings->is_static) + + @else + + @endif +
diff --git a/resources/views/livewire/project/new/public-git-repository.blade.php b/resources/views/livewire/project/new/public-git-repository.blade.php index fcaa3f399..b40697727 100644 --- a/resources/views/livewire/project/new/public-git-repository.blade.php +++ b/resources/views/livewire/project/new/public-git-repository.blade.php @@ -21,8 +21,12 @@ @isset($chosenDestination)
- - + + @if ($is_static) + + @else + + @endif diff --git a/resources/views/project/application/configuration.blade.php b/resources/views/project/application/configuration.blade.php index 0a83858d5..5b6877a32 100644 --- a/resources/views/project/application/configuration.blade.php +++ b/resources/views/project/application/configuration.blade.php @@ -1,4 +1,6 @@ - + +

Configuration

+
General @@ -25,4 +27,4 @@
- + diff --git a/resources/views/project/application/deployment.blade.php b/resources/views/project/application/deployment.blade.php index 48c245f98..44e234bc4 100644 --- a/resources/views/project/application/deployment.blade.php +++ b/resources/views/project/application/deployment.blade.php @@ -1,3 +1,5 @@ - + +

Deployment

+ -
+ diff --git a/resources/views/project/application/deployments.blade.php b/resources/views/project/application/deployments.blade.php index 71df4c7df..dd159d173 100644 --- a/resources/views/project/application/deployments.blade.php +++ b/resources/views/project/application/deployments.blade.php @@ -1,4 +1,6 @@ - + +

Deployments

+
@forelse ($deployments as $deployment) @@ -6,4 +8,4 @@

No deployments found.

@endforelse
-
+