From c6c9d5a591866b26b1e96839fd14e0611b42b96b Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Thu, 18 Dec 2025 19:36:54 +0100 Subject: [PATCH] fix(deployment): Skip docker rm -f for builder containers with --rm flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builder containers are started with the --rm flag, which automatically removes them when stopped. The explicit docker rm -f is redundant and adds unnecessary steps to deployment logs. This change adds a skipRemove parameter to graceful_shutdown_container() and sets it to true for builder container shutdowns (uuid-based) while keeping the default behavior for application containers. Fixes #7566 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 --- app/Jobs/ApplicationDeploymentJob.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index cc1a44f9a..56a29276b 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -371,7 +371,7 @@ public function handle(): void try { $this->application_deployment_queue->addLogEntry("Gracefully shutting down build container: {$this->deployment_uuid}"); - $this->graceful_shutdown_container($this->deployment_uuid); + $this->graceful_shutdown_container($this->deployment_uuid, skipRemove: true); } catch (Exception $e) { // Log but don't fail - container cleanup errors are expected when container is already gone \Log::warning('Failed to shutdown container '.$this->deployment_uuid.': '.$e->getMessage()); @@ -1968,7 +1968,7 @@ private function prepare_builder_image(bool $firstTry = true) $this->application_deployment_queue->addLogEntry('Preparing container with helper image with updated envs.'); } - $this->graceful_shutdown_container($this->deployment_uuid); + $this->graceful_shutdown_container($this->deployment_uuid, skipRemove: true); $this->execute_remote_command( [ $runCommand, @@ -1983,8 +1983,8 @@ private function prepare_builder_image(bool $firstTry = true) private function restart_builder_container_with_actual_commit() { - // Stop and remove the current helper container - $this->graceful_shutdown_container($this->deployment_uuid); + // Stop the current helper container (no need for rm -f as it was started with --rm) + $this->graceful_shutdown_container($this->deployment_uuid, skipRemove: true); // Clear cached env_args to force regeneration with actual SOURCE_COMMIT value $this->env_args = null; @@ -3171,14 +3171,20 @@ private function build_image() $this->application_deployment_queue->addLogEntry('Building docker image completed.'); } - private function graceful_shutdown_container(string $containerName) + private function graceful_shutdown_container(string $containerName, bool $skipRemove = false) { try { $timeout = isDev() ? 1 : 30; - $this->execute_remote_command( - ["docker stop -t $timeout $containerName", 'hidden' => true, 'ignore_errors' => true], - ["docker rm -f $containerName", 'hidden' => true, 'ignore_errors' => true] - ); + if ($skipRemove) { + $this->execute_remote_command( + ["docker stop -t $timeout $containerName", 'hidden' => true, 'ignore_errors' => true] + ); + } else { + $this->execute_remote_command( + ["docker stop -t $timeout $containerName", 'hidden' => true, 'ignore_errors' => true], + ["docker rm -f $containerName", 'hidden' => true, 'ignore_errors' => true] + ); + } } catch (Exception $error) { $this->application_deployment_queue->addLogEntry("Error stopping container $containerName: ".$error->getMessage(), 'stderr'); }