initial upload
This commit is contained in:
45
README.md
Normal file
45
README.md
Normal file
@@ -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.
|
||||
47
repo-app-source/.gitea/workflows/docker-build.yaml
Normal file
47
repo-app-source/.gitea/workflows/docker-build.yaml
Normal file
@@ -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
|
||||
33
repo-gitops/apps/whoami/base/deployment.yaml
Normal file
33
repo-gitops/apps/whoami/base/deployment.yaml
Normal file
@@ -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
|
||||
5
repo-gitops/apps/whoami/base/kustomization.yaml
Normal file
5
repo-gitops/apps/whoami/base/kustomization.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
resources:
|
||||
- deployment.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
|
||||
20
repo-gitops/bootstrap/root-app.yaml
Normal file
20
repo-gitops/bootstrap/root-app.yaml
Normal file
@@ -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
|
||||
20
repo-gitops/cluster/production/whoami.yaml
Normal file
20
repo-gitops/cluster/production/whoami.yaml
Normal file
@@ -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')
|
||||
Reference in New Issue
Block a user