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_dual_cert = $this->is_dual_cert;
$this->application->settings->save();
$this->application->refresh();
}
public function mount()
{

View File

@@ -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,

View File

@@ -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,
],

View File

@@ -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(

View File

@@ -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);

View File

@@ -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,
) {
}