refactor(deployment): remove commented-out code and streamline environment variable handling in ApplicationDeploymentJob

This commit is contained in:
Andras Bacsai 2025-09-29 12:05:51 +02:00
parent ed7ecbb49d
commit 249ab06295

View file

@ -1792,22 +1792,11 @@ private function ensure_nixpacks_php_variables()
$created_new = true; $created_new = true;
} }
// Always refresh the relationships to ensure we have the latest data
// This is critical for the first deployment where variables were just created
if ($this->pull_request_id === 0) { if ($this->pull_request_id === 0) {
$this->application->load(['nixpacks_environment_variables', 'environment_variables']); $this->application->load(['nixpacks_environment_variables', 'environment_variables']);
} else { } else {
$this->application->load(['nixpacks_environment_variables_preview', 'environment_variables_preview']); $this->application->load(['nixpacks_environment_variables_preview', 'environment_variables_preview']);
} }
// // Export these variables to /etc/environment in the helper container
// $this->execute_remote_command([
// executeInDocker($this->deployment_uuid, "echo 'NIXPACKS_PHP_FALLBACK_PATH=\"{$nixpacks_php_fallback_path->value}\"' >> /etc/environment"),
// 'hidden' => true,
// ], [
// executeInDocker($this->deployment_uuid, "echo 'NIXPACKS_PHP_ROOT_DIR=\"{$nixpacks_php_root_dir->value}\"' >> /etc/environment"),
// 'hidden' => true,
// ]);
} }
private function cleanup_git() private function cleanup_git()
@ -2530,16 +2519,7 @@ private function build_image()
} }
} }
// if ($this->dockerBuildkitSupported && $this->application->settings->use_build_secrets) {
// $build_script = "#!/bin/bash\n";
// $build_script .= "set -a\n";
// $build_script .= "source /etc/environment 2>/dev/null || true\n";
// $build_script .= "set +a\n";
// $build_script .= $build_command;
// $base64_build_command = base64_encode($build_script);
// } else {
$base64_build_command = base64_encode($build_command); $base64_build_command = base64_encode($build_command);
// }
$this->execute_remote_command( $this->execute_remote_command(
[ [
executeInDocker($this->deployment_uuid, "echo '{$base64_build_command}' | base64 -d | tee /artifacts/build.sh > /dev/null"), executeInDocker($this->deployment_uuid, "echo '{$base64_build_command}' | base64 -d | tee /artifacts/build.sh > /dev/null"),
@ -2605,16 +2585,7 @@ private function build_image()
} }
} }
$build_command = "docker build {$this->addHosts} --network host -f {$this->workdir}/Dockerfile {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}"; $build_command = "docker build {$this->addHosts} --network host -f {$this->workdir}/Dockerfile {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}";
// if ($this->dockerBuildkitSupported && $this->application->settings->use_build_secrets) {
// $build_script = "#!/bin/bash\n";
// $build_script .= "set -a\n";
// $build_script .= "source /etc/environment 2>/dev/null || true\n";
// $build_script .= "set +a\n";
// $build_script .= $build_command;
// $base64_build_command = base64_encode($build_script);
// } else {
$base64_build_command = base64_encode($build_command); $base64_build_command = base64_encode($build_command);
// }
$this->execute_remote_command( $this->execute_remote_command(
[ [
executeInDocker($this->deployment_uuid, "echo '{$dockerfile}' | base64 -d | tee {$this->workdir}/Dockerfile > /dev/null"), executeInDocker($this->deployment_uuid, "echo '{$dockerfile}' | base64 -d | tee {$this->workdir}/Dockerfile > /dev/null"),
@ -2655,16 +2626,7 @@ private function build_image()
$build_command = "docker build --pull {$this->buildTarget} {$this->addHosts} --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}"; $build_command = "docker build --pull {$this->buildTarget} {$this->addHosts} --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}";
} }
} }
// if ($this->dockerBuildkitSupported && $this->application->settings->use_build_secrets) {
// $build_script = "#!/bin/bash\n";
// $build_script .= "set -a\n";
// $build_script .= "source /etc/environment 2>/dev/null || true\n";
// $build_script .= "set +a\n";
// $build_script .= $build_command;
// $base64_build_command = base64_encode($build_script);
// } else {
$base64_build_command = base64_encode($build_command); $base64_build_command = base64_encode($build_command);
// }
$this->execute_remote_command( $this->execute_remote_command(
[ [
executeInDocker($this->deployment_uuid, "echo '{$base64_build_command}' | base64 -d | tee /artifacts/build.sh > /dev/null"), executeInDocker($this->deployment_uuid, "echo '{$base64_build_command}' | base64 -d | tee /artifacts/build.sh > /dev/null"),
@ -2716,17 +2678,7 @@ private function build_image()
$build_command = "docker build {$this->addHosts} --network host -f {$this->workdir}/.nixpacks/Dockerfile --progress plain -t {$this->production_image_name} {$this->build_args} {$this->workdir}"; $build_command = "docker build {$this->addHosts} --network host -f {$this->workdir}/.nixpacks/Dockerfile --progress plain -t {$this->production_image_name} {$this->build_args} {$this->workdir}";
} }
} }
// If using build secrets, prepend source of /etc/environment to the build script
// if ($this->dockerBuildkitSupported && $this->application->settings->use_build_secrets) {
// $build_script = "#!/bin/bash\n";
// $build_script .= "set -a\n";
// $build_script .= "source /etc/environment 2>/dev/null || true\n";
// $build_script .= "set +a\n";
// $build_script .= $build_command;
// $base64_build_command = base64_encode($build_script);
// } else {
$base64_build_command = base64_encode($build_command); $base64_build_command = base64_encode($build_command);
// }
$this->execute_remote_command( $this->execute_remote_command(
[ [
executeInDocker($this->deployment_uuid, "echo '{$base64_build_command}' | base64 -d | tee /artifacts/build.sh > /dev/null"), executeInDocker($this->deployment_uuid, "echo '{$base64_build_command}' | base64 -d | tee /artifacts/build.sh > /dev/null"),
@ -2760,17 +2712,7 @@ private function build_image()
$build_command = "docker build {$this->buildTarget} {$this->addHosts} --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}"; $build_command = "docker build {$this->buildTarget} {$this->addHosts} --network host -f {$this->workdir}{$this->dockerfile_location} {$this->build_args} --progress plain -t {$this->production_image_name} {$this->workdir}";
} }
} }
// If using build secrets, prepend source of /etc/environment to the build script
// if ($this->dockerBuildkitSupported && $this->application->settings->use_build_secrets) {
// $build_script = "#!/bin/bash\n";
// $build_script .= "set -a\n";
// $build_script .= "source /etc/environment 2>/dev/null || true\n";
// $build_script .= "set +a\n";
// $build_script .= $build_command;
// $base64_build_command = base64_encode($build_script);
// } else {
$base64_build_command = base64_encode($build_command); $base64_build_command = base64_encode($build_command);
// }
$this->execute_remote_command( $this->execute_remote_command(
[ [
executeInDocker($this->deployment_uuid, "echo '{$base64_build_command}' | base64 -d | tee /artifacts/build.sh > /dev/null"), executeInDocker($this->deployment_uuid, "echo '{$base64_build_command}' | base64 -d | tee /artifacts/build.sh > /dev/null"),