From 040cf3b3adc1ff09305c5e1c1d242b16b48feb27 Mon Sep 17 00:00:00 2001 From: peterxcli Date: Thu, 25 Jan 2024 22:53:40 +0800 Subject: [PATCH] feat: update deploy_image method to allow changing the image of a service --- monitor/service/cloudrun.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/monitor/service/cloudrun.py b/monitor/service/cloudrun.py index eacfa7e..403f911 100644 --- a/monitor/service/cloudrun.py +++ b/monitor/service/cloudrun.py @@ -185,24 +185,18 @@ def increase_instance_count(self, service_id: str, delta: int): except Exception: return False - def deploy_image(self, drone_id, image): + def deploy_image(self, service_id, image): """ Deploys a new image to a cloud run. :param image: The new image to deploy. """ - request = run_v2.UpdateServiceRequest( - service=run_v2.Service( - name=drone_id, - template=run_v2.RevisionTemplate( - containers=[ - run_v2.Container( - image=image, - ) - ] - ), - ) - ) + # Retrieve the current configuration of the service + service_name = f"projects/{self.project_id}/locations/{self.location}/services/{service_id}" + current_service = self.cloud_run_client.get_service(name=service_name) + + current_service.template.containers[0].image = image + request = run_v2.UpdateServiceRequest(service=current_service) operation = self.cloud_run_client.update_service(request=request)