#!/bin/bash

# Define variables from configuration
github_repo_url="git@github.com:suno-ai/glockenspiel.git"
github_repo_path="argo-apps"
github_repo_branch="main"

# Create the argocd namespace
kubectl create namespace argocd || true

# Add the argocd helm repository
helm repo add argoproj https://argoproj.github.io/argo-helm

# Install argocd using helm
helm upgrade --install argocd argoproj/argo-cd --version 6.7.10 --namespace argocd

# Define the ArgoCD application manifest
cat <<EOF | kubectl apply -f -
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: argo-apps
  namespace: argocd
spec:
  project: default
  source:
    repoURL: "$github_repo_url"
    path: "$github_repo_path"
    targetRevision: "$github_repo_branch"
  destination:
    server: "https://kubernetes.default.svc"
    namespace: argocd
EOF
