|
| 1 | +version: "3.9" |
| 2 | + |
| 3 | +x-labels: &oncall-labels |
| 4 | + - "com.grafana.oncall.env=dev" |
| 5 | + |
| 6 | +x-user: &oncall-user "root" |
| 7 | + |
| 8 | +x-oncall-build: &oncall-build-args |
| 9 | + context: ./engine |
| 10 | + target: ${ONCALL_IMAGE_TARGET:-dev} |
| 11 | + labels: *oncall-labels |
| 12 | + |
| 13 | +x-oncall-volumes: &oncall-volumes |
| 14 | + - ./engine:/etc/app |
| 15 | + # see all the fun answers/comments here on why we need to do this |
| 16 | + # tldr; using /dev/null as a default leads to a lot of fun problems |
| 17 | + # https://stackoverflow.com/a/60456034 |
| 18 | + - ${ENTERPRISE_ENGINE:-/dev/null}:${ENTERPRISE_ENGINE_VOLUME_MOUNT_DEST_DIR:-/tmp/empty:ro} |
| 19 | + - ${SQLITE_DB_FILE:-/dev/null}:/var/lib/oncall/oncall.db |
| 20 | + # this is mounted for testing purposes. Some of the authorization tests |
| 21 | + # reference this file |
| 22 | + - ./grafana-plugin/src/plugin.json:/etc/grafana-plugin/src/plugin.json |
| 23 | + |
| 24 | +x-env-files: &oncall-env-files |
| 25 | + - ./dev/.env.dev |
| 26 | + - ./dev/.env.${DB}.dev |
| 27 | + |
| 28 | +x-env-vars: &oncall-env-vars |
| 29 | + BROKER_TYPE: ${BROKER_TYPE} |
| 30 | + GRAFANA_API_URL: http://localhost:3000 |
| 31 | + GOOGLE_APPLICATION_CREDENTIALS: /etc/app/gcp_service_account.json |
| 32 | + FCM_PROJECT_ID: oncall-mobile-dev |
| 33 | + |
| 34 | +# basically this is needed because the oncall backend containers have been configured to communicate w/ grafana via |
| 35 | +# http://localhost:3000 (GRAFANA_API_URL). This URL is used in two scenarios: |
| 36 | +# 1. oncall backend -> grafana API communication (happens within docker) |
| 37 | +# 2. accessing templated URLs generated by the oncall backend - meant to be accessed via a browser on your host machine |
| 38 | +# The alternative is to set GRAFANA_API_URL to http://grafana:3000. However, this would only work in scenario #1 |
| 39 | +# as http://grafana:3000 would not be resolvable on the host machine (without modifying /etc/hosts) |
| 40 | +# |
| 41 | +# by adding this extra_host entry to the oncall backend containers any calls to localhost will get routed to the docker |
| 42 | +# gateway, onto the host machine, where localhost:3000 points to grafana |
| 43 | +x-extra-hosts: &oncall-extra-hosts |
| 44 | + - "localhost:host-gateway" |
| 45 | + |
| 46 | +services: |
| 47 | + oncall_ui: |
| 48 | + container_name: oncall_ui |
| 49 | + labels: *oncall-labels |
| 50 | + build: |
| 51 | + context: ./grafana-plugin |
| 52 | + dockerfile: Dockerfile.dev |
| 53 | + labels: *oncall-labels |
| 54 | + environment: |
| 55 | + ONCALL_API_URL: http://host.docker.internal:8080 |
| 56 | + volumes: |
| 57 | + - ./grafana-plugin:/etc/app |
| 58 | + - node_modules_dev:/etc/app/node_modules |
| 59 | + # https://stackoverflow.com/a/60456034 |
| 60 | + # see the explaination above that uses the $ENTERPRISE_ENGINE env var |
| 61 | + - ${ENTERPRISE_FRONTEND:-/dev/null}:${ENTERPRISE_FRONTEND_VOLUME_MOUNT_DEST_DIR:-/tmp/empty:ro} |
| 62 | + profiles: |
| 63 | + - oncall_ui |
| 64 | + |
| 65 | + oncall_engine: |
| 66 | + container_name: oncall_engine |
| 67 | + labels: *oncall-labels |
| 68 | + build: *oncall-build-args |
| 69 | + restart: always |
| 70 | + user: *oncall-user |
| 71 | + command: sh -c "uwsgi --disable-logging --py-autoreload 3 --ini uwsgi.ini" |
| 72 | + env_file: *oncall-env-files |
| 73 | + environment: *oncall-env-vars |
| 74 | + volumes: *oncall-volumes |
| 75 | + extra_hosts: *oncall-extra-hosts |
| 76 | + ports: |
| 77 | + - "8080:8080" |
| 78 | + depends_on: |
| 79 | + oncall_db_migration: |
| 80 | + condition: service_completed_successfully |
| 81 | + profiles: |
| 82 | + - engine |
| 83 | + |
| 84 | + oncall_telegram_polling: |
| 85 | + container_name: oncall_telegram_polling |
| 86 | + labels: *oncall-labels |
| 87 | + build: *oncall-build-args |
| 88 | + restart: always |
| 89 | + user: *oncall-user |
| 90 | + command: sh -c "python manage.py start_telegram_polling" |
| 91 | + env_file: *oncall-env-files |
| 92 | + environment: *oncall-env-vars |
| 93 | + volumes: *oncall-volumes |
| 94 | + extra_hosts: *oncall-extra-hosts |
| 95 | + depends_on: |
| 96 | + oncall_db_migration: |
| 97 | + condition: service_completed_successfully |
| 98 | + profiles: |
| 99 | + - telegram_polling |
| 100 | + |
| 101 | + # used to invoke one-off commands, primarily from the Makefile |
| 102 | + # oncall_engine couldn't (easily) be used due to it's depends_on property |
| 103 | + # we could alternatively just use `docker run` however that would require |
| 104 | + # duplicating the env-files, volume mounts, etc in the Makefile |
| 105 | + oncall_engine_commands: |
| 106 | + container_name: oncall_engine_commands |
| 107 | + labels: *oncall-labels |
| 108 | + build: *oncall-build-args |
| 109 | + user: *oncall-user |
| 110 | + env_file: *oncall-env-files |
| 111 | + environment: *oncall-env-vars |
| 112 | + volumes: *oncall-volumes |
| 113 | + extra_hosts: *oncall-extra-hosts |
| 114 | + profiles: |
| 115 | + # no need to start this except from within the Makefile |
| 116 | + - _engine_commands |
| 117 | + |
| 118 | + oncall_celery: |
| 119 | + container_name: oncall_celery |
| 120 | + labels: *oncall-labels |
| 121 | + build: *oncall-build-args |
| 122 | + restart: always |
| 123 | + user: *oncall-user |
| 124 | + command: "python manage.py start_celery" |
| 125 | + env_file: *oncall-env-files |
| 126 | + environment: *oncall-env-vars |
| 127 | + volumes: *oncall-volumes |
| 128 | + extra_hosts: *oncall-extra-hosts |
| 129 | + depends_on: |
| 130 | + oncall_db_migration: |
| 131 | + condition: service_completed_successfully |
| 132 | + profiles: |
| 133 | + - engine |
| 134 | + |
| 135 | + flower: |
| 136 | + container_name: flower |
| 137 | + labels: *oncall-labels |
| 138 | + image: mher/flower:1.2.0 |
| 139 | + environment: |
| 140 | + # TODO: make this work properly w/ BROKER_TYPE env var |
| 141 | + CELERY_BROKER_URL: "redis://redis:6379/0" |
| 142 | + ports: |
| 143 | + - "5555:5555" |
| 144 | + depends_on: |
| 145 | + oncall_celery: |
| 146 | + condition: service_started |
| 147 | + profiles: |
| 148 | + - engine |
| 149 | + |
| 150 | + oncall_db_migration: |
| 151 | + container_name: oncall_db_migration |
| 152 | + labels: *oncall-labels |
| 153 | + build: *oncall-build-args |
| 154 | + user: *oncall-user |
| 155 | + command: "python manage.py migrate --noinput" |
| 156 | + env_file: *oncall-env-files |
| 157 | + environment: *oncall-env-vars |
| 158 | + volumes: *oncall-volumes |
| 159 | + extra_hosts: *oncall-extra-hosts |
| 160 | + depends_on: |
| 161 | + postgres: |
| 162 | + condition: service_healthy |
| 163 | + required: false |
| 164 | + mysql: |
| 165 | + condition: service_healthy |
| 166 | + required: false |
| 167 | + rabbitmq: |
| 168 | + condition: service_healthy |
| 169 | + required: false |
| 170 | + redis: |
| 171 | + condition: service_healthy |
| 172 | + required: false |
| 173 | + profiles: |
| 174 | + - engine |
| 175 | + |
| 176 | + redis: |
| 177 | + container_name: redis |
| 178 | + labels: *oncall-labels |
| 179 | + image: redis:7.0.5 |
| 180 | + restart: always |
| 181 | + ports: |
| 182 | + - "6379:6379" |
| 183 | + deploy: |
| 184 | + labels: *oncall-labels |
| 185 | + resources: |
| 186 | + limits: |
| 187 | + memory: 500m |
| 188 | + cpus: "0.5" |
| 189 | + healthcheck: |
| 190 | + test: ["CMD", "redis-cli", "ping"] |
| 191 | + timeout: 5s |
| 192 | + interval: 5s |
| 193 | + retries: 10 |
| 194 | + volumes: |
| 195 | + - redisdata_dev:/data |
| 196 | + profiles: |
| 197 | + - redis |
| 198 | + |
| 199 | + rabbitmq: |
| 200 | + container_name: rabbitmq |
| 201 | + labels: *oncall-labels |
| 202 | + image: "rabbitmq:3.12.0-management" |
| 203 | + restart: always |
| 204 | + environment: |
| 205 | + RABBITMQ_DEFAULT_USER: "rabbitmq" |
| 206 | + RABBITMQ_DEFAULT_PASS: "rabbitmq" |
| 207 | + RABBITMQ_DEFAULT_VHOST: "/" |
| 208 | + ports: |
| 209 | + - "15672:15672" |
| 210 | + - "5672:5672" |
| 211 | + deploy: |
| 212 | + labels: *oncall-labels |
| 213 | + resources: |
| 214 | + limits: |
| 215 | + memory: 1000m |
| 216 | + cpus: "0.5" |
| 217 | + healthcheck: |
| 218 | + test: rabbitmq-diagnostics -q ping |
| 219 | + interval: 30s |
| 220 | + timeout: 30s |
| 221 | + retries: 3 |
| 222 | + volumes: |
| 223 | + - rabbitmqdata_dev:/var/lib/rabbitmq |
| 224 | + profiles: |
| 225 | + - rabbitmq |
| 226 | + |
| 227 | + mysql: |
| 228 | + container_name: mysql |
| 229 | + labels: *oncall-labels |
| 230 | + image: mysql:8.0.32 |
| 231 | + command: >- |
| 232 | + --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 |
| 233 | + --collation-server=utf8mb4_unicode_ci --max_connections=1024 |
| 234 | + restart: always |
| 235 | + environment: |
| 236 | + MYSQL_ROOT_PASSWORD: empty |
| 237 | + MYSQL_DATABASE: oncall_local_dev |
| 238 | + ports: |
| 239 | + - "3306:3306" |
| 240 | + deploy: |
| 241 | + labels: *oncall-labels |
| 242 | + resources: |
| 243 | + limits: |
| 244 | + memory: 1000m |
| 245 | + cpus: "0.5" |
| 246 | + healthcheck: |
| 247 | + test: "mysql -uroot -pempty oncall_local_dev -e 'select 1'" |
| 248 | + timeout: 20s |
| 249 | + retries: 10 |
| 250 | + volumes: |
| 251 | + - mysqldata_dev:/var/lib/mysql |
| 252 | + profiles: |
| 253 | + - mysql |
| 254 | + |
| 255 | + mysql_to_create_grafana_db: |
| 256 | + container_name: mysql_to_create_grafana_db |
| 257 | + labels: *oncall-labels |
| 258 | + image: mysql:8.0.32 |
| 259 | + command: >- |
| 260 | + bash -c "mysql -h mysql -uroot -pempty |
| 261 | + -e 'CREATE DATABASE IF NOT EXISTS grafana CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'" |
| 262 | + depends_on: |
| 263 | + mysql: |
| 264 | + condition: service_healthy |
| 265 | + profiles: |
| 266 | + - mysql |
| 267 | + |
| 268 | + postgres: |
| 269 | + container_name: postgres |
| 270 | + labels: *oncall-labels |
| 271 | + image: postgres:14.4 |
| 272 | + restart: always |
| 273 | + environment: |
| 274 | + POSTGRES_DB: oncall_local_dev |
| 275 | + POSTGRES_PASSWORD: empty |
| 276 | + POSTGRES_INITDB_ARGS: --encoding=UTF-8 |
| 277 | + ports: |
| 278 | + - "5432:5432" |
| 279 | + deploy: |
| 280 | + labels: *oncall-labels |
| 281 | + resources: |
| 282 | + limits: |
| 283 | + memory: 500m |
| 284 | + cpus: "0.5" |
| 285 | + healthcheck: |
| 286 | + test: ["CMD", "pg_isready", "-U", "postgres"] |
| 287 | + interval: 10s |
| 288 | + timeout: 5s |
| 289 | + retries: 5 |
| 290 | + volumes: |
| 291 | + - postgresdata_dev:/var/lib/postgresql/data |
| 292 | + profiles: |
| 293 | + - postgres |
| 294 | + |
| 295 | + postgres_to_create_grafana_db: |
| 296 | + container_name: postgres_to_create_grafana_db |
| 297 | + labels: *oncall-labels |
| 298 | + image: postgres:14.4 |
| 299 | + command: >- |
| 300 | + bash -c "PGPASSWORD=empty psql -U postgres |
| 301 | + -h postgres -tc \"SELECT 1 FROM pg_database WHERE datname = 'grafana'\" | grep -q 1 || PGPASSWORD=empty psql |
| 302 | + -U postgres -h postgres -c \"CREATE DATABASE grafana\"" |
| 303 | + depends_on: |
| 304 | + postgres: |
| 305 | + condition: service_healthy |
| 306 | + profiles: |
| 307 | + - postgres |
| 308 | + |
| 309 | + prometheus: |
| 310 | + container_name: prometheus |
| 311 | + labels: *oncall-labels |
| 312 | + image: prom/prometheus |
| 313 | + volumes: |
| 314 | + - ./dev/prometheus.yml:/etc/prometheus/prometheus.yml |
| 315 | + ports: |
| 316 | + - "9090:9090" |
| 317 | + profiles: |
| 318 | + - prometheus |
| 319 | + |
| 320 | + grafana: |
| 321 | + container_name: grafana |
| 322 | + labels: *oncall-labels |
| 323 | + image: "grafana/${GRAFANA_IMAGE:-grafana:latest}" |
| 324 | + restart: always |
| 325 | + environment: |
| 326 | + GF_SECURITY_ADMIN_USER: oncall |
| 327 | + GF_SECURITY_ADMIN_PASSWORD: oncall |
| 328 | + GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: grafana-oncall-app |
| 329 | + env_file: |
| 330 | + - ./dev/.env.${DB}.dev |
| 331 | + ports: |
| 332 | + - "3000:3000" |
| 333 | + deploy: |
| 334 | + labels: *oncall-labels |
| 335 | + resources: |
| 336 | + limits: |
| 337 | + memory: 500m |
| 338 | + cpus: "0.5" |
| 339 | + extra_hosts: |
| 340 | + - "host.docker.internal:host-gateway" |
| 341 | + volumes: |
| 342 | + - grafanadata_dev:/var/lib/grafana |
| 343 | + - ./grafana-plugin:/var/lib/grafana/plugins/grafana-plugin |
| 344 | + - ./dev/grafana/provisioning:/etc/grafana/provisioning |
| 345 | + - ${GRAFANA_DEV_PROVISIONING:-/dev/null}:/etc/grafana/grafana.ini |
| 346 | + depends_on: |
| 347 | + postgres: |
| 348 | + condition: service_healthy |
| 349 | + required: false |
| 350 | + mysql: |
| 351 | + condition: service_healthy |
| 352 | + required: false |
| 353 | + profiles: |
| 354 | + - grafana |
| 355 | + |
| 356 | +volumes: |
| 357 | + redisdata_dev: |
| 358 | + labels: *oncall-labels |
| 359 | + grafanadata_dev: |
| 360 | + labels: *oncall-labels |
| 361 | + rabbitmqdata_dev: |
| 362 | + labels: *oncall-labels |
| 363 | + postgresdata_dev: |
| 364 | + labels: *oncall-labels |
| 365 | + mysqldata_dev: |
| 366 | + labels: *oncall-labels |
| 367 | + node_modules_dev: |
| 368 | + labels: *oncall-labels |
| 369 | + |
| 370 | +networks: |
| 371 | + default: |
| 372 | + name: oncall_dev |
| 373 | + labels: *oncall-labels |
0 commit comments