Skip to content

Commit 20c719f

Browse files
beneschdef-
authored andcommitted
mzbuild: push docker images in parallel
This should speed up builds substantially.
1 parent 441d45c commit 20c719f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

misc/python/materialize/mzbuild.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import json
2323
import os
2424
import re
25+
import shlex
2526
import shutil
2627
import stat
2728
import subprocess
@@ -836,10 +837,30 @@ def ensure(self) -> None:
836837
"""
837838
deps_to_build = [dep for dep in self if not dep.is_published_if_necessary()]
838839
self._prepare_batch(deps_to_build)
840+
841+
images_to_push = []
839842
for dep in deps_to_build:
840843
dep.build()
841844
if dep.publish:
842-
spawn.runv(["docker", "push", dep.spec()])
845+
images_to_push.append(dep.spec())
846+
847+
# Push all Docker images in parallel to minimize build time.
848+
pushes: list[subprocess.Popen] = []
849+
for image in images_to_push:
850+
# Piping through `cat` disables terminal control codes, and so the
851+
# interleaved progress output from multiple pushes is less hectic.
852+
# We don't use `docker push --quiet`, as that disables progress
853+
# output entirely.
854+
push = subprocess.Popen(
855+
f"docker push {shlex.quote(image)} | cat",
856+
shell=True,
857+
)
858+
pushes.append(push)
859+
860+
for push in pushes:
861+
returncode = push.wait()
862+
if returncode:
863+
raise subprocess.CalledProcessError(returncode, push.args)
843864

844865
def __iter__(self) -> Iterator[ResolvedImage]:
845866
return iter(self._dependencies.values())

0 commit comments

Comments
 (0)