build-multinode-image.py 962 B

1234567891011121314151617181920212223242526272829303132333435
  1. import argparse
  2. import os
  3. import shutil
  4. import subprocess
  5. import tempfile
  6. def build_multinode_image(source_image: str, target_image: str):
  7. """Build docker image from source_image.
  8. This docker image will contain packages needed for the fake multinode
  9. docker cluster to work.
  10. """
  11. tempdir = tempfile.mkdtemp()
  12. dockerfile = os.path.join(tempdir, "Dockerfile")
  13. with open(dockerfile, "wt") as f:
  14. f.write(f"FROM {source_image}\n")
  15. f.write("RUN sudo apt update\n")
  16. f.write("RUN sudo apt install -y openssh-server\n")
  17. subprocess.check_output(
  18. f"docker build -t {target_image} .", shell=True, cwd=tempdir
  19. )
  20. shutil.rmtree(tempdir)
  21. if __name__ == "__main__":
  22. parser = argparse.ArgumentParser()
  23. parser.add_argument("source_image", type=str)
  24. parser.add_argument("target_image", type=str)
  25. args = parser.parse_args()
  26. build_multinode_image(args.source_image, args.target_image)