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: disable gzip compression on service applications

Andras Bacsai45e404b15be4
diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php
index f9d5166347..8dca584f23 100644
--- a/app/Actions/Database/StartMariadb.php
+++ b/app/Actions/Database/StartMariadb.php
@@ -106,7 +106,6 @@ class StartMariadb
$this->commands[] = "echo 'Pulling {$database->image} image.'";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml pull";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d";
- $database_name = addslashes($database->name);
$this->commands[] = "echo 'Database started.'";
return remote_process($this->commands, $database->destination->server, callEventOnFinish: 'DatabaseStatusChanged');
}
diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php
index b5c4dde887..ef04a9be83 100644
--- a/app/Actions/Database/StartMongodb.php
+++ b/app/Actions/Database/StartMongodb.php
@@ -122,7 +122,6 @@ class StartMongodb
$this->commands[] = "echo 'Pulling {$database->image} image.'";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml pull";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d";
- $database_name = addslashes($database->name);
$this->commands[] = "echo 'Database started.'";
return remote_process($this->commands, $database->destination->server, callEventOnFinish: 'DatabaseStatusChanged');
}
diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.php
index a103b3531b..3b47483a3d 100644
--- a/app/Actions/Database/StartMysql.php
+++ b/app/Actions/Database/StartMysql.php
@@ -106,7 +106,6 @@ class StartMysql
$this->commands[] = "echo 'Pulling {$database->image} image.'";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml pull";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d";
- $database_name = addslashes($database->name);
$this->commands[] = "echo 'Database started.'";
return remote_process($this->commands, $database->destination->server,callEventOnFinish: 'DatabaseStatusChanged');
}
diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php
index a77d09381b..844f81c311 100644
--- a/app/Actions/Database/StartPostgresql.php
+++ b/app/Actions/Database/StartPostgresql.php
@@ -128,7 +128,6 @@ class StartPostgresql
$this->commands[] = "echo 'Pulling {$database->image} image.'";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml pull";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d";
- $database_name = addslashes($database->name);
$this->commands[] = "echo 'Database started.'";
return remote_process($this->commands, $database->destination->server, callEventOnFinish: 'DatabaseStatusChanged');
}
diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php
index f6e8b37809..e1a8eef41b 100644
--- a/app/Actions/Database/StartRedis.php
+++ b/app/Actions/Database/StartRedis.php
@@ -117,7 +117,6 @@ class StartRedis
$this->commands[] = "echo 'Pulling {$database->image} image.'";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml pull";
$this->commands[] = "docker compose -f $this->configuration_dir/docker-compose.yml up -d";
- $database_name = addslashes($database->name);
$this->commands[] = "echo 'Database started.'";
return remote_process($this->commands, $database->destination->server, callEventOnFinish: 'DatabaseStatusChanged');
}
diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.php
index 84f954e804..6ec71c4f36 100644
--- a/app/Actions/Service/StartService.php
+++ b/app/Actions/Service/StartService.php
@@ -13,10 +13,6 @@ class StartService
{
ray('Starting service: ' . $service->name);
$service->saveComposeConfigs();
-
- $service_name = addslashes($service->name);
- $server_name = addslashes($service->server->name);
-
$commands[] = "cd " . $service->workdir();
$commands[] = "echo 'Saved configuration files to {$service->workdir()}.'";
$commands[] = "echo 'Creating Docker network.'";
diff --git a/app/Livewire/Project/Service/ServiceApplicationView.php b/app/Livewire/Project/Service/ServiceApplicationView.php
index a17494d1df..53532a855f 100644
--- a/app/Livewire/Project/Service/ServiceApplicationView.php
+++ b/app/Livewire/Project/Service/ServiceApplicationView.php
@@ -17,6 +17,7 @@ class ServiceApplicationView extends Component
'application.exclude_from_status' => 'required|boolean',
'application.required_fqdn' => 'required|boolean',
'application.is_log_drain_enabled' => 'nullable|boolean',
+ 'application.is_gzip_enabled' => 'nullable|boolean',
];
public function render()
{
diff --git a/app/Livewire/Project/Service/StackForm.php b/app/Livewire/Project/Service/StackForm.php
index 894428182d..44672fe64b 100644
--- a/app/Livewire/Project/Service/StackForm.php
+++ b/app/Livewire/Project/Service/StackForm.php
@@ -45,8 +45,10 @@ class StackForm extends Component
$this->service->docker_compose_raw = $raw;
$this->submit();
}
- public function instantSave() {
+ public function instantSave()
+ {
$this->service->save();
+ $this->dispatch('success', 'Service settings saved successfully.');
}
public function submit()
diff --git a/app/Models/ServiceApplication.php b/app/Models/ServiceApplication.php
index be1eb0f6d1..314a01ba3a 100644
--- a/app/Models/ServiceApplication.php
+++ b/app/Models/ServiceApplication.php
@@ -23,6 +23,10 @@ class ServiceApplication extends BaseModel
{
return data_get($this, 'is_log_drain_enabled', false);
}
+ public function isGzipEnabled()
+ {
+ return data_get($this, 'is_gzip_enabled', true);
+ }
public function type()
{
return 'service';
diff --git a/app/Models/ServiceDatabase.php b/app/Models/ServiceDatabase.php
index 0bde42c20c..31bd2786d2 100644
--- a/app/Models/ServiceDatabase.php
+++ b/app/Models/ServiceDatabase.php
@@ -21,6 +21,10 @@ class ServiceDatabase extends BaseModel
{
return data_get($this, 'is_log_drain_enabled', false);
}
+ public function isGzipEnabled()
+ {
+ return true;
+ }
public function type()
{
return 'service';
diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php
index f01eb972f7..7b367c63cc 100644
--- a/bootstrap/helpers/docker.php
+++ b/bootstrap/helpers/docker.php
@@ -7,7 +7,6 @@ use App\Models\ServiceApplication;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Spatie\Url\Url;
-use Visus\Cuid2\Cuid2;
function getCurrentApplicationContainerStatus(Server $server, int $id, ?int $pullRequestId = null): Collection
{
@@ -213,7 +212,7 @@ function generateServiceSpecificFqdns(ServiceApplication|Application $resource,
}
return $payload;
}
-function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null)
+function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_https_enabled = false, $onlyPort = null, ?Collection $serviceLabels = null, ?bool $is_gzip_enabled = true)
{
$labels = collect([]);
$labels->push('traefik.enable=true');
@@ -276,23 +275,35 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
}
if ($path !== '/') {
$labels->push("traefik.http.middlewares.{$https_label}-stripprefix.stripprefix.prefixes={$path}");
- $middlewares = "gzip,{$https_label}-stripprefix";
- if ($basic_auth && $basic_auth_middleware) {
- $middlewares = $middlewares . ',' . $basic_auth_middleware;
+ $middlewares = collect(["{$https_label}-stripprefix"]);
+ if ($is_gzip_enabled) {
+ $middlewares->push('gzip');
+ }
+ if ($basic_auth && $basic_auth_middleware) {
+ $middlewares->push($basic_auth_middleware);
}
if ($redirect && $redirect_middleware) {
- $middlewares = $middlewares . ',' . $redirect_middleware;
+ $middlewares->push($redirect_middleware);
+ }
+ if ($middlewares->isNotEmpty()) {
+ $middlewares = $middlewares->join(',');
+ $labels->push("traefik.http.routers.{$https_label}.middlewares={$middlewares}");
}
- $labels->push("traefik.http.routers.{$https_label}.middlewares={$middlewares}");
} else {
- $middlewares = "gzip";
+ $middlewares = collect([]);
+ if ($is_gzip_enabled) {
+ $middlewares->push('gzip');
+ }
if ($basic_auth && $basic_auth_middleware) {
- $middlewares = $middlewares . ',' . $basic_auth_middleware;
+ $middlewares->push($basic_auth_middleware);
}
if ($redirect && $redirect_middleware) {
- $middlewares = $middlewares . ',' . $redirect_middleware;
+ $middlewares->push($redirect_middleware);
+ }
+ if ($middlewares->isNotEmpty()) {
+ $middlewares = $middlewares->join(',');
+ $labels->push("traefik.http.routers.{$https_label}.middlewares={$middlewares}");
}
- $labels->push("traefik.http.routers.{$https_label}.middlewares={$middlewares}");
}
$labels->push("traefik.http.routers.{$https_label}.tls=true");
$labels->push("traefik.http.routers.{$https_label}.tls.certresolver=letsencrypt");
@@ -317,23 +328,35 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_
}
if ($path !== '/') {
$labels->push("traefik.http.middlewares.{$http_label}-stripprefix.stripprefix.prefixes={$path}");
- $middlewares = "gzip,{$http_label}-stripprefix";
- if ($basic_auth && $basic_auth_middleware) {
- $middlewares = $middlewares . ',' . $basic_auth_middleware;
+ $middlewares = collect(["{$http_label}-stripprefix"]);
+ if ($is_gzip_enabled) {
+ $middlewares->push('gzip');
+ }
+ if ($basic_auth && $basic_auth_middleware) {
+ $middlewares->push($basic_auth_middleware);
}
if ($redirect && $redirect_middleware) {
- $middlewares = $middlewares . ',' . $redirect_middleware;
+ $middlewares->push($redirect_middleware);
+ }
+ if ($middlewares->isNotEmpty()) {
+ $middlewares = $middlewares->join(',');
+ $labels->push("traefik.http.routers.{$http_label}.middlewares={$middlewares}");
}
- $labels->push("traefik.http.routers.{$http_label}.middlewares={$middlewares}");
} else {
- $middlewares = "gzip";
+ $middlewares = collect([]);
+ if ($is_gzip_enabled) {
+ $middlewares->push('gzip');
+ }
if ($basic_auth && $basic_auth_middleware) {
- $middlewares = $middlewares . ',' . $basic_auth_middleware;
+ $middlewares->push($basic_auth_middleware);
}
if ($redirect && $redirect_middleware) {
- $middlewares = $middlewares . ',' . $redirect_middleware;
+ $middlewares->push($redirect_middleware);
+ }
+ if ($middlewares->isNotEmpty()) {
+ $middlewares = $middlewares->join(',');
+ $labels->push("traefik.http.routers.{$http_label}.middlewares={$middlewares}");
}
- $labels->push("traefik.http.routers.{$http_label}.middlewares={$middlewares}");
}
}
} catch (\Throwable $e) {
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index bc33388eb7..f7939c9c38 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -1039,7 +1039,7 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
$serviceLabels = $serviceLabels->merge($defaultLabels);
if (!$isDatabase && $fqdns->count() > 0) {
if ($fqdns) {
- $serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik($resource->uuid, $fqdns, true, serviceLabels: $serviceLabels));
+ $serviceLabels = $serviceLabels->merge(fqdnLabelsForTraefik($resource->uuid, $fqdns, true, serviceLabels: $serviceLabels, is_gzip_enabled: $savedService->isGzipEnabled()));
}
}
if ($resource->server->isLogDrainEnabled() && $savedService->isLogDrainEnabled()) {
diff --git a/database/migrations/2024_02_15_192025_add_is_gzip_enabled_to_services.php b/database/migrations/2024_02_15_192025_add_is_gzip_enabled_to_services.php
new file mode 100644
index 0000000000..5f724e5cea
--- /dev/null
+++ b/database/migrations/2024_02_15_192025_add_is_gzip_enabled_to_services.php
@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ Schema::table('service_applications', function (Blueprint $table) {
+ $table->boolean('is_gzip_enabled')->default(true);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('service_applications', function (Blueprint $table) {
+ $table->dropColumn('is_gzip_enabled');
+ });
+ }
+};
diff --git a/resources/views/livewire/project/service/service-application-view.blade.php b/resources/views/livewire/project/service/service-application-view.blade.php
index 57ad0403af..a696533852 100644
--- a/resources/views/livewire/project/service/service-application-view.blade.php
+++ b/resources/views/livewire/project/service/service-application-view.blade.php
@@ -32,7 +32,9 @@
</div>
</div>
<h3 class="pt-2">Advanced</h3>
- <div class="w-64">
+ <div class="w-96">
+ <x-forms.checkbox instantSave id="application.is_gzip_enabled" label="Enable gzip compression"
+ helper="You can disable gzip compression if you want. Some services are compressing data by default. In this case, you do not need this." />
<x-forms.checkbox instantSave label="Exclude from service status"
helper="If you do not need to monitor this resource, enable. Useful if this service is optional."
id="application.exclude_from_status"></x-forms.checkbox>
diff --git a/resources/views/livewire/project/service/stack-form.blade.php b/resources/views/livewire/project/service/stack-form.blade.php
index 440d80f1b3..b9593087b0 100644
--- a/resources/views/livewire/project/service/stack-form.blade.php
+++ b/resources/views/livewire/project/service/stack-form.blade.php
@@ -15,7 +15,8 @@
<x-forms.input id="service.description" label="Description" />
</div>
<div class="w-96">
- <x-forms.checkbox instantSave id="service.connect_to_docker_network" label="Connect To Predefined Network" helper="By default, you do not reach the Coolify defined networks.<br>Starting a docker compose based resource will have an internal network. <br>If you connect to a Coolify defined network, you maybe need to use different internal DNS names to connect to a resource.<br><br>For more information, check <a class='text-white underline' href='https://coolify.io/docs/docker/compose#connect-to-predefined-networks'>this</a>." />
+ <x-forms.checkbox instantSave id="service.connect_to_docker_network" label="Connect To Predefined Network"
+ helper="By default, you do not reach the Coolify defined networks.<br>Starting a docker compose based resource will have an internal network. <br>If you connect to a Coolify defined network, you maybe need to use different internal DNS names to connect to a resource.<br><br>For more information, check <a class='text-white underline' href='https://coolify.io/docs/docker/compose#connect-to-predefined-networks'>this</a>." />
</div>
@if ($fields)
<div>