fix(deployment): use mainServer consistently instead of redundant original_server

Remove the redundant $original_server property and use $mainServer throughout
ApplicationDeploymentJob. Both properties held the same value (the deployment
target server), causing unnecessary duplication.

Also fixes two bugs in generate_compose_file() where $this->server was used
instead of $this->mainServer for isSwarm() and isLogDrainEnabled() checks.
When using a build server, $this->server could point to the build server,
causing incorrect configuration for the deployment target.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Andras Bacsai 2026-01-05 11:55:18 +01:00
parent 162eaa9f0d
commit 81780d652f

View file

@ -87,9 +87,6 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
private bool $use_build_server = false; private bool $use_build_server = false;
// Save original server between phases
private Server $original_server;
private Server $mainServer; private Server $mainServer;
private bool $is_this_additional_server = false; private bool $is_this_additional_server = false;
@ -325,18 +322,14 @@ public function handle(): void
if ($buildServers->count() === 0) { if ($buildServers->count() === 0) {
$this->application_deployment_queue->addLogEntry('No suitable build server found. Using the deployment server.'); $this->application_deployment_queue->addLogEntry('No suitable build server found. Using the deployment server.');
$this->build_server = $this->server; $this->build_server = $this->server;
$this->original_server = $this->server;
} else { } else {
$this->build_server = $buildServers->random(); $this->build_server = $buildServers->random();
$this->application_deployment_queue->build_server_id = $this->build_server->id; $this->application_deployment_queue->build_server_id = $this->build_server->id;
$this->application_deployment_queue->addLogEntry("Found a suitable build server ({$this->build_server->name})."); $this->application_deployment_queue->addLogEntry("Found a suitable build server ({$this->build_server->name}).");
$this->original_server = $this->server;
$this->use_build_server = true; $this->use_build_server = true;
} }
} else { } else {
// Set build server & original_server to the same as deployment server
$this->build_server = $this->server; $this->build_server = $this->server;
$this->original_server = $this->server;
} }
$this->detectBuildKitCapabilities(); $this->detectBuildKitCapabilities();
$this->decide_what_to_do(); $this->decide_what_to_do();
@ -937,7 +930,7 @@ private function write_deployment_configurations()
{ {
if ($this->preserveRepository) { if ($this->preserveRepository) {
if ($this->use_build_server) { if ($this->use_build_server) {
$this->server = $this->original_server; $this->server = $this->mainServer;
} }
if (str($this->configuration_dir)->isNotEmpty()) { if (str($this->configuration_dir)->isNotEmpty()) {
$this->execute_remote_command( $this->execute_remote_command(
@ -960,7 +953,7 @@ private function write_deployment_configurations()
} }
if (isset($this->docker_compose_base64)) { if (isset($this->docker_compose_base64)) {
if ($this->use_build_server) { if ($this->use_build_server) {
$this->server = $this->original_server; $this->server = $this->mainServer;
} }
$readme = generate_readme_file($this->application->name, $this->application_deployment_queue->updated_at); $readme = generate_readme_file($this->application->name, $this->application_deployment_queue->updated_at);
@ -1342,7 +1335,7 @@ private function save_runtime_environment_variables()
// Also create in configuration directory // Also create in configuration directory
if ($this->use_build_server) { if ($this->use_build_server) {
$this->server = $this->original_server; $this->server = $this->mainServer;
$this->execute_remote_command( $this->execute_remote_command(
[ [
"touch $this->configuration_dir/.env", "touch $this->configuration_dir/.env",
@ -1359,7 +1352,7 @@ private function save_runtime_environment_variables()
} else { } else {
// For non-Docker Compose deployments, clean up any existing .env files // For non-Docker Compose deployments, clean up any existing .env files
if ($this->use_build_server) { if ($this->use_build_server) {
$this->server = $this->original_server; $this->server = $this->mainServer;
$this->execute_remote_command( $this->execute_remote_command(
[ [
'command' => "rm -f $this->configuration_dir/.env", 'command' => "rm -f $this->configuration_dir/.env",
@ -1407,7 +1400,7 @@ private function save_runtime_environment_variables()
// Write .env file to configuration directory // Write .env file to configuration directory
if ($this->use_build_server) { if ($this->use_build_server) {
$this->server = $this->original_server; $this->server = $this->mainServer;
$this->execute_remote_command( $this->execute_remote_command(
[ [
"echo '$envs_base64' | base64 -d | tee $this->configuration_dir/.env > /dev/null", "echo '$envs_base64' | base64 -d | tee $this->configuration_dir/.env > /dev/null",
@ -1744,7 +1737,7 @@ private function rolling_update()
} else { } else {
if ($this->use_build_server) { if ($this->use_build_server) {
$this->write_deployment_configurations(); $this->write_deployment_configurations();
$this->server = $this->original_server; $this->server = $this->mainServer;
} }
if (count($this->application->ports_mappings_array) > 0 || (bool) $this->application->settings->is_consistent_container_name_enabled || str($this->application->settings->custom_internal_name)->isNotEmpty() || $this->pull_request_id !== 0 || str($this->application->custom_docker_run_options)->contains('--ip') || str($this->application->custom_docker_run_options)->contains('--ip6')) { if (count($this->application->ports_mappings_array) > 0 || (bool) $this->application->settings->is_consistent_container_name_enabled || str($this->application->settings->custom_internal_name)->isNotEmpty() || $this->pull_request_id !== 0 || str($this->application->custom_docker_run_options)->contains('--ip') || str($this->application->custom_docker_run_options)->contains('--ip6')) {
$this->application_deployment_queue->addLogEntry('----------------------------------------'); $this->application_deployment_queue->addLogEntry('----------------------------------------');
@ -1913,7 +1906,7 @@ private function deploy_pull_request()
private function create_workdir() private function create_workdir()
{ {
if ($this->use_build_server) { if ($this->use_build_server) {
$this->server = $this->original_server; $this->server = $this->mainServer;
$this->execute_remote_command( $this->execute_remote_command(
[ [
'command' => "mkdir -p {$this->configuration_dir}", 'command' => "mkdir -p {$this->configuration_dir}",
@ -2563,7 +2556,7 @@ private function generate_compose_file()
if (! is_null($this->application->limits_cpuset)) { if (! is_null($this->application->limits_cpuset)) {
data_set($docker_compose, 'services.'.$this->container_name.'.cpuset', $this->application->limits_cpuset); data_set($docker_compose, 'services.'.$this->container_name.'.cpuset', $this->application->limits_cpuset);
} }
if ($this->server->isSwarm()) { if ($this->mainServer->isSwarm()) {
data_forget($docker_compose, 'services.'.$this->container_name.'.container_name'); data_forget($docker_compose, 'services.'.$this->container_name.'.container_name');
data_forget($docker_compose, 'services.'.$this->container_name.'.expose'); data_forget($docker_compose, 'services.'.$this->container_name.'.expose');
data_forget($docker_compose, 'services.'.$this->container_name.'.restart'); data_forget($docker_compose, 'services.'.$this->container_name.'.restart');
@ -2613,7 +2606,7 @@ private function generate_compose_file()
} else { } else {
$docker_compose['services'][$this->container_name]['labels'] = $labels; $docker_compose['services'][$this->container_name]['labels'] = $labels;
} }
if ($this->original_server->isLogDrainEnabled() && $this->application->isLogDrainEnabled()) { if ($this->mainServer->isLogDrainEnabled() && $this->application->isLogDrainEnabled()) {
$docker_compose['services'][$this->container_name]['logging'] = generate_fluentd_configuration(); $docker_compose['services'][$this->container_name]['logging'] = generate_fluentd_configuration();
} }
if ($this->application->settings->is_gpu_enabled) { if ($this->application->settings->is_gpu_enabled) {