droboticflow/scripts/ops-rollout-api-image.sh
eust-w d5da39f5c6 🔖 Prepare POC rendering build with API-only rollout
Bump the workspace build version to 1.1.10 per the release policy.
Add poc.api-image to pin only the API container by digest, with server
 dry-run, POC/repository guards and a resource-version precondition.
Preserve all other deployments, operator pins, ConfigMaps and Secrets.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-11-05 05:09:20 +08:00

44 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Pin only the POC API image and its reported image metadata. Never re-render cluster configuration.
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source "$ROOT_DIR/scripts/load-deploy-env.sh"
if [[ "${DEPLOY_ENV:-}" != "poc" || "${K8S_NAMESPACE:-}" != "droboticflow" ]]; then
printf 'ERROR: this action only targets POC namespace droboticflow.\n' >&2
exit 2
fi
if [[ ! "${API_IMAGE:-}" =~ ^[^/[:space:]]+/dataflow-poc/droboticflow-api@sha256:[a-f0-9]{64}$ ]]; then
printf 'ERROR: API_IMAGE must be a dataflow-poc/droboticflow-api image pinned by sha256 digest.\n' >&2
exit 2
fi
case "${DRY_RUN:-true}" in
true) dry_mode=server ;;
false) dry_mode=none ;;
*) printf 'ERROR: DRY_RUN must be true or false.\n' >&2; exit 2 ;;
esac
export API_IMAGE
patch="$(kubectl -n "$K8S_NAMESPACE" get deployment droboticflow-api -o json | python3 -c '
import json, os, sys
current = json.load(sys.stdin)
image = os.environ["API_IMAGE"]
repo = image.split("@", 1)[0]
api = next(c for c in current["spec"]["template"]["spec"]["containers"] if c["name"] == "api")
old = api["image"]
if not (old == repo or old.startswith(repo + "@") or old.startswith(repo + ":")):
raise SystemExit("refusing to switch the API to a different image repository")
print("Previous API revision=" + current["metadata"].get("annotations", {}).get("deployment.kubernetes.io/revision", "unknown") + " image=" + old, file=sys.stderr)
print(json.dumps({
"metadata": {"resourceVersion": current["metadata"]["resourceVersion"]},
"spec": {"template": {"spec": {"containers": [{"name": "api", "image": image,
"env": [{"name": "DROBOTICFLOW_IMAGE", "value": image, "valueFrom": None}]}]}}}
}))
')"
kubectl -n "$K8S_NAMESPACE" patch deployment droboticflow-api --type strategic --dry-run="$dry_mode" -p "$patch"
if [[ "${DRY_RUN:-true}" == "true" ]]; then
printf 'DRY-RUN: validated API-only image update; no deployment was changed.\n'
exit 0
fi
kubectl -n "$K8S_NAMESPACE" rollout status deployment/droboticflow-api --timeout=600s