From b8dfdb60ba1ff5f285b65f4b69624070494c9ece Mon Sep 17 00:00:00 2001 From: Maxime Fournes Date: Wed, 10 Jan 2018 17:19:16 +0000 Subject: [PATCH 1/2] Added argument in python wrapper to change the name of the generated docker image, added arguments documentation. --- wrappers/python/wrap_model.py | 44 +++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/wrappers/python/wrap_model.py b/wrappers/python/wrap_model.py index 9643dd70d3..07e6bc9488 100644 --- a/wrappers/python/wrap_model.py +++ b/wrappers/python/wrap_model.py @@ -7,9 +7,22 @@ def populate_template(template,file_out,**kwargs): with open(file_out,'w') as fout: fout.write(ftmp.read().format(**kwargs)) -def wrap_model(repo,model_folder,base_image,model_name,service_type,version,REST=True,out_folder=None,force_erase=False,persistence=False): +def wrap_model( + repo, + model_folder, + base_image, + model_name, + service_type, + version, + REST=True, + out_folder=None, + force_erase=False, + persistence=False, + image_name=None): if out_folder is None: out_folder = model_folder + if image_name is None: + image_name = model_name.lower() build_folder = out_folder+'/build' if os.path.isdir(build_folder): if not force_erase: @@ -36,24 +49,24 @@ def wrap_model(repo,model_folder,base_image,model_name,service_type,version,REST './Makefile.tmp', build_folder+'/Makefile', docker_repo=repo, - docker_image_name=model_name.lower(), + docker_image_name=image_name, version=version) if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Utility script to wrap a python model into a docker build") + parser = argparse.ArgumentParser(description="Utility script to wrap a python model into a docker build. The scipt will generate build folder that contains a Makefile that can be used to build and publish a Docker Image.") - parser.add_argument("model_folder",type=str) - parser.add_argument("model_name",type=str) - parser.add_argument("version",type=str) - parser.add_argument("repo",type=str) - parser.add_argument("--grpc",action="store_true") - parser.add_argument("--out-folder",type=str,default=None) - parser.add_argument("--service-type",type=str,choices=["MODEL","ROUTER","TRANSFORMER","COMBINER","OUTLIER_DETECTOR"],default="MODEL") - - parser.add_argument("--base-image",type=str,default="python:2") - parser.add_argument("-f","--force",action="store_true") - parser.add_argument("-p","--persistence",action="store_true",help="Use redis to make the model persistent") + parser.add_argument("model_folder", type=str, help="Path to the folder that contains the model and all the files to copy in the docker image.") + parser.add_argument("model_name", type=str, help="Name of the model class and model file without the .py extension") + parser.add_argument("version", type=str, help="Version string that will be given to the model docker image") + parser.add_argument("repo", type=str, help="Name of the docker repository to publish the image on") + parser.add_argument("--grpc", action="store_true", help="When this flag is present the model will be wrapped as a GRPC microservice. By default the model is wrapped as a REST microservice.") + parser.add_argument("--out-folder", type=str, default=None, help="Path to the folder where the pre-wrapped model will be created. Defaults to a 'build' folder in the model directory.") + parser.add_argument("--service-type", type=str, choices=["MODEL","ROUTER","TRANSFORMER","COMBINER","OUTLIER_DETECTOR"], default="MODEL", help="The type of Seldon API the wrapped model will use. Defaults to MODEL.") + parser.add_argument("--base-image", type=str, default="python:2", help="The base docker image to inherit from. Defaults to python:2. Caution: this must be a debian based image.") + parser.add_argument("-f", "--force", action="store_true", help="When this flag is present the script will overwrite the contents of the output folder even if it already exists. By default the script would abort.") + parser.add_argument("-p", "--persistence", action="store_true", help="Use redis to make the model persistent") + parser.add_argument("--image-name",type=str,default=None,help="Name to give to the model's docker image. Defaults to the model name in lowercase.") args = parser.parse_args() @@ -67,4 +80,5 @@ def wrap_model(repo,model_folder,base_image,model_name,service_type,version,REST REST = not args.grpc, out_folder = args.out_folder, force_erase = args.force, - persistence = args.persistence) + persistence = args.persistence, + image_name = args.image_name) From 68b86ee5710cfdfde9253bf240a003b7fe3715ca Mon Sep 17 00:00:00 2001 From: Maxime Fournes Date: Thu, 11 Jan 2018 18:16:17 +0000 Subject: [PATCH 2/2] Simplified wrapper docker image so that the wrapping can be done in one line --- wrappers-docker/Dockerfile | 8 +++++--- wrappers-docker/Makefile | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/wrappers-docker/Dockerfile b/wrappers-docker/Dockerfile index be3fe6336e..9240ab5409 100644 --- a/wrappers-docker/Dockerfile +++ b/wrappers-docker/Dockerfile @@ -19,13 +19,15 @@ RUN \ apt-get update && \ apt-get install -y docker-ce + + RUN python -m pip install grpcio-tools==1.1.3 RUN cd /wrappers && make build_protos # deps to get tester.py to work RUN pip install numpy requests redis flask -WORKDIR /work - -CMD ["sh"] +WORKDIR /wrappers/python +ENTRYPOINT ["python","wrap_model.py"] +CMD [] \ No newline at end of file diff --git a/wrappers-docker/Makefile b/wrappers-docker/Makefile index cbb485df7b..dd32af4445 100644 --- a/wrappers-docker/Makefile +++ b/wrappers-docker/Makefile @@ -1,5 +1,5 @@ IMAGE_NAME=docker.io/seldonio/core-python-wrapper -IMAGE_VERSION=0.3 +IMAGE_VERSION=0.4 SELDON_CORE_DIR=..