Compare commits

..
2 Commits
Author SHA1 Message Date
TapTap f1dc60aae5 chart: show the newest chart in the Charts repository README
CI / chart (push) Successful in 2s
CI / chart-push (push) Successful in 4s
CI / test (push) Successful in 1m39s
CI / image (push) Successful in 3m31s
The chart repository README was static, so the published version was only
visible in index.yaml. push-chart.sh now regenerates a marked "Newest chart"
section with the version, app version, publish time and source commit, plus a
table of the newest version of every chart in the repository. Plain markdown
only, so the README stays readable on the Gitea front page.

The section is inserted before the first section on the first publish and
replaced in place afterwards.
2026-11-14 21:59:51 +00:00
TapTap 8e87fed93f chart: refuse to render without an explicit namespace
Helm falls back to the "default" namespace when --namespace is omitted, so a
forgotten flag (or a Kustomize helmCharts entry without namespace) silently
deployed into the wrong place. Render the namespace through one helper that
fails on an empty or implicit "default" namespace, with allowDefaultNamespace
as an explicit opt-in.

scripts/check-chart.sh lints the chart, asserts every namespaced resource
carries the passed namespace, and checks both failure and opt-in paths. CI runs
it instead of the plain template call.

Bump the chart to 0.2.1.
2026-11-14 21:59:48 +00:00
12 changed files with 209 additions and 10 deletions

No files matched your search

+1 -3
View File
@@ -35,9 +35,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Lint and render the chart
run: |
helm lint charts/audiomanager
helm template audiomanager charts/audiomanager --set users.existingSecret=test > /dev/null
run: scripts/check-chart.sh
chart-push:
needs:
+13 -1
View File
@@ -259,6 +259,11 @@ Image: gitea.tap-tap.win/taptap/audiomanager:<tag>
Chart: https://gitea.tap-tap.win/TapTap/Charts/raw/branch/main
```
The [Charts README](https://gitea.tap-tap.win/TapTap/Charts) always shows the
newest published chart version; `scripts/push-chart.sh` regenerates that section
on every publish.
Kustomize example:
```yaml
@@ -271,6 +276,12 @@ helmCharts:
valuesFile: values.yaml
```
The chart renders every resource into the namespace passed to Helm
(`--namespace` or `helmCharts[].namespace`) and refuses to render when that
namespace is missing or falls back to `default`, so a forgotten namespace cannot
deploy into the wrong place. Set `allowDefaultNamespace=true` to opt in to
`default`. `scripts/check-chart.sh` lints the chart and enforces this in CI.
The chart expects:
- a `users.yaml` Secret (Vault-managed) referenced by `users.existingSecret`;
@@ -300,8 +311,9 @@ The shared module owns the API client, auth store, SQLDelight offline database,
## Testing
```bash
gradle test # unit + API integration tests
gradle test # unit + API integration tests
GRADLE=gradle scripts/smoke.sh # end-to-end server smoke test
scripts/check-chart.sh # lint the chart and enforce the namespace rule
```
The smoke test generates tagged MP3s, starts the server, and verifies login, sync, moods, radio, add-to-mood, streaming, transcoding, covers, scan and logout.
+1 -1
View File
@@ -2,5 +2,5 @@ apiVersion: v2
name: audiomanager
description: Self-hosted OpenSubsonic music server
type: application
version: 0.2.0
version: 0.2.1
appVersion: "0.1.0"
@@ -31,3 +31,22 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- define "audiomanager.image" -}}
{{- printf "%s:%s" .Values.image.repository (default .Chart.AppVersion .Values.image.tag) -}}
{{- end -}}
{{/*
The namespace every resource is rendered into.
Helm falls back to "default" when --namespace is omitted, which would silently
put the release somewhere the operator did not ask for. Refuse to render in
that case unless the fallback is explicitly allowed, so a forgotten --namespace
(or a kustomization without namespace:) fails instead of deploying.
*/}}
{{- define "audiomanager.namespace" -}}
{{- $namespace := .Release.Namespace -}}
{{- if not $namespace -}}
{{- fail "a namespace is required: pass --namespace <namespace> (or set namespace: in the Kustomize helmCharts entry)" -}}
{{- end -}}
{{- if and (eq $namespace "default") (not .Values.allowDefaultNamespace) -}}
{{- fail "refusing to deploy into the implicit \"default\" namespace: pass --namespace <namespace>, or set allowDefaultNamespace=true to opt in" -}}
{{- end -}}
{{- $namespace -}}
{{- end -}}
@@ -2,7 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "audiomanager.fullname" . }}-library
namespace: {{ .Release.Namespace }}
namespace: {{ include "audiomanager.namespace" . }}
labels:
{{- include "audiomanager.labels" . | nindent 4 }}
data:
@@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "audiomanager.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ include "audiomanager.namespace" . }}
labels:
{{- include "audiomanager.labels" . | nindent 4 }}
spec:
+1 -1
View File
@@ -3,7 +3,7 @@ apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "audiomanager.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ include "audiomanager.namespace" . }}
labels:
{{- include "audiomanager.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
+1 -1
View File
@@ -3,7 +3,7 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "audiomanager.fullname" . }}-data
namespace: {{ .Release.Namespace }}
namespace: {{ include "audiomanager.namespace" . }}
labels:
{{- include "audiomanager.labels" . | nindent 4 }}
spec:
+1 -1
View File
@@ -2,7 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ include "audiomanager.fullname" . }}
namespace: {{ .Release.Namespace }}
namespace: {{ include "audiomanager.namespace" . }}
labels:
{{- include "audiomanager.labels" . | nindent 4 }}
spec:
+5
View File
@@ -1,5 +1,10 @@
replicaCount: 1
# Every resource is rendered into the namespace passed with --namespace (or
# helmCharts[].namespace in Kustomize). Rendering fails when that namespace is
# missing or falls back to "default"; set this to true to allow "default".
allowDefaultNamespace: false
image:
repository: gitea.tap-tap.win/taptap/audiomanager
# CI publishes :latest and :sha-<commit> for every push to main.
+80
View File
@@ -0,0 +1,80 @@
#!/usr/bin/env bash
#
# Render and verify the Helm chart. Every namespaced resource must be rendered
# into the namespace that was passed to Helm, and rendering must fail when no
# namespace is passed instead of silently falling back to "default".
#
# Requires helm on PATH (`nix-shell` provides it).
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
CHART_DIR="${CHART_DIR:-$ROOT/charts/audiomanager}"
RELEASE="${RELEASE:-audiomanager}"
NAMESPACE="${NAMESPACE:-audiomanager}"
workdir="$(mktemp -d "${TMPDIR:-/tmp}/chart-check.XXXXXX")"
trap 'rm -rf "$workdir"' EXIT
# An empty kubeconfig makes the implicit namespace deterministic ("default"),
# independent of whatever context the developer or runner has configured.
(umask 077 && : > "$workdir/kubeconfig")
echo "helm lint ($NAMESPACE)"
helm lint "$CHART_DIR" --namespace "$NAMESPACE" >/dev/null
echo "render ($NAMESPACE)"
helm template "$RELEASE" "$CHART_DIR" \
--namespace "$NAMESPACE" \
--set users.existingSecret=test \
> "$workdir/rendered.yaml"
# A namespace per document: fail if a namespaced kind has no metadata.namespace
# or carries a different one. Cluster-scoped kinds are listed explicitly so a
# new template cannot quietly skip the namespace.
NAMESPACE="$NAMESPACE" awk '
function cluster_scoped(kind) {
return kind == "Namespace" \
|| kind ~ /^Cluster/ \
|| kind ~ /^(PersistentVolume|StorageClass|IngressClass|Node|PriorityClass)$/ \
|| kind ~ /^(CustomResourceDefinition|APIService|RuntimeClass|CSIDriver|CSINode|VolumeAttachment)$/ \
|| kind ~ /(WebhookConfiguration)$/
}
function check_document() {
if (kind == "") return
if (cluster_scoped(kind)) return
if (namespace == "") {
printf "FAIL: %s has no metadata.namespace\n", kind
failed = 1
} else if (namespace != ENVIRON["NAMESPACE"]) {
printf "FAIL: %s is in namespace %s, want %s\n", kind, namespace, ENVIRON["NAMESPACE"]
failed = 1
}
kind = ""
namespace = ""
}
/^---[[:space:]]*$/ { check_document(); next }
/^kind:[[:space:]]/ { kind = $2 }
/^metadata:[[:space:]]*$/ { in_metadata = 1; next }
/^[^[:space:]]/ { in_metadata = 0 }
in_metadata && /^ namespace:[[:space:]]/ { namespace = $2; in_metadata = 0 }
END { check_document(); exit failed }
' "$workdir/rendered.yaml"
echo "render without a namespace must fail"
if helm template "$RELEASE" "$CHART_DIR" \
--kubeconfig "$workdir/kubeconfig" \
--set users.existingSecret=test \
> "$workdir/without-namespace.yaml" 2>/dev/null; then
echo "FAIL: the chart rendered without --namespace" >&2
exit 1
fi
echo "render with allowDefaultNamespace=true"
helm template "$RELEASE" "$CHART_DIR" \
--kubeconfig "$workdir/kubeconfig" \
--set users.existingSecret=test \
--set allowDefaultNamespace=true >/dev/null
echo "chart check passed"
+85
View File
@@ -99,6 +99,91 @@ fi
helm package "$CHART_DIR" --version "$VERSION" --destination "$workdir/repo"
helm repo index "$workdir/repo" --url "$CHARTS_RAW_URL"
# Keep the repository README pointing at the newest version of every chart so
# the published version is visible without reading index.yaml.
app_version="$(awk '/^appVersion:/ { print $2; exit }' "$CHART_DIR/Chart.yaml" | tr -d '"')"
source_sha="${GITHUB_SHA:-$(git -C "$ROOT" rev-parse HEAD)}"
source_repo="${GITHUB_REPOSITORY:-TapTap/AudioManager}"
source_server="${GITHUB_SERVER_URL:-https://gitea.tap-tap.win}"
published_at="$(date -u '+%Y-%m-%d %H:%M UTC')"
newest_charts="$(
for archive in "$workdir/repo"/*.tgz; do
[[ -f "$archive" ]] || continue
helm show chart "$archive" 2>/dev/null \
| awk '
/^name:/ { name = $2 }
/^version:/ { version = $2 }
/^appVersion:/ { app = $2; gsub(/"/, "", app) }
END { if (name != "") printf "%s|%s|%s\n", name, version, app }
'
done | sort -t '|' -k1,1 -k2,2V \
| awk -F '|' '
{ if ($1 == last) { row = $0 } else { if (last != "") print row; last = $1; row = $0 } }
END { if (last != "") print row }
'
)"
section="$workdir/newest-chart.md"
{
echo '<!-- newest-chart:begin -->'
echo '## Newest chart'
echo
echo "\`$chart_name\` **$VERSION** (app \`$app_version\`), published $published_at"
echo "from commit [\`${source_sha:0:7}\`]($source_server/$source_repo/commit/$source_sha)."
echo
echo '| Chart | Newest version | App version |'
echo '| --- | --- | --- |'
while IFS='|' read -r name version app; do
[[ -n "$name" ]] || continue
echo "| \`$name\` | \`$version\` | ${app:--} |"
done <<< "$newest_charts"
echo '<!-- newest-chart:end -->'
} > "$section"
readme="$workdir/repo/README.md"
updated_readme="$workdir/repo/README.md.new"
if [[ -f "$readme" ]] && grep -q '<!-- newest-chart:begin -->' "$readme"; then
awk -v section="$section" '
/<!-- newest-chart:begin -->/ {
while ((getline line < section) > 0) print line
skipping = 1
next
}
/<!-- newest-chart:end -->/ { skipping = 0; next }
!skipping { print }
' "$readme" > "$updated_readme"
else
# No generated section yet: put it before the first "## " heading.
{
if [[ -f "$readme" ]]; then
awk -v section="$section" '
!inserted && /^## / {
while ((getline line < section) > 0) print line
print ""
inserted = 1
}
{ print }
END {
if (!inserted) {
print ""
while ((getline line < section) > 0) print line
}
}
' "$readme"
else
{
echo '# Charts'
echo
echo 'Published Helm chart repository for TapTap projects.'
echo
}
cat "$section"
fi
} > "$updated_readme"
fi
mv "$updated_readme" "$readme"
git -C "$workdir/repo" add .
if git -C "$workdir/repo" diff --cached --quiet; then
echo "Chart $(basename "$CHART_DIR") $VERSION is already published."