ray/ci/travis/build-multinode-image.py
Kai Fricke a3442df584
[ci/multinode] Build multinode image with OpenSSH before running tests (#21544)
Currently we install OpenSSH on the fly in fake multinode docker testing. Instead we can speed testing up a fair bit by building a Docker image which includes OpenSSH first and then run tests with this image.
2022-01-13 08:47:04 -08:00

35 lines
1,005 B
Python

import argparse
import os
import shutil
import subprocess
import tempfile
def build_multinode_image(source_image: str, target_image: str):
"""Build docker image from source_image.
This docker image will contain packages needed for the fake multinode
docker cluster to work.
"""
tempdir = tempfile.mkdtemp()
dockerfile = os.path.join(tempdir, "Dockerfile")
with open(dockerfile, "wt") as f:
f.write(f"FROM {source_image}\n")
f.write("RUN sudo apt update\n")
f.write("RUN sudo apt install -y openssh-server\n")
f.write("RUN sudo service ssh start\n")
subprocess.check_output(
f"docker build -t {target_image} .", shell=True, cwd=tempdir)
shutil.rmtree(tempdir)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("source_image", type=str)
parser.add_argument("target_image", type=str)
args = parser.parse_args()
build_multinode_image(args.source_image, args.target_image)