From 2be0c0da673fad138c7d768f527f2db62ea20a98 Mon Sep 17 00:00:00 2001 From: Joao Da Silva Date: Tue, 20 Dec 2022 16:36:03 +0100 Subject: [PATCH] feat: allow for custom cloud-build timeout (#74) --- src/wanna/core/models/docker.py | 2 ++ src/wanna/core/services/docker.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wanna/core/models/docker.py b/src/wanna/core/models/docker.py index e88e7c46..78b03793 100644 --- a/src/wanna/core/models/docker.py +++ b/src/wanna/core/models/docker.py @@ -86,6 +86,7 @@ class DockerModel(BaseModel, extra=Extra.forbid, validate_assignment=True): - `repository` - [str] (optional) GCP Artifact Registry repository for pushing images - `registry` - [str] (optional) GCP Artifact Registry, when not set it defaults to `{gcp_profile.region}-docker.pkg.dev` + - `cloud_build_timeout` - [int] `12000` how many seconds before cloud build timeout - `cloud_build` - [str] (optional) `false` (default) to build locally, `true` to use GCP Cloud Build - `cloud_build_workerpool` - [str] (optional) Name of the GCP Cloud Build workerpool if you want to use one - `cloud_build_workerpool_location` - [str] (optional) Location of the GCP Cloud Build workerpool. Must be specified @@ -95,6 +96,7 @@ class DockerModel(BaseModel, extra=Extra.forbid, validate_assignment=True): images: List[DockerImageModel] = [] repository: Optional[str] registry: Optional[str] + cloud_build_timeout: int = 12000 cloud_build: bool = False cloud_build_workerpool: Optional[str] cloud_build_workerpool_location: Optional[str] diff --git a/src/wanna/core/services/docker.py b/src/wanna/core/services/docker.py index e9a092a4..c4c894d2 100644 --- a/src/wanna/core/services/docker.py +++ b/src/wanna/core/services/docker.py @@ -72,6 +72,7 @@ def __init__( self.location = gcp_profile.region self.docker_build_config_path = os.getenv("WANNA_DOCKER_BUILD_CONFIG", self.work_dir / "dockerbuild.yaml") self.build_config = self._read_build_config(self.docker_build_config_path) + self.cloud_build_timeout = docker_model.cloud_build_timeout self.cloud_build = gcp_access_allowed and docker_model.cloud_build self.cloud_build_workerpool = docker_model.cloud_build_workerpool self.cloud_build_workerpool_location = docker_model.cloud_build_workerpool_location or self.location @@ -297,7 +298,7 @@ def _build_image_on_gcp_cloud_build( steps = BuildStep(name="gcr.io/cloud-builders/docker", args=["build", ".", "-f", dockerfile] + tags_args) timeout = Duration() - timeout.seconds = 7200 + timeout.seconds = self.cloud_build_timeout if self.cloud_build_workerpool: project_number = convert_project_id_to_project_number(self.project_id) options = BuildOptions(