Skip to content

Commit

Permalink
Merge pull request #27 from Maximophone/17-wrappers_update
Browse files Browse the repository at this point in the history
17 wrappers update
  • Loading branch information
ukclivecox authored Jan 12, 2018
2 parents cc16a17 + 68b86ee commit d5487ce
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
8 changes: 5 additions & 3 deletions wrappers-docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
2 changes: 1 addition & 1 deletion wrappers-docker/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IMAGE_NAME=docker.io/seldonio/core-python-wrapper
IMAGE_VERSION=0.3
IMAGE_VERSION=0.4

SELDON_CORE_DIR=..

Expand Down
44 changes: 29 additions & 15 deletions wrappers/python/wrap_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()

Expand All @@ -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)

0 comments on commit d5487ce

Please sign in to comment.