This repository has been archived on 2026-10-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
authentik-deployment/create-ci-kubeconfig.sh
T
feedc0de d988c8831a
Validate and deploy Authentik / validate (push) Successful in 18s
Validate and deploy Authentik / deploy (push) Successful in 26s
Introduce CI/CD
2026-09-05 11:51:27 +02:00

16 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
project_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd); namespace=authentik
account=authentik-deployer; secret=authentik-deployer-token; remote=${KUBECTL_SSH_HOST:-}
k() { if [[ -n "${remote}" ]]; then ssh "${remote}" kubectl "$@"; else kubectl "$@"; fi; }
if [[ -n "${remote}" ]]; then k apply -f - < "${project_dir}/ci-deployer.yaml" >&2; else k apply -f "${project_dir}/ci-deployer.yaml" >&2; fi
for attempt in {1..30}; do data=$(k -n "$namespace" get secret "$secret" -o jsonpath='{.data.token}' 2>/dev/null || true); [[ -n "$data" ]] && break; sleep 1; done
[[ -n "${data:-}" ]] || { echo "Token was not issued" >&2; exit 1; }
work=$(mktemp -d); trap 'rm -rf "${work}"' EXIT
server=$(k config view --minify -o jsonpath='{.clusters[0].cluster.server}')
k -n "$namespace" get secret "$secret" -o jsonpath='{.data.ca\.crt}' | base64 -d > "$work/ca"
export KUBECONFIG="$work/config"; kubectl config set-cluster cluster --server="$server" --certificate-authority="$work/ca" --embed-certs=true >/dev/null
kubectl config set-credentials "$account" --token="$(printf %s "$data" | base64 -d)" >/dev/null
kubectl config set-context authentik --cluster=cluster --user="$account" --namespace="$namespace" >/dev/null; kubectl config use-context authentik >/dev/null
echo "Store as Gitea Actions secret KUBE_CONFIG_BASE64; do not commit." >&2; base64 -w0 "$KUBECONFIG"; printf '\n'