Skip to content

khuyentran1401/heroku-deploy

 
 

Repository files navigation

Heroku Operator


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

Table of Contents

Prerequisites

Deploy to Heroku with bentoctl

  1. Install bentoctl

    $ pip install bentoctl
  2. Add Heroku operator

    $ bentoctl operator add heroku
    
    Added heroku!   
  3. 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
  4. Get deployment information

    $ bentoctl describe my_deployment_spec.yaml
  5. 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]%
  6. Delete deployment with bentoctl

    $ bentoctl delete deployment_spec.yaml

Deploy to Heroku using scripts

  1. 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
  2. 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/
  3. 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/
  4. 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]%
  5. Delete Heroku deployment

    $ ./delete test-script
    
    # Output
    Removing app btml-test-script

Configuring the Deployment

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 information
  • dyno_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

Deployment Command Reference

Create a Deployment

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"

Update a Deployment

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"

Get a Deployment’s Status and Information

Use command line

$ ./describe <DEPLOYMENT_NAME>

Use Python API

from heroku_deploy import describe

describe(DEPLOYMENT_NAME)

Delete a Deployment

Use command line

$ ./delete <Deployment_name>

Use Python API

from heroku_deploy import delete

delete(DEPLOYMENT_NAME)

About

Deploy BentoML bundled models to Heroku

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 60.4%
  • Python 39.6%