docker-compose.yml169 lines, 4.9 KB
| 1 | services: |
| 2 | postgres: |
| 3 | image: postgres:17-alpine |
| 4 | environment: |
| 5 | POSTGRES_USER: murmur |
| 6 | POSTGRES_PASSWORD: murmur |
| 7 | POSTGRES_DB: murmur |
| 8 | # one extra module: it counts what every statement costs, and it has to be loaded at startup |
| 9 | command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", |
| 10 | "-c", "pg_stat_statements.track_planning=on"] |
| 11 | ports: |
| 12 | - "5432:5432" |
| 13 | volumes: |
| 14 | - pgdata:/var/lib/postgresql/data |
| 15 | - ./deploy/primary.sh:/docker-entrypoint-initdb.d/primary.sh:ro |
| 16 | healthcheck: |
| 17 | test: ["CMD-SHELL", "pg_isready -U murmur"] |
| 18 | interval: 2s |
| 19 | timeout: 2s |
| 20 | retries: 15 |
| 21 | |
| 22 | # a copy of the database that follows the primary, for reads that may be a moment old |
| 23 | replica: |
| 24 | image: postgres:17-alpine |
| 25 | entrypoint: ["sh", "/replica.sh"] |
| 26 | command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", |
| 27 | "-c", "pg_stat_statements.track_planning=on", "-c", "wal_receiver_status_interval=1s"] |
| 28 | volumes: |
| 29 | - replicadata:/var/lib/postgresql/data |
| 30 | - ./deploy/replica.sh:/replica.sh:ro |
| 31 | depends_on: |
| 32 | postgres: |
| 33 | condition: service_healthy |
| 34 | healthcheck: |
| 35 | test: ["CMD-SHELL", "pg_isready -U murmur"] |
| 36 | interval: 2s |
| 37 | timeout: 2s |
| 38 | retries: 15 |
| 39 | start_period: 10m |
| 40 | |
| 41 | # a cache: everything in it can be rebuilt from Postgres, so nothing is saved to disk |
| 42 | redis: |
| 43 | image: redis:8-alpine |
| 44 | command: ["redis-server", "--save", "", "--appendonly", "no"] |
| 45 | ports: |
| 46 | - "6379:6379" |
| 47 | healthcheck: |
| 48 | test: ["CMD", "redis-cli", "ping"] |
| 49 | interval: 2s |
| 50 | timeout: 2s |
| 51 | retries: 15 |
| 52 | |
| 53 | # our own code: two API servers, from one image |
| 54 | api: |
| 55 | build: . |
| 56 | image: murmur |
| 57 | deploy: |
| 58 | replicas: ${API:-2} |
| 59 | environment: |
| 60 | DATABASE_URL: postgres://murmur:murmur@postgres:5432/murmur?sslmode=disable&connect_timeout=5 |
| 61 | REPLICA_URL: postgres://murmur:murmur@replica:5432/murmur?sslmode=disable&connect_timeout=5 |
| 62 | REDIS_URL: redis://redis:6379/0 |
| 63 | TRUSTED_PROXIES: 172.30.0.0/24 |
| 64 | IP_PER_MINUTE: ${IP_PER_MINUTE:-3000} |
| 65 | IP_BURST: ${IP_BURST:-100} |
| 66 | depends_on: |
| 67 | postgres: |
| 68 | condition: service_healthy |
| 69 | replica: |
| 70 | condition: service_healthy |
| 71 | redis: |
| 72 | condition: service_healthy |
| 73 | healthcheck: |
| 74 | test: ["CMD", "/api", "ready"] |
| 75 | interval: 2s |
| 76 | timeout: 3s |
| 77 | retries: 3 |
| 78 | restart: unless-stopped |
| 79 | stop_grace_period: 15s |
| 80 | |
| 81 | # and the worker, from the same image. The API runs the migrations, so it goes first |
| 82 | worker: |
| 83 | image: murmur |
| 84 | entrypoint: ["/worker"] |
| 85 | deploy: |
| 86 | replicas: ${WORKER:-1} |
| 87 | environment: |
| 88 | DATABASE_URL: postgres://murmur:murmur@postgres:5432/murmur?sslmode=disable&connect_timeout=5 |
| 89 | REDIS_URL: redis://redis:6379/0 |
| 90 | depends_on: |
| 91 | api: |
| 92 | condition: service_healthy |
| 93 | healthcheck: |
| 94 | test: ["CMD", "/worker", "ready"] |
| 95 | interval: 2s |
| 96 | timeout: 3s |
| 97 | retries: 3 |
| 98 | restart: unless-stopped |
| 99 | stop_grace_period: 25s |
| 100 | |
| 101 | # the load balancer: one door for every client, and the API servers behind it |
| 102 | nginx: |
| 103 | image: nginx:1.30.7 |
| 104 | ports: |
| 105 | - "8080:8080" |
| 106 | - "8088:8088" # the web app (make web) |
| 107 | volumes: |
| 108 | - ./deploy/nginx.conf:/etc/nginx/nginx.conf:ro |
| 109 | - ./web/dist:/srv/web:ro |
| 110 | depends_on: |
| 111 | api: |
| 112 | condition: service_healthy |
| 113 | |
| 114 | # metrics: Prometheus asks every process for its numbers, and keeps them |
| 115 | prometheus: |
| 116 | image: prom/prometheus:v3.16.0 |
| 117 | ports: |
| 118 | - "9090:9090" |
| 119 | volumes: |
| 120 | - ./deploy/prometheus.yml:/etc/prometheus/prometheus.yml:ro |
| 121 | - promdata:/prometheus |
| 122 | healthcheck: |
| 123 | test: ["CMD", "wget", "-qO-", "http://localhost:9090/-/ready"] |
| 124 | interval: 2s |
| 125 | timeout: 2s |
| 126 | retries: 15 |
| 127 | |
| 128 | # dashboards. Nobody logs in, and everybody may edit: for a laptop, never for a server |
| 129 | grafana: |
| 130 | image: grafana/grafana:13.3.1 |
| 131 | ports: |
| 132 | - "3000:3000" |
| 133 | environment: |
| 134 | GF_AUTH_ANONYMOUS_ENABLED: "true" |
| 135 | GF_AUTH_ANONYMOUS_ORG_ROLE: Admin |
| 136 | GF_AUTH_DISABLE_LOGIN_FORM: "true" |
| 137 | GF_ANALYTICS_REPORTING_ENABLED: "false" |
| 138 | GF_ANALYTICS_CHECK_FOR_UPDATES: "false" |
| 139 | GF_ANALYTICS_CHECK_FOR_PLUGIN_UPDATES: "false" |
| 140 | GF_NEWS_NEWS_FEED_ENABLED: "false" |
| 141 | volumes: |
| 142 | - ./deploy/grafana/provisioning:/etc/grafana/provisioning:ro |
| 143 | - ./deploy/grafana/dashboards:/var/lib/grafana/dashboards:ro |
| 144 | healthcheck: |
| 145 | test: ["CMD", "wget", "-qO-", "http://localhost:3000/api/health"] |
| 146 | interval: 2s |
| 147 | timeout: 2s |
| 148 | retries: 30 |
| 149 | |
| 150 | # load tests: docker compose run --rm k6 run /load/feed.js |
| 151 | k6: |
| 152 | image: grafana/k6:2.4.0 |
| 153 | profiles: [load] |
| 154 | volumes: |
| 155 | - ./load:/load |
| 156 | environment: |
| 157 | BASE_URL: http://nginx:8080 |
| 158 | |
| 159 | # one network for everything in this file, with a range of addresses that we choose |
| 160 | networks: |
| 161 | default: |
| 162 | ipam: |
| 163 | config: |
| 164 | - subnet: 172.30.0.0/24 |
| 165 | |
| 166 | volumes: |
| 167 | pgdata: |
| 168 | promdata: |
| 169 | replicadata: |