Skip to content

Commit

Permalink
feat: values.schema.json to support air-gapped environments (#141)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Coufal <tcoufal@redhat.com>
  • Loading branch information
tumido authored Oct 25, 2023
1 parent b0e4aaf commit 703768c
Show file tree
Hide file tree
Showing 7 changed files with 5,733 additions and 645 deletions.
2 changes: 2 additions & 0 deletions .helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
.idea/
*.tmproj
.vscode/

values.schema.tmpl.json
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ repos:
- --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]
34 changes: 34 additions & 0 deletions .pre-commit/jsonschema-dereference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import json
from typing import List, Dict, Any
from pathlib import Path

import jsonref

JSONSCHEMA_TEMPLATE_NAME = "values.schema.tmpl.json"
JSONSCHEMA_NAME = "values.schema.json"
CHART_LOCK = "Chart.lock"

def load_template_schema(chart_dir: Path) -> Dict[str, Any]:
"""Load values.schema.tmpl.json and template it via Jinja2."""
with open(chart_dir / JSONSCHEMA_TEMPLATE_NAME, "r") as f:
return json.loads(f.read())

def save(chart_dir: Path, schema: Any):
"""Take schema containing $refs and dereference them."""
with open(chart_dir / JSONSCHEMA_NAME, "w") as f:
json.dump(schema, f, indent=4, sort_keys=True)

if __name__ == '__main__':
charts = [p.parent for p in Path(".").rglob(CHART_LOCK)]

errors: List[BaseException] = []
for chart in charts:
try:
schema_template = load_template_schema(chart)
schema = jsonref.replace_refs(schema_template)
save(chart, schema)
except BaseException as e:
print(f"Could not process schema for '{chart}': {e}")
errors.append(e)
if errors:
exit(1)
2 changes: 1 addition & 1 deletion charts/backstage/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ sources:
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.5.1
version: 1.6.0
2 changes: 1 addition & 1 deletion charts/backstage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Backstage Helm Chart

[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/backstage)](https://artifacthub.io/packages/search?repo=backstage)
![Version: 1.5.1](https://img.shields.io/badge/Version-1.5.1-informational?style=flat-square)
![Version: 1.6.0](https://img.shields.io/badge/Version-1.6.0-informational?style=flat-square)
![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

A Helm chart for deploying a Backstage application
Expand Down
Loading

0 comments on commit 703768c

Please sign in to comment.