Demo deployment

In this document you will learn how to deploy and run your demo code on zlab's demo infrastructure.

Preparing your code

In order to deploy your demos you have to create a docker image that holds your code and it's required packages and models (weights). In order to build a docker image you need proper code structure and Dockerfile Let's say you have a very simple demo: Print Hello world!

Your main module, service.py:

from fastapi import FastAPI

app = FastAPI()


@app.get("/hello")
def say_hello():
    return {"Hello": "World"}

You have to have a requirements.txt in order to have re-usable code:

python fastapi == 0.89 .1 uvicorn == 0.20 .0

Finally you need to write a Dockerfile in our example it is a very simple one:

FROM python:slim-buster WORKDIR /api COPY ./requirements.txt ./requirements.txt RUN pip install -r requirements.txt COPY . . CMD ["uvicorn", "service:app", "--host", "0.0.0.0", "--port", "80"]

Note the very last line:

CMD ["uvicorn", "service:app", "--host", "0.0.0.0", "--port", "80"]

Your dockerfile must always have a CMD that starts the service and your service must be bound to 0.0.0.0 and port 80

Building and pushing your image

To build your image, following the deployment conventions, simply run:

docker build -t <your_favourite_temporary_name> .

Pushing your image to Harbor

Harbor is a private docker registry that holds docker images. Zlab has it's own Harbor server and it's located at zlcr.ir. Once you got your credentials from your tech lead go on and login to harbor.

Harbor home page

Choosing a tag

Visit versioning documentation and choose a proper name and tag for your docker image for example backend:1.0.0.

Copy tag command from Harbor

Copy tag command

Edit the tag command according to name of the image that you previously built and the name and tag that you chose for your demo so in this case:

docker tag <your_favourite_temporary_name> zlcr.ir/<project_name>/backend:1.0.0

and execute the command.

Now copy the push command from the same page in Harbor:

Copy push command

Edit the push command like the previous one in this case:

docker push zlcr.ir/<project_name>/backend:1.0.0

and execute the command.

Done!

Congratulations! Your image is now located at zlcr.ir/<project_name>/backend:1.0.0 you should then give this link to the devops team to deploy your demo.

Automated deployment config

Coming soon....