Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXPERIMENTAL: gRPC support #2808

Merged
merged 8 commits into from Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 19 additions & 9 deletions .devcontainer/Dockerfile
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.4-labs

FROM python:3-bullseye
FROM --platform=linux/amd64 python:3-bullseye

# [Option] Install zsh
ARG INSTALL_ZSH="true"
Expand All @@ -12,27 +12,37 @@ ARG ENABLE_NONROOT_DOCKER="true"
ARG USE_MOBY="true"
# [Option] Select CLI version
ARG CLI_VERSION="latest"

# Enable new "BUILDKIT" mode for Docker CLI
ENV DOCKER_BUILDKIT=1

ENV DEBIAN_FRONTEND=noninteractive

# Install needed packages and setup non-root user. Use a separate RUN statement to add your
# own dependencies. A user of "automatic" attempts to reuse an user ID if one already exists.
ARG USERNAME=automatic
ARG USER_UID=1000
ARG USER_GID=$USER_UID
COPY library-scripts/*.sh /tmp/library-scripts/
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
apt-get update \
&& apt-get install -y build-essential software-properties-common vim \
COPY .devcontainer/library-scripts/*.sh /tmp/library-scripts/

RUN --mount=type=cache,target=/var/lib/apt \
--mount=type=cache,target=/var/cache/apt \
apt-get update -y \
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
&& apt-get purge -y imagemagick imagemagick-6-common

# install common packages
RUN --mount=type=cache,target=/var/lib/apt \
--mount=type=cache,target=/var/cache/apt \
apt-get install -y build-essential software-properties-common vim \
&& /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \
# Use Docker script from script library to set things up
&& /bin/bash /tmp/library-scripts/docker-debian.sh "${ENABLE_NONROOT_DOCKER}" "/var/run/docker-host.sock" "/var/run/docker.sock" "${USERNAME}" "${USE_MOBY}" "${CLI_VERSION}" \
# Clean up
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts/
&& rm -rf /var/lib/apt/lists/* /tmp/library-scripts/

COPY requirements/*.txt /tmp/pip-tmp/
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --no-warn-script-location -r /tmp/pip-tmp/dev-requirements.txt -r /tmp/pip-tmp/docs-requirements.txt \
&& rm -rf /tmp/pip-tmp

# Setting the ENTRYPOINT to docker-init.sh will configure non-root access to
# the Docker socket if "overrideCommand": false is set in devcontainer.json.
Expand Down
20 changes: 9 additions & 11 deletions .devcontainer/devcontainer.json
Expand Up @@ -3,6 +3,7 @@
{
"name": "BentoML",
"dockerFile": "Dockerfile",
"context": "..",
"containerEnv": {
"BENTOML_DEBUG": "True",
"BENTOML_BUNDLE_LOCAL_BUILD": "True",
Expand All @@ -22,15 +23,16 @@
// Configure properties specific to VS Code.
"vscode": {
"extensions": [
"ms-azuretools.vscode-docker",
"ms-python.vscode-pylance",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-docker",
"ms-vsliveshare.vsliveshare",
"ms-python.black-formatter",
"ms-python.pylint",
"samuelcolvin.jinjahtml",
"GitHub.copilot",
"esbenp.prettier-vscode"
"esbenp.prettier-vscode",
"VisualStudioExptTeam.intellicode-api-usage-examples"
],
"settings": {
"files.watcherExclude": {
Expand All @@ -52,18 +54,14 @@
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.minimap.enabled": true,
"editor.minimap.enabled": false,
"editor.formatOnSave": true,
"editor.wordWrapColumn": 88,
"editor.wordWrapColumn": 88
}
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000, 8080, 9000, 9090],
// Link some default configs to codespace container.
"postCreateCommand": "bash ./.devcontainer/lifecycle/post-create",
"forwardPorts": [3000, 3001],
// install BentoML and tools
"postStartCommand": "bash ./.devcontainer/lifecycle/post-start",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
"postStartCommand": "bash ./.devcontainer/lifecycle/post-start"
}
3 changes: 0 additions & 3 deletions .devcontainer/lifecycle/post-create

This file was deleted.

14 changes: 13 additions & 1 deletion .devcontainer/lifecycle/post-start
Expand Up @@ -7,4 +7,16 @@ git config --global pull.ff only
git fetch upstream --tags && git pull

# install editable wheels & tools for bentoml
pip install --user -e ".[tracing]" --isolated
pip install -e ".[tracing,grpc]" --verbose
pip install -r requirements/dev-requirements.txt
pip install -U "grpcio-tools>=1.41.0" "mypy-protobuf>=3.3.0"
# generate stubs
OPTS=(-I. --grpc_python_out=. --python_out=. --mypy_out=. --mypy_grpc_out=.)
python -m grpc_tools.protoc "${OPTS[@]}" bentoml/grpc/v1alpha1/service.proto
python -m grpc_tools.protoc "${OPTS[@]}" bentoml/grpc/v1alpha1/service_test.proto
# uninstall broken protobuf typestubs
pip uninstall -y types-protobuf

# setup docker buildx
docker buildx install
docker buildx ls | grep bentoml-builder &>/dev/null || docker buildx create --use --name bentoml-builder --platform linux/amd64,linux/arm64 &>/dev/null
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -257,9 +257,15 @@ jobs:
path: ${{ steps.cache-dir.outputs.dir }}
key: ${{ runner.os }}-tests-${{ hashFiles('requirements/tests-requirements.txt') }}

# Simulate ./scripts/generate_grpc_stubs.sh
- name: Generate gRPC stubs
run: |
pip install protobuf==3.19.4 "grpcio-tools==1.41"
find bentoml/grpc/v1alpha1 -type f -name "*.proto" -exec python -m grpc_tools.protoc -I. --grpc_python_out=. --python_out=. "{}" \;

- name: Install dependencies
run: |
pip install -e .
pip install -e ".[grpc]"
pip install -r requirements/tests-requirements.txt
pip install -r tests/e2e/bento_server_general_features/requirements.txt

Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Expand Up @@ -114,3 +114,10 @@ typings

# test files
catboost_info

# ignore pyvenv
pyvenv.cfg

# generated stub that is included in distribution
*_pb2*.py
*_pb2*.pyi