Skip to content

Commit

Permalink
Merge pull request #122 from rhatdan/bootc
Browse files Browse the repository at this point in the history
Make it easier to substitute image names
  • Loading branch information
sallyom authored Mar 29, 2024
2 parents 954b53d + af9cde5 commit 36c6389
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion models/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
FROM registry.access.redhat.com/ubi9/ubi-micro:9.3-13
ARG MODEL_URL=https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q4_K_M.gguf
WORKDIR /model
ADD $MODEL_URL .
ADD $MODEL_URL /model/model.file
26 changes: 23 additions & 3 deletions recipes/natural_language_processing/chatbot/Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
APP=chatbot
MODELIMAGE=quay.io/ai-lab/mistral-7b-instruct:latest
APPIMAGE=quay.io/ai-lab/${APP}:latest
SERVERIMAGE=quay.io/ai-lab/llamacpp-python:latest
SSHPUBKEY := $(shell cat ${HOME}/.ssh/id_rsa.pub;)
.PHONY: build
build:
podman build -f builds/Containerfile -t ghcr.io/ai-lab-recipes/chatbot .
podman build -f builds/Containerfile -t ghcr.io/ai-lab-recipes/${APP} .

.PHONY: bootc
bootc:
podman build --cap-add SYS_ADMIN --build-arg "SSHPUBKEY=$(SSHPUBKEY)" --build-arg MODEL-IMAGE=${MODEL-IMAGE} -f bootc/Containerfile -t ghcr.io/ai-lab-recipes/chatbot-bootc .
podman build --cap-add SYS_ADMIN --build-arg "SSHPUBKEY=$(SSHPUBKEY)" -f bootc/Containerfile -t ghcr.io/ai-lab-recipes/${APP}-bootc .

.PHONY: quadlet
quadlet:
# Modify quadlet files to match the server, model and app image
sed -e "s|SERVERIMAGE|${SERVERIMAGE}|" \
-e "s|APPIMAGE|${APPIMAGE}|g" \
-e "s|MODELIMAGE|${MODELIMAGE}|g" \
quadlet/${APP}.image \
> /tmp/${APP}.image
sed -e "s|SERVERIMAGE|${SERVERIMAGE}|" \
-e "s|APPIMAGE|${APPIMAGE}|g" \
-e "s|MODELIMAGE|${MODELIMAGE}|g" \
quadlet/${APP}.yaml \
> /tmp/${APP}.yaml
cp quadlet/${APP}.kube /tmp/${APP}.kube


.PHONY: install
install:
pip install -r tests/requirements-test.txt

.PHONY: run
run:
podman run -it -p 8501:8501 -e MODEL_SERVICE_ENDPOINT=http://10.88.0.1:8001/v1 ghcr.io/ai-lab-recipes/chatbot
podman run -it -p 8501:8501 -e MODEL_SERVICE_ENDPOINT=http://10.88.0.1:8001/v1 ghcr.io/ai-lab-recipes/${APP}

.PHONY: test
test:
Expand Down
14 changes: 11 additions & 3 deletions recipes/natural_language_processing/chatbot/bootc/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ RUN mkdir /usr/etc-system && \

RUN dnf -y update && (dnf install -y vim || true) && dnf clean all

# Add quadlet files to setup system to automatically run AI application on boot
COPY quadlet/chatbot.kube quadlet/chatbot.yaml quadlet/chatbot.image /usr/share/containers/systemd

# pre-pull workload images:
# Comment the pull commands to keep bootc image smaller.
# The quadlet .image file added above pulls following images on boot if not
Expand All @@ -27,6 +24,17 @@ ARG MODELIMAGE=quay.io/ai-lab/mistral-7b-instruct:latest
ARG APPIMAGE=quay.io/ai-lab/chatbot:latest
ARG SERVERIMAGE=quay.io/ai-lab/llamacpp-python:latest

# Add quadlet files to setup system to automatically run AI application on boot
COPY quadlet/chatbot.kube quadlet/chatbot.yaml quadlet/chatbot.image /usr/share/containers/systemd

# Modify quadlet files to match the server, model and app image
RUN sed -e "s|SERVERIMAGE|${SERVERIMAGE}|" \
-e "s|APPIMAGE|${APPIMAGE}|g" \
-e "s|MODELIMAGE|${MODELIMAGE}|g" \
-i \
/usr/share/containers/systemd/chatbot.image \
/usr/share/containers/systemd/chatbot.yaml

RUN podman pull --root /usr/lib/containers/storage ${SERVERIMAGE}
RUN podman pull --root /usr/lib/containers/storage ${APPIMAGE}
RUN podman pull --root /usr/lib/containers/storage ${MODELIMAGE}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
WantedBy=chatbot.service

[Image]
Image=quay.io/ai-lab/llamacpp-python:latest
Image=quay.io/ai-lab/mistral-7b-instruct:latest
Image=quay.io/ai-lab/chatbot:latest
Image=APPIMAGE
Image=MODELIMAGE
Image=SERVERIMAGE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description=Python script to run against downloaded LLM
Description=Kubernetes YAML file used to do chatbot inferencing
Documentation=man:podman-generate-systemd(1)
Wants=network-online.target
After=network-online.target
Expand Down
10 changes: 5 additions & 5 deletions recipes/natural_language_processing/chatbot/quadlet/chatbot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ metadata:
spec:
initContainers:
- name: model-file
image: quay.io/ai-lab/mistral-7b-instruct:latest
command: ['/usr/bin/install', "/model/mistral-7b-instruct-v0.1.Q4_K_M.gguf", "/shared/"]
image: MODELIMAGE
command: ['/usr/bin/install', "/model/model.file", "/shared/"]
volumeMounts:
- name: model-file
mountPath: /shared
containers:
- env:
- name: MODEL_SERVICE_ENDPOINT
value: http://0.0.0.0:8001/v1
image: quay.io/ai-lab/chatbot:latest
image: APPIMAGE
name: chatbot-inference
ports:
- containerPort: 8501
Expand All @@ -29,8 +29,8 @@ spec:
- name: PORT
value: 8001
- name: MODEL_PATH
value: /model/mistral-7b-instruct-v0.1.Q4_K_M.gguf
image: quay.io/ai-lab/llamacpp-python:latest
value: /model/model.file
image: SERVERIMAGE
name: chatbot-model-service
ports:
- containerPort: 8001
Expand Down

0 comments on commit 36c6389

Please sign in to comment.