Skip to content

Commit

Permalink
helm testing and linting initial commit
Browse files Browse the repository at this point in the history
Co-authored-by: Theofanis Petkos <[email protected]>
  • Loading branch information
coreydaley and thepetk committed Jan 16, 2025
1 parent c18c981 commit 5dd01a0
Show file tree
Hide file tree
Showing 14 changed files with 536 additions and 204 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Lint Charts

on:
pull_request:
paths:
- "charts/**"

jobs:
check-readme:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v3

- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # pin@v4
with:
python-version: 3.12

- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # pin@v3
with:
go-version: ^1

- name: Setup helm-docs
run: go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest

- name: Run pre-commit
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # [email protected]
with:
extra_args: helm-docs --all-files

check-jsonschema-dereference:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v3

- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # pin@v4
with:
python-version: 3.12

- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # pin@v3
with:
go-version: ^1

- name: Run pre-commit
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd
with:
extra_args: jsonschema-dereference --all-files
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
private-values.yaml
*~
env
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/norwoodj/helm-docs
rev: v1.2.0
hooks:
- id: helm-docs
args:
# Make the tool search for charts only under the ``charts` directory
- --chart-search-root=charts
# The `./` makes it relative to the chart-search-root set above
- --template-files=./_templates.gotmpl
# A base filename makes it relative to each chart directory found
- --template-files=README.md.gotmpl
- repo: local
hooks:
- id: jsonschema-dereference
name: jsonschema-dereference
entry: python .pre-commit/jsonschema_dereference.py
additional_dependencies: [jsonref]
language: python
types_or: [yaml, json]
54 changes: 54 additions & 0 deletions .pre-commit/jsonschema_dereference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
This Python module:
- Searches for JSON Schema templates with the name values.schema.tmpl.json
- Dereferences any $refs contained in those files
- Outputs the new Schema to a values.schema.json file in the same directory
"""

import sys
import json
from typing import List, Dict, Any
from pathlib import Path

# External library dependency
# Install with 'pip install jsonref'
import jsonref

# File to write the dereferenced JSON Schema to
JSONSCHEMA_NAME = "values.schema.json"
# File that contains the JSON Schema that needs dereferencing
JSONSCHEMA_TEMPLATE_NAME = "values.schema.tmpl.json"

def load_template_schema(schema_dir: Path) -> Dict[str, Any]:
"""Load the schema template values.schema.tmpl.json"""
with open(schema_dir / JSONSCHEMA_TEMPLATE_NAME, "r", encoding="utf-8") as f:
return json.loads(f.read())

def save(schema_dir: Path, schema_data: Any) -> None:
"""Save the dereferenced schema to values.schema.json"""
with open(schema_dir / JSONSCHEMA_NAME, "w", encoding="utf-8") as f:
json.dump(schema_data, f, indent=4, sort_keys=True)

if __name__ == '__main__':
# Search for all values.schema.tmpl.json files
schema_templates = [p.parent for p in Path(".").rglob(JSONSCHEMA_TEMPLATE_NAME)]

# Create a list to hold any exceptions
errors: List[BaseException] = []
# Iterate over the List of found schema templates
for schema_template in schema_templates:
try:
# Load the schema into a variable as JSON
st = load_template_schema(schema_template)
# Dereference all of the $refs
s = jsonref.replace_refs(st)
# Save the dereferenced JSON
save(schema_template, s)
except BaseException as e:
# Print any errors to the screen
print(f"Could not process schema for '{schema_template}': {e}")
# Append any exceptions to the errors List
errors.append(e)
if errors:
# Exit with status 1 if any exceptions were thrown
sys.exit(1)
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
##@ Generation

.PHONY: generate
generate: ## Run all generation commands
pre-commit run --all-files

.PHONY: helm-docs
helm-docs: ## Generate README.md from the README.md.gotmpl file
pre-commit run helm-docs --all-files

.PHONY: jsonschema-dereference
jsonschema-dereference: ## Generate values.schema.json from the values.schema.tmpl.json file
pre-commit run jsonschema-dereference --all-files

##@ Scripts

.PHONY: install-pre-commit
install-pre-commit: ## Install the pre-commit script
pre-commit install

##@ General

# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
7 changes: 7 additions & 0 deletions charts/_templates.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ define "chart.valuesTable" }}
| Key | Type | Default | Description |
|-----|------|---------|-------------|
{{- range .Values }}
| {{ .Key }} | {{ .Type }} | {{ if .Default }}{{ .Default }}{{ else }}{{ .AutoDefault }}{{ end }} | {{ if .Description }}{{ .Description }}{{ else }}{{ .AutoDescription }}{{ end }} |
{{- end }}
{{ end }}
37 changes: 33 additions & 4 deletions charts/ai-software-templates/chatbot/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
# The chart API version (required)
apiVersion: v2
# The name of the chart (required)
name: chatbot-ai-sample
# A SemVer 2 version (required)
version: 0.1.1
# A SemVer range of compatible Kubernetes versions (optional)
kubeVersion: ">= 1.27.0-0"
# A single-sentence description of this project (optional)
description: This Helm Chart deploys a Large Language Model (LLM)-enabled [chat bot application](https://github.com/redhat-ai-dev/ai-lab-samples/tree/main/chatbot).
# The type of the chart (optional)
type: application
# A list of keywords about this project (optional)
keywords:
- chatbot
- llama.cpp
- ai-lab
# The URL of this projects home page (optional)
home: https://github.com/redhat-ai-dev/ai-lab-helm-charts
# A list of URLs to source code for this project (optional)
sources:
- https://github.com/redhat-ai-dev/ai-lab-template
# A list of the chart requirements (optional)
dependencies: []
# A list of maintainers of this project (optional)
maintainers:
- name: Red Hat AI Development Team
url: https://github.com/redhat-ai-dev
# A URL to an SVG or PNG image to be used as an icon (optional)
# icon: ""
# The version of the app that this contains (optional). Needn't be SemVer. Quotes recommended.
# appVersion:
# Whether this chart is deprecated (optional, boolean)
deprecated: false
# A list of annotations keyed by name (optional)
annotations:
charts.openshift.io/name: Chatbot AI Sample
description: A Helm chart for the Chatbot AI Sample app. For more information please check https://github.com/redhat-ai-dev/ai-lab-helm-charts.git
name: chatbot-ai-sample
tags: chatbot,llama.cpp,ai-lab
version: 0.1.1
Loading

0 comments on commit 5dd01a0

Please sign in to comment.