add docker swarm deployment stack
Signed-off-by: Areeb Ahmed [email protected]
Summary by CodeRabbit
- New Features
- Full Docker Swarm stack: multi-node PostgreSQL (master + replicas), Redis, MinIO, backend, Celery, Traefik (Let’s Encrypt TLS) and Portainer.
- HAProxy read/write routing for PostgreSQL.
- Automated manager/worker onboarding with shared storage (GlusterFS) and swap setup.
- Scheduled backups with MinIO -> S3 sync and DB backup automation.
- Automated DB initialization/replication and preconfigured DB connections for management tools.
📝 Walkthrough
Walkthrough
Adds a Docker Swarm stack and supporting configs/scripts to deploy a multi-service application: PostgreSQL HA (HAProxy + master + 2 slaves), Redis, MinIO with backups, backend/Celery services, Traefik and Portainer, plus node provisioning scripts for manager/worker (GlusterFS mounts), swap setup, and pgAdmin server config.
Changes
| Cohort / File(s) | Change Summary |
|---|---|
Compose stackdocker-compose.swarm.yaml |
New Swarm Compose stack declaring services (HAProxy/db, db-master, db-slave1, db-slave2, db-backup, redis, minio, minio-backup, backend, celery-worker, celery-beat, traefik, portainer-agent, portainer), overlay network, host-bind volumes, configs, YAML anchors for env/policy, and deployment/update/health policies. |
HAProxy confighaproxy.cfg |
New TCP load‑balancer config for PostgreSQL: write listener -> master, read listener -> slaves, Docker DNS resolver and TCP health checks. |
Postgres init scriptsscripts/postgres_master.sh, scripts/postgres_slave.sh |
New master init (create replicator user, WAL/replication settings, create replication slots) and slave init (wait for master, pg_basebackup, standby.signal, primary_conninfo) scripts. |
Node setup scriptsscripts/setup_manager.sh, scripts/setup_worker.sh |
New manager and worker provisioning scripts: system updates, Docker install, Swarm init/join flows, GlusterFS cluster/volume creation and mounts, hosts entries and directory setup. |
MinIO backup & cronscripts/minio_cron.sh |
New script installing MinIO client, creating a backup script to mirror MinIO buckets to S3, scheduling a daily cron job, and running cron in foreground. |
Utility scriptsscripts/setup_swap.sh |
New script to create/enable a 2GB swapfile and persist swappiness across reboots. |
pgAdmin configpgadmin_servers.json |
New JSON defining three PostgreSQL server entries (db-master, db-slave1, db-slave2) for pgAdmin (file currently referenced/commented in compose). |
Swarm configshaproxy.cfg, scripts/postgres_master.sh, scripts/postgres_slave.sh, scripts/minio_cron.sh |
New Swarm configs declared and referenced in the compose file (haproxy-config, postgres-master, postgres-slave, minio-cron). |
Sequence Diagram(s)
sequenceDiagram
autonumber
participant User
participant Manager
participant Worker
participant GlusterFS
participant Swarm
User->>Manager: run scripts/setup_manager.sh
Manager->>Manager: system update & install Docker/Gluster
Manager->>Swarm: init or join as manager
Manager->>GlusterFS: create/probe/volume and start
Manager->>Manager: mount volume, create service dirs
User->>Worker: run scripts/setup_worker.sh
Worker->>Worker: system update & install Docker/Gluster client
Worker->>Swarm: join as worker
Worker->>GlusterFS: mount shared volume
sequenceDiagram
autonumber
participant Client
participant HAProxy
participant PGMaster
participant PGSlave1
participant PGSlave2
Client->>HAProxy: connect :5432 (writes)
HAProxy->>PGMaster: forward (first)
Client->>HAProxy: connect :5433 (reads)
HAProxy->>PGSlave1: forward (round-robin)
HAProxy->>PGSlave2: forward (round-robin)
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Suggested reviewers
- vigneshhari
Pre-merge checks (2 passed, 1 warning)
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description Check | ⚠️ Warning | The PR description currently contains only a Signed-off-by line and does not follow the repository's required template; it is missing the "Proposed Changes" summary, "Associated Issue" link, the Merge Checklist (tests/docs/linting), and any architecture or deployment notes, leaving reviewers without necessary context and forcing them to guess the intent. | Please replace the current description with the repository PR template filled out: include a brief summary of the changes (what was added/modified and why), link to the associated issue(s) and explain how this PR resolves them, add any architecture or deployment notes, and complete the Merge Checklist (tests, docs, linting). Keep the Signed-off-by line and add any relevant file-level notes or rollout instructions so reviewers can evaluate the change without extra digging. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title Check | ✅ Passed | The title "add docker swarm deployment stack" is concise and accurately reflects the primary change in the changeset (addition of a Docker Swarm compose file and supporting deployment scripts/configs), so it communicates the main intent to reviewers without noise or irrelevant detail. It is specific enough for a quick scan and directly related to the files added in the PR. |
| Docstring Coverage | ✅ Passed | No functions found in the changes. Docstring coverage check skipped. |
Poem
🐣 Swarm wakes, HAProxy at the quay,
Masters push WAL while two shy slaves play.
MinIO mirrors, cron hums in the night,
Gluster tucks volumes so services sleep tight.
Swap added, scripts primed — deploy and try it, if you may.
[!TIP]
👮 Agentic pre-merge checks are now available in preview!
Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
- Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
- Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.
Please see the documentation for more information.
Example:
reviews: pre_merge_checks: custom_checks: - name: "Undocumented Breaking Changes" mode: "warning" instructions: | Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post.
✨ Finishing touches
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Comment @coderabbitai help to get the list of available commands and usage tips.
@sainak review required!