GitHub Actions#
GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create various workflows to accelerate and simplify the BentoML workflow by automating important operations, such as building and deploying Bentos.
Set up BentoML#
You can create a GitHub Action to bootstrap BentoML and any necessary supporting tools to run BentoML in a CI process.
To use it, define a workflow file as below:
name: ci
on:
push:
branches:
- 'main'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: bentoml/setup-bentoml-action@v1
with:
python-version: '3.10'
bentoml-version: 'main'
Once triggered, this workflow sets up BentoML in an Ubuntu environment, ensuring that it’s using Python 3.10 and the main
branch version of BentoML.
For more information, see the setup-bentoml-action repository.
Deploy Bentos to the cloud#
You can create a GitHub Actions workflow to automate the process of building Bentos and deploying them to the cloud.
To use it, define a workflow file as below:
name: Deploy Bento
on:
push:
tags:
- v*
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
- name: Build and Deploy
uses: bentoml/deploy-bento-action@main
with:
deployment_name: test-iris
cloud_api_token: ${{ secrets.CLOUD_API_TOKEN }}
cloud_endpoint: ${{ secrets.CLOUD_ENDPOINT }}
The workflow bentoml/deploy-bento-action requires cloud_api_token
and cloud_endpoint
. You can set the repository secrets to make sure the job has correct privilege.
See also
You can get more details about this file in Deploying Your Bento and the GitHub Actions documentation.
With this workflow, every time you push changes to the repository, a new Bento will be built and rolled out to the existing deployment.
Read the usage and available input parameters of this workflow in the deploy-bento-action GitHub repository.
Build Bentos from a GitHub repository#
You can create a GitHub Action workflow to automate the process of building Bentos either from a GitHub repository or from a specified context path.
To use it, define a workflow file as below:
name: ci
on:
push:
branches:
- 'main'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: bentoml/setup-bentoml-action@v1
with:
python-version: '3.10'
bentoml-version: 'main'
- uses: bentoml/build-bento-action@v1
id: bento
- run: |
echo "Bento tag: ${{ steps.bento.outputs.bento-tag }}"
echo "Bento name: ${{ steps.bento.outputs.bento-name }}"
echo "Bento version: ${{ steps.bento.outputs.bento-version }}"
echo "Bento metadata: ${{ steps.bento.outputs.bento-metadata }}"
This workflow first uses the BentoML setup workflow to prepare the necessary environment and
then builds the Bento using the default GitHub context. To specify a different context, set the context
path:
- uses: bentoml/build-bento-action@v1
with:
context: 'path/to/context'
To specify a version, use the version
field:
- uses: bentoml/build-bento-action@v1
with:
version: '1.0.0'
To specify a different bentofile.yaml
file, use the bentofile
field:
- uses: bentoml/build-bento-action@v1
with:
bentofile: 'path/to/bentofile'
Note
bentofile
must be a path relative to the context
directory.
For more information, see the build-bento-action repository.
Create and push Bento images to a container registry#
You can create a GitHub Actions workflow to create and push Bento images to any container registry (Docker Hub, GHCR, ECR, GCR, etc.). This workflow uses Docker Buildx, which offers extended capabilities for building containers and is enhanced by the Moby BuildKit builder toolkit.
To use it, define a workflow file as below:
name: ci
on:
push:
branches:
- 'main'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: bentoml/setup-bentoml-action@v1
with:
python-version: '3.10'
bentoml-version: 'main'
cache: 'pip'
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: bentoml/build-bento-action@v1
id: bento
- name: Build and push BentoContainer
uses: bentoml/containerize-push-action@v1
with:
bento-tag: ${{ steps.bento.outputs.bento-tag }}
push: true
tags: user/app:latest
In this example, the workflow first uses the BentoML setup workflow to prepare the necessary environment. It then sets up Docker QEMU and Docker Buildx, and configures Docker Hub authentication. Lastly, it builds a Bento, creates a Docker image, and pushes it to Docker Hub.
Note
The workflow is essentially an adaptation of Docker’s build-push-action,
specifically tailored for implementing Bento containerization. You can also use docker/login-action@v2
to log in to other container registries
supported by that action. Refer to the login action for more information.