From c409145cedd903b20b834130ccc6b1d5099ea8cf Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sat, 10 Jan 2026 21:43:12 +0000 Subject: [PATCH] initial upload --- README.md | 45 ++++++++++++++++++ .../.gitea/workflows/docker-build.yaml | 47 +++++++++++++++++++ repo-gitops/apps/whoami/base/deployment.yaml | 33 +++++++++++++ .../apps/whoami/base/kustomization.yaml | 5 ++ .../overlays/production/kustomization.yaml | 20 ++++++++ repo-gitops/bootstrap/root-app.yaml | 20 ++++++++ repo-gitops/cluster/production/whoami.yaml | 20 ++++++++ 7 files changed, 190 insertions(+) create mode 100644 README.md create mode 100644 repo-app-source/.gitea/workflows/docker-build.yaml create mode 100644 repo-gitops/apps/whoami/base/deployment.yaml create mode 100644 repo-gitops/apps/whoami/base/kustomization.yaml create mode 100644 repo-gitops/apps/whoami/overlays/production/kustomization.yaml create mode 100644 repo-gitops/bootstrap/root-app.yaml create mode 100644 repo-gitops/cluster/production/whoami.yaml diff --git a/README.md b/README.md new file mode 100644 index 0000000..2d66f07 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# CI/CD Strategie: Gitea Actions & ArgoCD + +Diese Strategie trennt den **Build-Prozess** (CI) strikt vom **Deployment-Prozess** (CD). + +## Der Workflow + +1. **Code Change (CI):** + * Du pushst Code in ein App-Repo (z.B. `stabify/whoami`). + * **Gitea Actions** springt an. + * Der Code wird getestet und ein Docker Image gebaut. + * Das Image wird in die Container Registry gepusht (z.B. `harbor.stabify.de/library/whoami:v1.0.1`). + +2. **Config Change (GitOps):** + * Um das neue Image zu deployen, änderst du den Tag im **GitOps Repo** (`stabify/gitops`). + * Datei: `apps/whoami/overlays/production/kustomization.yaml` -> `newTag: v1.0.1`. + * Du commitest und pushst diese Änderung. + +3. **Deployment (CD):** + * **ArgoCD** (läuft im Cluster) bemerkt den neuen Commit im GitOps Repo. + * ArgoCD vergleicht IST-Zustand (Cluster) mit SOLL-Zustand (Git). + * ArgoCD führt das Update durch (Rolling Update). + +--- + +## Repository Struktur (Simuliert in diesem Ordner) + +### 1. `repo-app-source` +Hier liegt der Quellcode deiner Anwendung. +* Enthält den Source Code (Go, Node, Python...). +* Enthält das `Dockerfile`. +* Enthält die `.gitea/workflows/ci.yaml` Pipeline Definition. + +### 2. `repo-gitops` +Hier liegt der Zustand deines Clusters. +* **`bootstrap/`**: Der Einstiegspunkt für ArgoCD ("App of Apps"). +* **`cluster/production/`**: Definiert, WELCHE Apps auf dem Produktions-Cluster laufen sollen. +* **`apps/`**: Enthält die eigentlichen K8s Manifeste (Deployments, Services, Ingress). + * Wir nutzen **Kustomize** (Base/Overlay Struktur). + * **Base**: Allgemeine Definition der App. + * **Overlay**: Umgebungsspezifische Anpassungen (z.B. Hostnames, Replicas, Image Tags für Prod). + +## Vorteile dieser Struktur +* **Sicherheit:** CI Server braucht keinen Cluster-Zugriff. +* **Übersicht:** Das GitOps Repo ist die "Single Source of Truth". +* **Wiederherstellbarkeit:** Cluster kaputt? Einfach ArgoCD installieren, auf das Repo zeigen, warten -> Fertig. diff --git a/repo-app-source/.gitea/workflows/docker-build.yaml b/repo-app-source/.gitea/workflows/docker-build.yaml new file mode 100644 index 0000000..8352d5b --- /dev/null +++ b/repo-app-source/.gitea/workflows/docker-build.yaml @@ -0,0 +1,47 @@ +name: Build and Push Docker Image +run-name: ${{ gitea.actor }} is building Docker Image 🚀 + +on: + push: + branches: + - main + tags: + - 'v*' + +jobs: + build-push: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io # Oder deine eigene Registry (z.B. harbor.stabify.de) + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ gitea.repository }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=sha + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/repo-gitops/apps/whoami/base/deployment.yaml b/repo-gitops/apps/whoami/base/deployment.yaml new file mode 100644 index 0000000..2ac2bf1 --- /dev/null +++ b/repo-gitops/apps/whoami/base/deployment.yaml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: whoami + labels: + app: whoami +spec: + replicas: 1 + selector: + matchLabels: + app: whoami + template: + metadata: + labels: + app: whoami + spec: + containers: + - name: whoami + image: traefik/whoami:latest + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: whoami +spec: + selector: + app: whoami + ports: + - protocol: TCP + port: 80 + targetPort: 80 diff --git a/repo-gitops/apps/whoami/base/kustomization.yaml b/repo-gitops/apps/whoami/base/kustomization.yaml new file mode 100644 index 0000000..88a04b5 --- /dev/null +++ b/repo-gitops/apps/whoami/base/kustomization.yaml @@ -0,0 +1,5 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - deployment.yaml diff --git a/repo-gitops/apps/whoami/overlays/production/kustomization.yaml b/repo-gitops/apps/whoami/overlays/production/kustomization.yaml new file mode 100644 index 0000000..ab3e494 --- /dev/null +++ b/repo-gitops/apps/whoami/overlays/production/kustomization.yaml @@ -0,0 +1,20 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - ../../base + +# Patches für Produktion +patches: + - target: + kind: Deployment + name: whoami + patch: |- + - op: replace + path: /spec/replicas + value: 2 + +# Hier ändern wir das Image für Produktion (Das ist die Zeile, die wir beim Release anpassen!) +images: + - name: traefik/whoami + newTag: v1.8.0 diff --git a/repo-gitops/bootstrap/root-app.yaml b/repo-gitops/bootstrap/root-app.yaml new file mode 100644 index 0000000..175be67 --- /dev/null +++ b/repo-gitops/bootstrap/root-app.yaml @@ -0,0 +1,20 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: production-cluster + namespace: argocd + finalizers: + - resources-finalizer.argocd.argoproj.io # Löscht alle Apps, wenn diese App gelöscht wird (Vorsicht!) +spec: + project: default + source: + repoURL: https://git.stabify.de/stabify/gitops.git # URL DEINES GitOps Repos anpassen! + targetRevision: HEAD + path: cluster/production + destination: + server: https://kubernetes.default.svc + namespace: argocd + syncPolicy: + automated: + prune: true # Löscht Ressourcen, die nicht mehr im Git sind + selfHeal: true # Repariert manuelle Änderungen automatisch diff --git a/repo-gitops/cluster/production/whoami.yaml b/repo-gitops/cluster/production/whoami.yaml new file mode 100644 index 0000000..675aba2 --- /dev/null +++ b/repo-gitops/cluster/production/whoami.yaml @@ -0,0 +1,20 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: whoami + namespace: argocd +spec: + project: default + source: + repoURL: https://git.stabify.de/stabify/gitops.git + targetRevision: HEAD + path: apps/whoami/overlays/production # Zeigt auf das Overlay, nicht die Base! + destination: + server: https://kubernetes.default.svc + namespace: default # Ziel-Namespace der App + syncPolicy: + automated: + prune: true + selfHeal: true + syncOptions: + - CreateNamespace=true # Erstellt den Namespace 'default' falls nicht vorhanden (oder 'whoami-ns')