ADR 0022: Compose with four containers is the supported deployment
Status: Superseded in part by ADR 0037: Compose remains supported, but the Keycloak service is optional in external-provider mode.
Context
Karyo is tenanted by silo: one instance per operating company (ADR 0014), on a host that company or its implementer controls. The application is one deployable (ADR 0001), and it needs three things beside it: a PostgreSQL database (ADR 0004), Keycloak for identity (ADR 0013), and a web server that serves both front ends and the API from one origin (ADR 0016).
The scaling unit is the customer, not a module, and every module releases together, so nothing in the product consumes independent scaling or independent deployment of its parts. Whatever runs the stack is operated by the customer or their implementer, on one host, for the life of the installation, and its fixed overhead is paid by every installation.
Decision
The supported deployment is
infrastructure/docker/docker-compose.prod.yml: four containers on one bridge network, with one named volume for the database.Service Image Role postgresqlpostgres:16-alpinethe database; Keycloak's own database lives in the same server keycloakquay.io/keycloak/keycloak, tag pinned in the Compose fileidentity karyo-appbuilt from infrastructure/docker/Dockerfile.servicethe application, which migrates the schema at boot nginxbuilt from infrastructure/docker/Dockerfile.nginxboth front ends, and the reverse proxy for the API and Keycloak Only nginx publishes a host port, and it listens on plain HTTP. PostgreSQL, Keycloak and the application are reachable only on the Compose network. TLS, where an installation has it, terminates in front of the stack; nothing in this repository configures a certificate.
scripts/deploy-server.shis the installation mechanism. It checks the host, builds both images from source, renders one environment file into a file per service so that each container receives only its own values, and brings the stack up in dependency order behind healthchecks. Docker with the Compose plugin and Podman withpodman-composeare both supported.One host, one instance. There is no orchestrator, no second replica and no rolling restart.
Consequences
- The whole deployment is one file an operator can read, and it runs on any Linux host with a container runtime and systemd-journald - one virtual machine, or one machine in the warehouse.
- Every deploy is an outage. The deploy script stops the running stack before it starts the new one, and its header says to plan for that. With one instance there is nothing to fail over to.
- Nothing in the containers survives a redeploy except what is in the database volume. The
containers are removed, but their logs are in the host's journal (ADR 0026), because every service
uses the
journaldlogging driver. A host without systemd-journald cannot start the stack, and Stage 1 of the deploy script checks for it. - The application's memory is capped by Compose (
mem_limit, 1536 MiB unlessAPP_MEM_LIMITsays otherwise), not by an orchestrator's scheduler. - The deploy script builds both images on the target host, so that host carries a JDK and a Node toolchain.
- The images it builds are tagged
:latestunlessKARYO_APP_IMAGEandKARYO_NGINX_IMAGEsay otherwise. Why the default is a mutable tag is not recorded. - Horizontal scaling, zero-downtime upgrades and high availability are not available. A second application instance would not be safe as the product stands: the webhook relay's schedulers lock no rows, so two instances would deliver every event twice (ADR 0009).
- The application build also declares the Quarkus Kubernetes and Jib extensions, so every
quarkusBuildwrites Kubernetes manifests underservices/karyo-app/build/kubernetes/. Nothing uses them; the images come from the two Dockerfiles. Why the extensions are declared is not recorded.
Alternatives considered
- Kubernetes, with a lightweight distribution for small sites. Rejected. Its auto-scaling, self-healing and rolling updates each depend on having more than one replica of something, which one instance per company does not have. It costs specialised operational knowledge and a control plane whose overhead is significant against one modest host - a cost every installation would pay for as long as it runs.
- Pull-based continuous delivery, with a controller reconciling the cluster against a configuration repository. Rejected with Kubernetes: it assumes a cluster, and the controller is one more service to deploy and keep available. A single-host deployment is re-run by one script.
- An API gateway product in front of the application. Rejected. With one application behind it there is no routing across services to centralise; nginx serves the front ends and proxies the API and Keycloak from one configuration file. Rate limiting, which a gateway would have supplied, exists nowhere in the stack, and whether that is a decision is not recorded.
- Mutual TLS between internal services through a service mesh. Rejected: there are no service-to-service calls inside the application to protect. It reaches PostgreSQL and Keycloak over the private Compose network.
Evidence
infrastructure/docker/docker-compose.prod.yml,services, networks.karyo-net, volumes.karyo-pgdata- the four services, one network, one volumeinfrastructure/docker/docker-compose.prod.yml,services.nginx.ports- the one published portinfrastructure/docker/docker-compose.prod.yml,services.karyo-app.image, services.nginx.image- the:latestdefaultsinfrastructure/docker/docker-compose.prod.yml,services.karyo-app.mem_limit- the memory capinfrastructure/docker/nginx/nginx.conf,listen 80- nginx listens on plain HTTPinfrastructure/docker/init-db.sh,CREATE DATABASE keycloak- Keycloak's database in the same serverscripts/deploy-server.sh,header outage warning- the installation mechanism, and its warning to plan an outagescripts/deploy-server.sh,Stage 4: Build container images, build_image- both images built on the target hostscripts/deploy-server.sh,Stage 6: Start infrastructure (compose down)- the running stack is stopped before the new one startsservices/karyo-app/build.gradle.kts,libs.quarkus.container.image.jib, libs.quarkus.kubernetes- the Jib and Kubernetes extensions- Deploying
- Runtime and configuration