From 7763594e6e3538d8a578d0fc40fd1058e644f844 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 13 Nov 2023 12:30:25 +0100 Subject: [PATCH] Add pull_latest_image function and update build_image function to use it. Also add check for dockerfile existence in start_by_compose_file function. --- app/Jobs/ApplicationDeploymentJob.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 71cf9026d..de32ad1fb 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -934,7 +934,16 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted } return implode(' ', $generated_healthchecks_commands); } + private function pull_latest_image($image) + { + $this->execute_remote_command( + ["echo -n 'Pulling latest image ($image) from the registry.'"], + [ + executeInDocker($this->deployment_uuid, "docker pull {$image}"), "hidden" => true + ] + ); + } private function build_image() { if ($this->application->build_pack === 'static') { @@ -948,6 +957,9 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted } if ($this->application->settings->is_static || $this->application->build_pack === 'static') { + if ($this->application->static_image) { + $this->pull_latest_image($this->application->static_image); + } if ($this->application->build_pack === 'static') { $dockerfile = base64_encode("FROM {$this->application->static_image} WORKDIR /usr/share/nginx/html/ @@ -1012,8 +1024,9 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); ] ); } else { + // Pure Dockerfile based deployment $this->execute_remote_command([ - executeInDocker($this->deployment_uuid, "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}"), "hidden" => true + executeInDocker($this->deployment_uuid, "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}"), "hidden" => true ]); } } @@ -1049,6 +1062,17 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf"); private function start_by_compose_file() { + if ( + !$this->application->dockerfile && + ( + $this->application->build_pack === 'dockerimage' || + $this->application->build_pack === 'dockerfile') + ) { + $this->execute_remote_command( + ["echo -n 'Pulling latest images from the registry.'"], + [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} pull"), "hidden" => true], + ); + } $this->execute_remote_command( ["echo -n 'Starting application (could take a while).'"], [executeInDocker($this->deployment_uuid, "docker compose --project-directory {$this->workdir} up --build -d"), "hidden" => true],