#!/usr/bin/env bash
# Build + deploy the fxhnt cockpit via Argo Workflows (in-cluster Kaniko build, no laptop push).
#
# Prereqs (one-time): the `fxhnt-cockpit` WorkflowTemplate is registered
#   (kubectl -n foxhunt apply -f infra/argo/cockpit-build-deploy.yaml)
# and this repo is pushed to the in-cluster GitLab as root/fxhnt.git.
#
# Usage:
#   ./scripts/argo-deploy-cockpit.sh                 # build+deploy HEAD of root/fxhnt master
#   ./scripts/argo-deploy-cockpit.sh <commit-sha>    # a specific commit
set -euo pipefail

SHA="${1:-HEAD}"
NS="foxhunt"

# Resolve HEAD to the real master sha so the in-cluster clone checks out exactly what was pushed.
if [ "$SHA" = "HEAD" ]; then
  SHA="$(git rev-parse HEAD)"
fi

echo "Submitting fxhnt-cockpit build+deploy for ${SHA} ..."
argo submit -n "$NS" --from=wftmpl/fxhnt-cockpit \
  -p commit-sha="$SHA" \
  --watch
