Compare commits
2
Commits
0cd0b9582d
...
f1dc60aae5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1dc60aae5 | ||
|
|
8e87fed93f |
No files matched your search
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
Executable
+80
@@ -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"
|
||||
@@ -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."
|
||||
|
||||
Reference in new issue
Block a user