Files
k3s_auto_deploy/scripts/create-argocd-app.sh

53 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
CONFIG_FILE="$PROJECT_DIR/config/cluster-vars.yml"
echo "=== 创建ArgoCD Application ==="
# 读取配置
GIT_REPO=$(yq eval '.git_repo_url' "$CONFIG_FILE")
GIT_USERNAME=$(yq eval '.gitea_user_name' "$CONFIG_FILE")
GIT_PASSWORD=$(yq eval '.gitea_user_password' "$CONFIG_FILE")
# 配置Gitea仓库凭证
echo "🔐 配置Gitea仓库凭证..."
kubectl create secret generic gitea-creds \
-n argocd \
--from-literal=username="$GIT_USERNAME" \
--from-literal=password="$GIT_PASSWORD" \
--dry-run=client -o yaml | kubectl apply -f -
# 生成Application配置
cat > /tmp/argocd-app.yaml <<EOF
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: demo-app
namespace: argocd
spec:
project: default
source:
repoURL: $GIT_REPO
targetRevision: main
path: manifests
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
EOF
# 应用配置
kubectl apply -f /tmp/argocd-app.yaml
echo "✅ ArgoCD Application创建成功"
echo "📊 查看状态: kubectl get application -n argocd"
echo "🌐 访问ArgoCD查看同步状态"