Skip to content

Commit

Permalink
feat: update deploy_image method to allow changing the image of a ser…
Browse files Browse the repository at this point in the history
…vice
  • Loading branch information
peterxcli committed Jan 25, 2024
1 parent df79885 commit 040cf3b
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions monitor/service/cloudrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 040cf3b

Please sign in to comment.