Skip to content

Commit f823c19

Browse files
author
zhangxq
committed
feat(helm): add helper scripts and CI lint workflow
Add 5 helper scripts under deploy/helm/scripts/ and 1 CI workflow that lints and renders all Helm profiles. Scripts (executable, set -euo pipefail) - render.sh [profile]: renders one or all profiles (dev|staging|prod|all) to rendered/<profile>.yaml - install-dev.sh: one-click dev install with namespace xarch-dev, port-forwards instructions - install-prod.sh: one-click prod install requiring IMAGE_REGISTRY, IMAGE_TAG, DB_PASSWORD, NACOS_PASSWORD, REDIS_PASSWORD env vars; uses --atomic and 30m timeout - dry-run.sh: helm install --dry-run all profiles, writes to /tmp/xarch-<profile>-dryrun.yaml - lint.sh: helm lint + helm template (default + prod) CI (helm-lint.yml) - Triggers on push to deploy/helm/**, PR to same path, manual - Sets up helm v3.16.2 via azure/setup-helm@v4 - Runs helm lint on root chart + all 6 sub-charts - helm template for dev, staging, prod into /tmp/*.yaml - helm install --dry-run --debug for prod to /tmp/prod-dryrun.yaml - Uploads render artifacts (retained 7 days) on success - Optional helm-docs run with continue-on-error
1 parent 606376a commit f823c19

6 files changed

Lines changed: 266 additions & 0 deletions

File tree

.github/workflows/helm-lint.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# ===============================================
2+
# Helm chart CI: lint + render all profiles
3+
# ===============================================
4+
name: helm-lint
5+
6+
on:
7+
push:
8+
paths:
9+
- 'deploy/helm/**'
10+
- '.github/workflows/helm-lint.yml'
11+
pull_request:
12+
paths:
13+
- 'deploy/helm/**'
14+
workflow_dispatch:
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
lint:
21+
name: Lint and render
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 10
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Setup Helm
29+
uses: azure/setup-helm@v4
30+
with:
31+
version: v3.16.2
32+
33+
- name: helm lint
34+
run: |
35+
echo "==> helm lint (root chart)"
36+
helm lint deploy/helm/xarch
37+
echo "==> helm lint (microservice subchart)"
38+
helm lint deploy/helm/xarch/charts/microservice
39+
echo "==> helm lint (gateway subchart)"
40+
helm lint deploy/helm/xarch/charts/gateway
41+
echo "==> helm lint (mysql subchart)"
42+
helm lint deploy/helm/xarch/charts/mysql
43+
echo "==> helm lint (redis subchart)"
44+
helm lint deploy/helm/xarch/charts/redis
45+
echo "==> helm lint (nacos subchart)"
46+
helm lint deploy/helm/xarch/charts/nacos
47+
echo "==> helm lint (observability subchart)"
48+
helm lint deploy/helm/xarch/charts/observability
49+
50+
- name: helm template (dev)
51+
run: helm template xarch deploy/helm/xarch --values deploy/helm/values-dev.yaml > /tmp/dev.yaml
52+
53+
- name: helm template (staging)
54+
run: helm template xarch deploy/helm/xarch --values deploy/helm/values-staging.yaml > /tmp/staging.yaml
55+
56+
- name: helm template (prod)
57+
run: helm template xarch deploy/helm/xarch --values deploy/helm/values-prod.yaml > /tmp/prod.yaml
58+
59+
- name: helm install --dry-run (prod)
60+
run: |
61+
helm install xarch deploy/helm/xarch \
62+
--values deploy/helm/values-prod.yaml \
63+
--dry-run --debug \
64+
> /tmp/prod-dryrun.yaml 2>&1
65+
echo "Dry-run render: $(wc -l < /tmp/prod-dryrun.yaml) lines"
66+
67+
- name: Upload render artifacts
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: helm-rendered
71+
path: |
72+
/tmp/dev.yaml
73+
/tmp/staging.yaml
74+
/tmp/prod.yaml
75+
/tmp/prod-dryrun.yaml
76+
if-no-files-found: error
77+
retention-days: 7
78+
79+
- name: helm-docs (if available)
80+
run: |
81+
if command -v helm-docs >/dev/null 2>&1; then
82+
helm-docs --chart-search-root=deploy/helm
83+
else
84+
echo "helm-docs not installed; skipping README regeneration"
85+
fi
86+
continue-on-error: true

deploy/helm/scripts/dry-run.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
# ===============================================
3+
# Helm install --dry-run all profiles
4+
# ===============================================
5+
set -euo pipefail
6+
7+
HERE="$(cd "$(dirname "$0")" && pwd)"
8+
CHART_DIR="$(cd "$HERE/../xarch" && pwd)"
9+
10+
for profile in dev staging prod; do
11+
echo "==> Dry-run: $profile"
12+
helm install xarch "$CHART_DIR" \
13+
--values "$CHART_DIR/../values-$profile.yaml" \
14+
--dry-run --debug \
15+
> "/tmp/xarch-$profile-dryrun.yaml" 2>&1
16+
echo " rendered to /tmp/xarch-$profile-dryrun.yaml ($(wc -l < /tmp/xarch-$profile-dryrun.yaml) lines)"
17+
done
18+
19+
echo ""
20+
echo "All dry-runs complete."

deploy/helm/scripts/install-dev.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
# ===============================================
3+
# One-click install for development
4+
# ===============================================
5+
set -euo pipefail
6+
7+
HERE="$(cd "$(dirname "$0")" && pwd)"
8+
CHART_DIR="$(cd "$HERE/../xarch" && pwd)"
9+
VALUES_FILE="$CHART_DIR/../values-dev.yaml"
10+
11+
echo "==> Installing xarch (dev profile) via Helm"
12+
helm upgrade --install xarch "$CHART_DIR" \
13+
--namespace xarch-dev --create-namespace \
14+
--values "$VALUES_FILE" \
15+
--set global.imageRegistry="${IMAGE_REGISTRY:-ghcr.io/processcrash}" \
16+
--wait --timeout 10m \
17+
"$@"
18+
19+
echo ""
20+
echo "==> Useful commands:"
21+
echo " kubectl -n xarch-dev get pods"
22+
echo " kubectl -n xarch-dev get svc"
23+
echo " kubectl -n xarch-dev port-forward svc/xarch-gateway 8080:9000"
24+
echo " kubectl -n xarch-dev port-forward svc/xarch-nacos 8848:8848"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
# ===============================================
3+
# One-click install for production
4+
# ===============================================
5+
# Required env vars:
6+
# IMAGE_REGISTRY - container registry (e.g. ghcr.io/processcrash)
7+
# IMAGE_TAG - image tag to deploy (e.g. 1.0.0)
8+
# DB_PASSWORD - master database password
9+
# NACOS_PASSWORD - Nacos admin password
10+
# REDIS_PASSWORD - Redis password
11+
# Optional:
12+
# STORAGE_CLASS - Kubernetes storage class (default: gp3)
13+
# INGRESS_HOST - public hostname for ingress
14+
# TLS_SECRET_NAME - TLS secret name in the cluster
15+
16+
set -euo pipefail
17+
18+
: "${IMAGE_REGISTRY:?must be set}"
19+
: "${IMAGE_TAG:?must be set}"
20+
: "${DB_PASSWORD:?must be set}"
21+
: "${NACOS_PASSWORD:?must be set}"
22+
: "${REDIS_PASSWORD:?must be set}"
23+
STORAGE_CLASS="${STORAGE_CLASS:-gp3}"
24+
INGRESS_HOST="${INGRESS_HOST:-xarch.example.com}"
25+
TLS_SECRET_NAME="${TLS_SECRET_NAME:-xarch-tls}"
26+
27+
HERE="$(cd "$(dirname "$0")" && pwd)"
28+
CHART_DIR="$(cd "$HERE/../xarch" && pwd)"
29+
VALUES_FILE="$CHART_DIR/../values-prod.yaml"
30+
31+
# Pre-create TLS secret if not already there
32+
if ! kubectl get secret "$TLS_SECRET_NAME" >/dev/null 2>&1; then
33+
echo "WARN: TLS secret $TLS_SECRET_NAME does not exist; provision cert-manager first" >&2
34+
fi
35+
36+
echo "==> Installing xarch (prod profile) via Helm"
37+
helm upgrade --install xarch "$CHART_DIR" \
38+
--namespace xarch --create-namespace \
39+
--values "$VALUES_FILE" \
40+
--set global.imageRegistry="$IMAGE_REGISTRY" \
41+
--set global.imageTag="$IMAGE_TAG" \
42+
--set mysql.auth.rootPassword="$DB_PASSWORD" \
43+
--set nacos.auth.admin.password="$NACOS_PASSWORD" \
44+
--set redis.auth.password="$REDIS_PASSWORD" \
45+
--set ingress.hosts[0].host="$INGRESS_HOST" \
46+
--set ingress.tls[0].secretName="$TLS_SECRET_NAME" \
47+
--set persistence.storageClass="$STORAGE_CLASS" \
48+
--atomic \
49+
--wait --timeout 30m \
50+
"$@"
51+
52+
echo ""
53+
echo "==> Production install complete. Verify:"
54+
echo " kubectl -n xarch get pods"
55+
echo " kubectl -n xarch get ingress"
56+
echo " curl -k https://$INGRESS_HOST/actuator/health"

deploy/helm/scripts/lint.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
# ===============================================
3+
# Helm chart lint + render test
4+
# ===============================================
5+
set -euo pipefail
6+
7+
HERE="$(cd "$(dirname "$0")" && pwd)"
8+
CHART_DIR="$(cd "$HERE/../xarch" && pwd)"
9+
10+
echo "==> helm lint"
11+
helm lint "$CHART_DIR"
12+
13+
echo ""
14+
echo "==> helm template (default values)"
15+
helm template xarch "$CHART_DIR" \
16+
--debug \
17+
> /tmp/xarch-lint.yaml 2>&1
18+
echo " wrote /tmp/xarch-lint.yaml ($(wc -l < /tmp/xarch-lint.yaml) lines)"
19+
20+
echo ""
21+
echo "==> helm template (prod profile)"
22+
helm template xarch "$CHART_DIR" \
23+
--values "$CHART_DIR/../values-prod.yaml" \
24+
> /tmp/xarch-prod.yaml 2>&1
25+
echo " wrote /tmp/xarch-prod.yaml ($(wc -l < /tmp/xarch-prod.yaml) lines)"
26+
27+
echo ""
28+
echo "Lint and template complete."

deploy/helm/scripts/render.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
# ===============================================
3+
# Render all Helm profiles for review
4+
# ===============================================
5+
# Usage:
6+
# ./deploy/helm/scripts/render.sh [profile]
7+
# profiles: dev (default) | staging | prod | all
8+
9+
set -euo pipefail
10+
11+
HERE="$(cd "$(dirname "$0")" && pwd)"
12+
CHART_DIR="$(cd "$HERE/../xarch" && pwd)"
13+
OUTPUT_DIR="$CHART_DIR/rendered"
14+
PROFILE="${1:-all}"
15+
16+
mkdir -p "$OUTPUT_DIR"
17+
18+
render_profile() {
19+
local profile="$1"
20+
local values_file="$CHART_DIR/values-$profile.yaml"
21+
local output_file="$OUTPUT_DIR/$profile.yaml"
22+
23+
if [[ ! -f "$values_file" ]]; then
24+
echo "ERROR: values file not found: $values_file" >&2
25+
return 1
26+
fi
27+
28+
echo "==> Rendering $profile (using $values_file)"
29+
helm template xarch "$CHART_DIR" \
30+
--values "$values_file" \
31+
> "$output_file"
32+
echo " wrote $output_file ($(wc -l < "$output_file") lines)"
33+
}
34+
35+
case "$PROFILE" in
36+
all)
37+
for p in dev staging prod; do
38+
render_profile "$p"
39+
done
40+
;;
41+
dev|staging|prod)
42+
render_profile "$PROFILE"
43+
;;
44+
*)
45+
echo "Unknown profile: $PROFILE (use dev|staging|prod|all)" >&2
46+
exit 1
47+
;;
48+
esac
49+
50+
echo ""
51+
echo "All renders complete. Diff against k8s/base for sanity:"
52+
echo " diff -r $OUTPUT_DIR $CHART_DIR/../../k8s/base"

0 commit comments

Comments
 (0)