#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" usage() { echo "Usage: $0 --context " >&2 } if [[ "${1:-}" != "--context" || -z "${2:-}" || -n "${3:-}" ]]; then usage exit 1 fi expected_context="$2" for cmd in curl kubectl sha256sum; do if ! command -v "$cmd" >/dev/null 2>&1; then echo "$cmd is required" >&2 exit 1 fi done current_context="$(kubectl config current-context)" if [[ "$current_context" != "$expected_context" ]]; then echo "Refusing bootstrap: current context is ${current_context}, expected ${expected_context}." >&2 exit 1 fi source "${REPO_ROOT}/bootstrap/argocd/version.env" manifest="$(mktemp)" cleanup() { rm -f "$manifest" } trap cleanup EXIT INT TERM curl -fsSL \ "https://raw.githubusercontent.com/argoproj/argo-cd/${ARGOCD_VERSION}/manifests/install.yaml" \ -o "$manifest" printf '%s %s\n' "$ARGOCD_INSTALL_SHA256" "$manifest" | sha256sum -c - kubectl --context "$expected_context" create namespace argocd --dry-run=client -o yaml | kubectl --context "$expected_context" apply -f - kubectl --context "$expected_context" apply \ --server-side \ --force-conflicts \ -n argocd \ -f "$manifest" kubectl --context "$expected_context" -n argocd \ rollout status deployment/argocd-server --timeout=300s kubectl --context "$expected_context" -n argocd \ rollout status deployment/argocd-repo-server --timeout=300s kubectl --context "$expected_context" apply \ -f "${REPO_ROOT}/bootstrap/argocd/control-plane-project.yaml" kubectl --context "$expected_context" apply \ -f "${REPO_ROOT}/bootstrap/argocd/root-application.yaml" echo "Argo CD ${ARGOCD_VERSION}, its control-plane project, and the root Application are installed."