#!/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