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
This tool can be used as an Operator for the bentoctl. See steps on how to add Heroku Deployment Tool as an Operator here
- Prerequisites
- Deploy to Heroku with bentoctl
- Deploy to Heroku using scripts
- Configuring the Deployment
- Deployment Command Reference
- An active Heroku account configured on the machine with AWS CLI installed and configured
- Install instruction: https://devcenter.heroku.com/articles/heroku-cli#getting-started
- Login Heroku CLI:
$heroku login
- Docker is installed and running on the machine
- Install instruction: https://docs.docker.com/install
- Built bento
- Checkout BentoML quickstart guide for how to get started
-
Install bentoctl
$ pip install bentoctl
-
Add Heroku operator
$ bentoctl operator add heroku Added heroku!
-
Deploy to Heroku use bentoctl deploy command in interactive mode
# Use the interactive mode $ bentoctl deploy Bentoctl Interactive Deployment Config Builder Welcome! You are now in interactive mode. This mode will help you setup 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 metadata: name: testdeployment operator: heroku spec: bento: testservice:vj2wrqs7egy6zn5zusy4drbc6 dyno_counts: 1 dyno_type: free deployment config generated to: deployment_config.yaml Deploying with generated deployment_config
-
Get deployment information
$ bentoctl describe my_deployment_spec.yaml
-
Make sample request
$ curl -i \ --header "Content-Type: application/json" \ --request POST \ --data '[[5.1, 3.5, 1.4, 0.2]]' \ https://btml-test-script.herokuapp.com/predict # Output HTTP/1.1 200 OK Connection: keep-alive Content-Type: application/json X-Request-Id: f499b6d0-ad9b-4d79-850a-3dc058bd67b2 Content-Length: 3 Date: Mon, 28 Jun 2021 02:50:35 GMT Server: Python/3.7 aiohttp/3.7.4.post0 Via: 1.1 vegur [0]%
-
Delete deployment with bentoctl
$ bentoctl delete deployment_spec.yaml
-
Download Heroku deployment and install the required packages
$ git clone https://github.com/bentoml/heroku-deploy.git $ cd heroku-deploy $ pip install -r requirements.txt
-
Create Heroku deployment with deployment
Run deploy script in the command line:
$ BENTO_BUNDLE_PATH=$(bentoml get IrisClassifier:latest --print-location -q) $ ./deploy $BENTO_BUNDLE_PATH test-script heroku_config.json # Output Login Heroku registry Create Heroku app btml-test-script Build Heroku app btml-test-script Deploy Heroku app btml-test-script === btml-test-script Auto Cert Mgmt: false Dynos: web: 1 Git URL: https://git.heroku.com/btml-test-script.git Owner: yubz86@gmail.com Region: us Repo Size: 0 B Slug Size: 0 B Stack: container Web URL: https://btml-test-script.herokuapp.com/
-
Get deployment information
$ ./describe test-script # Output === btml-test-script Auto Cert Mgmt: false Dynos: web: 1 Git URL: https://git.heroku.com/btml-test-script.git Owner: yubz86@gmail.com Region: us Repo Size: 0 B Slug Size: 0 B Stack: container Web URL: https://btml-test-script.herokuapp.com/
-
Make sample request against deployed service
$ curl -i \ --header "Content-Type: application/json" \ --request POST \ --data '[[5.1, 3.5, 1.4, 0.2]]' \ https://btml-test-script.herokuapp.com/predict # Output HTTP/1.1 200 OK Connection: keep-alive Content-Type: application/json X-Request-Id: f499b6d0-ad9b-4d79-850a-3dc058bd67b2 Content-Length: 3 Date: Mon, 28 Jun 2021 02:50:35 GMT Server: Python/3.7 aiohttp/3.7.4.post0 Via: 1.1 vegur [0]%
-
Delete Heroku deployment
$ ./delete test-script # Output Removing app btml-test-script
There is an optional config file available that you can use to specify the configs for your deployment, heroku_config.json. This is the list of configurations you can use to deploy your bento to Heroku. Please refer to the documenation attached to each point for more information about the options
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
Use command line
$ ./deploy <BENTO_BUNDLE_PATH> <DEPLOYMENT_NAME> <CONFIG_JSON, default is heroku_config.json>
Example:
BENTO_BUNDLE_PATH=${bentoml get IrisClassifier:latest --print-location -q)
$ ./deploy $BENTO_BUNDLE_PATH my_first_deployment heroku_config.json
Use Python API
from heroku_deploy import deploy
deploy_heroku(BENTO_BUNDLE_PATH, DEPLOYMENT_NAME, HEROKU_CONFIG)
- where
HEROKU_CONFIG
is a dictionary with keys for"dyno_counts"
and"dyno_type"
Use command line
$ ./update <Bento_bundle_path> <Deployment_name> <Config_JSON>
Use Python API
from heroku_deploy import update
update(BENTO_BUNDLE_PATH, DEPLOYMENT_NAME, HEROKU_CONFIG)
- where
HEROKU_CONFIG
is a dictionary with keys for"dyno_counts"
and"dyno_type"
Use command line
$ ./describe <DEPLOYMENT_NAME>
Use Python API
from heroku_deploy import describe
describe(DEPLOYMENT_NAME)
Use command line
$ ./delete <Deployment_name>
Use Python API
from heroku_deploy import delete
delete(DEPLOYMENT_NAME)