Kata (型) means form / model / pattern. This project provides a tiny “micro-PaaS” wrapper around Docker (Compose or Swarm) with implicit HTTP routing via Traefik.
- Parses an application
kata-compose.yamland generates a.docker-compose.yamlused for deployment - Supports either Docker Swarm (
docker stack deploy) or Docker Compose (docker compose up -d) per app (auto‑selects, overridable) - Implicitly wires HTTP routing through Traefik using generated labels
- Builds lightweight runtime images on‑demand for
runtime: python,runtime: nodejs,runtime: php,runtime: bun, or static assets. - Manages per‑app bind‑mounted directories (code, data, config, venv, logs, repos)
- Merges environment variables from multiple sources and injects them into each service
- Provides simple git push deployment hooks (
git-receive-pack/git-hook) - Offers helper commands for secrets (Swarm only), mode switching, and Traefik inspection
Mandatory:
- Docker 20.10+ (Swarm optional; if inactive, Compose mode is used)
- Python 3.12+ with
clickandpyyaml - Git and OpenSSH for push deployments; the Compose plugin for Compose mode
Optional (HTTP routing via Traefik):
- Traefik v3 on the host (containerized). Kata will create or reuse the external Docker network
traefik-proxyand the volumetraefik-acmefor certificate storage, and will start a shared Traefik container (kata-traefik) if none is running.
systemd / Podman are not required by the current code path (earlier design notes referenced them).
See installation, the operating manual, and verification limits. The implementation stays single-file.
Traefik is opt-in. Without a nonempty traefik: block, Kata does not generate routing labels. Deployment still calls shared Traefik setup, which may start a proxy even for an unrouted app. Add a traefik block to the root of your kata-compose.yaml to enable routing.
You can always add Traefik labels manually on any service; the traefik block is just a convenience that generates a consistent set of labels for one target service.
Key defaults (when traefik is provided):
- Router name:
<app> - Host rule:
traefik.host(required) - Entry points:
websecureby default;web→websecureredirect only if you setenable_http_redirect - Service:
traefik.service(defaults to the first service listed if omitted); settraefik.portto the actual container listen port (defaults to 8000; it is not inferred fromports/expose) - TLS: enabled by default when using
websecure; certificates stored in the external volumetraefik-acme - Network: only the Traefik-targeted service is attached to the external Docker network
traefik-proxy; other services are untouched
Kata can start or reuse a shared Traefik container named kata-traefik on the traefik-proxy network with the traefik-acme volume. If you already run Traefik, keep it attached to that network/volume and Kata will reuse it.
You can override host/entrypoint/redirect/port via labels under your service (Compose syntax), e.g.:
services:
web:
labels:
traefik.http.routers.websecure.rule: Host(`app.example.com`)
traefik.http.routers.websecure.entrypoints: websecure
traefik.http.services.web.loadbalancer.server.port: "5000"Traefik needs a reachable listening socket, a shared network and the correct upstream port. expose documents that port; it is not an access-control boundary. This is fine for workers/cron jobs:
services:
worker:
image: busybox
command: ["sh", "-c", "echo worker started; sleep infinity"]
# Do not select this worker as the Traefik targetkata config:traefik <app> [--json]— render generated labels and router/service ruleskata traefik:ls <app>— list routers/services for the generated stackkata traefik:inspect <app>— show labels per service
Use runtime: static to serve a directory via BusyBox httpd (image kata/static). Defaults: PORT=8000, DOCROOT=/app.
Paths are rooted at KATA_ROOT (default: $HOME). The current directory names (note: singular app/) are:
- Code:
$KATA_ROOT/app/<app> - Data:
$KATA_ROOT/data/<app> - Config:
$KATA_ROOT/config/<app>(placeENVor.envhere to override variables) - Virtual env / runtime state:
$KATA_ROOT/envs/<app> - Logs:
$KATA_ROOT/logs/<app> - Git bare repos:
$KATA_ROOT/repos/<app>
Generated file: .docker-compose.yaml inside the app code directory (regenerated each deploy).
Add only the labels you need; Kata supplies sensible defaults.
services:
web:
labels:
traefik.http.routers.websecure.rule: Host(`app.example.com`)
traefik.http.routers.websecure.entrypoints: websecure
traefik.http.routers.websecure.tls: "true"
traefik.http.middlewares.web-redirect.redirectscheme.scheme: https
traefik.http.routers.websecure.middlewares: web-redirect
traefik.http.services.web.loadbalancer.server.port: "5000"Merged from (later sources override earlier):
- Base:
PUID,PGID, and per‑app root paths (APP_ROOT,DATA_ROOT,ENV_ROOT,CONFIG_ROOT,GIT_ROOT,LOG_ROOT) - Top‑level
environment:mapping inkata-compose.yaml(optional) ENVor.envfile in the app’s config directory- Service‑level
environmententries
Compose list form (["KEY=VALUE", "BARE_KEY"]) is normalized; bare keys default to empty string.
Recommended to set:
PORT(service listen port, especially for reverse proxying)BIND_ADDRESS(application-defined; use0.0.0.0for container-to-container access)DOMAIN_NAME(for host matchers / TLS)
Declare ports or expose on the service you want Traefik to reach; Kata no longer adds these automatically. If you prefer a different target, set traefik.service (and traefik.port if it differs from the declared port).
Base variables are merged during service normalisation, including services using an image default command.
For more details on Traefik labels, see the Traefik reference.
- Inspect generated config for an app:
kata config:traefik <app> --json- List routers/services for your stack:
kata traefik:ls APP- Typical errors:
- “PORT not set”: ensure your service declares
ports/exposeand the app listens there (or settraefik.http.services.<name>.loadbalancer.server.port; Kata assumes 8000 if nothing is specified). - Traefik not running: start it or allow Kata to inject the minimal service; ensure the
traefik-proxynetwork exists. - DNS/TLS: verify your host rule matches a reachable domain and that ports 80/443 are open to the world.
- “PORT not set”: ensure your service declares
Each example declares a PORT and exposes it on the web service so Traefik can route to it. By default the first service (web) is targeted; set traefik.service/traefik.port if you need a different mapping.
- docs/examples/minimal-python — FastAPI on the Python runtime
- docs/examples/minimal-nodejs — Express on the Node.js runtime
- docs/examples/minimal-php — Built-in PHP server on the PHP runtime
- docs/examples/minimal-bun — Bun server on the Bun runtime
- docs/examples/static-site — BusyBox httpd with the static runtime
- docs/examples/generic-whoami — Stock image path without runtime helpers
Default per host state:
- Swarm active → deploy via
docker stack deploy - Swarm inactive → deploy via
docker compose up -d
Override per app:
x-kata-mode: compose # or swarmOr with CLI:
kata mode <app> # show
kata mode <app> compose # set & restart
kata mode <app> swarmHelper file .kata-mode in the app root persists the selection.
If a service defines:
services:
web:
runtime: python # or nodejs | php | bun | static
command: ["python", "-m", "app"]Kata will build (once) or reuse a kata/<runtime> image from an internal Dockerfile, bind‑mount app/config/data/venv, and run runtime-specific prep:
- python: create venv +
pip install -r requirements.txt - nodejs:
npm install - php:
composer install --no-dev --optimize-autoloader - bun:
bun install - static: no prep; use BusyBox httpd
If you supply image: yourself, no runtime automation runs.
Commands:
kata secrets:set NAME=VALUE # NAME=@file, NAME=- (stdin), or just NAME (prompt)
kata secrets:ls
kata secrets:rm NAMESecrets require a Swarm manager. Creation validates names before reading input, preserves binary file/stdin data, and fails non-zero. Avoid putting literal secret values in shell history.
Two internal commands (git-receive-pack / git-upload-pack) plus the git-hook are used when you push to a bare repo under $KATA_ROOT/repos/<app>. The post‑receive hook triggers git-hook which runs do_deploy.
You can also manually trigger deployment by piping a synthetic ref update:
echo "0000000000000000000000000000000000000000 $(git rev-parse HEAD) refs/heads/main" | kata git-hook <app>Selected commands (run kata help for full output):
| Command | Purpose |
|---|---|
| setup | Create root directories |
| ls | List apps & running state |
| restart | Restart whole app, or restart <app> <service...> (mode-aware) |
| stop / rm | Lifecycle management |
| mode | Get/set deploy mode |
| services | List an app's services (mode-aware) |
| containers [service] | Resolve concrete container IDs/names (label-based) |
| logs [service] | Tail logs (mode-aware; -f, --tail) |
| config:stack | Show original kata-compose.yaml |
| config:docker | Show generated .docker-compose.yaml |
| config:traefik | Show generated Traefik labels/config |
| traefik:ls / traefik:inspect | Inspect routers/services and labels |
| secrets:* | Manage Swarm secrets (validated names) |
| docker ... | Passthrough to docker |
| docker:services / ps | Inspect Swarm/Compose processes |
| run <cmd...> | Autodetect the container and exec into it |
| update | Self‑update kata.py from upstream (validates, backs up, re-execs) |
For a forced-command deployment key, use ssh kata@paas restart APP builder --logs.
For a regular shell account, use ssh user@host kata restart APP builder --logs.
restart needs an existing generated deployment; first deploy with Git, not by
copying an example and restarting it. run resolves local containers only and
supports non-interactive SSH without forcing a TTY.
make testUse an environment with click and pyyaml installed. The 31 regression tests cover lifecycle failures, cleanup guards, binary secrets, mode ordering, updater replacement and SSH exit status. Live Compose/Swarm lifecycle verification remains outstanding; see the spec.
Feedback / issues welcome. This README tracks the current code in kata.py; if something here is missing in code, file a bug.
