Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Scaffolder committed Jan 24, 2025
0 parents commit ebc395d
Show file tree
Hide file tree
Showing 19 changed files with 386 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Trigger PipelineRun on Push

on:
workflow_dispatch:
inputs:
pr_url:
description: 'The PR URL that need to be merged to trigger the pipelinerun'
required: true
jobs:
automerge:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
repository-projects: write
steps:
- name: Enable Automerge
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.inputs.pr_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 22 additions & 0 deletions .tekton/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# docker-build-ai-rhdh

## Shared Git resolver model for shared pipeline and tasks

This pipeline is used to create Containerfile based SSCS (Software Supply Chain Security) builds. The pipeline run by this runner clones the source, builds an image with SBOM (Software Bill of Materials), attests, and pushes these to the users image registry.

Tasks references come from this [repository](https://github.com/redhat-ai-dev/rhdh-pipelines) `pac/pipelines` and the tasks are defined in `pac/tasks`. The tasks are referenced by URL using the git resolver in tekton.

When the pipelines in this repository are updated, all future runs in existing pipelines are shared.

A developer can override these tasks with a local copy and updated annotations.

Example

To override the git-clone task, you may simply copy the git reference into your .tekton directory and then reference it from the remote task annotation.

`pipelinesascode.tekton.dev/task-0: ".tekton/git-clone.yaml"`

## Templates
These pipelines are in template format. The references to this repository in the PaC template is `{{values.rawUrl}}` which is updated to point to this repo or the fork of this repo.

The intent of the template is to fork this repository and update its use in the Developer Hub templates directory.
52 changes: 52 additions & 0 deletions .tekton/docker-pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: 'test-2-resnet-on-pull-request'
annotations:
pipelinesascode.tekton.dev/on-event: "[pull_request]"
pipelinesascode.tekton.dev/on-target-branch: "[main]"
pipelinesascode.tekton.dev/max-keep-runs: "2"
pipelinesascode.tekton.dev/pipeline: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/pipelines/docker-build-ai-rhdh-pull-request.yaml"
pipelinesascode.tekton.dev/task-0: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/tasks/init.yaml"
pipelinesascode.tekton.dev/task-1: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/tasks/git-clone.yaml"
pipelinesascode.tekton.dev/task-2: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/tasks/buildah-ai-rhdh.yaml"
pipelinesascode.tekton.dev/task-3: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/tasks/show-sbom-rhdh.yaml"
pipelinesascode.tekton.dev/task-4: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/tasks/summary.yaml"
labels:
argocd/app-name: test-2-resnet
janus-idp.io/tekton: test-2-resnet
backstage.io/kubernetes-id: test-2-resnet
backstage.io/kubernetes-namespace: rhdh-app
app.kubernetes.io/part-of: test-2-resnet
spec:
params:
- name: dockerfile
value: 'Containerfile'
- name: git-url
value: '{{repo_url}}'
- name: image-expires-after
value: 5d
- name: output-image
value: 'quay.io/jdubrick-ai/test-2-resnet:on-pr-{{revision}}'
- name: path-context
value: '.'
- name: revision
value: '{{revision}}'
- name: event-type
value: '{{event_type}}'
- name: gitops-auth-secret-name
value: 'gitops-auth-secret'
pipelineRef:
name: docker-build-ai-rhdh-pull-request
workspaces:
- name: git-auth
secret:
secretName: "{{ git_auth_secret }}"
- name: workspace
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
54 changes: 54 additions & 0 deletions .tekton/docker-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: 'test-2-resnet-on-push'
annotations:
pipelinesascode.tekton.dev/on-event: "[push]"
pipelinesascode.tekton.dev/on-target-branch: "[main]"
pipelinesascode.tekton.dev/max-keep-runs: "2"
pipelinesascode.tekton.dev/pipeline: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/pipelines/docker-build-ai-rhdh-push-gitops.yaml"
pipelinesascode.tekton.dev/task-0: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/tasks/init.yaml"
pipelinesascode.tekton.dev/task-1: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/tasks/git-clone.yaml"
pipelinesascode.tekton.dev/task-2: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/tasks/buildah-ai-rhdh.yaml"
pipelinesascode.tekton.dev/task-3: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/tasks/update-deployment-gitops.yaml"
pipelinesascode.tekton.dev/task-4: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/tasks/show-sbom-rhdh.yaml"
pipelinesascode.tekton.dev/task-5: "https://raw.githubusercontent.com/redhat-ai-dev/rhdh-pipelines/main/pac/tasks/summary.yaml"
labels:
argocd/app-name: test-2-resnet
janus-idp.io/tekton: test-2-resnet
backstage.io/kubernetes-id: test-2-resnet
backstage.io/kubernetes-namespace: rhdh-app
app.kubernetes.io/part-of: test-2-resnet
spec:
params:
- name: dockerfile
value: 'Containerfile'
- name: git-url
value: '{{repo_url}}'
- name: image-expires-after
value: 5d
- name: output-image
value: 'quay.io/jdubrick-ai/test-2-resnet:{{revision}}'
- name: path-context
value: '.'
- name: revision
value: '{{revision}}'
- name: gitops-auth-secret-name
value: 'gitops-auth-secret'
pipelineRef:
name: docker-build-ai-rhdh-push-gitops
workspaces:
- name: git-auth
secret:
secretName: "{{ git_auth_secret }}"
- name: gitops-auth
secret:
secretName: $(params.gitops-auth-secret-name)
- name: workspace
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
8 changes: 8 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM registry.access.redhat.com/ubi9/python-311:1-77.1726664316
WORKDIR /locallm
COPY requirements.txt /locallm/requirements.txt
RUN pip install --upgrade pip && \
pip install --no-cache-dir --upgrade -r requirements.txt
COPY object_detection_client.py object_detection_client.py
EXPOSE 8501
ENTRYPOINT [ "streamlit", "run", "object_detection_client.py" ]
23 changes: 23 additions & 0 deletions catalog-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: test-2-resnet
description: Secure Supply Chain Example for Object Detection Application
links:
- url: https://www.redhat.com/en/solutions/trusted-software-supply-chain
title: Trusted Secure Supply Chain
icon: dashboard
type: admin-dashboard
annotations:
# ArgoCD apps from this template used rhtap-gitops as the grouping
argocd/app-selector: rhtap/gitops=test-2-resnet
janus-idp.io/tekton: test-2-resnet
backstage.io/kubernetes-id: test-2-resnet
backstage.io/techdocs-ref: dir:.
quay.io/repository-slug: jdubrick-ai/test-2-resnet
tags: ["ai", "detr", "python"]
spec:
type: service
owner: user:guest
lifecycle: experimental

15 changes: 15 additions & 0 deletions docs/gitops-application.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ai-lab-template-gitops

# Gitops Repo Patterns

This repository contains an HTTP Gitops repository format component for use as the AI-Lab Gitops template.

## HTTP

This contains a deployment with the following characteristics:

**Model service image** `quay.io/redhat-ai-dev/object_detection_python:latest` **listening on port** `8000`.

**App interface image** `quay.io/redhat-ai-dev/ai-template-bootstrap-app:latest` **listening on port** `8501` for service and routing.

This matches the current AI-Lab software template default deployment.
Binary file added docs/images/access-openshift-ai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/access-workbench.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/data-science-projects.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/open-terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/workbench-name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# AI Software Template

This application, test-2-resnet, is created from an AI Software Template. These software templates create a new source code repository as well as a new GitOps deployment repository.

The chosen sample source applicable is included in the source code repository.

## Sample Source Application

A DEtection TRansformer (DETR) model streamlit application. Upload an image to identify and locate objects in the image.

## Repositories

The source code for your application can be found in [https://github.com/jdubrick-ai/test-2-resnet ](https://github.com/jdubrick-ai/test-2-resnet ).

The GitOps repository, which contains the Kubernetes manifests for the application can be found in
[https://github.com/jdubrick-ai/test-2-resnet-gitops ](https://github.com/jdubrick-ai/test-2-resnet-gitops ).

## Application namespaces

The default application is found in the namespace: **`rhdh-app`**. Applications can be deployed into their own unique namespace or multiple software templates can generate numerous applications into the same namespace.
22 changes: 22 additions & 0 deletions docs/pipelines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# docker-build-ai-rhdh

## Shared Git resolver model for shared pipeline and tasks

This pipeline is used to create Containerfile based SSCS (Software Supply Chain Security) builds. The pipeline run by this runner clones the source, builds an image with SBOM (Software Bill of Materials), attests, and pushes these to the users image registry.

Tasks references come from this [repository](https://github.com/redhat-ai-dev/rhdh-pipelines) `pac/pipelines` and the tasks are defined in `pac/tasks`. The tasks are referenced by URL using the git resolver in tekton.

When the pipelines in this repository are updated, all future runs in existing pipelines are shared.

A developer can override these tasks with a local copy and updated annotations.

Example

To override the git-clone task, you may simply copy the git reference into your .tekton directory and then reference it from the remote task annotation.

`pipelinesascode.tekton.dev/task-0: ".tekton/git-clone.yaml"`

## Templates
These pipelines are in template format. The references to this repository in the PaC template is `{{values.rawUrl}}` which is updated to point to this repo or the fork of this repo.

The intent of the template is to fork this repository and update its use in the Developer Hub templates directory.
48 changes: 48 additions & 0 deletions docs/rhoai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Running Samples in OpenShift AI

This document outlines how you can build and run your sample applications within an OpenShift AI workbench.

## Prerequisites

- Red Hat OpenShift AI installed, and `Create workbench for OpenShift AI` selected during component creation.
- `oc` cli installed
- `oc` can be downloaded from https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/
- Permissions to run `oc port-forward` on the cluster, specifically an account with the following roles:
- `get`, `create`, and `list` for the `pods/portforward` subresource

## Running the Sample

1) On the Console, click the square "apps" icon on the upper-right corner (next to the notifications icon). `Openshift AI` is listed in the drop-down list.

![image](./images/access-openshift-ai.png)

2) Go to the `Data Science Projects` section and access your application's project named `rhdh-app`.

![image](./images/data-science-projects.png)

3) Access the `workbench` named `test-2-resnet-notebook`.

![image](./images/access-workbench.png)

4) Go to `File->Open` and select `Terminal`.

![image](./images/open-terminal.png)

5) In the terminal, run `cd test-2-resnet` to navigate to your sample app's directory.

6) Run `pip install --upgrade -r requirements.txt` to install the dependencies for your application.

7) Run `streamlit run object_detection_client.py` to run the sample in the workbench.

## Accessing the Sample

With the sample app now running, complete the following steps to access the sample app in your browser:

1) Go to the OpenShift AI dashboard, and find the name of your workbench.
![image](./images/workbench-name.png)

2) In a terminal window on your machine, run `oc get pods -l app=<workbench-name>`. This retrieves the name of the pod where the workbench is running.

3) Run `oc port-forward <pod-name> 8501` to port forward the sample application's port to your local machine.

4) Finally, visit `http://localhost:8501` in your browser to access the application.
9 changes: 9 additions & 0 deletions docs/source-component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# AI-lab samples

## Usage in AI-lab templates

This repository is being used in [ai-lab-template](https://github.com/redhat-ai-dev/ai-lab-template) as component source code for users to start with.

This is a copy of the ai lab sample apps source code. The master copy of those apps are under [ai-lab-recipes](https://github.com/containers/ai-lab-recipes)

To pull in the latest changes, run `./pull-sample-app.sh`, and commit the changes.
11 changes: 11 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
site_name: 'Documentation'

nav:
- Home: index.md
- Source Component: source-component.md
- Pipelines: pipelines.md
- GitOps Application: gitops-application.md
- OpenShift AI: rhoai.md

plugins:
- techdocs-core
41 changes: 41 additions & 0 deletions object_detection_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import streamlit as st
import base64
import requests
from PIL import Image
import os
import io

st.title("🕵️‍♀️ Object Detection")
endpoint =os.getenv("MODEL_ENDPOINT", default = "http://0.0.0.0:8000")
endpoint_bearer = os.getenv("MODEL_ENDPOINT_BEARER")
headers = {"accept": "application/json",
"Content-Type": "application/json"}
if endpoint_bearer:
headers["Authorization"] = f"Bearer {endpoint_bearer}"
image = st.file_uploader("Upload Image")
window = st.empty()

if image:
#Ensure image dimensions are appropriate
img = Image.open(io.BytesIO(image.read()))
scale_factor = (500 * 500)/(img.height * img.width)
if scale_factor < 0.20:
scale_factor = 0.20
img = img.resize((int(img.width * scale_factor) ,
int(img.height * scale_factor)))
window.image(img, use_column_width=True)
# convert PIL image into bytes for post request
bytes_io = io.BytesIO()
if img.mode in ("RGBA", "P"):
img = img.convert("RGB")
img.save(bytes_io, "JPEG")
img_bytes = bytes_io.getvalue()
b64_image = base64.b64encode(img_bytes).decode('utf-8')
data = {'image': b64_image}
response = requests.post(f'{endpoint}/detection', headers=headers,json=data, verify=False)
# parse response and display outputs
response_json = response.json()
image = response_json["image"]
window.image(base64.b64decode(image), use_column_width=True)
for box in response_json["boxes"]:
st.markdown(box)
Loading

0 comments on commit ebc395d

Please sign in to comment.