Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Pre-commit

on:
pull_request:
push:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pre-commit:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: '3.11'
cache: pip
cache-dependency-path: |
**/requirements*.txt
.pre-commit-config.yaml

- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
env:
SKIP: no-commit-to-branch
RUFF_OUTPUT_FORMAT: github

- name: Verify if there are any diff files after pre-commit
run: |
git diff --exit-code || (echo "There are uncommitted changes, run pre-commit locally and commit again" && exit 1)

- name: Verify if there are any new files after pre-commit
run: |
unstaged_files=$(git ls-files --others --exclude-standard)
if [ -n "$unstaged_files" ]; then
echo "There are uncommitted new files, run pre-commit locally and commit again"
echo "$unstaged_files"
exit 1
fi
2 changes: 1 addition & 1 deletion .github/workflows/redhat-distro-container-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
file: redhat-distribution/Containerfile
file: distribution/Containerfile
platforms: ${{ matrix.platform }}
push: ${{ github.event_name == 'push' }}
tags: ${{ env.IMAGE_NAME }}:${{ github.sha }},${{ env.IMAGE_NAME }}:${{ env.BRANCH }}-latest
49 changes: 49 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
exclude: 'build/'

default_language_version:
python: python3.12

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0 # Latest stable version
hooks:
- id: check-merge-conflict
args: ['--assume-in-merge']
- id: trailing-whitespace
exclude: '\.py$' # Exclude Python files as Ruff already handles them
- id: check-added-large-files
args: ['--maxkb=1000']
- id: end-of-file-fixer
exclude: '^(.*\.svg)$'
- id: no-commit-to-branch
- id: check-yaml
args: ["--unsafe"]
- id: detect-private-key
- id: requirements-txt-fixer
- id: mixed-line-ending
args: [--fix=lf] # Forces to replace line ending by LF (line feed)
- id: check-executables-have-shebangs
- id: check-json
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-toml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.4
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format

- repo: local
hooks:
- id: pkg-gen
name: Distribution Build
entry: ./distribution/build.py
language: python
pass_filenames: false
require_serial: true
always_run: true
files: ^distribution/.*$
additional_dependencies:
- llama-stack==0.2.18
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# WARNING: This file is auto-generated. Do not modify it manually.
# Generated by: redhat-distribution/build.py
# Generated by: distribution/build.py

FROM registry.access.redhat.com/ubi9/python-312@sha256:95ec8d3ee9f875da011639213fd254256c29bc58861ac0b11f290a291fa04435
WORKDIR /opt/app-root
Expand All @@ -17,7 +17,7 @@ RUN pip install \
llama_stack_provider_lmeval==0.1.7 \
llama_stack_provider_trustyai_fms==0.1.2 \
matplotlib \
mcp \
mcp>=1.8.1 \
nltk \
numpy \
openai \
Expand All @@ -40,9 +40,9 @@ RUN pip install \
uvicorn
RUN pip install --index-url https://download.pytorch.org/whl/cpu torch torchvision
RUN pip install --no-deps sentence-transformers
RUN pip install --no-cache llama-stack==0.2.14
RUN pip install --no-cache llama-stack==0.2.18
RUN mkdir -p ${HOME}/.llama/providers.d ${HOME}/.cache
COPY redhat-distribution/run.yaml ${APP_ROOT}/run.yaml
COPY redhat-distribution/providers.d/ ${HOME}/.llama/providers.d/
COPY distribution/run.yaml ${APP_ROOT}/run.yaml
COPY distribution/providers.d/ ${HOME}/.llama/providers.d/

ENTRYPOINT ["python", "-m", "llama_stack.distribution.server.server", "--config", "/opt/app-root/run.yaml"]
ENTRYPOINT ["python", "-m", "llama_stack.core.server.server", "/opt/app-root/run.yaml"]
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ WORKDIR /opt/app-root

RUN pip install sqlalchemy # somehow sqlalchemy[asyncio] is not sufficient
{dependencies}
RUN pip install --no-cache llama-stack==0.2.14
RUN pip install --no-cache llama-stack==0.2.18
RUN mkdir -p ${{HOME}}/.llama/providers.d ${{HOME}}/.cache
COPY redhat-distribution/run.yaml ${{APP_ROOT}}/run.yaml
COPY redhat-distribution/providers.d/ ${{HOME}}/.llama/providers.d/
COPY distribution/run.yaml ${{APP_ROOT}}/run.yaml
COPY distribution/providers.d/ ${{HOME}}/.llama/providers.d/

ENTRYPOINT ["python", "-m", "llama_stack.distribution.server.server", "--config", "/opt/app-root/run.yaml"]
ENTRYPOINT ["python", "-m", "llama_stack.core.server.server", "/opt/app-root/run.yaml"]
6 changes: 3 additions & 3 deletions redhat-distribution/README.md → distribution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The Containerfile is auto-generated from a template. To generate it:
1. Make sure you have the `llama` CLI tool installed
2. Run the build script from root of this git repo:
```bash
./redhat-distribution/build.py
./distribution/build.py
```

This will:
Expand All @@ -25,7 +25,7 @@ This will:

## Editing the Containerfile

The Containerfile is auto-generated from a template. To edit it, you can modify the template in `redhat-distribution/Containerfile.in` and run the build script again.
The Containerfile is auto-generated from a template. To edit it, you can modify the template in `distribution/Containerfile.in` and run the build script again.
NEVER edit the generated `Containerfile` manually.

## Building the Container Image
Expand All @@ -34,7 +34,7 @@ Once the Containerfile is generated, you can build the image using either Podman

### Using Podman build image for x86_64
```bash
podman build --platform linux/amd64 -f redhat-distribution/Containerfile -t rh .
podman build --platform linux/amd64 -f distribution/Containerfile -t rh .
```

## Notes
Expand Down
25 changes: 16 additions & 9 deletions redhat-distribution/build.py → distribution/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.

# Usage: ./redhat-distribution/build.py
# Usage: ./distribution/build.py

import shutil
import subprocess
import sys
from pathlib import Path

BASE_REQUIREMENTS = [
"llama-stack==0.2.14",
"llama-stack==0.2.18",
]


Expand Down Expand Up @@ -59,9 +59,11 @@ def check_llama_stack_version():

def get_dependencies():
"""Execute the llama stack build command and capture dependencies."""
cmd = "llama stack build --config redhat-distribution/build.yaml --print-deps-only"
cmd = "llama stack build --config distribution/build.yaml --print-deps-only"
try:
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, check=True)
result = subprocess.run(
cmd, shell=True, capture_output=True, text=True, check=True
)
# Categorize and sort different types of pip install commands
standard_deps = []
torch_deps = []
Expand All @@ -74,7 +76,9 @@ def get_dependencies():
parts = line.replace("uv ", "RUN ", 1).split(" ", 3)
if len(parts) >= 4: # We have packages to sort
cmd_parts = parts[:3] # "RUN pip install"
packages = sorted(set(parts[3].split())) # Sort the package names and remove duplicates
packages = sorted(
set(parts[3].split())
) # Sort the package names and remove duplicates

# Determine command type and format accordingly
if "--index-url" in line:
Expand Down Expand Up @@ -104,13 +108,14 @@ def get_dependencies():
except subprocess.CalledProcessError as e:
print(f"Error executing command: {e}")
print(f"Command output: {e.output}")
print(f"Command stderr: {e.stderr}")
sys.exit(1)


def generate_containerfile(dependencies):
"""Generate Containerfile from template with dependencies."""
template_path = Path("redhat-distribution/Containerfile.in")
output_path = Path("redhat-distribution/Containerfile")
template_path = Path("distribution/Containerfile.in")
output_path = Path("distribution/Containerfile")

if not template_path.exists():
print(f"Error: Template file {template_path} not found")
Expand All @@ -121,10 +126,12 @@ def generate_containerfile(dependencies):
template_content = f.read()

# Add warning message at the top
warning = "# WARNING: This file is auto-generated. Do not modify it manually.\n# Generated by: redhat-distribution/build.py\n\n"
warning = "# WARNING: This file is auto-generated. Do not modify it manually.\n# Generated by: distribution/build.py\n\n"

# Process template using string formatting
containerfile_content = warning + template_content.format(dependencies=dependencies.rstrip())
containerfile_content = warning + template_content.format(
dependencies=dependencies.rstrip()
)

# Write output
with open(output_path, "w") as f:
Expand Down
36 changes: 36 additions & 0 deletions distribution/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 2
distribution_spec:
description: Red Hat distribution of Llama Stack
providers:
inference:
- provider_type: remote::vllm
- provider_type: inline::sentence-transformers
vector_io:
- provider_type: inline::milvus
safety:
- provider_type: remote::trustyai_fms
agents:
- provider_type: inline::meta-reference
eval:
- provider_type: remote::trustyai_lmeval
datasetio:
- provider_type: remote::huggingface
- provider_type: inline::localfs
scoring:
- provider_type: inline::basic
- provider_type: inline::llm-as-judge
- provider_type: inline::braintrust
telemetry:
- provider_type: inline::meta-reference
tool_runtime:
- provider_type: remote::brave-search
- provider_type: remote::tavily-search
- provider_type: inline::rag-runtime
- provider_type: remote::model-context-protocol
container_image: registry.redhat.io/ubi9/python-311:9.6-1749631027
additional_pip_packages:
- aiosqlite
- sqlalchemy[asyncio]
image_type: container
image_name: llama-stack-rh
external_providers_dir: distribution/providers.d
File renamed without changes.
36 changes: 0 additions & 36 deletions redhat-distribution/build.yaml

This file was deleted.