chore(repo): init helm-charts repo with two charts and automated package/push

This commit is contained in:
Ivan087
2025-11-17 16:50:28 +08:00
commit e8451c0675
28 changed files with 1905 additions and 0 deletions

90
scripts/helm_publish.sh Executable file
View File

@ -0,0 +1,90 @@
#!/usr/bin/env bash
set -euo pipefail
# Package and push all Helm charts found under the repo
# Required env:
# HELM_OCI_NAMESPACE e.g. ghcr.io/OWNER or gitea.example.com/OWNER
# Optional env:
# HELM_USERNAME / HELM_PASSWORD for registry login
# CHART_DIRS: space-separated list of chart directories; if empty, auto-discover
# DRY_RUN=1: only package, do not push
# HELM_PUSH_EXTRA_ARGS: extra flags for `helm push` (e.g., --insecure-skip-tls-verify)
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT_DIR"
if [[ -z "${HELM_OCI_NAMESPACE:-}" ]]; then
echo "[helm_publish] HELM_OCI_NAMESPACE not set (e.g., ghcr.io/owner or gitea.example.com/owner)." >&2
exit 1
fi
# Derive registry host from HELM_OCI_NAMESPACE
HELM_REGISTRY_HOST="${HELM_OCI_NAMESPACE%%/*}"
# Auto-discover charts when CHART_DIRS not provided
if [[ -z "${CHART_DIRS:-}" ]]; then
mapfile -t chart_paths < <(find . -maxdepth 2 -type f -name Chart.yaml -not -path "*/charts/*" | sort)
if [[ ${#chart_paths[@]} -eq 0 ]]; then
echo "[helm_publish] No charts found (no Chart.yaml)." >&2
exit 1
fi
CHART_DIRS=""
for p in "${chart_paths[@]}"; do
d="$(dirname "$p")"
CHART_DIRS+=" ${d#./}"
done
fi
# Login if credentials present
if [[ -n "${HELM_USERNAME:-}" && -n "${HELM_PASSWORD:-}" ]]; then
echo "[helm_publish] Logging into registry ${HELM_REGISTRY_HOST} as ${HELM_USERNAME}"
helm registry login "$HELM_REGISTRY_HOST" -u "$HELM_USERNAME" -p "$HELM_PASSWORD"
else
echo "[helm_publish] HELM_USERNAME/HELM_PASSWORD not set; assuming registry creds already configured"
fi
status=0
for chart_dir in ${CHART_DIRS}; do
if [[ ! -f "$chart_dir/Chart.yaml" ]]; then
echo "[helm_publish] Skip $chart_dir (no Chart.yaml)"
continue
fi
echo "[helm_publish] Processing chart: $chart_dir"
# Ensure dependencies are built
if [[ -f "$chart_dir/Chart.yaml" ]]; then
helm dependency build "$chart_dir" || true
fi
pkg_out_dir="$chart_dir/.packages"
mkdir -p "$pkg_out_dir"
# Lint chart (non-fatal)
if ! helm lint "$chart_dir"; then
echo "[helm_publish] Warning: helm lint failed for $chart_dir"
fi
# Package chart
pkg_path=$(helm package "$chart_dir" --destination "$pkg_out_dir" | awk '{print $NF}')
if [[ ! -f "$pkg_path" ]]; then
echo "[helm_publish] Failed to package $chart_dir" >&2
status=1
continue
fi
echo "[helm_publish] Packaged: $pkg_path"
if [[ "${DRY_RUN:-}" == "1" ]]; then
echo "[helm_publish] DRY_RUN enabled; skip push for $pkg_path"
continue
fi
# Push to OCI registry; Helm will use chart name from the package
echo "[helm_publish] Pushing $pkg_path to oci://$HELM_OCI_NAMESPACE"
if ! helm push ${HELM_PUSH_EXTRA_ARGS:-} "$pkg_path" "oci://$HELM_OCI_NAMESPACE"; then
echo "[helm_publish] Push failed for $pkg_path" >&2
status=1
fi
done
exit $status