diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php index f9d516634..8dca584f2 100644 --- a/app/Actions/Database/StartMariadb.php +++ b/app/Actions/Database/StartMariadb.php @@ -106,7 +106,6 @@ public function handle(StandaloneMariadb $database) $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 b5c4dde88..ef04a9be8 100644 --- a/app/Actions/Database/StartMongodb.php +++ b/app/Actions/Database/StartMongodb.php @@ -122,7 +122,6 @@ public function handle(StandaloneMongodb $database) $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 a103b3531..3b47483a3 100644 --- a/app/Actions/Database/StartMysql.php +++ b/app/Actions/Database/StartMysql.php @@ -106,7 +106,6 @@ public function handle(StandaloneMysql $database) $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 a77d09381..844f81c31 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -128,7 +128,6 @@ public function handle(StandalonePostgresql $database) $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 f6e8b3780..e1a8eef41 100644 --- a/app/Actions/Database/StartRedis.php +++ b/app/Actions/Database/StartRedis.php @@ -117,7 +117,6 @@ public function handle(StandaloneRedis $database) $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 84f954e80..6ec71c4f3 100644 --- a/app/Actions/Service/StartService.php +++ b/app/Actions/Service/StartService.php @@ -13,10 +13,6 @@ public function handle(Service $service) { 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 a17494d1d..53532a855 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 894428182..44672fe64 100644 --- a/app/Livewire/Project/Service/StackForm.php +++ b/app/Livewire/Project/Service/StackForm.php @@ -45,8 +45,10 @@ public function saveCompose($raw) $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 be1eb0f6d..314a01ba3 100644 --- a/app/Models/ServiceApplication.php +++ b/app/Models/ServiceApplication.php @@ -23,6 +23,10 @@ public function isLogDrainEnabled() { 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 0bde42c20..31bd2786d 100644 --- a/app/Models/ServiceDatabase.php +++ b/app/Models/ServiceDatabase.php @@ -21,6 +21,10 @@ public function isLogDrainEnabled() { 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 f01eb972f..7b367c63c 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -7,7 +7,6 @@ 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 ($redirect && $redirect_middleware) { - $middlewares = $middlewares . ',' . $redirect_middleware; - } - $labels->push("traefik.http.routers.{$https_label}.middlewares={$middlewares}"); - } else { - $middlewares = "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}"); + } + } else { + $middlewares = collect([]); + if ($is_gzip_enabled) { + $middlewares->push('gzip'); + } + if ($basic_auth && $basic_auth_middleware) { + $middlewares->push($basic_auth_middleware); + } + if ($redirect && $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 ($redirect && $redirect_middleware) { - $middlewares = $middlewares . ',' . $redirect_middleware; - } - $labels->push("traefik.http.routers.{$http_label}.middlewares={$middlewares}"); - } else { - $middlewares = "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}"); + } + } else { + $middlewares = collect([]); + if ($is_gzip_enabled) { + $middlewares->push('gzip'); + } + if ($basic_auth && $basic_auth_middleware) { + $middlewares->push($basic_auth_middleware); + } + if ($redirect && $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 bc33388eb..f7939c9c3 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 000000000..5f724e5ce --- /dev/null +++ b/database/migrations/2024_02_15_192025_add_is_gzip_enabled_to_services.php @@ -0,0 +1,28 @@ +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 57ad0403a..a69653385 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 @@

Advanced

-
+
+ diff --git a/resources/views/livewire/project/service/stack-form.blade.php b/resources/views/livewire/project/service/stack-form.blade.php index 440d80f1b..b9593087b 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 @@
- +
@if ($fields)