From 9947158f7e232bce8a212d1299848bd5a5ee3a8a Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 15 Jan 2024 12:12:34 +0100 Subject: [PATCH 1/3] fix gzip compression --- bootstrap/helpers/docker.php | 9 ++++++--- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index 1ae92ff3a..10240c02c 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -230,7 +230,6 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_ $https_label = "https-{$loop}-{$uuid}"; $labels->push("traefik.http.middlewares.gzip.compress=true"); - $labels->push("traefik.http.routers.{$https_label}.middlewares=gzip"); if ($schema === 'https') { // Set labels for https $labels->push("traefik.http.routers.{$https_label}.rule=Host(`{$host}`) && PathPrefix(`{$path}`)"); @@ -240,8 +239,10 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_ $labels->push("traefik.http.services.{$https_label}.loadbalancer.server.port=$port"); } if ($path !== '/') { - $labels->push("traefik.http.routers.{$https_label}.middlewares={$https_label}-stripprefix"); $labels->push("traefik.http.middlewares.{$https_label}-stripprefix.stripprefix.prefixes={$path}"); + $labels->push("traefik.http.routers.{$https_label}.middlewares={$https_label}-stripprefix,gzip"); + } else { + $labels->push("traefik.http.routers.{$https_label}.middlewares=gzip"); } $labels->push("traefik.http.routers.{$https_label}.tls=true"); @@ -267,8 +268,10 @@ function fqdnLabelsForTraefik(string $uuid, Collection $domains, bool $is_force_ $labels->push("traefik.http.routers.{$http_label}.service={$http_label}"); } if ($path !== '/') { - $labels->push("traefik.http.routers.{$http_label}.middlewares={$http_label}-stripprefix"); $labels->push("traefik.http.middlewares.{$http_label}-stripprefix.stripprefix.prefixes={$path}"); + $labels->push("traefik.http.routers.{$http_label}.middlewares={$http_label}-stripprefix,gzip"); + } else { + $labels->push("traefik.http.routers.{$http_label}.middlewares=gzip"); } } } catch (\Throwable $e) { diff --git a/config/sentry.php b/config/sentry.php index f8d1e0846..d8d09746b 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.192', + 'release' => '4.0.0-beta.193', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 7c6364103..40ea0dab6 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Mon, 15 Jan 2024 12:30:49 +0100 Subject: [PATCH 2/3] Replace comma with pipe in customLabels --- app/Livewire/Project/Application/General.php | 8 ++++---- app/Models/Application.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php index ab16f64d7..0e93d389c 100644 --- a/app/Livewire/Project/Application/General.php +++ b/app/Livewire/Project/Application/General.php @@ -117,7 +117,7 @@ class General extends Component $this->isConfigurationChanged = $this->application->isConfigurationChanged(); $this->customLabels = $this->application->parseContainerLabels(); if (!$this->customLabels && $this->application->destination->server->proxyType() === 'TRAEFIK_V2') { - $this->customLabels = str(implode(",", generateLabelsApplication($this->application)))->replace(',', "\n"); + $this->customLabels = str(implode("|", generateLabelsApplication($this->application)))->replace("|", "\n"); $this->application->custom_labels = base64_encode($this->customLabels); $this->application->save(); } @@ -182,7 +182,7 @@ class General extends Component } public function checkLabelUpdates() { - if (md5($this->application->custom_labels) !== md5(implode(",", generateLabelsApplication($this->application)))) { + if (md5($this->application->custom_labels) !== md5(implode("|", generateLabelsApplication($this->application)))) { $this->labelsChanged = true; } else { $this->labelsChanged = false; @@ -201,7 +201,7 @@ class General extends Component } public function resetDefaultLabels($showToaster = true) { - $this->customLabels = str(implode(",", generateLabelsApplication($this->application)))->replace(',', "\n"); + $this->customLabels = str(implode("|", generateLabelsApplication($this->application)))->replace("|", "\n"); $this->ports_exposes = $this->application->ports_exposes; $this->submit($showToaster); } @@ -215,7 +215,7 @@ class General extends Component { try { if (!$this->customLabels && $this->application->destination->server->proxyType() === 'TRAEFIK_V2') { - $this->customLabels = str(implode(",", generateLabelsApplication($this->application)))->replace(',', "\n"); + $this->customLabels = str(implode("|", generateLabelsApplication($this->application)))->replace("|", "\n"); $this->application->custom_labels = base64_encode($this->customLabels); $this->application->save(); } diff --git a/app/Models/Application.php b/app/Models/Application.php index 5f3b7afe2..4e845fe0d 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -1066,7 +1066,7 @@ class Application extends BaseModel $customLabels = base64_decode($this->custom_labels); if (mb_detect_encoding($customLabels, 'ASCII', true) === false) { ray('custom_labels contains non-ascii characters'); - $customLabels = str(implode(",", generateLabelsApplication($this, $preview)))->replace(',', "\n"); + $customLabels = str(implode("|", generateLabelsApplication($this, $preview)))->replace("|", "\n"); } $this->custom_labels = base64_encode($customLabels); $this->save(); From 8e7040bf7cb942efabbd0a923c1fa04edbe810ff Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 15 Jan 2024 12:59:21 +0100 Subject: [PATCH 3/3] Update Docker Compose commands to include SOURCE_COMMIT environment variable --- app/Jobs/ApplicationDeploymentJob.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 3d11a9dbf..5755b5a57 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -477,7 +477,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted ); } else { $this->execute_remote_command( - [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build"), "hidden" => true], + [executeInDocker($this->deployment_uuid, "SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build"), "hidden" => true], ); } @@ -521,7 +521,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted ); } else { $this->execute_remote_command( - [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} up -d"), "hidden" => true], + [executeInDocker($this->deployment_uuid, "SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} up -d"), "hidden" => true], ); } $this->application_deployment_queue->addLogEntry("New container started."); @@ -756,7 +756,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted } else { $this->execute_remote_command( ["echo -n 'Starting preview deployment.'"], - [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} up -d"), "hidden" => true], + [executeInDocker($this->deployment_uuid, "SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->workdir} up -d"), "hidden" => true], ); } } @@ -917,6 +917,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted $merged_envs = $this->env_args->merge(collect(data_get($parsed, 'variables', []))); data_set($parsed, 'variables', $merged_envs->toArray()); $this->nixpacks_plan = json_encode($parsed, JSON_PRETTY_PRINT); + ray($this->nixpacks_plan); } } } @@ -964,6 +965,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted $this->env_args->put($env->key, $env->value); } } + $this->env_args->put('SOURCE_COMMIT', $this->commit); } private function generate_compose_file() @@ -1190,12 +1192,14 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted } } // Add PORT if not exists, use the first port as default - if ($environment_variables->filter(fn ($env) => Str::of($env)->contains('PORT'))->isEmpty()) { + if ($environment_variables->filter(fn ($env) => Str::of($env)->startsWith('PORT'))->isEmpty()) { $environment_variables->push("PORT={$ports[0]}"); } - if ($environment_variables->filter(fn ($env) => Str::of($env)->contains('SOURCE_COMMIT'))->isEmpty()) { + if ($environment_variables->filter(fn ($env) => Str::of($env)->startsWith('SOURCE_COMMIT'))->isEmpty()) { if (!is_null($this->commit)) { $environment_variables->push("SOURCE_COMMIT={$this->commit}"); + } else { + $environment_variables->push("SOURCE_COMMIT=unknown"); } } return $environment_variables->all(); @@ -1440,11 +1444,11 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); $this->application_deployment_queue->addLogEntry("Pulling latest images from the registry."); $this->execute_remote_command( [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} pull"), "hidden" => true], - [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} build"), "hidden" => true], + [executeInDocker($this->deployment_uuid, "SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->workdir} build"), "hidden" => true], ); } else { $this->execute_remote_command( - [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build"), "hidden" => true], + [executeInDocker($this->deployment_uuid, "SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build"), "hidden" => true], ); } $this->application_deployment_queue->addLogEntry("New images built."); @@ -1456,16 +1460,16 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); $this->application_deployment_queue->addLogEntry("Pulling latest images from the registry."); $this->execute_remote_command( [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} pull"), "hidden" => true], - [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} up --build -d"), "hidden" => true], + [executeInDocker($this->deployment_uuid, "SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->workdir} up --build -d"), "hidden" => true], ); } else { if ($this->docker_compose_location) { $this->execute_remote_command( - [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} up --build -d"), "hidden" => true], + [executeInDocker($this->deployment_uuid, "SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} up --build -d"), "hidden" => true], ); } else { $this->execute_remote_command( - [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} up --build -d"), "hidden" => true], + [executeInDocker($this->deployment_uuid, "SOURCE_COMMIT={$this->commit} docker compose --project-directory {$this->workdir} up --build -d"), "hidden" => true], ); } }