mirror of
https://github.com/plcnk/charts.git
synced 2026-04-06 09:40:52 +00:00
feat(charts): Now using bjw-s's common library chart (#7)
This commit is contained in:
committed by
GitHub
parent
8a84b5e13a
commit
31bbf1ca94
39
hack/gen-chart-summary.sh
Executable file
39
hack/gen-chart-summary.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# require yq
|
||||
command -v yq >/dev/null 2>&1 || {
|
||||
echo >&2 'yq (https://github.com/mikefarah/yq) is not installed. Aborting.'
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Absolute path of repository
|
||||
repository="$(git rev-parse --show-toplevel)"
|
||||
charts_folder="$repository/charts"
|
||||
charts_summary_file="$repository/README.md"
|
||||
charts_header='## Chart Overview'
|
||||
|
||||
# Gather all charts
|
||||
stable_charts="$(find "$charts_folder" -name "Chart.yaml" | sort)"
|
||||
|
||||
sed -i '' '/^'"$charts_header"'$/,$d' "$charts_summary_file"
|
||||
|
||||
{
|
||||
echo "$charts_header"
|
||||
echo
|
||||
echo "| Chart | Description |"
|
||||
echo "| ----- | ----------- |"
|
||||
for chart_yaml in ${stable_charts[@]}; do
|
||||
if ! git ls-files --error-unmatch "$chart_yaml" &>/dev/null; then continue; fi
|
||||
IFS=$'\t' read -r chart_name chart_description chart_icon < <(yq eval -o=tsv '[.name, .description, .icon // ""]' "$chart_yaml")
|
||||
if [[ -n "$chart_icon" ]]; then
|
||||
width=18
|
||||
if [[ "$chart_name" == mnemonic-ninja ]]; then
|
||||
width=12
|
||||
fi
|
||||
chart_icon="<img src='$chart_icon' alt='$chart_name icon' width='${width}px' align='right' loading='lazy'>"
|
||||
fi
|
||||
pretty_name="$(head -n1 "$(dirname "$chart_yaml")/README.md" | sed 's/^# //')"
|
||||
echo "| [$pretty_name $chart_icon](charts/$chart_name/) | $chart_description |"
|
||||
done
|
||||
} >> "$charts_summary_file"
|
||||
59
hack/gen-helm-docs.sh
Executable file
59
hack/gen-helm-docs.sh
Executable file
@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Generate helm-docs for Helm charts
|
||||
# Usage ./gen-helm-docs.sh [chart]
|
||||
|
||||
# require helm-docs
|
||||
command -v helm-docs >/dev/null 2>&1 || {
|
||||
echo >&2 'helm-docs (https://github.com/norwoodj/helm-docs) is not installed. Aborting.'
|
||||
exit 1
|
||||
}
|
||||
|
||||
# require yq
|
||||
command -v yq >/dev/null 2>&1 || {
|
||||
echo >&2 'yq (https://github.com/mikefarah/yq) is not installed. Aborting.'
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Absolute path of repository
|
||||
repository="$(git rev-parse --show-toplevel)"
|
||||
charts_folder="$repository/charts"
|
||||
|
||||
# Templates to copy into each chart directory
|
||||
template_dir="$repository/hack/templates"
|
||||
readme_config_template="$template_dir/README_CONFIG.md.gotmpl"
|
||||
icon_template=$(<"$template_dir/icon.gotmpl")
|
||||
|
||||
# Gather all charts using the common library, excluding common-test
|
||||
charts="$(find "$charts_folder" -name Chart.yaml)"
|
||||
|
||||
# Allow for a specific chart to be passed in as a argument
|
||||
if [ $# -ge 1 ] && [ -n "$1" ]; then
|
||||
root="$(find "$charts_folder" -name "$1")"
|
||||
charts="$root/Chart.yaml"
|
||||
if [ ! -f "$charts" ]; then
|
||||
echo "Chart $1 does not exist."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
root="$charts_folder"
|
||||
fi
|
||||
|
||||
for chart in $charts; do (
|
||||
chart_directory="$(dirname "$chart")"
|
||||
icon="$(yq eval '.icon // ""' "$chart" 2>/dev/null)"
|
||||
|
||||
# Copy CONFIG template to each Chart directory, do not overwrite if exists
|
||||
cp -n "$readme_config_template" "$chart_directory" || true
|
||||
|
||||
# Run helm-docs for charts
|
||||
helm-docs \
|
||||
--log-level=warning \
|
||||
--template-files="$template_dir/README.md.gotmpl" \
|
||||
--template-files=<(echo "${icon_template/\$ICON/$icon}") \
|
||||
--template-files="$(basename "$readme_config_template")" \
|
||||
--badge-style=flat \
|
||||
--chart-search-root="$root" \
|
||||
--chart-to-generate="$chart_directory"
|
||||
) done
|
||||
170
hack/templates/README.md.gotmpl
Normal file
170
hack/templates/README.md.gotmpl
Normal file
@ -0,0 +1,170 @@
|
||||
{{- define "custom.repository.organization" -}}
|
||||
plcnk
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.repository.url" -}}
|
||||
https://github.com/plcnk/charts
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.helm.url" -}}
|
||||
https://charts.plcnk.net
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.helm.path" -}}
|
||||
{{ template "custom.repository.organization" . }}/{{ template "chart.name" . }}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.helm.oci_url" -}}
|
||||
oci://ghcr.io/plcnk/charts
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.notes" -}}
|
||||
**This chart is not maintained by the upstream project and any issues with the chart should be raised
|
||||
[here]({{ template "custom.repository.url" . }}/issues/new?assignees=plcnk&labels=bug&template=bug_report.yaml&name={{ template "chart.name" . }}&version={{ template "chart.version" . }})**
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.requirements" -}}
|
||||
## Requirements
|
||||
|
||||
{{ template "chart.kubeVersionLine" . }}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.dependencies" -}}
|
||||
## Dependencies
|
||||
|
||||
{{ if gt (len .Dependencies) 0 }}
|
||||
| Repository | Name | Version |
|
||||
|------------|------|---------|
|
||||
{{- range .Dependencies }}
|
||||
{{- if .Alias }}
|
||||
| <{{ .Repository }}> | {{ .Alias }}({{ .Name }}) | {{ .Version }} |
|
||||
{{- else }}
|
||||
| <{{ .Repository }}> | {{ .Name }} | {{ .Version }} |
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{ else }}
|
||||
This chart has no dependencies.
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.install" -}}
|
||||
## Installing the Chart
|
||||
|
||||
To install the chart with the release name `{{ template "chart.name" . }}`
|
||||
|
||||
### OCI (Recommended)
|
||||
|
||||
```console
|
||||
helm install {{ template "chart.name" . }} {{ template "custom.helm.oci_url" . }}/{{ template "chart.name" . }}
|
||||
```
|
||||
|
||||
### Traditional
|
||||
|
||||
```console
|
||||
helm repo add {{ template "custom.repository.organization" . }} {{ template "custom.helm.url" . }}
|
||||
helm repo update
|
||||
helm install {{ template "chart.name" . }} {{ template "custom.helm.path" . }}
|
||||
```
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.uninstall" -}}
|
||||
## Uninstalling the Chart
|
||||
|
||||
To uninstall the `{{ template "chart.name" . }}` deployment
|
||||
|
||||
```console
|
||||
helm uninstall {{ template "chart.name" . }}
|
||||
```
|
||||
|
||||
The command removes all the Kubernetes components associated with the chart **including persistent volumes** and deletes the release.
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.configuration.header" -}}
|
||||
## Configuration
|
||||
{{- end -}}
|
||||
|
||||
|
||||
{{- define "custom.bjwsRef" -}}
|
||||
{{- $ref := "" -}}
|
||||
{{- range .Dependencies -}}
|
||||
{{- if and (eq .Repository "https://bjw-s.github.io/helm-charts") (eq .Name "common") (semverCompare "^1.x" .Version) -}}
|
||||
{{- $ref = "a081de5" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- default "main" $ref -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.configuration.readValues" -}}
|
||||
Read through the [values.yaml](./values.yaml) file. It has several commented out suggested values.
|
||||
Other values may be used from the [values.yaml](https://github.com/bjw-s/helm-charts/tree/{{ template "custom.bjwsRef" . }}/charts/library/common/values.yaml) from the [bjw-s common library](https://github.com/bjw-s/helm-charts/tree/{{ template "custom.bjwsRef" . }}/charts/library/common).
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.configuration.example.set" -}}
|
||||
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`.
|
||||
|
||||
```console
|
||||
helm install {{ template "chart.name" . }} \
|
||||
--set env.TZ="America/New York" \
|
||||
{{ template "custom.helm.path" . }}
|
||||
```
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.configuration.example.file" -}}
|
||||
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart.
|
||||
|
||||
```console
|
||||
helm install {{ template "chart.name" . }} {{ template "custom.helm.path" . }} -f values.yaml
|
||||
```
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.valuesSection" -}}
|
||||
## Values
|
||||
|
||||
**Important**: When deploying an application Helm chart you can add more values from the bjw-s common library chart [here](https://github.com/bjw-s/helm-charts/tree/{{ template "custom.bjwsRef" . }}/charts/library/common)
|
||||
|
||||
{{ template "chart.valuesTable" . }}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.helm-docs.versionFooter" -}}
|
||||
---
|
||||
Autogenerated from chart metadata using [helm-docs](https://github.com/norwoodj/helm-docs)
|
||||
{{- end -}}
|
||||
|
||||
# {{ template "custom.chart.name" . }}
|
||||
|
||||
{{ template "custom.chart.icon" . }}
|
||||
|
||||
{{ template "chart.versionBadge" . }}
|
||||
{{ template "chart.typeBadge" . }}
|
||||
{{ template "chart.appVersionBadge" . }}
|
||||
|
||||
{{ template "chart.description" . }}
|
||||
|
||||
{{ template "chart.homepageLine" . }}
|
||||
|
||||
{{ template "custom.notes" . }}
|
||||
|
||||
{{ template "chart.sourcesSection" . }}
|
||||
|
||||
{{ template "custom.requirements" . }}
|
||||
|
||||
{{ template "custom.dependencies" . }}
|
||||
|
||||
{{ template "custom.install" . }}
|
||||
|
||||
{{ template "custom.uninstall" . }}
|
||||
|
||||
{{ template "custom.configuration.header" . }}
|
||||
|
||||
{{ template "custom.configuration.readValues" . }}
|
||||
|
||||
{{ template "custom.configuration.example.set" . }}
|
||||
|
||||
{{ template "custom.configuration.example.file" . }}
|
||||
|
||||
{{ template "custom.custom.configuration" . }}
|
||||
|
||||
{{ template "custom.valuesSection" . }}
|
||||
|
||||
{{ template "custom.helm-docs.versionFooter" . }}
|
||||
{{ "" }}
|
||||
13
hack/templates/README_CONFIG.md.gotmpl
Normal file
13
hack/templates/README_CONFIG.md.gotmpl
Normal file
@ -0,0 +1,13 @@
|
||||
{{- define "custom.chart.name" -}}
|
||||
# {{ .Name }}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.custom.configuration.header" -}}
|
||||
## Custom configuration
|
||||
{{- end -}}
|
||||
|
||||
{{- define "custom.custom.configuration" -}}
|
||||
{{ template "custom.custom.configuration.header" . }}
|
||||
|
||||
N/A
|
||||
{{- end -}}
|
||||
5
hack/templates/icon.gotmpl
Normal file
5
hack/templates/icon.gotmpl
Normal file
@ -0,0 +1,5 @@
|
||||
{{- define "custom.chart.icon" -}}
|
||||
{{- with "$ICON" -}}
|
||||
<img src="{{ . }}" align="right" width="92" alt="{{ template "chart.name" $ }} logo">
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
56
hack/update-changelog.sh
Executable file
56
hack/update-changelog.sh
Executable file
@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# require yq
|
||||
command -v yq >/dev/null 2>&1 || {
|
||||
echo >&2 'yq (https://github.com/mikefarah/yq) is not installed. Aborting.'
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ "$#" -lt 2 ]; then
|
||||
echo 'Usage: {append | replace} changelog [chart...]'
|
||||
exit
|
||||
fi
|
||||
|
||||
update_type="$1"
|
||||
shift
|
||||
|
||||
changelog="$(yq -P <<<"$1")"
|
||||
export changelog
|
||||
shift
|
||||
|
||||
CHARTS=()
|
||||
if [ "$#" -gt 0 ]; then
|
||||
# Get changed dirs from params
|
||||
for file in "$@"; do
|
||||
CHARTS+=( "$(dirname "$file")" )
|
||||
done
|
||||
else
|
||||
# Get changed dirs from uncommitted changes
|
||||
for file in $(git status --porcelain charts | grep '^M' | cut -c4-); do
|
||||
CHARTS+=( "$(dirname "$file")" )
|
||||
done
|
||||
fi
|
||||
CHARTS=( $(sort -u <<<"${CHARTS[*]}") )
|
||||
|
||||
case "$update_type" in
|
||||
append)
|
||||
expression='.annotations."artifacthub.io/changes" |= (@yamld + (strenv(changelog) | @yamld) | @yaml | trim)'
|
||||
;;
|
||||
replace)
|
||||
expression='.annotations."artifacthub.io/changes" = (env(changelog) | @yaml | trim)'
|
||||
;;
|
||||
*)
|
||||
echo "Invalid update type: $update_type" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
for chart in "${CHARTS[@]}"; do (
|
||||
meta_file="$chart/Chart.yaml"
|
||||
if [ ! -f "$meta_file" ]; then echo >&2 "Invalid file: $meta_file"; exit; fi
|
||||
|
||||
yq --inplace "$expression" "$meta_file"
|
||||
echo "Updated $(basename "$chart") changelog"
|
||||
) done
|
||||
53
hack/update-version.sh
Executable file
53
hack/update-version.sh
Executable file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# require yq
|
||||
command -v yq >/dev/null 2>&1 || {
|
||||
echo >&2 'yq (https://github.com/mikefarah/yq) is not installed. Aborting.'
|
||||
exit 1
|
||||
}
|
||||
|
||||
function _print_usage() {
|
||||
echo 'Usage: {major|minor|patch} [chart...]'
|
||||
exit "${1:-0}"
|
||||
}
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
_print_usage
|
||||
fi
|
||||
|
||||
UPDATE_TYPE="$(tr '[:upper:]' '[:lower:]' <<<"$1")"
|
||||
shift
|
||||
case "$UPDATE_TYPE" in
|
||||
major) SCRIPT='[(.0 | @yamld | . + 1), 0, 0]' ;;
|
||||
minor) SCRIPT='[.0, (.1 | @yamld | . + 1), 0]' ;;
|
||||
patch) SCRIPT='[.0, .1, (.2 | @yamld | . + 1)]' ;;
|
||||
*) echo >&2 "Invalid update type: $UPDATE_TYPE"; _print_usage 1 ;;
|
||||
esac
|
||||
|
||||
echo "Performing $UPDATE_TYPE version bump"
|
||||
|
||||
CHARTS=()
|
||||
if [ "$#" -gt 0 ]; then
|
||||
# Get changed dirs from params
|
||||
for file in "$@"; do
|
||||
CHARTS+=( "$(dirname "$file")" )
|
||||
done
|
||||
else
|
||||
# Get changed dirs from uncommitted changes
|
||||
for file in $(git status --porcelain charts | grep '^M' | cut -c4-); do
|
||||
CHARTS+=( "$(dirname "$file")" )
|
||||
done
|
||||
fi
|
||||
CHARTS=( $(sort -u <<<"${CHARTS[*]}") )
|
||||
|
||||
for chart in "${CHARTS[@]}"; do (
|
||||
meta_file="$chart/Chart.yaml"
|
||||
if [ ! -f "$meta_file" ]; then echo >&2 "Invalid file: $meta_file"; exit; fi
|
||||
|
||||
current="$(yq '.version' "$meta_file")"
|
||||
yq -i '.version |= (split(".") | '"$SCRIPT"' | join("."))' "$meta_file"
|
||||
new="$(yq '.version' "$meta_file")"
|
||||
echo "Updated $(basename "$chart") from v$current to v$new"
|
||||
) done
|
||||
Reference in New Issue
Block a user