From efe043ec9d7799ab44d8e7af6a9a14e1da38bac4 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Sat, 9 Dec 2023 19:14:06 -0800 Subject: [PATCH] Build images prior to rollout. --- app/Jobs/ApplicationDeploymentJob.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 838bd7dd6..4de85f6ae 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -451,6 +451,8 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted executeInDocker($this->deployment_uuid, "echo '{$this->docker_compose_base64}' | base64 -d > {$this->workdir}{$this->docker_compose_location}"), "hidden" => true ]); $this->save_environment_variables(); + // Build new container to limit downtime. + $this->build_by_compose_file(); $this->stop_running_container(force: true); $networkId = $this->application->uuid; @@ -1243,6 +1245,27 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); } } + private function build_by_compose_file() { + if ($this->application->build_pack === 'dockerimage') { + $this->application_deployment_queue->addLogEntry("Pulling latest images from the registry."); + $this->execute_remote_command( + [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} pull"), "hidden" => true], + [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} build"), "hidden" => true], + ); + } else { + if ($this->docker_compose_location) { + $this->execute_remote_command( + [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} build"), "hidden" => true], + ); + } else { + $this->execute_remote_command( + [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} build"), "hidden" => true], + ); + } + } + $this->application_deployment_queue->addLogEntry("New images built."); + } + private function start_by_compose_file() { if ($this->application->build_pack === 'dockerimage') {