Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: values.schema.json to support air-gapped environments #141

Merged
merged 1 commit into from
Oct 25, 2023
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
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