my-app-sandbox/.github/workflows/deploy.yml
bast 6339aa6496
Some checks failed
Build, Push and GitOps Deploy / test-and-deploy (push) Failing after 16s
.github/workflows/deploy.yml aktualisiert
2026-10-31 18:51:25 +00:00

68 lines
2.8 KiB
YAML
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.

name: Build, Push and GitOps Deploy
on:
push:
branches: [ "main" ]
workflow_dispatch:
jobs:
test-and-deploy:
runs-on: ubuntu-latest
container: catthehacker/ubuntu:act-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Activate Included Terraform Binary
run: |
mv ./terraform /usr/local/bin/terraform 2>/dev/null || echo "Nutze vorhandenes File"
chmod +x /usr/local/bin/terraform
terraform --version
- name: Trust Local Nginx Certificate Inside Container
run: |
mkdir -p /usr/local/share/ca-certificates/
cp nginx_ssl/nginx.crt /usr/local/share/ca-certificates/nginx-sandbox.crt 2>/dev/null || echo "Nutze Workspace-Zertifikat"
update-ca-certificates
- name: Log in to Local Registry
run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login localhost:3005 -u ${{ github.actor }} --password-stdin
- name: Inject Version into Dockerfile
run: sed -i "s/{{APP_VERSION}}/${{ github.sha }}/g" Dockerfile
- name: Build App Image
run: |
docker build -t localhost:3005/${{ github.repository }}:${{ github.sha }} .
docker build -t localhost:3005/${{ github.repository }}:latest .
- name: Push App Image
run: |
docker push localhost:3005/${{ github.repository }}:${{ github.sha }}
docker push localhost:3005/${{ github.repository }}:latest
# --- DIE OFFIZIELLE INFRASTRUKTUR-RETTUNG ---
# Schreibt die echten Cluster-Zugangsdaten direkt sicher in den Workspace
- name: Prepare Kubernetes Access
run: |
echo "${{ secrets.KUBECONFIG_DATA }}" > ./kind_kubeconfig
chmod 600 ./kind_kubeconfig
- name: Terraform Deploy
run: |
terraform init
# Wir adoptieren die bestehenden Kubernetes-Ressourcen fliegend in den lokalen State
terraform import -var="app_version=${{ github.sha }}" -insecure kubernetes_deployment.webapp default/webapp || echo "Bereits importiert oder übersprungen"
terraform import -var="app_version=${{ github.sha }}" -insecure kubernetes_service.webapp_service default/webapp-service || echo "Bereits importiert oder übersprungen"
terraform import -var="app_version=${{ github.sha }}" -insecure helm_release.nginx_ingress kube-system/nginx-ingress || echo "Bereits importiert oder übersprungen"
# Jetzt sauber updaten – zieht das neue Image via registry.local!
terraform apply -auto-approve -var="app_version=${{ github.sha }}"
- name: Verify App Health
run: |
echo "Warte auf das Ingress-Routing..."
sleep 15
curl --fail --connect-timeout 5 http://local-k3s-platform:80/ || exit 1
echo "Erfolg: Die App läuft fehlerfrei nach dem Update!"