How diggerhq/digger works
Project type and purpose
• This is an open-source, Go-based full-stack tool (“Digger”) providing CI/CD orchestration for Terraform. It comprises:
a. A CLI that users invoke inside their existing CI pipelines (GitHub Actions, Jenkins, etc.) to run Terraform commands.
b. An orchestrator backend (with two flavors: the original in backend/ and a newer “next” version in next/), which exposes HTTP APIs, handles webhooks, schedules jobs, manages locks, and triggers CI runs.
c. A drift detection service (drift/) that periodically compares real infrastructure state with Terraform state.
d. Enterprise extensions (ee/) that add RBAC, multi-VCS support, advanced UI templates, and policy enforcement.
File structure
• Top-level modules:
• cli/: the Digger CLI implementation & platform-agnostic libs under cli/pkg.
• backend/: original orchestrator service (controllers, middleware, migrations, models, services).
• next/: next-generation orchestrator service (controllers, supabase integration, schema, services).
• drift/: drift-detection microservice.
• ee/: enterprise edition overrides for backend/, cli/, and drift/.
• libs/: shared libraries (locking, storage, CI backends, policy, execution, etc.).
• dgctl/: a control-plane CLI for ad-hoc actions against the orchestrator.
• cli_e2e/: end-to-end tests for the CLI.
• Configuration and deployment: Dockerfiles for each component, GitHub Actions workflows, Fly.toml for Fly.io, atlas.hcl for DB migrations.
• The orchestrator uses Atlas for migrations (backend/migrations/…) and a relational DB (Postgres, Supabase). Cloud storage for plan persistence and locking (AWS DynamoDB & S3 or equivalents).
a. External Systems
• Git hosting (GitHub, GitLab, Bitbucket) – delivers webhooks & pull-request events.
• CI/CD provider (GitHub Actions, Jenkins, etc.) – executes jobs that run the CLI.
• Cloud provider services – object storage (e.g., S3, Azure Blob, GCS) for plan artifacts; DynamoDB (or equivalent) for locking; relational DB (Postgres/Supabase) for orchestrator state.
b. Digger Components
• CLI Container (docker image invoked by CI)
• Reads digger.yml, calls Terraform/terragrunt, interacts with cloud stores, then POSTs status to the orchestrator API.
• Orchestrator API Service (backend/ or next/ service)
• HTTP server with controllers (webhooks, connections, plans, runs, policies).
• Middleware for auth (JWT, cookies, job tokens).
• Scheduler & services to enqueue CI jobs via CI-backend libraries.
• Uses Atlas migrations & models to maintain its Postgres schema.
• Drift Service (drift/)
• Cron-driven or continuously running Go service
• Scans Terraform states vs. real infra, writes findings back via orchestrator API or notifications.
• Enterprise Edition Extensions (ee/)
• Overlay controllers, policy providers, richer templates, and RBAC via OPA.
Relationships and data flows
1. A developer comments on a PR (e.g., “/digger plan”) in GitHub → GitHub webhook → Orchestrator API
2. Orchestrator validates the request (middleware/JWT/OPA), enqueues a job via CI-backend library (e.g., calls GitHub Actions API or Jenkins API)
3. CI runner spins up the CLI container → CLI calls Terraform/Terragrunt → CLI stores plan in S3 and lock in DynamoDB → CLI reports result back to Orchestrator API
4. Orchestrator posts a comment on the PR with plan results via GitHub API
5. Upon merge, Orchestrator triggers “apply” jobs similarly
6. Drift Service periodically polls state → detects drift → reports back to Orchestrator or via notification channels
Architectural patterns and principles
• Microservices separation: each Go service (CLI, orchestrator, drift) is a self-contained container
• Library reuse: CI-backends, storage, locking are factored into libs/ for consistency across services
• Event-driven orchestration: webhooks → API → job queue → CI → callbacks
• Cloud-native persistence: RDBMS for core metadata, object store & NoSQL for plan artifacts & locks
• Configuration as code: digger.yml, Dockerfiles, Terraform modules
Technologies, frameworks, and libraries
• Go modules, Go HTTP server (net/http), Go templates for UI
• Atlas for DB migrations
• AWS (S3, DynamoDB), Azure/GCP equivalents
• CI providers: GitHub Actions, Jenkins, Bitbucket Pipelines (via backend/ci_backends and libs/ci/*)
• Open Policy Agent for RBAC (middleware/, ee/cli/pkg/policy)