From a336dae84c3d608d2ecc3ea58f333634df8a4727 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 14 Mar 2024 23:00:06 +0100 Subject: [PATCH] fix: $ in env variable feat: multiline envs --- app/Jobs/ApplicationDeploymentJob.php | 17 ++++++++--- .../Shared/EnvironmentVariable/Show.php | 2 ++ bootstrap/helpers/docker.php | 10 ++++++- config/sentry.php | 2 +- config/version.php | 2 +- .../2024_03_14_214402_add_multiline_envs.php | 28 +++++++++++++++++++ .../environment-variable/show.blade.php | 11 ++++++-- templates/compose/uptime-kuma.yaml | 2 +- templates/service-templates.json | 2 +- versions.json | 2 +- 10 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 database/migrations/2024_03_14_214402_add_multiline_envs.php diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index f96a68582..ca0efd2c3 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1359,23 +1359,31 @@ private function generate_environment_variables($ports) $environment_variables = collect(); if ($this->pull_request_id === 0) { foreach ($this->application->runtime_environment_variables as $env) { - $environment_variables->push("$env->key=$env->real_value"); + $real_value = escapeEnvVariables($env->real_value); + $environment_variables->push("$env->key=$real_value"); } foreach ($this->application->nixpacks_environment_variables as $env) { - $environment_variables->push("$env->key=$env->real_value"); + $real_value = escapeEnvVariables($env->real_value); + $environment_variables->push("$env->key=$real_value"); } } else { foreach ($this->application->runtime_environment_variables_preview as $env) { - $environment_variables->push("$env->key=$env->real_value"); + $real_value = escapeEnvVariables($env->real_value); + $environment_variables->push("$env->key=$real_value"); } foreach ($this->application->nixpacks_environment_variables_preview as $env) { - $environment_variables->push("$env->key=$env->real_value"); + $real_value = escapeEnvVariables($env->real_value); + $environment_variables->push("$env->key=$real_value"); } } // Add PORT if not exists, use the first port as default if ($environment_variables->filter(fn ($env) => Str::of($env)->startsWith('PORT'))->isEmpty()) { $environment_variables->push("PORT={$ports[0]}"); } + // Add HOST if not exists + if ($environment_variables->filter(fn ($env) => Str::of($env)->startsWith('HOST'))->isEmpty()) { + $environment_variables->push("HOST=0.0.0.0"); + } 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}"); @@ -1383,6 +1391,7 @@ private function generate_environment_variables($ports) $environment_variables->push("SOURCE_COMMIT=unknown"); } } + ray($environment_variables->all()); return $environment_variables->all(); } diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php index 9252c44f8..7903e8e51 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php @@ -21,6 +21,7 @@ class Show extends Component 'env.key' => 'required|string', 'env.value' => 'nullable', 'env.is_build_time' => 'required|boolean', + 'env.is_multiline' => 'required|boolean', 'env.is_shown_once' => 'required|boolean', 'env.real_value' => 'nullable', ]; @@ -28,6 +29,7 @@ class Show extends Component 'env.key' => 'Key', 'env.value' => 'Value', 'env.is_build_time' => 'Build Time', + 'env.is_multiline' => 'Multiline', 'env.is_shown_once' => 'Shown Once', ]; diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php index 898789adf..aed77a7bb 100644 --- a/bootstrap/helpers/docker.php +++ b/bootstrap/helpers/docker.php @@ -557,7 +557,8 @@ function convert_docker_run_to_compose(?string $custom_docker_run_options = null return $compose_options->toArray(); } -function validateComposeFile(string $compose, int $server_id): string|Throwable { +function validateComposeFile(string $compose, int $server_id): string|Throwable +{ return 'OK'; try { $uuid = Str::random(10); @@ -578,3 +579,10 @@ function validateComposeFile(string $compose, int $server_id): string|Throwable ], $server); } } + +function escapeEnvVariables($value) +{ + $search = array("\\", "\r", "\t", "\x0", '"', "'", "$"); + $replace = array("\\\\", "\\r", "\\t", "\\0", '\"', "\'", "$$"); + return str_replace($search, $replace, $value); +} diff --git a/config/sentry.php b/config/sentry.php index 1fe45fcc9..5d46ba7f3 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ // 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.239', + 'release' => '4.0.0-beta.240', // 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 cf8c3ba8b..c7e1008fc 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ boolean('is_multiline')->default(false); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('environment_variables', function (Blueprint $table) { + $table->dropColumn('is_multiline'); + }); + } +}; diff --git a/resources/views/livewire/project/shared/environment-variable/show.blade.php b/resources/views/livewire/project/shared/environment-variable/show.blade.php index 5b2c95373..d64490605 100644 --- a/resources/views/livewire/project/shared/environment-variable/show.blade.php +++ b/resources/views/livewire/project/shared/environment-variable/show.blade.php @@ -20,11 +20,18 @@ class="flex flex-col gap-2 p-4 m-2 border lg:items-center border-coolgray-300 lg @endif @else - - + @if ($env->is_multiline) + + + @else + + + @endif @if ($env->is_shared) @endif + @if ($type !== 'service' && !$isSharedVariable) @endif diff --git a/templates/compose/uptime-kuma.yaml b/templates/compose/uptime-kuma.yaml index d5c07684d..cd20d60cb 100644 --- a/templates/compose/uptime-kuma.yaml +++ b/templates/compose/uptime-kuma.yaml @@ -8,7 +8,7 @@ services: uptime-kuma: image: louislam/uptime-kuma:1 environment: - - SERVICE_FQDN_3001 + - SERVICE_FQDN_UPTIME-KUMA_3001 volumes: - uptime-kuma:/app/data healthcheck: diff --git a/templates/service-templates.json b/templates/service-templates.json index c7a4d91db..76bdf2bd8 100644 --- a/templates/service-templates.json +++ b/templates/service-templates.json @@ -772,7 +772,7 @@ "uptime-kuma": { "documentation": "https:\/\/github.com\/louislam\/uptime-kuma?tab=readme-ov-file", "slogan": "Uptime Kuma is a monitoring tool for tracking the status and performance of your applications in real-time.", - "compose": "c2VydmljZXM6CiAgdXB0aW1lLWt1bWE6CiAgICBpbWFnZTogJ2xvdWlzbGFtL3VwdGltZS1rdW1hOjEnCiAgICBlbnZpcm9ubWVudDoKICAgICAgLSBTRVJWSUNFX0ZRRE5fMzAwMQogICAgdm9sdW1lczoKICAgICAgLSAndXB0aW1lLWt1bWE6L2FwcC9kYXRhJwogICAgaGVhbHRoY2hlY2s6CiAgICAgIHRlc3Q6CiAgICAgICAgLSBDTUQtU0hFTEwKICAgICAgICAtIGV4dHJhL2hlYWx0aGNoZWNrCiAgICAgIGludGVydmFsOiAycwogICAgICB0aW1lb3V0OiAxMHMKICAgICAgcmV0cmllczogMTUK", + "compose": "c2VydmljZXM6CiAgdXB0aW1lLWt1bWE6CiAgICBpbWFnZTogJ2xvdWlzbGFtL3VwdGltZS1rdW1hOjEnCiAgICBlbnZpcm9ubWVudDoKICAgICAgLSBTRVJWSUNFX0ZRRE5fVVBUSU1FLUtVTUFfMzAwMQogICAgdm9sdW1lczoKICAgICAgLSAndXB0aW1lLWt1bWE6L2FwcC9kYXRhJwogICAgaGVhbHRoY2hlY2s6CiAgICAgIHRlc3Q6CiAgICAgICAgLSBDTUQtU0hFTEwKICAgICAgICAtIGV4dHJhL2hlYWx0aGNoZWNrCiAgICAgIGludGVydmFsOiAycwogICAgICB0aW1lb3V0OiAxMHMKICAgICAgcmV0cmllczogMTUK", "tags": [ "monitoring", "status", diff --git a/versions.json b/versions.json index 8f30ba88c..ba197ca84 100644 --- a/versions.json +++ b/versions.json @@ -4,7 +4,7 @@ "version": "3.12.36" }, "v4": { - "version": "4.0.0-beta.239" + "version": "4.0.0-beta.240" } } }