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.

Refactor environment variable saving logic in ApplicationDeploymentJob.php and escapeEnvVariables function in docker.php

Andras Bacsai2382a10bbac3
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index 729b2e049e..c8bc5c1176 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -716,19 +716,27 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
{
$envs = collect([]);
if ($this->pull_request_id !== 0) {
+ $filename = ".env-pr-$this->pull_request_id";
foreach ($this->application->environment_variables_preview as $env) {
$envs->push($env->key . '=' . $env->real_value);
}
} else {
+ $filename = ".env";
foreach ($this->application->environment_variables as $env) {
$envs->push($env->key . '=' . $env->real_value);
}
}
+ if ($envs->isEmpty()) {
+ return;
+ }
$envs_base64 = base64_encode($envs->implode("\n"));
$this->execute_remote_command(
[
executeInDocker($this->deployment_uuid, "echo '$envs_base64' | base64 -d > $this->workdir/.env")
],
+ [
+ "echo '$envs_base64' | base64 -d > $this->configuration_dir/$filename"
+ ]
);
}
@@ -1334,6 +1342,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
$this->docker_compose = Yaml::dump($docker_compose, 10);
$this->docker_compose_base64 = base64_encode($this->docker_compose);
$this->execute_remote_command([executeInDocker($this->deployment_uuid, "echo '{$this->docker_compose_base64}' | base64 -d > {$this->workdir}/docker-compose.yml"), "hidden" => true]);
+ $this->save_environment_variables();
}
private function generate_local_persistent_volumes()
diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.php
index aed77a7bb9..afcc4622b3 100644
--- a/bootstrap/helpers/docker.php
+++ b/bootstrap/helpers/docker.php
@@ -582,7 +582,7 @@ function validateComposeFile(string $compose, int $server_id): string|Throwable
function escapeEnvVariables($value)
{
- $search = array("\\", "\r", "\t", "\x0", '"', "'", "$");
- $replace = array("\\\\", "\\r", "\\t", "\\0", '\"', "\'", "$$");
+ $search = array("\\", "\r", "\t", "\x0", '"', "'");
+ $replace = array("\\\\", "\\r", "\\t", "\\0", '\"', "\'");
return str_replace($search, $replace, $value);
}