Skip to content

Monorepo Best Practices

When managing multiple Compose or Podman Quadlet applications in a single Git repository, following a consistent layout keeps host configs minimal, secrets isolated, and rollbacks predictable.

Keep each app self-contained in its own subdirectory, and optionally store host-level docker-works configs in the same repo:

infra-monorepo/
├── .sops.yaml                       # Shared SOPS encryption rules
├── hosts/
│   └── prod-01/
│       ├── config.yaml              # Pulled via config_git
│       └── apps.d/                  # Loaded via apps_dir
│           ├── prom-nfv-a1.yaml
│           └── prom-nfv-a2.yaml
└── docker-works-apps/
    ├── prom-nfv-a1/
    │   ├── prom-nfv-a1.container
    │   ├── prometheus.yml.tmpl
    │   └── secrets.enc.env
    └── prom-nfv-a2/
        ├── prom-nfv-a2.container
        └── prometheus.yml

2. Use defaults.git + Per-App git.path

Define repo, branch, poll_interval, and auth once in defaults.git, and set only path under each app:

defaults:
  runtime: "podman"
  git:
    repo: "https://gitlab.example.com/group/infra-monorepo.git"
    branch: "main"
    poll_interval: "2m"
    auth:
      token: "${GITLAB_TOKEN}"

apps:
  - name: "prom-nfv-a1"
    mode: "quadlet"
    git:
      path: "docker-works-apps/prom-nfv-a1"

  - name: "prom-nfv-a2"
    mode: "quadlet"
    git:
      path: "docker-works-apps/prom-nfv-a2"

3. Manage Host Configs via config_git + apps_dir

Point each host's minimal /etc/docker-works/config.yaml at hosts/<hostname>/config.yaml using config_git, and split app definitions into apps.d/*.yaml so adding or updating an app only requires a Git PR.

4. Use Portable ./ Paths & Keep Data Outside Git

  • In Compose and Quadlet files, use ./ relative paths (Volume=./prometheus.yml:/etc/prometheus/prometheus.yml:Z,ro, EnvironmentFile=./secrets.env) so app folders remain portable across hosts.
  • Keep persistent data directories (/data/kafka, /var/lib/...) outside Git on the host.
  • With rootless Podman Quadlets, avoid :U on ./ bind mounts inside work_dir (use :Z,ro or :z) so container UID remapping doesn't block future Git pulls or template renders.

5. Share One .sops.yaml at the Monorepo Root

Place .sops.yaml at the repository root (e.g. matching \.enc\.(env|yaml|yml|json)$) so all apps use the same age key or AWS KMS ARN while decrypting into each app's own work_dir (0600).

6. Isolate Rollbacks & Validate Before Cutover

  • Keep auto_rollback: true enabled per app so a failing change in one subdirectory rolls back without affecting other apps.
  • Test new app subdirectories safely before enabling live deploys:
docker-works sync --config /etc/docker-works/config.yaml --app prom-nfv-a1 --dry-run