From 0ac226b0119340b4d263669db39f8bce477fa00a Mon Sep 17 00:00:00 2001 From: TapTap Date: Sat, 14 Nov 2026 10:03:44 +0000 Subject: [PATCH] ci: publish charts to TapTap/Charts Replace the OCI chart push with a classic Helm repository in the public TapTap/Charts repository. CI packages the chart, regenerates index.yaml and pushes both to main, so `helm repo add` and Kustomize helmCharts work. The publisher authenticates with the AUDIOMANAGER_CHARTS_TOKEN secret and supports an explicit VERSION for local releases. --- .gitea/workflows/ci.yaml | 12 ++---- README.md | 60 +++++++++++++++++++++-------- scripts/push-chart.sh | 83 ++++++++++++++++++++++++++++++---------- 3 files changed, 109 insertions(+), 46 deletions(-) diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index b09fdb0..2936b12 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -12,7 +12,6 @@ on: env: REGISTRY: gitea.tap-tap.win IMAGE_NAME: taptap/audiomanager - CHART_REPO: taptap/charts # Built by scripts/build-ci-image.sh from ci/Dockerfile. Bump the tag when # ci/Dockerfile changes. CI_IMAGE: gitea.tap-tap.win/taptap/audiomanager-ci:2 @@ -49,16 +48,11 @@ jobs: image: gitea.tap-tap.win/taptap/audiomanager-ci:2 permissions: contents: read - packages: write + env: + CHARTS_TOKEN: ${{ secrets.AUDIOMANAGER_CHARTS_TOKEN }} steps: - uses: actions/checkout@v4 - - name: Log in to the registry - run: | - echo "${{ secrets.AUDIOMANAGER_REGISTRY_TOKEN }}" \ - | helm registry login "$REGISTRY" \ - --username "${{ gitea.actor }}" \ - --password-stdin - - name: Package and push the chart + - name: Package and publish the chart run: scripts/push-chart.sh image: diff --git a/README.md b/README.md index cc49f13..981284d 100644 --- a/README.md +++ b/README.md @@ -704,50 +704,76 @@ UID 10001 (the chart sets `fsGroup: 10001`). The server exits at startup if a configured root path is missing or unreadable, so the pod will not pass its readiness probe in that case. -### 9.3 Chart registry +### 9.3 Chart repository -CI packages the chart and pushes it to the Gitea OCI registry after the `chart` -job passes. The package is available at: +The chart source lives in `charts/audiomanager` in this repository. CI packages +it and publishes the `.tgz` plus `index.yaml` to the public `TapTap/Charts` +repository: ```text -oci://gitea.tap-tap.win/taptap/charts/audiomanager +https://gitea.tap-tap.win/TapTap/Charts/raw/branch/main ``` +This is a classic Helm repository, so it supports both `helm repo add` and +Kustomize's `helmCharts` generator. The chart repository is public; the image +registry remains private. + Versions published by CI: - `main`: `-sha.`, for example `0.1.2-sha.` - `v*` tag: the tag without the leading `v`, for example `v0.2.0` -> `0.2.0` -The registry is private, and Helm keeps its own credentials (a Docker login is -not enough): +Use it with Helm: ```bash -helm registry login gitea.tap-tap.win -u TapTap +helm repo add taptap \ + https://gitea.tap-tap.win/TapTap/Charts/raw/branch/main +helm repo update +helm search repo taptap/audiomanager ``` Install a published chart: ```bash VERSION="0.1.2-sha." -helm upgrade --install audiomanager \ - oci://gitea.tap-tap.win/taptap/charts/audiomanager \ +helm upgrade --install audiomanager taptap/audiomanager \ --version "$VERSION" \ --namespace audiomanager \ --set users.existingSecret=audiomanager-users \ --set imagePullSecrets[0].name=audiomanager-registry ``` -Replace `VERSION` with the commit build shown in Gitea Actions or the package -list. +For Kustomize, use the same repository with `build --enable-helm`: -To package and push from a workstation, run `helm registry login` first and then: - -```bash -scripts/push-chart.sh # version from CI env, git, or Chart.yaml -VERSION=0.2.0 scripts/push-chart.sh # explicit version +```yaml +helmCharts: + - name: audiomanager + releaseName: audiomanager + namespace: audiomanager + repo: https://gitea.tap-tap.win/TapTap/Charts/raw/branch/main + version: 0.1.2-sha. + valuesFile: values.yaml ``` -The script writes the `.tgz` to `dist/`, which is ignored by git. +```bash +kustomize build --enable-helm deploy/overlays/prod | kubectl apply -f - +``` + +`kubectl apply -k` does not run the Helm inflator; render with `kustomize build +--enable-helm` (or `kubectl kustomize --enable-helm`) first. Kustomize's Helm +generator cannot authenticate, which is why `TapTap/Charts` is public. + +To publish from a workstation, either configure git credentials for +`TapTap/Charts` or pass a token explicitly: + +```bash +CHARTS_TOKEN= scripts/push-chart.sh +VERSION=0.2.0 CHARTS_TOKEN= scripts/push-chart.sh +``` + +The CI job uses the `AUDIOMANAGER_CHARTS_TOKEN` repository secret. The script +clones the chart repository, adds the packaged chart, regenerates `index.yaml` +and pushes to `main`. ### 9.4 Operations diff --git a/scripts/push-chart.sh b/scripts/push-chart.sh index 9ea15db..4828fef 100755 --- a/scripts/push-chart.sh +++ b/scripts/push-chart.sh @@ -1,9 +1,11 @@ #!/usr/bin/env bash # -# Package the Helm chart and push it to the OCI registry. +# Package the Helm chart and publish it to the classic Helm chart repository +# in TapTap/Charts. # -# Run `helm registry login ` first (CI does this with the package -# token). The version is: +# The repository keeps index.yaml and the packaged .tgz files on its main +# branch, so it works with `helm repo add` and Kustomize's helmCharts +# generator. The version is: # - VERSION if set, # - the pushed tag for a v* tag build, # - -sha. for a main branch build, @@ -12,30 +14,35 @@ set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -REGISTRY="${REGISTRY:-gitea.tap-tap.win}" -CHART_REPO="${CHART_REPO:-taptap/charts}" +CHARTS_REPO_URL="${CHARTS_REPO_URL:-https://gitea.tap-tap.win/TapTap/Charts.git}" +CHARTS_BRANCH="${CHARTS_BRANCH:-main}" +CHARTS_USERNAME="${CHARTS_USERNAME:-TapTap}" +CHARTS_TOKEN="${CHARTS_TOKEN:-}" +CHARTS_RAW_URL="${CHARTS_RAW_URL:-https://gitea.tap-tap.win/TapTap/Charts/raw/branch/main}" CHART_DIR="${CHART_DIR:-$ROOT/charts/audiomanager}" -OUTPUT_DIR="${OUTPUT_DIR:-$ROOT/dist}" VERSION="${VERSION:-}" usage() { cat <<'EOF' Usage: scripts/push-chart.sh [options] -Push the chart to oci:////audiomanager. +Package the chart and publish it to the classic Helm repository in +TapTap/Charts. Options: -h, --help Show this help Environment: - REGISTRY OCI registry (default: gitea.tap-tap.win) - CHART_REPO Repository path below the registry (default: taptap/charts) - CHART_DIR Chart directory (default: charts/audiomanager) - OUTPUT_DIR Directory for the packaged chart (default: dist) - VERSION Chart version to package (overrides auto-detection) - -Run `helm registry login ` before this script if the registry is -private. + CHARTS_REPO_URL Git URL of the chart repository + (default: https://gitea.tap-tap.win/TapTap/Charts.git) + CHARTS_BRANCH Published branch (default: main) + CHARTS_USERNAME Git username for the chart repository (default: TapTap) + CHARTS_TOKEN Token with write access to the chart repository. When empty, + normal git credentials are used. + CHARTS_RAW_URL Public URL written into index.yaml + (default: https://gitea.tap-tap.win/TapTap/Charts/raw/branch/main) + CHART_DIR Chart directory (default: charts/audiomanager) + VERSION Chart version to package (overrides auto-detection) EOF } @@ -62,10 +69,46 @@ if [[ -z "$VERSION" ]]; then fi fi -mkdir -p "$OUTPUT_DIR" -package="$OUTPUT_DIR/$(basename "$CHART_DIR")-${VERSION}.tgz" +workdir="$(mktemp -d "${TMPDIR:-/tmp}/charts-publish.XXXXXX")" +trap 'rm -rf "$workdir"' EXIT -helm package "$CHART_DIR" --version "$VERSION" --destination "$OUTPUT_DIR" -helm push "$package" "oci://${REGISTRY}/${CHART_REPO}" +if [[ -n "$CHARTS_TOKEN" ]]; then + askpass="$workdir/askpass.sh" + cat > "$askpass" <<'SH' +#!/bin/sh +case "$1" in + *Username*) printf '%s\n' "${CHARTS_USERNAME:?}" ;; + *Password*) printf '%s\n' "${CHARTS_TOKEN:?}" ;; +esac +SH + chmod 700 "$askpass" + export CHARTS_USERNAME CHARTS_TOKEN + export GIT_ASKPASS="$askpass" + export GIT_TERMINAL_PROMPT=0 +fi -echo "Pushed chart to oci://${REGISTRY}/${CHART_REPO}/$(basename "$CHART_DIR") --version ${VERSION}" +git clone --quiet --depth=1 --branch "$CHARTS_BRANCH" \ + "$CHARTS_REPO_URL" "$workdir/repo" + +chart_name="$(awk '/^name:/ { print $2; exit }' "$CHART_DIR/Chart.yaml")" +if [[ -f "$workdir/repo/${chart_name}-${VERSION}.tgz" ]]; then + echo "Chart $chart_name $VERSION is already published." + exit 0 +fi + +helm package "$CHART_DIR" --version "$VERSION" --destination "$workdir/repo" +helm repo index "$workdir/repo" --url "$CHARTS_RAW_URL" + +git -C "$workdir/repo" add . +if git -C "$workdir/repo" diff --cached --quiet; then + echo "Chart $(basename "$CHART_DIR") $VERSION is already published." + exit 0 +fi + +git -C "$workdir/repo" \ + -c user.name="${GIT_AUTHOR_NAME:-Chart Publisher}" \ + -c user.email="${GIT_AUTHOR_EMAIL:-charts@tap-tap.win}" \ + commit -q -m "chart: publish $(basename "$CHART_DIR") $VERSION" +git -C "$workdir/repo" push -q origin "$CHARTS_BRANCH" + +echo "Published $(basename "$CHART_DIR") $VERSION to $CHARTS_RAW_URL"