static hosting

This commit is contained in:
Andras Bacsai 2023-04-26 13:01:09 +02:00
parent cc1c08786f
commit f4210e39f2
14 changed files with 90 additions and 28 deletions

View File

@ -55,6 +55,7 @@ class General extends Component
$this->application->settings->is_auto_deploy = $this->is_auto_deploy; $this->application->settings->is_auto_deploy = $this->is_auto_deploy;
$this->application->settings->is_dual_cert = $this->is_dual_cert; $this->application->settings->is_dual_cert = $this->is_dual_cert;
$this->application->settings->save(); $this->application->settings->save();
$this->application->refresh();
} }
public function mount() public function mount()
{ {

View File

@ -24,14 +24,17 @@ class PublicGitRepository extends Component
public $swarm_docker; public $swarm_docker;
public $chosenServer; public $chosenServer;
public $chosenDestination; public $chosenDestination;
public $is_static = false;
public $github_apps; public $github_apps;
public $gitlab_apps; public $gitlab_apps;
public bool $is_static = false;
public string $publish_directory = '';
protected $rules = [ protected $rules = [
'public_repository_url' => 'required|url', 'public_repository_url' => 'required|url',
'port' => 'required|numeric', 'port' => 'required|numeric',
'is_static' => 'required|boolean', 'is_static' => 'required|boolean',
'publish_directory' => 'string',
]; ];
public function mount() public function mount()
{ {
@ -54,10 +57,20 @@ class PublicGitRepository extends Component
$this->chosenDestination = $instance::where('uuid', $destination_uuid)->first(); $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() public function submit()
{ {
$this->validate(); $this->validate();
$url = Url::fromString($this->public_repository_url); $url = Url::fromString($this->public_repository_url);
$git_host = $url->getHost(); $git_host = $url->getHost();
$git_repository = $url->getSegment(1) . '/' . $url->getSegment(2); $git_repository = $url->getSegment(1) . '/' . $url->getSegment(2);
@ -75,6 +88,7 @@ class PublicGitRepository extends Component
'git_branch' => $git_branch, 'git_branch' => $git_branch,
'build_pack' => 'nixpacks', 'build_pack' => 'nixpacks',
'ports_exposes' => $this->port, 'ports_exposes' => $this->port,
'publish_directory' => $this->publish_directory,
'environment_id' => $environment->id, 'environment_id' => $environment->id,
'destination_id' => $this->chosenDestination->id, 'destination_id' => $this->chosenDestination->id,
'destination_type' => $this->chosenDestination->getMorphClass(), 'destination_type' => $this->chosenDestination->getMorphClass(),
@ -88,6 +102,8 @@ class PublicGitRepository extends Component
} elseif ($git_host == 'bitbucket.org') { } elseif ($git_host == 'bitbucket.org') {
} }
$application = Application::create($application_init); $application = Application::create($application_init);
$application->settings->is_static = $this->is_static;
$application->settings->save();
return redirect()->route('project.application.configuration', [ return redirect()->route('project.application.configuration', [
'project_uuid' => $project->uuid, 'project_uuid' => $project->uuid,

View File

@ -222,6 +222,7 @@ COPY --from={$this->application->uuid}:{$this->git_commit}-build /app/{$this->ap
{ {
$persistentStorages = $this->generate_local_persistent_volumes(); $persistentStorages = $this->generate_local_persistent_volumes();
$volume_names = $this->generate_local_persistent_volumes_only_volume_names(); $volume_names = $this->generate_local_persistent_volumes_only_volume_names();
$ports = $this->application->settings->is_static ? [80] : $this->application->ports_exposes_array;
$docker_compose = [ $docker_compose = [
'version' => '3.8', 'version' => '3.8',
'services' => [ 'services' => [
@ -230,10 +231,10 @@ COPY --from={$this->application->uuid}:{$this->git_commit}-build /app/{$this->ap
'container_name' => $this->application->uuid, 'container_name' => $this->application->uuid,
'restart' => 'always', 'restart' => 'always',
'environment' => [ 'environment' => [
'PORT' => $this->application->ports_exposes_array[0] 'PORT' => $ports[0]
], ],
'labels' => $this->set_labels_for_applications(), 'labels' => $this->set_labels_for_applications(),
'expose' => $this->application->ports_exposes_array, 'expose' => $ports,
'networks' => [ 'networks' => [
$this->destination->network, $this->destination->network,
], ],

View File

@ -33,7 +33,9 @@ class Application extends BaseModel
'source_type', 'source_type',
'ports_mappings', 'ports_mappings',
'ports_exposes', 'ports_exposes',
'publish_directory',
]; ];
public function environment() public function environment()
{ {
return $this->belongsTo(Environment::class); return $this->belongsTo(Environment::class);
@ -55,6 +57,18 @@ class Application extends BaseModel
return $this->morphMany(LocalPersistentVolume::class, 'resource'); 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 public function portsMappingsArray(): Attribute
{ {
return Attribute::make( return Attribute::make(

View File

@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class ApplicationSetting extends Model class ApplicationSetting extends Model
@ -11,6 +12,20 @@ class ApplicationSetting extends Model
'is_git_submodules_allowed', 'is_git_submodules_allowed',
'is_git_lfs_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() public function application()
{ {
return $this->belongsTo(Application::class); return $this->belongsTo(Application::class);

View File

@ -18,6 +18,7 @@ class FormInput extends Component
public string|null $label = null, public string|null $label = null,
public string|null $type = 'text', public string|null $type = 'text',
public bool $instantSave = false, public bool $instantSave = false,
public bool $disabled = false,
) { ) {
} }

View File

@ -1,7 +0,0 @@
<x-layout>
<h1>{{ $title ?? 'NOT SET' }}</h1>
<x-applications.navbar :applicationId="$applicationId" />
<div>
{{ $slot }}
</div>
</x-layout>

View File

@ -26,8 +26,8 @@
@endif @endif
</label> </label>
<input type={{ $type }} id={{ $id }} wire:model.defer={{ $id }} <input type={{ $type }} id={{ $id }} wire:model.defer={{ $id }}
@if ($required) required @endif @if ($required) required @endif @if ($disabled) disabled @endif
@if ($readonly) readOnly=true disabled=true @endif /> @if ($readonly) readOnly disabled @endif />
@error($id) @error($id)
<div class="text-red-500">{{ $message }}</div> <div class="text-red-500">{{ $message }}</div>
@enderror @enderror

View File

@ -17,11 +17,11 @@
<a target="_blank" href="{{ data_get($application, 'fqdn') }}">Open URL</a> <a target="_blank" href="{{ data_get($application, 'fqdn') }}">Open URL</a>
@endif @endif
@if (data_get($application, 'ports_exposes_array')) @if (data_get($application, 'ports_mappings_array'))
@foreach ($application->ports_exposes_array as $port) @foreach ($application->ports_mappings_array as $port)
@if (env('APP_ENV') === 'local') @if (env('APP_ENV') === 'local')
<a target="_blank" href="http://localhost:{{ $port }}">Open <a target="_blank" href="http://localhost:{{ explode(':', $port)[0] }}">Open
{{ $port }}</a> {{ explode(':', $port)[0] }}</a>
@else @else
<a target="_blank" <a target="_blank"
href="http://{{ $application->destination->server->ip }}:{{ $port }}">Open href="http://{{ $application->destination->server->ip }}:{{ $port }}">Open

View File

@ -11,15 +11,26 @@
<x-form-input id="application.start_command" label="Start Command" /> <x-form-input id="application.start_command" label="Start Command" />
<x-form-input id="application.build_pack" label="Build Pack" /> <x-form-input id="application.build_pack" label="Build Pack" />
@if ($application->settings->is_static) @if ($application->settings->is_static)
<x-form-input id="application.static_image" label="Static Image" /> <x-form-input id="application.static_image" label="Static Image" required />
@endif @endif
</div> </div>
<div class="flex flex-col w-96"> <div class="flex flex-col w-96">
<x-form-input id="application.base_directory" label="Base Directory" /> <x-form-input id="application.base_directory" label="Base Directory" />
<x-form-input id="application.publish_directory" label="Publish Directory" /> @if ($application->settings->is_static)
<x-form-input id="application.publish_directory" label="Publish Directory" required />
@else
<x-form-input id="application.publish_directory" label="Publish Directory" />
@endif
</div> </div>
<div class="flex flex-col w-96"> <div class="flex flex-col w-96">
<x-form-input id="application.ports_exposes" label="Ports Exposes" /> @if ($application->settings->is_static)
<x-form-input id="application.ports_exposes" label="Ports Exposes" disabled />
@else
<x-form-input id="application.ports_exposes" label="Ports Exposes" />
@endif
<x-form-input id="application.ports_mappings" label="Ports Mappings" /> <x-form-input id="application.ports_mappings" label="Ports Mappings" />
</div> </div>
</div> </div>

View File

@ -21,8 +21,12 @@
@isset($chosenDestination) @isset($chosenDestination)
<form wire:submit.prevent='submit'> <form wire:submit.prevent='submit'>
<x-form-input id="public_repository_url" label="Repository URL" /> <x-form-input id="public_repository_url" label="Repository URL" />
<x-form-input type="checkbox" id="is_static" label="Static Site?" /> <x-form-input instantSave type="checkbox" id="is_static" label="Static Site?" />
<x-form-input type="number" id="port" label="Port" /> @if ($is_static)
<x-form-input id="publish_directory" label="Publish Directory" />
@else
<x-form-input type="number" id="port" label="Port" :disabled="$is_static" />
@endif
<button type="submit"> <button type="submit">
Submit Submit
</button> </button>

View File

@ -1,4 +1,6 @@
<x-applications.layout :applicationId="$application->id" title="Configurations"> <x-layout>
<h1>Configuration</h1>
<x-applications.navbar :applicationId="$application->id" />
<div x-data="{ tab: window.location.hash ? window.location.hash.substring(1) : 'general' }"> <div x-data="{ tab: window.location.hash ? window.location.hash.substring(1) : 'general' }">
<div class="flex gap-4"> <div class="flex gap-4">
<a @click.prevent="tab = 'general'; window.location.hash = 'general'" href="#">General</a> <a @click.prevent="tab = 'general'; window.location.hash = 'general'" href="#">General</a>
@ -25,4 +27,4 @@
<livewire:project.application.storages :storages="$application->persistentStorages" /> <livewire:project.application.storages :storages="$application->persistentStorages" />
</div> </div>
</div> </div>
</x-applications.layout> </x-layout>

View File

@ -1,3 +1,5 @@
<x-applications.layout :applicationId="$application->id" title="Deployment"> <x-layout>
<h1>Deployment</h1>
<x-applications.navbar :applicationId="$application->id" />
<livewire:project.application.poll-deployment :activity="$activity" :deployment_uuid="$deployment_uuid" /> <livewire:project.application.poll-deployment :activity="$activity" :deployment_uuid="$deployment_uuid" />
</x-applications.layout> </x-layout>

View File

@ -1,4 +1,6 @@
<x-applications.layout :applicationId="$application->id" title="Deployments"> <x-layout>
<h1>Deployments</h1>
<x-applications.navbar :applicationId="$application->id" />
<div class="pt-2"> <div class="pt-2">
@forelse ($deployments as $deployment) @forelse ($deployments as $deployment)
<livewire:project.application.get-deployments :deployment_uuid="data_get($deployment->properties, 'deployment_uuid')" :created_at="data_get($deployment, 'created_at')" :status="data_get($deployment->properties, 'status')" /> <livewire:project.application.get-deployments :deployment_uuid="data_get($deployment->properties, 'deployment_uuid')" :created_at="data_get($deployment, 'created_at')" :status="data_get($deployment->properties, 'status')" />
@ -6,4 +8,4 @@
<p>No deployments found.</p> <p>No deployments found.</p>
@endforelse @endforelse
</div> </div>
</x-applications.layout> </x-layout>