docker-compose.yml295 lines, 10 KB
| 1 | # Our five services, from their images, are in the app profile: |
| 2 | # docker compose --profile app up -d --build --wait |
| 3 | # Plain docker compose up still starts only the infrastructure. |
| 4 | x-service: &service |
| 5 | profiles: [app] |
| 6 | restart: unless-stopped |
| 7 | # Our binaries write nothing to disk, and need no Linux capabilities. |
| 8 | read_only: true |
| 9 | cap_drop: [ALL] |
| 10 | security_opt: [no-new-privileges:true] |
| 11 | |
| 12 | # A service's migrations: its own image, with -migrate, once, before it starts. |
| 13 | x-migrate: &migrate |
| 14 | profiles: [app] |
| 15 | command: ["-migrate"] |
| 16 | depends_on: |
| 17 | postgres: {condition: service_healthy} |
| 18 | |
| 19 | # What every service gets: JSON logs, like production, and traces to Jaeger. |
| 20 | # APP_ENV stays development, to keep every trace: production keeps one in ten. |
| 21 | x-env: &env |
| 22 | APP_ENV: development |
| 23 | LOG_FORMAT: json |
| 24 | OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger:4318 |
| 25 | |
| 26 | services: |
| 27 | postgres: |
| 28 | image: postgres:17-alpine |
| 29 | container_name: payments-postgres |
| 30 | # pg_stat_statements keeps statistics on every query: how often it ran, |
| 31 | # and how long it took. It has to be loaded when Postgres starts. |
| 32 | command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements"] |
| 33 | environment: |
| 34 | POSTGRES_USER: payments |
| 35 | POSTGRES_PASSWORD: payments |
| 36 | POSTGRES_DB: payments |
| 37 | ports: |
| 38 | - "5432:5432" |
| 39 | volumes: |
| 40 | - pgdata:/var/lib/postgresql/data |
| 41 | - ./deploy/postgres:/docker-entrypoint-initdb.d:ro |
| 42 | healthcheck: |
| 43 | # Over TCP: while its init scripts run, Postgres only listens on its |
| 44 | # socket, so a check through the socket says ready too early. |
| 45 | test: ["CMD-SHELL", "pg_isready -U payments -h 127.0.0.1"] |
| 46 | interval: 5s |
| 47 | timeout: 3s |
| 48 | retries: 10 |
| 49 | |
| 50 | redis: |
| 51 | image: redis:8-alpine |
| 52 | container_name: payments-redis |
| 53 | ports: |
| 54 | - "6379:6379" |
| 55 | |
| 56 | nats: |
| 57 | image: nats:2.11-alpine |
| 58 | container_name: payments-nats |
| 59 | command: ["-js", "-m", "8222"] |
| 60 | ports: |
| 61 | - "4222:4222" |
| 62 | - "8222:8222" |
| 63 | # Busybox's wget is in the image: healthy once JetStream is up. |
| 64 | healthcheck: |
| 65 | test: ["CMD", "wget", "-q", "--spider", "http://localhost:8222/healthz?js-enabled-only=true"] |
| 66 | interval: 5s |
| 67 | timeout: 3s |
| 68 | retries: 10 |
| 69 | |
| 70 | # Catches every email we send, in development. Its inbox: localhost:8025. |
| 71 | mailpit: |
| 72 | image: axllent/mailpit:v1.27 |
| 73 | container_name: payments-mailpit |
| 74 | ports: |
| 75 | - "1025:1025" |
| 76 | - "8025:8025" |
| 77 | |
| 78 | # Traces: OTLP comes in on 4317 (gRPC) and 4318 (HTTP), and the UI is on |
| 79 | # 16686. It keeps traces in memory, which is plenty for development. |
| 80 | jaeger: |
| 81 | image: jaegertracing/jaeger:2.22.0 |
| 82 | container_name: payments-jaeger |
| 83 | ports: |
| 84 | - "4317:4317" |
| 85 | - "4318:4318" |
| 86 | - "16686:16686" |
| 87 | |
| 88 | # Metrics: it scrapes every service's /metrics. Its UI is on 9090. |
| 89 | prometheus: |
| 90 | image: prom/prometheus:v3.15.1 |
| 91 | container_name: payments-prometheus |
| 92 | volumes: |
| 93 | - ./deploy/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro |
| 94 | ports: |
| 95 | - "9090:9090" |
| 96 | # Our services run on the host, outside Docker. Docker Desktop knows |
| 97 | # this name; on Linux, it needs this line. |
| 98 | extra_hosts: |
| 99 | - "host.docker.internal:host-gateway" |
| 100 | |
| 101 | # Dashboards, on port 3000. Its data sources and dashboards come from |
| 102 | # files, so nothing is ever clicked together by hand. |
| 103 | grafana: |
| 104 | image: grafana/grafana:13.2.6 |
| 105 | container_name: payments-grafana |
| 106 | environment: |
| 107 | # Development only: no login, and everyone is an admin. |
| 108 | GF_AUTH_ANONYMOUS_ENABLED: "true" |
| 109 | GF_AUTH_ANONYMOUS_ORG_ROLE: Admin |
| 110 | GF_AUTH_DISABLE_LOGIN_FORM: "true" |
| 111 | volumes: |
| 112 | - ./deploy/grafana/provisioning:/etc/grafana/provisioning:ro |
| 113 | - ./deploy/grafana/dashboards:/var/lib/grafana/dashboards:ro |
| 114 | ports: |
| 115 | - "3000:3000" |
| 116 | |
| 117 | wallet: |
| 118 | <<: *service |
| 119 | build: {context: ., args: {SERVICE: wallet, VERSION: "${VERSION:-dev}"}} |
| 120 | image: payments/wallet |
| 121 | environment: &wallet-env |
| 122 | <<: *env |
| 123 | WALLET_DATABASE_URL: postgres://wallet_app:wallet_app@postgres:5432/wallet?sslmode=disable |
| 124 | WALLET_REDIS_URL: redis://redis:6379/0 |
| 125 | WALLET_NATS_URL: nats://nats:4222 |
| 126 | WALLET_AUTH_PUBLIC_KEY_FILE: /run/secrets/auth_public_key |
| 127 | # Every fifteen seconds here, to watch it work. By default: daily, at 02:00 UTC. |
| 128 | WALLET_RECONCILE_EVERY: 15s |
| 129 | WALLET_TLS_DIR: /run/secrets/wallet_tls |
| 130 | secrets: [auth_public_key, wallet_tls] |
| 131 | ports: ["8081:8081", "9081:9081", "9091:9091"] # gRPC and internal: mTLS |
| 132 | depends_on: |
| 133 | wallet-migrate: {condition: service_completed_successfully} |
| 134 | nats: {condition: service_healthy} |
| 135 | |
| 136 | wallet-migrate: |
| 137 | <<: *migrate |
| 138 | image: payments/wallet |
| 139 | environment: |
| 140 | <<: *wallet-env |
| 141 | # The owner: the only role that can change the schema. |
| 142 | WALLET_DATABASE_URL: postgres://wallet_owner:wallet_owner@postgres:5432/wallet?sslmode=disable |
| 143 | |
| 144 | auth: |
| 145 | <<: *service |
| 146 | build: {context: ., args: {SERVICE: auth, VERSION: "${VERSION:-dev}"}} |
| 147 | image: payments/auth |
| 148 | environment: &auth-env |
| 149 | <<: *env |
| 150 | AUTH_DATABASE_URL: postgres://auth_app:auth_app@postgres:5432/auth?sslmode=disable |
| 151 | AUTH_PRIVATE_KEY_FILE: /run/secrets/auth_private_key |
| 152 | AUTH_TLS_DIR: /run/secrets/auth_tls |
| 153 | secrets: [auth_private_key, auth_tls] |
| 154 | ports: ["8082:8082"] |
| 155 | depends_on: |
| 156 | auth-migrate: {condition: service_completed_successfully} |
| 157 | |
| 158 | auth-migrate: |
| 159 | <<: *migrate |
| 160 | image: payments/auth |
| 161 | environment: |
| 162 | <<: *auth-env |
| 163 | AUTH_DATABASE_URL: postgres://auth_owner:auth_owner@postgres:5432/auth?sslmode=disable |
| 164 | |
| 165 | transfer: |
| 166 | <<: *service |
| 167 | build: {context: ., args: {SERVICE: transfer, VERSION: "${VERSION:-dev}"}} |
| 168 | image: payments/transfer |
| 169 | environment: &transfer-env |
| 170 | <<: *env |
| 171 | TRANSFER_DATABASE_URL: postgres://transfer_app:transfer_app@postgres:5432/transfer?sslmode=disable |
| 172 | TRANSFER_WALLET_ADDR: ${TRANSFER_WALLET_ADDR:-dns:///wallet:9081} # make chaos-up: through Toxiproxy |
| 173 | TRANSFER_NATS_URL: nats://nats:4222 |
| 174 | TRANSFER_REDIS_URL: redis://redis:6379/0 |
| 175 | TRANSFER_AUTH_PUBLIC_KEY_FILE: /run/secrets/auth_public_key |
| 176 | TRANSFER_TLS_DIR: /run/secrets/transfer_tls |
| 177 | TRANSFER_RISK_MAX_COUNT: ${TRANSFER_RISK_MAX_COUNT:-5} # load tests need more: make loadtest-up |
| 178 | secrets: [auth_public_key, transfer_tls] |
| 179 | ports: ["8083:8083", "9083:9083"] |
| 180 | depends_on: |
| 181 | transfer-migrate: {condition: service_completed_successfully} |
| 182 | nats: {condition: service_healthy} |
| 183 | |
| 184 | transfer-migrate: |
| 185 | <<: *migrate |
| 186 | image: payments/transfer |
| 187 | environment: |
| 188 | <<: *transfer-env |
| 189 | TRANSFER_DATABASE_URL: postgres://transfer_owner:transfer_owner@postgres:5432/transfer?sslmode=disable |
| 190 | |
| 191 | # It consumes the wallet's and the transfer service's streams, which they |
| 192 | # create when they start: so it starts after them. |
| 193 | notification: |
| 194 | <<: *service |
| 195 | build: {context: ., args: {SERVICE: notification, VERSION: "${VERSION:-dev}"}} |
| 196 | image: payments/notification |
| 197 | environment: ¬ification-env |
| 198 | <<: *env |
| 199 | NOTIFICATION_DATABASE_URL: postgres://notification_app:notification_app@postgres:5432/notification?sslmode=disable |
| 200 | NOTIFICATION_NATS_URL: nats://nats:4222 |
| 201 | NOTIFICATION_AUTH_URL: https://auth:9082 |
| 202 | NOTIFICATION_SMTP_ADDR: mailpit:1025 |
| 203 | NOTIFICATION_TLS_DIR: /run/secrets/notification_tls |
| 204 | secrets: [notification_tls] |
| 205 | ports: ["8084:8084"] |
| 206 | depends_on: |
| 207 | notification-migrate: {condition: service_completed_successfully} |
| 208 | wallet: {condition: service_healthy} |
| 209 | transfer: {condition: service_healthy} |
| 210 | |
| 211 | notification-migrate: |
| 212 | <<: *migrate |
| 213 | image: payments/notification |
| 214 | environment: |
| 215 | <<: *notification-env |
| 216 | NOTIFICATION_DATABASE_URL: postgres://notification_owner:notification_owner@postgres:5432/notification?sslmode=disable |
| 217 | |
| 218 | # The only one that faces the internet. 9080 is its metrics and probes port. |
| 219 | gateway: |
| 220 | <<: *service |
| 221 | build: {context: ., args: {SERVICE: gateway, VERSION: "${VERSION:-dev}"}} |
| 222 | image: payments/gateway |
| 223 | environment: |
| 224 | <<: *env |
| 225 | GATEWAY_WALLET_ADDR: dns:///wallet:9081 |
| 226 | GATEWAY_AUTH_URL: http://auth:8082 |
| 227 | GATEWAY_TRANSFER_URL: ${GATEWAY_TRANSFER_URL:-http://transfer:8083} # make chaos-up: through Toxiproxy |
| 228 | GATEWAY_WEBHOOK_URL: http://webhook:8085 |
| 229 | GATEWAY_WALLET_URL: http://wallet:8081 |
| 230 | GATEWAY_REDIS_URL: redis://redis:6379/0 |
| 231 | GATEWAY_AUTH_PUBLIC_KEY_FILE: /run/secrets/auth_public_key |
| 232 | GATEWAY_IP_LIMIT: ${GATEWAY_IP_LIMIT:-20} |
| 233 | GATEWAY_TLS_DIR: /run/secrets/gateway_tls |
| 234 | secrets: [auth_public_key, gateway_tls] |
| 235 | ports: ["8080:8080", "9080:9080", "9088:9088"] # 9088: internal, mTLS |
| 236 | |
| 237 | # Webhooks. It consumes the transfer service's stream, so it starts after it. |
| 238 | webhook: |
| 239 | <<: *service |
| 240 | build: {context: ., args: {SERVICE: webhook, VERSION: "${VERSION:-dev}"}} |
| 241 | image: payments/webhook |
| 242 | environment: &webhook-env |
| 243 | <<: *env |
| 244 | WEBHOOK_DATABASE_URL: postgres://webhook_app:webhook_app@postgres:5432/webhook?sslmode=disable |
| 245 | WEBHOOK_NATS_URL: nats://nats:4222 |
| 246 | WEBHOOK_AUTH_PUBLIC_KEY_FILE: /run/secrets/auth_public_key |
| 247 | WEBHOOK_RETRY_SCHEDULE: ${WEBHOOK_RETRY_SCHEDULE:-} # empty: the real one |
| 248 | secrets: [auth_public_key] |
| 249 | ports: ["8085:8085"] |
| 250 | # For receivers on this machine, outside Docker: Linux needs this line. |
| 251 | extra_hosts: ["host.docker.internal:host-gateway"] |
| 252 | depends_on: |
| 253 | webhook-migrate: {condition: service_completed_successfully} |
| 254 | transfer: {condition: service_healthy} |
| 255 | |
| 256 | webhook-migrate: |
| 257 | <<: *migrate |
| 258 | image: payments/webhook |
| 259 | environment: |
| 260 | <<: *webhook-env |
| 261 | WEBHOOK_DATABASE_URL: postgres://webhook_owner:webhook_owner@postgres:5432/webhook?sslmode=disable |
| 262 | |
| 263 | # Network faults, on demand, for chaos experiments: a TCP proxy that we can |
| 264 | # slow down or cut, through its API on port 8474. make chaos-up puts it in |
| 265 | # front of the transfer service, and of the wallet's gRPC port. |
| 266 | toxiproxy: |
| 267 | image: ghcr.io/shopify/toxiproxy:2.12.0 |
| 268 | profiles: [chaos] |
| 269 | command: ["-host=0.0.0.0", "-config=/etc/toxiproxy.json"] |
| 270 | volumes: |
| 271 | - ./deploy/chaos/toxiproxy.json:/etc/toxiproxy.json:ro |
| 272 | ports: |
| 273 | - "8474:8474" |
| 274 | |
| 275 | volumes: |
| 276 | pgdata: |
| 277 | |
| 278 | # Mounted as files under /run/secrets, never copied into an image. make keys |
| 279 | # and make certs create them. |
| 280 | secrets: |
| 281 | auth_private_key: |
| 282 | file: secrets/auth_ed25519.pem |
| 283 | auth_public_key: |
| 284 | file: secrets/auth_ed25519.pub.pem |
| 285 | # A directory each, from make certs. |
| 286 | wallet_tls: |
| 287 | file: secrets/tls/wallet |
| 288 | auth_tls: |
| 289 | file: secrets/tls/auth |
| 290 | transfer_tls: |
| 291 | file: secrets/tls/transfer |
| 292 | notification_tls: |
| 293 | file: secrets/tls/notification |
| 294 | gateway_tls: |
| 295 | file: secrets/tls/gateway |