Plese see the latest BentoML documentation on OCI-container based deployment workflow: https://docs.bentoml.com/
Heroku is a popular platform as a service(PaaS) based on managed container system. It provides a complete solution for building, running, and scaling applications With the combination of BentoML and bentoctl, you can deploy the models built with your favourite ML frameworks easily and manage the infrastructure via terraform.
Note: This operator is compatible with BentoML version 1.0.0 and above. For older versions, please switch to the branch
pre-v1.0
and follow the instructions in the README.md.
This quickstart will walk you through deploying a bento into Heroku. Make sure to go through the prerequisites section and follow the instructions to set everything up.
- Heroku CLI - Make sure that Heroku CLI is installed and you are logged in with an existing heroku account. Installation instructions
- Terraform - Terraform is a tool for building, configuring, and managing infrastructure. Installation instructions: www.terraform.io/downloads
- Docker - Install instructions: https://docs.docker.com/install
- A working bento - for this guide, we will use the iris-classifier bento from the BentoML quickstart guide or import a prebuilt bento from S3
-
Install bentoctl
$ pip install bentoctl
-
Install the operator
Bentoctl will install the official Heroku operator and its dependencies. The Operator contains the Terraform templates and sets up the registries reqired to deploy to GCP.
bentoctl operator install heroku
-
Initialize deployment with bentoctl
Follow the interactive guide to initialize the deployment project.
$ bentoctl init Bentoctl Interactive Deployment Config Builder Welcome! You are now in interactive mode. This mode will help you set up the deployment_config.yaml file required for deployment. Fill out the appropriate values for the fields. (deployment config will be saved to: ./deployment_config.yaml) api_version: v1 name: quickstart operator: heroku template: terraform spec: dyno_counts: 1 dyno_type: free filename for deployment_config [deployment_config.yaml]: deployment config generated to: deployment_config.yaml ✨ generated template files. - ./main.tf - ./bentoctl.tfvars
Note: the
name
attribute for the deployment config will be the same name the name for the heroku app that will be generated. If the a heroku app with the same name exists bentoctl will throw an error at the next step so you might have to change it.This will also run the
bentoctl generate
command for you and will generate themain.tf
terraform file, which specifies the resources to be created and thebentoctl.tfvars
file which contains the values for the variables used in themain.tf
file. -
Build and push docker image into Heroku registry.
bentoctl build -b iris_classifier:latest -f deployment_config.yaml
The iris-classifier service is now built and pushed into the container registry and the required terraform files have been created. Now we can use terraform to perform the deployment. The heroku app will also be created in this step an as noted above will throw an error if the app_name already exists. Please change the name in the deploymetn_config.yaml file and run the
bentoctl generate
andbentoctl build
command again. -
Apply Deployment with Terraform
-
Initialize terraform project. This installs the providers and sets up the terraform folders.
terraform init
-
Apply terraform project to create heroku deployment
terraform apply -var-file=bentoctl.tfvars -auto-approve
-
-
Test deployed endpoint
The
iris_classifier
uses the/classify
endpoint for receiving requests so the full URL for the classifier will be in the form{EndpointUrl}/classify
.URL=$(terraform output -json | jq -r .app_url.value)/classify curl -i \ --header "Content-Type: application/json" \ --request POST \ --data '[5.1, 3.5, 1.4, 0.2]' \ $URL
-
Delete deployment Use the
bentoctl destroy
command to remove the registry and the deploymentbentoctl destroy -f deployment_config.yaml
This is the list of configurations you can use to deploy your bento to Heroku. For more information about options check the corresponding Heroku docs provided.
dyno_counts
: Number of dynos running for the deployment. A dyno is an isolated, virtualized Linux container that is designed to execute your code. Check the docs, and article for more informationdyno_type
: Dyno (instance) type. Each dyno type provides a certain number of RAM, CPU share, Compute, and wheter it sleeps. Check the docs for more information