#!/usr/bin/env bash # build-push.sh — build and push humor-units image to the in-cluster registry # Usage: ./build-push.sh [tag] # Requires: buildah, kubectl set -euo pipefail TAG="${1:-latest}" # In-cluster address — how the deployment manifest references the image REGISTRY="registry.registry.svc.cluster.local:5000" IMAGE="$REGISTRY/humor-units:$TAG" echo "==> Port-forwarding registry (localhost:5000 -> in-cluster registry)..." kubectl port-forward -n registry svc/registry 5000:5000 & PF_PID=$! trap "kill $PF_PID 2>/dev/null" EXIT sleep 2 echo "==> Building $IMAGE..." buildah build \ --format docker \ --tag "$IMAGE" \ "$(dirname "$0")" echo "==> Pushing via port-forward (localhost:5000)..." # Push to localhost:5000 (the port-forward tunnel) but with the in-cluster tag. # buildah push accepts a separate destination so we don't retag. buildah push \ --tls-verify=false \ "$IMAGE" \ "docker://localhost:5000/humor-units:$TAG" echo "==> Restarting humor-units deployment..." kubectl rollout restart deployment/humor-units -n default echo "==> Done. Waiting for rollout..." kubectl rollout status deployment/humor-units -n default