How ein-plus/lain works
Project Type and Purpose
• From the README (“Lain 是一个基于 docker 的 PaaS 系统”) and the sprawling Ansible playbooks, this is an infrastructure‐as‐code project: a Docker-based PaaS bootstrap/orchestration system.
• It provides one‐click provisioning (via Vagrant for dev/test and Ansible for production), configures the control plane (etcd, DNS, registry, networking, firewall, monitoring, logging, storage) and the data plane (Docker hosts) to deliver a unified PaaS.
File‐Structure Analysis
• Top level:
• Vagrantfile + bootstrap scripts for local dev/test
• site.yaml + playbooks/ directory for Ansible orchestration
• bootstrap_test/ for CI tests
• playbooks/roles: dozens of Ansible roles, each encapsulating a single service or function:
• bootstrap‑* roles handle the multi‑layer initialization (layer0=infra, layer1=platform services)
• Services: etcd, Docker engine, registry, console, deployd (scheduler), swarm, calico (network), dnsmasq/tinydns, firewall, collectd (metrics), rsyslog, moosefs (storage), lainlet (node agent), SSL, etc.
• libraries/ contains custom Ansible modules (docker_pull, etcd_set_key, set_virtual_ip, etc.)
• bootstrap/: likely contains high‑level orchestrator entry points
• bootstrap_test/: pytest tests validating roles and playbooks
Key README Insights
• Design goals: reduce complexity, standardize dev→test→prod, support CI/CD
• Target environments: IaaS/bare‐metal or Vagrant for dev
a. Main Components
• Ansible Control Plane (Bootstrap server or CI runner)
• Inventory: host groups (bootstrap‐node, layer0, layer1)
• Infrastructure services (layer0):
– etcd cluster (key‐value store)
– DNS: tinydns + dnsmasq
– Docker registry
– Firewall rules (iptables via ansible)
– Overlay network (Calico)
• Platform services (layer1):
– deployd (application deploy scheduler)
– console (web UI)
– swarm managers & agents
– lainlet (node agent)
– monitoring (collectd + plugins)
– logging (rsyslog + relocation)
– storage (MooseFS metadata/master/chunk)
• Data plane: pool of Docker hosts running containers
• External integrations: SSL CA, external SSH key distribution, CI/CD hooks
b. Relationships & Interactions
• Ansible Control → (SSH/API) → target nodes to install/configure services
• Services communicate:
– deployd ↔ etcd
– console ↔ etcd + registry
– swarm manager ↔ Docker daemons
– lainlet ↔ deployd/console for health & scheduling
– collectd ↔ all nodes, push metrics to back‐end
– rsyslog → centralized log storage or syslog aggregator
• Overlay network spans Docker hosts; Calico agents configure routes via etcd
• Registry hosts Docker images pulled by Docker daemons
c. Architectural Patterns & Principles
• Infrastructure as Code: modular Ansible roles
• Layered bootstrap (layer0 infra → layer1 PaaS)
• Declarative state: idempotent roles, custom modules
• Separation of concerns: one role = one service/function
• High cohesion within roles, loose coupling between services via etcd + APIs
d. Key Technologies & Frameworks
• Ansible playbooks & custom modules
• Docker & Docker‑registry
• etcd (distributed key‐value store)
• Calico (container networking)
• DNS (tinydns/dnsmasq)
• Jenkins/GitLab CI (implied by bootstrap_test)
• Collectd, rsyslog, MooseFS, Swarm, Python (Ansible modules, test suite), Vagrant