.github/workflows/undeploy.yml hinzugefügt
This commit is contained in:
parent
1dc49dd2aa
commit
e7262e1c10
1 changed files with 66 additions and 0 deletions
66
.github/workflows/undeploy.yml
vendored
Normal file
66
.github/workflows/undeploy.yml
vendored
Normal 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
|
||||||
Loading…
Reference in a new issue