.github/workflows/undeploy.yml hinzugefügt
Some checks failed
Django Helm GitOps Deploy / build-and-test (push) Failing after 25s
Django Helm GitOps Deploy / deploy-prod (push) Has been skipped

This commit is contained in:
bast 2026-11-12 21:46:27 +00:00
parent 1dc49dd2aa
commit e7262e1c10

66
.github/workflows/undeploy.yml vendored Normal file
View file

@ -0,0 +1,66 @@
name: Undeploy (Terraform destroy)
# Nur manuell startbar: Forgejo -> Actions -> "Undeploy" -> Run workflow
on:
workflow_dispatch:
inputs:
environment:
description: "Welche Umgebung entfernen?"
type: choice
options: [ "test", "prod" ]
default: "test"
confirm:
description: "Zur Bestätigung den Umgebungsnamen nochmals eintippen"
type: string
required: true
delete_data:
description: "Auch die Datenbank (PVC) löschen? ACHTUNG: unwiderruflich"
type: boolean
default: false
jobs:
undeploy:
runs-on: ubuntu-latest
container: catthehacker/ubuntu:act-latest
steps:
- name: Check Confirmation
run: |
if [ "${{ inputs.confirm }}" != "${{ inputs.environment }}" ]; then
echo "Bestätigung stimmt nicht mit '${{ inputs.environment }}' überein, Abbruch."
exit 1
fi
- name: Checkout Code
uses: actions/checkout@v4
- name: Prepare Kubernetes Access
run: |
if [ "${{ inputs.environment }}" = "prod" ]; then
echo "${{ secrets.KUBECONFIG_TALOS }}" > ./talos_kubeconfig
chmod 600 ./talos_kubeconfig
test -s ./talos_kubeconfig || { echo "KUBECONFIG_TALOS ist leer oder fehlt"; exit 1; }
else
echo "${{ secrets.KUBECONFIG_DATA }}" > ./kind_kubeconfig
chmod 600 ./kind_kubeconfig
test -s ./kind_kubeconfig || { echo "KUBECONFIG_DATA ist leer oder fehlt"; exit 1; }
fi
# Entfernt den Helm-Release und räumt den Terraform-State auf
- name: Terraform Destroy
run: |
ENV=${{ inputs.environment }}
terraform init -reconfigure -backend-config=envs/${ENV}.backend.hcl
terraform destroy -auto-approve -var-file=envs/${ENV}.tfvars
# Helm löscht PVCs aus StatefulSets nicht – die DB bleibt sonst für den nächsten Deploy erhalten
- name: Delete Database Volume
if: inputs.delete_data
run: |
if [ "${{ inputs.environment }}" = "prod" ]; then
KC=./talos_kubeconfig; NS=boday-it
else
KC=./kind_kubeconfig; NS=default
fi
KARGS="--kubeconfig $KC"
[ "${{ inputs.environment }}" = "test" ] && KARGS="$KARGS --server https://local-k3s-platform:6443 --insecure-skip-tls-verify"
kubectl $KARGS delete pvc -n $NS db-data-boday-it-db-0 --ignore-not-found