@@ -51,10 +51,11 @@ def main(
51
51
env : str ,
52
52
all_pipelines : bool = False ,
53
53
skip_builds : bool = False ,
54
+ async_builds : bool = False ,
54
55
format_code : bool = True ,
55
56
):
56
57
if not skip_builds :
57
- build_images (dataset_id , env )
58
+ build_images (dataset_id , env , async_builds )
58
59
59
60
if all_pipelines :
60
61
for pipeline_dir in list_subdirs (DATASETS_PATH / dataset_id / "pipelines" ):
@@ -229,7 +230,7 @@ def copy_files_to_dot_dir(dataset_id: str, pipeline_id: str, env_dir: pathlib.Pa
229
230
)
230
231
231
232
232
- def build_images (dataset_id : str , env : str ):
233
+ def build_images (dataset_id : str , env : str , async_builds : bool ):
233
234
parent_dir = DATASETS_PATH / dataset_id / "pipelines" / "_images"
234
235
if not parent_dir .exists ():
235
236
return
@@ -238,7 +239,7 @@ def build_images(dataset_id: str, env: str):
238
239
dataset_id , parent_dir , PROJECT_ROOT / f".{ env } "
239
240
)
240
241
for image_dir in image_dirs :
241
- build_and_push_image (dataset_id , image_dir )
242
+ build_and_push_image (dataset_id , image_dir , async_builds )
242
243
243
244
244
245
def copy_image_files_to_dot_dir (
@@ -253,24 +254,27 @@ def copy_image_files_to_dot_dir(
253
254
return list_subdirs (target_dir / "_images" )
254
255
255
256
256
- def build_and_push_image (dataset_id : str , image_dir : pathlib .Path ):
257
+ def build_and_push_image (
258
+ dataset_id : str , image_dir : pathlib .Path , async_builds : bool = False
259
+ ):
257
260
image_name = f"{ dataset_id } __{ image_dir .name } "
258
- tag = f"gcr.io/{ gcp_project_id ()} /{ image_name } "
261
+ command = [
262
+ "gcloud" ,
263
+ "builds" ,
264
+ "submit" ,
265
+ "--async" ,
266
+ "--tag" ,
267
+ f"gcr.io/{ gcp_project_id ()} /{ image_name } " ,
268
+ ]
269
+
270
+ if not async_builds :
271
+ command .remove ("--async" )
259
272
260
273
# gcloud builds submit --tag gcr.io/PROJECT_ID/IMAGE_NAME
261
- subprocess .check_call (
262
- [
263
- "gcloud" ,
264
- "builds" ,
265
- "submit" ,
266
- "--tag" ,
267
- str (tag ),
268
- ],
269
- cwd = image_dir ,
270
- )
274
+ subprocess .check_call (command , cwd = image_dir )
271
275
272
276
273
- def gcp_project_id (project_id : str = None ) -> str :
277
+ def gcp_project_id () -> str :
274
278
_ , project_id = google .auth .default ()
275
279
return project_id
276
280
@@ -308,6 +312,16 @@ def gcp_project_id(project_id: str = None) -> str:
308
312
parser .add_argument (
309
313
"--skip-builds" , required = False , dest = "skip_builds" , action = "store_true"
310
314
)
315
+ parser .add_argument (
316
+ "--async-builds" , required = False , dest = "async_builds" , action = "store_false"
317
+ )
311
318
312
319
args = parser .parse_args ()
313
- main (args .dataset , args .pipeline , args .env , args .all_pipelines , args .skip_builds )
320
+ main (
321
+ args .dataset ,
322
+ args .pipeline ,
323
+ args .env ,
324
+ args .all_pipelines ,
325
+ args .skip_builds ,
326
+ args .async_builds ,
327
+ )
0 commit comments