Skip to content
DoratouPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

🚀 Doratou DevOps

GitOps-driven delivery & infrastructure platform for the Doratou application stack

K3s · Helm · Argo CD · Sealed Secrets · Ansible · GitHub Actions · Gitleaks · Trivy · SonarQube

Kubernetes Helm Argo CD Ansible GitHub Actions PostgreSQL Redis RabbitMQ Gitleaks SonarQube License: MIT


📑 Table of Contents


🔭 Overview

This repository is the single source of truth for provisioning, deploying, and operating the Doratou application stack. It automates server preparation with Ansible (K3s, NGINX Ingress, Headlamp, Sealed Secrets, Argo CD), packages the full application and data layer as a Helm chart, and delivers updates continuously through Argo CD (GitOps).

What Where
Application & data-layer Helm chart helm/app/
Monitoring chart scaffold (WIP) helm/monitoring/
Continuous delivery definitions (Argo CD) gitops/
Server & cluster provisioning (K3s, Ingress, Argo CD, etc.) ansible/
Encrypted secrets procedure (kubeseal) SECRETS.md
CI & security pipelines .github/
Secret-leak scanning rules .gitleaks.toml
Code quality analysis config sonar-project.properties

✨ Key Highlights

  • 📦 Full-stack Helm packaging – deploys the frontend (web), backend API (backend), API documentation (docs), background workers (email, sms), database migration Job, Adminer DB UI, PostgreSQL, Redis, RabbitMQ, and RustFS (S3-compatible storage).
  • 🔄 GitOps delivery – Argo CD continuously reconciles the doratou namespace using values-sealed.yaml.
  • 🗄️ Safe schema migrations – a dedicated Migration Job runs as an Argo CD Sync hook (sync-wave: "1") and waits for PostgreSQL readiness before the backend rolls out.
  • 🔐 Encrypted secrets in Git – Bitnami Sealed Secrets (kubeseal) encrypts app-db-credentials and doratou-secrets so no plaintext credentials are ever committed.
  • 🌐 Ingress & cluster tooling – automated installation of ingress-nginx, Headlamp Kubernetes UI, and optional Xray proxy support.
  • 🛡️ Multi-layered CI & security gates – Gitleaks, Helm lint, Kubeconform (Kubernetes 1.30.0 strict validation), Trivy IaC scan, KinD chart-testing install, ansible-lint, K3s integration tests, and SonarQube.
  • 🤖 Repeatable server bootstrap – Ansible playbook (site.yml) prepares a fresh Linux host from scratch into a GitOps-ready K3s cluster.

🏗️ Architecture

End-to-end delivery flow

flowchart LR
    DEV([👩‍💻 Developer]) -->|push| FE_REPO[Frontend repo]
    DEV -->|push| BE_REPO[Backend / Workers / Docs]
    DEV -->|push| OPS_REPO[DevOps repo<br/>this repository]

    FE_REPO -->|build image| REG[(GHCR Registry)]
    BE_REPO -->|build image| REG

    OPS_REPO --> CI[GitHub Actions]
    CI --> GL[Gitleaks & Trivy<br/>security scans]
    CI --> KC[Helm Lint & Kubeconform<br/>+ KinD install test]
    CI --> ANS[Ansible Lint &<br/>K3s integration test]
    CI --> SQ[SonarQube<br/>code quality]

    OPS_REPO -->|watched by| ARGO[Argo CD]
    ARGO -->|helm/app + values-sealed.yaml| K8S

    subgraph K8S[☸️ K3s Kubernetes Cluster]
        direction TB
        ING[NGINX Ingress Controller]
        SS[Sealed Secrets Controller] --> SEC[[Secrets<br/>app-db-credentials & doratou-secrets]]
        CM[ConfigMap<br/>backend-config]
        MIG[Migration Job<br/>Argo CD Sync hook]

        WEB[Frontend Web]
        DOCS[API Docs]
        BE[Backend API]
        WRK[Workers<br/>email / sms]
        DBUI[Adminer DB UI]

        PG[(PostgreSQL)]
        RD[(Redis)]
        RMQ[(RabbitMQ)]
        RFS[(RustFS S3)]

        ING --> WEB
        ING --> RFS
        CM --> MIG
        MIG -->|migrate schema| PG
        MIG -.->|then| BE
        WEB --> BE
        BE --> PG
        BE --> RD
        BE --> RMQ
        BE --> RFS
        WRK --> RMQ
        DBUI --> PG
        SEC -.-> MIG
        SEC -.-> BE
        SEC -.-> WRK
        SEC -.-> PG
        SEC -.-> RD
        SEC -.-> RMQ
        SEC -.-> RFS
    end

    REG -.->|pull images| K8S
Loading

Argo CD sync order

The migration Job is guaranteed to run after the ConfigMap exists, waits for PostgreSQL to accept connections, and runs before the backend Deployment is updated.

sequenceDiagram
    autonumber
    participant Git as Git (this repo)
    participant Argo as Argo CD
    participant K8s as Kubernetes
    participant Job as Migration Job
    participant DB as PostgreSQL

    Git->>Argo: New commit detected
    Argo->>K8s: Apply SealedSecrets, ConfigMap & Data Services
    Argo->>Job: Run migration (Sync hook, wave 1)
    Job->>DB: Wait for PostgreSQL readiness (initContainer)
    Job->>DB: Apply schema migrations
    Job-->>Argo: Succeeded ✅
    Argo->>K8s: Delete Job (BeforeHookCreation,HookSucceeded)
    Argo->>K8s: Roll out Backend, Workers, Docs & Frontend
Loading

📂 Repository Structure

.
├── .github/
│   ├── ct.yaml                         # Helm chart-testing configuration
│   └── workflows/
│       ├── CI-Ansible.yml              # Ansible syntax, ansible-lint & K3s integration test
│       ├── CI-Chart.yml                # Gitleaks, Helm lint, Kubeconform, Trivy & KinD install test
│       └── CI-SonarQube.yml            # SonarQube static analysis on PRs and main
├── ansible/
│   ├── inventories/
│   │   ├── ci/                         # CI local inventory
│   │   └── dev/                        # Development inventory
│   ├── roles/
│   │   ├── common/                     # OS prep, kernel modules, sysctl, swap off
│   │   ├── xray/                       # Optional Xray proxy setup
│   │   ├── k3s/                        # K3s server installation & kubeconfig
│   │   ├── helm_cli/                   # Helm CLI installation
│   │   ├── headlamp/                   # Headlamp Kubernetes web UI
│   │   ├── sealed_secret/              # Bitnami Sealed Secrets controller
│   │   ├── ingress_nginx/              # NGINX Ingress Controller
│   │   └── helm_bootstrap/             # Argo CD install & Doratou Application apply
│   ├── requirements.yaml               # Ansible Galaxy collections
│   └── site.yml                        # Main provisioning playbook
├── gitops/
│   └── doratou.yaml                    # Argo CD Application manifest
├── helm/
│   ├── app/                            # Main Doratou Helm chart (v0.2.1)
│   │   ├── charts/                     # Vendored subcharts (postgresql-16.3.0, redis-20.0.0)
│   │   ├── sealed-secrets/             # Encrypted SealedSecret manifests
│   │   ├── templates/                  # K8s templates (web, backend, docs, migration,
│   │   │                               #   workers, rabbitmq, rustfs, dbUi, sealedsecret)
│   │   ├── Chart.yaml
│   │   ├── Chart.lock
│   │   ├── values.yaml                 # Default chart values (secrets disabled)
│   │   └── values-sealed.yaml          # GitOps values (SealedSecrets & Ingress enabled)
│   └── monitoring/                     # Monitoring chart scaffold (WIP)
├── .gitleaks.toml                      # Gitleaks secret-scanning configuration
├── .gitignore
├── LICENSE                             # MIT License
├── README.md
├── SECRETS.md                          # Guide for generating & rotating SealedSecrets
└── sonar-project.properties            # SonarQube project configuration

🧰 Technology Stack

Category Tools Purpose
Orchestration & Packaging K3s, Kubernetes, Helm v3.16+ Lightweight cluster runtime and application packaging
GitOps / CD Argo CD Continuous delivery, automated pruning, and self-healing
Ingress & Dashboard NGINX Ingress Controller, Headlamp External HTTP routing and cluster web dashboard
Secrets Management Bitnami Sealed Secrets (kubeseal), Ansible Vault Safe encrypted secrets in Git and encrypted Ansible vars
Automation / IaC Ansible Repeatable host and cluster provisioning
CI & Validation GitHub Actions, Kubeconform, Chart Testing (ct), KinD Manifest schema validation and live KinD install testing
Security & Quality Gitleaks, Trivy, SonarQube, ansible-lint Secret scanning, IaC vulnerability scanning, static analysis
Data, Queue & Storage PostgreSQL, Redis, RabbitMQ, RustFS (S3) Persistent DB, cache/pub-sub, async queues, object storage
Workloads Web (Frontend), Backend API, API Docs, Workers, Adminer The Doratou application services and DB admin UI

⎈ Helm Chart (helm/app)

A single umbrella chart (Chart.yaml v0.2.1, appVersion "1.0.0") deploys the entire Doratou application stack and its dependencies.

Workloads & Infrastructure Components

Component Kind Image / Chart Service / Port Description
Frontend (web) Deployment ghcr.io/doratou/frontend ClusterIP:80 (+ Ingress /) User-facing web app with hardened non-root security context
Backend (backend) Deployment (2 replicas) ghcr.io/doratou/backend LoadBalancer:3000 Core Go/Gin API service configured via ConfigMap & Secrets
API Docs (docs) Deployment ghcr.io/doratou/api-docs LoadBalancer:8080 Interactive API documentation
Migration (migration) Job (Argo CD Hook) ghcr.io/doratou/migration — Applies PostgreSQL schema migrations before backend rollout
Workers (workers) Deployments ghcr.io/doratou/worker-email, worker-sms Optional (ws available) Async background consumers connected to RabbitMQ
PostgreSQL (postgresql) Bitnami Subchart bitnami/postgresql (16.3.0) ClusterIP:5432 (5Gi PVC) Primary relational database (doratou)
Redis (redis) Bitnami Subchart bitnami/redis (20.0.0) ClusterIP:6379 (1Gi PVC) Cache, OTP/PoW state, and WebSocket pub/sub
RabbitMQ (rabbitmq) StatefulSet rabbitmq:4-management-alpine ClusterIP:5672, 15672 (2Gi PVC) Message broker for email, SMS, and notification queues
RustFS (rustfs) Deployment + Policy Job rustfs/rustfs ClusterIP:9000, 9001 (10Gi PVC + Ingress) S3-compatible object storage with automated bucket policy setup
DB UI (dbUi) Deployment adminer:6.3.1 LoadBalancer:4000 Web-based database administration interface

Values Profiles (values.yaml vs values-sealed.yaml)

  • values.yaml — Default values used for local linting, template rendering, and CI KinD tests (sealedSecrets.database.enabled: false, sealedSecrets.backend.enabled: false, hasIngress: false).
  • values-sealed.yaml — Production GitOps overrides loaded by Argo CD: enables both SealedSecret manifests and Ingress resources (hasIngress: true).

Local Chart Rendering & Validation

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm dependency build ./helm/app

helm lint ./helm/app
helm template doratou ./helm/app -f ./helm/app/values-sealed.yaml

🗄️ Database Migration Job

The migration is intentionally decoupled from the application runtime, so schema changes never depend on a backend pod starting up.

Property Behaviour
Trigger Argo CD Sync hook (argocd.argoproj.io/hook: Sync)
Ordering argocd.argoproj.io/sync-wave: "1" — runs after ConfigMap/Secrets and before the backend rollout
Readiness check initContainer (postgres:15-alpine) polls SELECT 1 against PostgreSQL before running migrations
Cleanup BeforeHookCreation,HookSucceeded — deleted automatically after a successful run (ttlSecondsAfterFinished: 86400)
Resilience backoffLimit: 3, activeDeadlineSeconds: 900
Credentials Reads PDB_USER / PDB_HOST / PDB_DB_NAME from backend-config ConfigMap and PDB_PASSWORD from app-db-credentials

🔐 Secrets Management

Plaintext secrets are never stored in Git. Depending on your environment, the chart supports two modes:

Option 1 — Sealed Secrets (GitOps / Production)

In production, Argo CD applies values-sealed.yaml, which enables templates/sealedsecret.yaml to render encrypted SealedSecret resources from helm/app/sealed-secrets/:

  • app-db-credentials.yaml — holds postgres-password, postgresql-password, redis-password, and rabbitmq-password.
  • doratou-secrets.yaml — holds application secrets (JWT_SECRET_KEY, INVITE_ENCRYPTION_SECRET, POW_HMAC_SECRET, RUSTFS_ACCESS_KEY_ID, RUSTFS_SECRET_ACCESS_KEY, SMTP/OAuth/seed credentials).

The sealed-secrets-controller (installed in kube-system by Ansible) decrypts them inside the cluster into standard Kubernetes Secrets.

📖 See SECRETS.md for the complete, non-echoing kubeseal script to generate, validate, and rotate app-db-credentials safely.

Option 2 — Pre-created Kubernetes Secrets (CI / Manual)

When sealedSecrets.*.enabled is false (default in values.yaml), create the two Secrets in your target namespace before installing the chart:

kubectl create secret generic app-db-credentials \
  --namespace <your-namespace> \
  --from-literal=postgres-password='<postgres-admin-password>' \
  --from-literal=postgresql-password='<postgres-user-password>' \
  --from-literal=redis-password='<redis-password>' \
  --from-literal=rabbitmq-password='<rabbitmq-password>'

kubectl create secret generic doratou-secrets \
  --namespace <your-namespace> \
  --from-literal=JWT_SECRET_KEY='<32-byte-secret>' \
  --from-literal=INVITE_ENCRYPTION_SECRET='<32-byte-secret>' \
  --from-literal=POW_HMAC_SECRET='<32-byte-secret>' \
  --from-literal=RUSTFS_ACCESS_KEY_ID='<access-key>' \
  --from-literal=RUSTFS_SECRET_ACCESS_KEY='<secret-key>'
# Add SMTP, OAuth, and seed password keys as required by your environment

🔄 GitOps with Argo CD

Argo CD watches this repository and keeps the cluster synchronized with helm/app.

  • Git is the source of truth – cluster drift is automatically corrected (selfHeal: true), and removed resources are cleaned up (prune: true).
  • Application manifest: gitops/doratou.yaml
Setting Value
Application name doratou
Argo CD namespace argocd
Target namespace doratou (auto-created via CreateNamespace=true)
Source repo ssh://git@ssh.github.com:443/Doratou/Devops.git (main, path helm/app)
Helm release & values Release doratou, values file values-sealed.yaml
Destination server https://kubernetes.default.svc
Sync policy Automated (prune: true, selfHeal: true)

To reach the Argo CD UI locally:

kubectl port-forward svc/argocd-server -n argocd 8080:80
# Open http://localhost:8080

🤖 Ansible Automation

The ansible/ directory prepares a bare Linux server and bootstraps the entire Kubernetes + GitOps stack via ansible/site.yml (using group_vars/production/vault.yml for encrypted variables).

Roles execute in the following order:

Order Role Tags Responsibility
1 common common, prepare Updates apt cache, installs base & K8s packages, disables swap, configures kernel modules & sysctl
2 xray xray, vpn Optionally installs & configures Xray from a local config.json and sets proxy env (skipped if absent)
3 k3s k3s, cluster Installs and starts K3s server, configures kubeconfig & proxy settings, waits for K8s API
4 helm_cli helm, helm_cli Installs the Helm CLI if not already present
5 headlamp headlamp, dashboard Installs the Headlamp Kubernetes dashboard via Helm
6 sealed_secret sealed_secret, secret Installs sealed-secrets-controller in kube-system and waits for availability
7 ingress_nginx ingress, ingress-nginx Installs the NGINX Ingress Controller
8 helm_bootstrap helm_bootstrap, gitops Installs Argo CD, waits for readiness, and applies gitops/doratou.yaml

Run the playbook (install required collections first):

cd ansible
ansible-galaxy collection install -r requirements.yaml
ansible-playbook -i inventories/dev/hosts.ini site.yml --ask-vault-pass

Use --tags (e.g. --tags k3s,gitops) to run specific stages, or --skip-tags vault when running without Ansible Vault.


✅ CI & Security Gates

All changes are verified automatically via GitHub Actions in .github/workflows/:

Workflow Trigger Checks & Tools
CI-Chart.yml PRs & pushes touching helm/** Gitleaks secret scan; Helm dependency build & lint; Kubeconform strict validation (Kubernetes 1.30.0); Trivy IaC config scan (CRITICAL,HIGH); KinD live chart install test (ct install)
CI-Ansible.yml PRs & pushes touching ansible/** or gitops/** ansible-playbook --syntax-check, ansible-lint, and a full K3s + bootstrap integration test on ubuntu-24.04
CI-SonarQube.yml PRs & pushes to main SonarQube static analysis & quality gate (sonar-project.properties)

🚦 Getting Started

Prerequisites

  • A fresh Ubuntu/Debian server (for Ansible bootstrap) or an existing Kubernetes cluster with kubectl and helm (v3.16+)
  • kubeseal CLI (if generating/rotating SealedSecrets)
  • Access to the Doratou container images on GHCR (ghcr.io/doratou/*)

1. Clone the repository

git clone https://github.com/Doratou/Devops.git
cd Devops

2. Provision the server with Ansible (optional for existing clusters)

cd ansible
ansible-galaxy collection install -r requirements.yaml
ansible-playbook -i inventories/dev/hosts.ini site.yml --ask-vault-pass

3. Configure Secrets

Follow SECRETS.md to seal your credentials for your cluster's sealed-secrets-controller, or create app-db-credentials and doratou-secrets manually (see Secrets Management).

4. Deploy

Option A – through Argo CD (recommended): If bootstrapped with Ansible, Argo CD is already configured via gitops/doratou.yaml and will automatically sync helm/app with values-sealed.yaml on every push to main.

Option B – directly with Helm:

helm dependency build ./helm/app
helm upgrade --install doratou ./helm/app \
  --namespace doratou --create-namespace

🧾 Useful Commands

# Check all pods, services, and ingresses in the doratou namespace
kubectl get pods,svc,ingress -n doratou

# Follow backend or worker logs
kubectl logs -n doratou deploy/doratou-backend -f
kubectl logs -n doratou deploy/doratou-worker-email -f

# Check the migration Job (present during sync / within TTL)
kubectl get jobs -n doratou

# Inspect SealedSecrets decryption status
kubectl get sealedsecrets -n doratou
kubectl describe sealedsecret app-db-credentials -n doratou

# Port-forward RabbitMQ management UI (15672) or RustFS console (9001)
kubectl port-forward -n doratou svc/doratou-rabbitmq 15672:15672
kubectl port-forward -n doratou svc/doratou-rustfs 9001:9001

# Access Argo CD UI
kubectl port-forward svc/argocd-server -n argocd 8080:80

# List Helm releases across all namespaces
helm list -A

🗺️ Project Status & Roadmap

  • Umbrella Helm chart (helm/app) for web, backend, API docs, workers, and DB UI
  • Data & messaging layer: PostgreSQL, Redis, RabbitMQ, and RustFS (S3)
  • Migration Job as an ordered Argo CD Sync hook (sync-wave: "1") with Postgres readiness wait & cleanup
  • Bitnami Sealed Secrets (kubeseal) integration with values-sealed.yaml & SECRETS.md
  • Argo CD GitOps delivery with automated pruning and self-healing
  • Ansible server bootstrap (common, xray, k3s, helm_cli, headlamp, sealed_secret, ingress_nginx, helm_bootstrap)
  • CI quality & security gates (Gitleaks, Kubeconform, Trivy, KinD ct install, ansible-lint, K3s integration, SonarQube)
  • Monitoring & logging stack (helm/monitoring/ — Prometheus / Grafana / Loki)
  • Horizontal Pod Autoscaler (HPA) for backend and workers
  • Multi-environment GitOps overlay (staging / production)

📄 License

Distributed under the MIT License. See LICENSE for details.


Maintained by @Doratou

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages