1414from google .cloud import artifactregistry_v1 , storage
1515from google .cloud .devtools import cloudbuild_v1
1616
17- from keras_remote .constants import get_default_zone , zone_to_ar_location
17+ from keras_remote .constants import (
18+ get_default_cluster_name ,
19+ get_default_zone ,
20+ zone_to_ar_location ,
21+ )
1822from keras_remote .core import accelerators
1923
2024REMOTE_RUNNER_FILE_NAME = "remote_runner.py"
2630
2731
2832def get_or_build_container (
29- base_image , requirements_path , accelerator_type , project , zone = None
33+ base_image ,
34+ requirements_path ,
35+ accelerator_type ,
36+ project ,
37+ zone = None ,
38+ cluster_name = None ,
3039):
3140 """Get existing container or build if requirements changed.
3241
@@ -38,11 +47,13 @@ def get_or_build_container(
3847 accelerator_type: TPU/GPU type (e.g., 'v3-8')
3948 project: GCP project ID
4049 zone: GCP zone for region derivation (defaults to KERAS_REMOTE_ZONE)
50+ cluster_name: GKE cluster name (defaults to KERAS_REMOTE_CLUSTER)
4151
4252 Returns:
4353 Container image URI in Artifact Registry
4454 """
4555 ar_location = zone_to_ar_location (zone or get_default_zone ())
56+ cluster_name = cluster_name or get_default_cluster_name ()
4657 category = accelerators .get_category (accelerator_type )
4758
4859 # Generate deterministic hash from requirements + base image + category
@@ -53,8 +64,9 @@ def get_or_build_container(
5364 # Use category for image name (e.g., 'tpu-hash', 'gpu-hash')
5465 image_tag = f"{ category } -{ requirements_hash [:12 ]} "
5566
56- # Use Artifact Registry
57- registry = f"{ ar_location } -docker.pkg.dev/{ project } /keras-remote"
67+ # Use Artifact Registry (cluster-scoped repo)
68+ repo_id = f"kr-{ cluster_name } "
69+ registry = f"{ ar_location } -docker.pkg.dev/{ project } /{ repo_id } "
5870 image_uri = f"{ registry } /base:{ image_tag } "
5971
6072 # Check if image exists
@@ -63,7 +75,7 @@ def get_or_build_container(
6375 ar_url = (
6476 "https://console.cloud.google.com/artifacts"
6577 f"/docker/{ project } /{ ar_location } "
66- f"/keras-remote /base?project={ project } "
78+ f"/{ repo_id } /base?project={ project } "
6779 )
6880 logging .info ("View image: %s" , ar_url )
6981 return image_uri
@@ -77,6 +89,7 @@ def get_or_build_container(
7789 project ,
7890 image_uri ,
7991 ar_location ,
92+ cluster_name ,
8093 )
8194
8295
@@ -155,6 +168,7 @@ def _build_and_push(
155168 project ,
156169 image_uri ,
157170 ar_location = "us" ,
171+ cluster_name = None ,
158172):
159173 """Build and push Docker image using Cloud Build.
160174
@@ -200,8 +214,9 @@ def _build_and_push(
200214 os .path .join (tmpdir , "requirements.txt" ), arcname = "requirements.txt"
201215 )
202216
203- # Upload source to GCS
204- bucket_name = f"{ project } -keras-remote-builds"
217+ # Upload source to GCS (cluster-scoped bucket)
218+ cluster_name = cluster_name or get_default_cluster_name ()
219+ bucket_name = f"{ project } -kr-{ cluster_name } -builds"
205220 source_gcs = _upload_build_source (tarball_path , bucket_name , project )
206221
207222 # Submit build to Cloud Build
0 commit comments