fix: multiline build args

This commit is contained in:
Andras Bacsai 2024-06-10 21:57:13 +02:00
parent e08dc777df
commit 2e4fd1530c

View File

@ -244,13 +244,13 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted
} else { } else {
$this->write_deployment_configurations(); $this->write_deployment_configurations();
} }
$this->execute_remote_command( // $this->execute_remote_command(
[ // [
"docker rm -f {$this->deployment_uuid} >/dev/null 2>&1", // "docker rm -f {$this->deployment_uuid} >/dev/null 2>&1",
"hidden" => true, // "hidden" => true,
"ignore_errors" => true, // "ignore_errors" => true,
] // ]
); // );
// $this->execute_remote_command( // $this->execute_remote_command(
@ -1949,22 +1949,17 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
if ($this->pull_request_id === 0) { if ($this->pull_request_id === 0) {
foreach ($this->application->build_environment_variables as $env) { foreach ($this->application->build_environment_variables as $env) {
$value = escapeshellarg($env->real_value); $value = escapeshellarg($env->real_value);
if (str($value)->contains("\n") && data_get($env, 'is_multiline') === true) {
$value = str_replace("\n", "\\\n", $value);
}
$this->build_args->push("--build-arg {$env->key}={$value}"); $this->build_args->push("--build-arg {$env->key}={$value}");
} }
} else { } else {
foreach ($this->application->build_environment_variables_preview as $env) { foreach ($this->application->build_environment_variables_preview as $env) {
$value = escapeshellarg($env->real_value); $value = escapeshellarg($env->real_value);
if (str($value)->contains("\n") && data_get($env, 'is_multiline') === true) {
$value = str_replace("\n", "\\\n", $value);
}
$this->build_args->push("--build-arg {$env->key}={$value}"); $this->build_args->push("--build-arg {$env->key}={$value}");
} }
} }
$this->build_args = $this->build_args->implode(' '); $this->build_args = $this->build_args->implode(' ');
ray($this->build_args);
} }
private function add_build_env_variables_to_dockerfile() private function add_build_env_variables_to_dockerfile()
@ -1975,19 +1970,18 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");
$dockerfile = collect(Str::of($this->saved_outputs->get('dockerfile'))->trim()->explode("\n")); $dockerfile = collect(Str::of($this->saved_outputs->get('dockerfile'))->trim()->explode("\n"));
if ($this->pull_request_id === 0) { if ($this->pull_request_id === 0) {
foreach ($this->application->build_environment_variables as $env) { foreach ($this->application->build_environment_variables as $env) {
if (str($env->real_value)->contains("\n") && data_get($env, 'is_multiline') === true) { if (data_get($env, 'is_multiline') === true) {
$value = str_replace("\n", "\\\n", $env->real_value); $dockerfile->splice(1, 0, "ARG {$env->key}");
} else { } else {
$value = $env->real_value; $dockerfile->splice(1, 0, "ARG {$env->key}={$env->real_value}");
} }
$dockerfile->splice(1, 0, "ARG {$env->key}={$value}");
} }
} else { } else {
foreach ($this->application->build_environment_variables_preview as $env) { foreach ($this->application->build_environment_variables_preview as $env) {
if (str($env->real_value)->contains("\n") && data_get($env, 'is_multiline') === true) { if (data_get($env, 'is_multiline') === true) {
$value = str_replace("\n", "\\\n", $env->real_value); $dockerfile->splice(1, 0, "ARG {$env->key}");
} else { } else {
$value = $env->real_value; $dockerfile->splice(1, 0, "ARG {$env->key}={$env->real_value}");
} }
$dockerfile->splice(1, 0, "ARG {$env->key}={$env->real_value}"); $dockerfile->splice(1, 0, "ARG {$env->key}={$env->real_value}");
} }