Files
ngqileandClaude Opus 5.5 c7bc7a8dcb feat(deploy): Kubernetes manifests, secret and release scripts, and a manifest check
deploy/k8s holds a Kustomize base (a Deployment and Service for each of the ten
images, with the probes, settings and mounts from docs/deployment.md) and a prod
overlay that pins every image to one commit SHA and routes only the admin portal
and mobile-api's exact WhatsApp webhook path through Traefik with TLS.

Secrets never enter git: deploy/k8s/secrets.example holds placeholders, the filled
copy in deploy/k8s/secrets is ignored, and deploy/create-secrets.sh loads it
without printing a value. deploy/set-release.sh pins or rolls back the release.

deploy/check.sh (also a CI step) renders the overlay in one pinned container,
validates it with kubeconform and refuses public routes to internal services,
latest or untagged images, Secret data or literal secret env values, mixed SHAs
and a second or rolling service-counter; --release also refuses unfilled cluster
facts. --self-test proves each rule fires on its fixture.

OpenSpec change: add-k8s-deployment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
2026-12-03 19:03:28 +08:00

48 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
# Checks the production manifests (openspec spec cluster-deployment): renders deploy/k8s/overlays/prod, validates it
# against the Kubernetes schemas, then applies check_rules.py (public routes, pinned images, no secret data,
# one service-counter, all ten services present). Needs only Docker. The deploy folder goes to the container through stdin, so this also works
# against a remote Docker daemon (CI's DOCKER_HOST).
# deploy/check.sh check the prod overlay
# deploy/check.sh --self-test prove every rule fires on its fixture in deploy/check-fixtures
# deploy/check.sh --release also refuse any <…> placeholder; run it before every real apply
# deploy/check.sh --render print the rendered prod manifests
set -eu
IMAGE=alpine/k8s:1.33.4@sha256:b0523f0a244ddc4c8e055aa335c040d3d78b3ead5528f4544395f7f9f69c7b68
# Traefik's IngressRoute schema comes from the CRDs catalog; Kubernetes' own from kubeconform's default location.
CRDS='https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{.Group}}/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json'
cd "$(dirname "$0")/.."
in_container() {
tar -cf - deploy | docker run --rm -i "$IMAGE" sh -c "set -e; mkdir -p /w && tar -xf - -C /w && cd /w && $1"
}
case "${1:-}" in
--render)
in_container 'kubectl kustomize deploy/k8s/overlays/prod'
;;
--self-test)
in_container '
fail=0
for f in deploy/check-fixtures/*.yaml; do
expect=$(sed -n "1s/^# expect: //p" "$f")
flags=$(sed -n "2s/^# flags: //p" "$f")
if out=$(python3 -I deploy/check_rules.py $flags < "$f"); then got=pass; else got=$out; fi
case "$got" in
*"$expect"*) echo "ok $f" ;;
*) echo "FAIL $f: expected \"$expect\", got: $got"; fail=1 ;;
esac
done
exit $fail'
;;
""|--release)
in_container "
kubectl kustomize deploy/k8s/overlays/prod > /tmp/prod.yaml
kubeconform -strict -summary -schema-location default -schema-location '$CRDS' /tmp/prod.yaml
python3 -I deploy/check_rules.py --full ${1:-} < /tmp/prod.yaml && echo 'prod manifests: rules passed'"
;;
*)
echo "usage: $0 [--release|--self-test|--render]" >&2; exit 2
;;
esac