Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

feat: resource limits

Andras Bacsai3b7456a5614f
diff --git a/app/Http/Livewire/Project/Application/ResourceLimits.php b/app/Http/Livewire/Project/Application/ResourceLimits.php
new file mode 100644
index 0000000000..d3f1096f86
--- /dev/null
+++ b/app/Http/Livewire/Project/Application/ResourceLimits.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace App\Http\Livewire\Project\Application;
+
+use App\Models\Application;
+use Livewire\Component;
+
+class ResourceLimits extends Component
+{
+ public Application $application;
+ protected $rules = [
+ 'application.limits_memory' => 'required|string',
+ 'application.limits_memory_swap' => 'required|string',
+ 'application.limits_memory_swappiness' => 'required|integer|min:0|max:100',
+ 'application.limits_memory_reservation' => 'required|string',
+ 'application.limits_memory_oom_kill' => 'boolean',
+ 'application.limits_cpus' => 'nullable',
+ 'application.limits_cpuset' => 'nullable',
+ 'application.limits_cpu_shares' => 'nullable',
+ ];
+ public function submit()
+ {
+ try {
+ if (!$this->application->limits_memory) {
+ $this->application->limits_memory = "0";
+ }
+ if (!$this->application->limits_memory_swap) {
+ $this->application->limits_memory_swap = "0";
+ }
+ if (!$this->application->limits_memory_swappiness) {
+ $this->application->limits_memory_swappiness = "60";
+ }
+ if (!$this->application->limits_memory_reservation) {
+ $this->application->limits_memory_reservation = "0";
+ }
+ if (!$this->application->limits_cpus) {
+ $this->application->limits_cpus = "0";
+ }
+ if (!$this->application->limits_cpuset) {
+ $this->application->limits_cpuset = "0";
+ }
+ if (!$this->application->limits_cpu_shares) {
+ $this->application->limits_cpu_shares = 1024;
+ }
+ $this->validate();
+ $this->application->save();
+ } catch (\Exception $e) {
+ return generalErrorHandler($e, $this);
+ }
+ }
+}
diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php
index 1f949a59a4..e90d627d45 100644
--- a/app/Jobs/DeployApplicationJob.php
+++ b/app/Jobs/DeployApplicationJob.php
@@ -309,6 +309,14 @@ COPY --from={$this->application->uuid}:{$this->git_commit}-build /app/{$this->ap
'retries' => $this->application->health_check_retries,
'start_period' => $this->application->health_check_start_period . 's'
],
+ 'mem_limit' => $this->application->limits_memory,
+ 'memswap_limit' => $this->application->limits_memory_swap,
+ 'mem_swappiness' => $this->application->limits_memory_swappiness,
+ 'mem_reservation' => $this->application->limits_memory_reservation,
+ 'oom_kill_disable' => $this->application->limits_memory_oom_kill,
+ 'cpus' => $this->application->limits_cpus,
+ 'cpuset' => $this->application->limits_cpuset,
+ 'cpu_shares' => $this->application->limits_cpu_shares,
]
],
'networks' => [
diff --git a/app/Models/Application.php b/app/Models/Application.php
index 57ef285014..6170b670c3 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -43,6 +43,7 @@ class Application extends BaseModel
public $casts = [
'previews' => SchemalessAttributes::class,
+ 'limits_memory_oom_kill' => 'boolean',
];
public function scopeWithExtraAttributes(): Builder
{
diff --git a/database/migrations/2023_03_27_081716_create_applications_table.php b/database/migrations/2023_03_27_081716_create_applications_table.php
index 500befe2c4..9cabae3e10 100644
--- a/database/migrations/2023_03_27_081716_create_applications_table.php
+++ b/database/migrations/2023_03_27_081716_create_applications_table.php
@@ -55,6 +55,16 @@ return new class extends Migration
$table->integer('health_check_retries')->default(10);
$table->integer('health_check_start_period')->default(5);
+ $table->string('limits_memory')->default("0");
+ $table->string('limits_memory_swap')->default("0");
+ $table->integer('limits_memory_swappiness')->default(60);
+ $table->string('limits_memory_reservation')->default("0");
+ $table->boolean('limits_memory_oom_kill')->default(false);
+
+ $table->string('limits_cpus')->default("0");
+ $table->string('limits_cpuset')->nullable()->default("");
+ $table->integer('limits_cpu_shares')->default(1024);
+
$table->string('status')->default('exited');
$table->nullableMorphs('destination');
diff --git a/resources/views/livewire/project/application/resource-limits.blade.php b/resources/views/livewire/project/application/resource-limits.blade.php
new file mode 100644
index 0000000000..f0d9402f9a
--- /dev/null
+++ b/resources/views/livewire/project/application/resource-limits.blade.php
@@ -0,0 +1,20 @@
+<div>
+ <h2>Resource Limits</h2>
+ <form wire:submit.prevent='submit'>
+ <h3>Memory</h3>
+ <x-inputs.input placeholder="69b or 420k or 1337m or 1g" label="Limit" id="application.limits_memory" />
+ <x-inputs.input placeholder="69b or 420k or 1337m or 1g" label="Swap" id="application.limits_memory_swap" />
+ <x-inputs.input placeholder="0-100" type="number" min="0" max="100" label="Swappiness"
+ id="application.limits_memory_swappiness" />
+ <x-inputs.input placeholder="69b or 420k or 1337m or 1g" label="Soft Limit"
+ id="application.limits_memory_reservation" />
+ <x-inputs.input type="checkbox" label="Is OOM Kill disabled?" id="application.limits_memory_oom_kill" />
+ <h3>CPU</h3>
+ <x-inputs.input placeholder="1.5" label="Number of CPUs" id="application.limits_cpus" />
+ <x-inputs.input placeholder="0-2" label="CPU set to use" id="application.limits_cpuset" />
+ <x-inputs.input placeholder="1024" label="CPU Weight" id="application.limits_cpu_shares" />
+ <div class="pt-4">
+ <x-inputs.button>Save</x-inputs.button>
+ </div>
+ </form>
+</div>
diff --git a/resources/views/project/application/configuration.blade.php b/resources/views/project/application/configuration.blade.php
index bcececbede..f132164807 100644
--- a/resources/views/project/application/configuration.blade.php
+++ b/resources/views/project/application/configuration.blade.php
@@ -21,6 +21,10 @@
<a :class="activeTab === 'revert' && 'text-white'"
@click.prevent="activeTab = 'revert'; window.location.hash = 'revert'" href="#">Revert
</a>
+ <a :class="activeTab === 'resource-limits' && 'text-white'"
+ @click.prevent="activeTab = 'resource-limits'; window.location.hash = 'resource-limits'"
+ href="#">Resource Limits
+ </a>
{{-- <a :class="activeTab === 'previews' && 'text-white'"
@click.prevent="activeTab = 'previews'; window.location.hash = 'previews'" href="#">Previews
</a> --}}
@@ -44,6 +48,9 @@
<div x-cloak x-show="activeTab === 'revert'">
<livewire:project.application.revert :application="$application" />
</div>
+ <div x-cloak x-show="activeTab === 'resource-limits'">
+ <livewire:project.application.resource-limits :application="$application" />
+ </div>
{{-- <div x-cloak x-show="activeTab === 'previews'">
<livewire:project.application.previews :application="$application" />
</div> --}}