This message was deleted.
# ask-for-help
s
This message was deleted.
j
Hi. This https://github.com/bentoml/yatai-image-builder could be what you are looking for?
g
Thanks @Jiang for responding I am not using yatai as I am trying to use bentoml in vertex ai end point, so building container image using
bentoml containerize
in order to use that to deploy a custom container. yatai-image-builder would require Kubernetes environment based on my understanding
j
I see. This error is common when you don't have docker installed or the permission to call docker build.
Let me take a look on the cloud builder
πŸ‘ 1
a
Do you have Docker setup?
I believe vertex ai might using kaniko instead of yatai. It might be good to support kaniko with containerize πŸ€”
g
hmm still no luck, I would agree it would be great if bentoml support kaniko for containerize, but I would like to find a solution that is doable as of now Looking at this I would assume that docker is supported, but still didn't figure our the right way to successfully run bentoml containerize using cloud build https://cloud.google.com/build/docs/interacting-with-dockerhub-images
j
Yeah, Ic. It seems that the key is to make docker available in the cloud builder.
gcr.io/cloud-builders/docker we are using this?
@Aaron Pham any idea?
ah ic
g
I tried to run the command using this as a base image but it failed as bentoml is not recognised and pip is not available to install it for trial sake, I'll try creating another image based on this and install all the required libraries and try with that if it works
j
Yeah. I went to a wrong direction. It is just because you are trying to run bentoml containerize in the image
xxx_bentoml
That image should be maintained by your team right? And bentoml containerize requires docker as a dependency.
Thus a base image that having both docker and bentoml installed is required.
@Ghawady Ehmaid Hi I was out of office last hour. I'd like to provide more detailed suggestions if you need.
g
Yes please I would appreciate it
That image should be maintained by your team right?
Yes
bentoml containerize requires docker as a dependency
I understand that, but still didn't find a proper way of how to build an image with docker, so far my attempt to modify the docker file to have all dependencies just fail with errors
j
I'm trying to draw a graph for the recommended workflow. It may take a while
πŸ‘ 1
BentoML didn't officially provide an official image builder image.
You can build your own. The idea is use a cloud builder image as the base image, and then install python, pip and bentoml. Then you can use that image to run bentoml containerize
bentoml containerize
is independent to your project's dependencies, thus this image builder image is reusable and do not need those project dependencies.
g
Makes sense that's exactly what I was trying to do in last hour but getting errors when trying to install pip
j
getting errors when trying to install pip
Any details? It might due to Google is using distroless in their cloud builder
g
This is the dockerfile content
Copy code
# Create image that is used to run bentoml build
FROM <http://gcr.io/cloud-builders/docker|gcr.io/cloud-builders/docker>

ARG HOME=/home

RUN apt-get update 
RUN apt-get install -y python3-dev
RUN apt-get install -y python3
RUN apt-get install -y wget git
RUN python3 --version
RUN apt-get install -y python3-pip
RUN apt-get clean

RUN pip install bentoml

# Set home directory
WORKDIR ${HOME}
But getting an error at
python3-pip
on executing docker build
j
Oh it looks like this is an issue related to Ubuntu. For this problem, we are on the same page and we need to do some searching.
At first we should use https sources I think
g
Ok good to know this the approach you suggested an we are on the same page with the direction
j
I noticed a hash mismatch, and it is possible that there has been a man-in-the-middle attack.
πŸ€” 1
You may consider adding some commands to first modify the source list in the apt configuration to use https addresses.
g
hmm strangely with retrying the hash mismatch didn't come up, but the error keep changing I attached the full output of two
docker build
command runs... In the meantime I am googling to know how to modify the source list in the apt configuration, if you have an easily shareable example that would handy
j
Personally I still suggest to change to https first. I saw it is still using http:
Copy code
#0 1.772 Get:1 <http://archive.ubuntu.com/ubuntu> focal/main amd64 liblocale-gettext-perl amd64 1.07-4 [17.1 kB]
#0 2.556 Get:2 <http://archive.ubuntu.com/ubuntu> focal-updates/main amd64 binutils-common amd64 2.34-6ubuntu1.4 [207 kB]
#0 4.122 Get:3 <http://archive.ubuntu.com/ubuntu> focal-updates/main amd64 libbinutils amd64 2.34-6ubuntu1.4 [474 kB]
An answer from chatgpt:
Copy code
FROM <http://gcr.io/cloud-builders/docker|gcr.io/cloud-builders/docker>

RUN sed -i 's/http:/https:/g' /etc/apt/sources.list
g
oh I totally forgot about consulting chatgpt! trying this now
j
I'm not familiar with GCP's tools, but I know in AWS's CodeBuild, you have to run your build job in
Privileged
mode if you're going to do Docker-in-Docker (as in, building a Docker image inside CodeBuild's Docker container). That way it has access to the Docker runtime inside the build container.
🍻 1
g
Finally managed to make it work πŸŽ‰. Below are the steps in case someone else needed to do the same: 1- Create following
Dockerfile
Copy code
# Create image that is used to run bentoml containerize
FROM docker:20.10.24 as static-docker-source

FROM python:3.9
COPY --from=static-docker-source /usr/local/bin/docker /usr/local/bin/docker
ARG HOME=/home

RUN sed -i 's/http:/https:/g' /etc/apt/sources.list

RUN pip install bentoml

# Set home directory
WORKDIR ${HOME}
2- run
docker build -t <http://gcr.io/project-id/bentoml_builder|gcr.io/project-id/bentoml_builder> -f bentobuilder.Dockerfile .
&
docker push <http://gcr.io/autograb-dev/bentoml_builder|gcr.io/autograb-dev/bentoml_builder>
to build the image and push it to google container registry 3- Create following
cloudbuild.yaml
Copy code
steps:
# Build bentoml
- name: '<http://gcr.io/project-id/poc_bentoml:latest|gcr.io/project-id/poc_bentoml:latest>'
  script: |
    python import_model.py --mlflow_run_id=${_MLFLOW_RUN_ID} --mlflow_model_uri=${_MLFLOW_MODEL_URI}
    echo running bentoml build
    bentoml build
    bentoml list
  env:
  - 'MLFLOW_TRACKING_URI=${_MLFLOW_TRACKING_URI}'
  - '_MLFLOW_RUN_ID=${_MLFLOW_RUN_ID}'
  - '_MLFLOW_MODEL_URI=${_MLFLOW_MODEL_URI}'
# Containerize bentoml
- name: '<http://gcr.io/project-id/bentoml_builder|gcr.io/project-id/bentoml_builder>'
  script: |
    echo running bentoml containerize ${_BENTO_SERVICE} -t <http://gcr.io/$PROJECT_ID/${_BENTO_SERVICE}|gcr.io/$PROJECT_ID/${_BENTO_SERVICE}>
    bentoml containerize ${_BENTO_SERVICE} -t <http://gcr.io/$PROJECT_ID/${_BENTO_SERVICE}|gcr.io/$PROJECT_ID/${_BENTO_SERVICE}>
  env:
  - 'PROJECT_ID=$PROJECT_ID'
  - '_BENTO_SERVICE=${_BENTO_SERVICE}'
# Push image to container registry
- name: '<http://gcr.io/cloud-builders/docker|gcr.io/cloud-builders/docker>'
  args: ['push', '<http://gcr.io/$PROJECT_ID/${_BENTO_SERVICE}|gcr.io/$PROJECT_ID/${_BENTO_SERVICE}>']
substitutions:  # default values
    _BENTO_SERVICE: "poc_service:latest"
    _MLFLOW_TRACKING_URI: "xxx"
    _MLFLOW_RUN_ID: "xxx"
    _MLFLOW_MODEL_URI: "xxx"
images:
- <http://gcr.io/$PROJECT_ID/${_BENTO_SERVICE}|gcr.io/$PROJECT_ID/${_BENTO_SERVICE}>
options:
    dynamic_substitutions: true
    logging: CLOUD_LOGGING_ONLY
4- Now it is possible to trigger the build by running
gcloud beta builds submit --project=project-id --config=cloudbuild.yaml --substitutions=_MLFLOW_TRACKING_URI="xxx",_BENTO_SERVICE="xxx",_MLFLOW_RUN_ID="xxx",_MLFLOW_MODEL_URI="xxx"
Note: The first step in the cloudbuild script is using an imaged built to conclude the required files to run
bentoml build
command such as
bentofile.yaml
,
service.py
, and other code required to create the bento service. Second and third steps would be common for any bento deployment. It would be great if there is a better way to do step 1 without having to bake a new image with the source code for every service.
πŸŽ‰ 1