Skip to content

Commit

Permalink
adding a object_detection_client workflow file
Browse files Browse the repository at this point in the history
Signed-off-by: greg pereira <[email protected]>
  • Loading branch information
Gregory-Pereira committed May 2, 2024
1 parent 958fdfa commit e4413ad
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 74 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/model_servers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ jobs:
strategy:
matrix:
include:
# - image_name: llamacpp_python
# model: granite
# flavor: base
# directory: llamacpp_python
# platforms: linux/amd64,linux/arm64
# no_gpu: 1
# - image_name: llamacpp_python_cuda
# model: granite
# flavor: cuda
# directory: llamacpp_python
# platforms: linux/amd64
# cuda: 1
# - image_name: whispercpp
# model: whisper-small
# flavor: base
# directory: whispercpp
# platforms: linux/amd64,linux/arm64
# no_gpu: 1
- image_name: llamacpp_python
model: granite
flavor: base
directory: llamacpp_python
platforms: linux/amd64,linux/arm64
no_gpu: 1
- image_name: llamacpp_python_cuda
model: granite
flavor: cuda
directory: llamacpp_python
platforms: linux/amd64
cuda: 1
- image_name: whispercpp
model: whisper-small
flavor: base
directory: whispercpp
platforms: linux/amd64,linux/arm64
no_gpu: 1
- image_name: object_detection_python
model: facebook-detr-resnet-101
flavor: base
Expand Down
89 changes: 89 additions & 0 deletions .github/workflows/object_detection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Object Detection

on:
pull_request:
branches:
- main
paths:
- ./recipes/computer_vision/object_detection/**
- .github/workflows/object_detection.yaml
push:
branches:
- main
paths:
- ./recipes/computer_vision/object_detection/**
- .github/workflows/object_detection.yaml

workflow_dispatch:

env:
REGISTRY: ghcr.io
REGISTRY_ORG: containers
RECIPE_NAME: object_detection
RECIPE_TYPE: computer_vision
IMAGE_NAME: object_detection_client

jobs:
chatbot-build-and-push:
if: "!contains(github.event.pull_request.labels.*.name, 'hold-tests')"
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
services:
registry:
image: registry:2.8.3
ports:
- 5000:5000
steps:
- uses: actions/[email protected]

- name: Install qemu dependency
run: |
sudo apt-get update
sudo apt-get install -y qemu-user-static
- name: Build Image
id: build_image
uses: redhat-actions/[email protected]
with:
image: ${{ env.REGISTRY }}/${{ env.REGISTRY_ORG }}/${{ env.IMAGE_NAME }}
tags: latest
platforms: linux/amd64,linux/arm64
containerfiles: ./recipes/${{ env.RECIPE_TYPE }}/${{ env.RECIPE_NAME }}/app/Containerfile
context: recipes/${{ env.RECIPE_TYPE }}/${{ env.RECIPE_NAME }}/app

- name: Set up Python
uses: actions/[email protected]
with:
python-version: '3.11'

- name: Install Dependencies
working-directory: ./recipes/${{ env.RECIPE_TYPE }}/${{ env.RECIPE_NAME }}
run: make install

- name: Download model
working-directory: ./models
run: make download-model-facebook-detr-resnet-101

- name: Run Functional Tests
shell: bash
run: make functional-tests
working-directory: ./recipes/${{ env.RECIPE_TYPE }}/${{ env.RECIPE_NAME }}

- name: Login to Registry
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: redhat-actions/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push Image
id: push_image
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: redhat-actions/[email protected]
with:
image: ${{ steps.build_image.outputs.image }}
tags: ${{ steps.build_image.outputs.tags }}
registry: ${{ env.REGISTRY }}
1 change: 1 addition & 0 deletions model_servers/object_detection_python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
IMAGE_NAME = os.getenv("IMAGE_NAME", "containers/object_detection_python:latest")
MODEL_NAME = os.getenv("MODEL_NAME", "facebook/detr-resnet-101")
MODELS_DIR = os.getenv("MODELS_DIR", "/app/models")

MODEL_PATH = f"{MODELS_DIR}/{MODEL_NAME}"

PORT = os.getenv("PORT", 8000)
Expand Down
15 changes: 15 additions & 0 deletions recipes/computer_vision/object_detection/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SHELL := /bin/bash
APP ?= object_detection_client
PORT ?= 8501
MODEL_NAME ?= facebook/detr-resnet-101

include ../../common/Makefile.common

.PHONY: functional-tests
functional-tests:
IMAGE_NAME=${IMAGE_NAME} REGISTRY=${REGISTRY} MODEL_NAME=${MODEL_NAME} pytest -vvv --driver=Chrome --driver-path=$(RECIPE_BINARIES_PATH)/chromedriver ${RELATIVE_TESTS_PATH}/functional

RECIPE_BINARIES_PATH := $(shell realpath ../../common/bin)
RELATIVE_MODELS_PATH := ../../../models
RELATIVE_TESTS_PATH := ../tests

54 changes: 0 additions & 54 deletions recipes/computer_vision/object_detection/tests/conftest.py

This file was deleted.

8 changes: 8 additions & 0 deletions recipes/computer_vision/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pytest
import os


@pytest.fixture
def chrome_options(chrome_options):
chrome_options.add_argument("--headless")
return chrome_options
58 changes: 58 additions & 0 deletions recipes/computer_vision/tests/functional/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import pytest_container
import os
import logging

REGISTRY=os.environ['REGISTRY']
IMAGE_NAME=os.environ['IMAGE_NAME']
MODEL_NAME=os.environ['MODEL_NAME']

logging.info("""
Starting pytest with the following ENV vars:
REGISTRY: {REGISTRY}
IMAGE_NAME: {IMAGE_NAME}
MODEL_NAME: {MODEL_NAME}
For:
model_server: whispercpp
""".format(REGISTRY=REGISTRY, IMAGE_NAME=IMAGE_NAME, MODEL_NAME=MODEL_NAME))


MS = pytest_container.Container(
url=f"containers-storage:{REGISTRY}/{IMAGE_NAME}",
volume_mounts=[
pytest_container.container.BindMount(
container_path=f"/locallm/models/${MODEL_NAME}",
host_path=f"./{MODEL_NAME}",
flags=["ro"]
)
],
extra_environment_variables={
"MODEL_PATH": f"/locall/models/{MODEL_NAME}",
"HOST": "0.0.0.0",
"PORT": "8001"
},
forwarded_ports=[
pytest_container.PortForwarding(
container_port=8001,
host_port=8001
)
],
)

CB = pytest_container.Container(
url=f"containers-storage:{os.environ['REGISTRY']}/containers/{os.environ['IMAGE_NAME']}",
extra_environment_variables={
"MODEL_ENDPOINT": "http://10.88.0.1:8001"
},
forwarded_ports=[
pytest_container.PortForwarding(
container_port=8501,
host_port=8501
)
],
)

def pytest_generate_tests(metafunc):
pytest_container.auto_container_parametrize(metafunc)

def pytest_addoption(parser):
pytest_container.add_logging_level_options(parser)
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import pytest_container
from .conftest import MS
from .conftest import CB
import tenacity

CONTAINER_IMAGES = [MS]
CONTAINER_IMAGES = [CB]

def test_etc_os_release_present(auto_container: pytest_container.container.ContainerData):
assert auto_container.connection.file("/etc/os-release").exists

@tenacity.retry(stop=tenacity.stop_after_attempt(5), wait=tenacity.wait_exponential())
def test_alive(auto_container: pytest_container.container.ContainerData, host):
host.run_expect([0],f"curl http://localhost:{auto_container.forwarded_ports[0].host_port}",).stdout.strip()

def test_title(auto_container: pytest_container.container.ContainerData, selenium):
selenium.get(f"http://localhost:{auto_container.forwarded_ports[0].host_port}")
assert selenium.title == "Streamlit"

Empty file.
7 changes: 7 additions & 0 deletions recipes/computer_vision/tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os
import pytest


@pytest.fixture()
def url():
return os.environ["URL"]
3 changes: 3 additions & 0 deletions recipes/computer_vision/tests/integration/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def test_title(url,selenium):
selenium.get(f"http://{url}:8501")
assert selenium.title == "Streamlit"

0 comments on commit e4413ad

Please sign in to comment.