version: '3'
name: fbl13

x-restart-policy: &restart-policy
  restart: unless-stopped
x-depends_on-default: &depends_on
  condition: service_started
x-depends_on-healthy: &depends_on-healthy
  condition: service_healthy
x-healthcheck_defaults: &healthcheck_defaults
  interval: 10s
  timeout: 2s
  retries: 5
  start_period: 5s
x-c3nav-defaults: &c3nav-defaults
  image: ghcr.io/c3nav/c3nav:${C3NAV_TAG}
  depends_on:
    redis:
      <<: *depends_on-healthy
  volumes:
    - type: bind
      source: ${C3NAV_DOCKER_DATA_DIR:-./data}
      target: /data
      bind:
        create_host_path: true
x-c3nav-environment: &c3nav-environment
  C3NAV_LOGLEVEL: info
  C3NAV_CONFIG: /data/c3nav.cfg
  C3NAV_DATA_DIR: /data
  UWSGI_WORKERS: ${C3NAV_CORE_WORKERS:-2}

services:
  c3nav-core:
    <<: [*restart-policy, *c3nav-defaults]
    command: webstatic-async
    environment:
      <<: *c3nav-environment
      C3NAV_AUTOMIGRATE: yes
    env_file:
      - .env
    healthcheck:
      <<: *healthcheck_defaults
      test: curl -f http://localhost:8000/
    ports:
      - "31025:8000"
    networks:
      - fbl13
      - rick_db

  c3nav-workers:
    <<: [*restart-policy, *c3nav-defaults]
    command: worker
    environment:
      <<: *c3nav-environment
      C3NAV_AUTOMIGRATE: no
    healthcheck:
      interval: 30s
      timeout: 15s
      retries: 2
      start_period: 5s
      test: entrypoint worker_healthcheck
    networks:
      - fbl13
      - rick_db

  redis:
    <<: *restart-policy
    image: redis:7.2
    command: redis-server --save 60 1 --loglevel warning
    healthcheck:
      <<: *healthcheck_defaults
      test: redis-cli ping
    volumes:
      - "fbl13:/data"
    ulimits:
      nofile:
        soft: 10032
        hard: 10032
    networks:
      - fbl13

volumes:
  fbl13:
    external: true

networks:
  rick_db:
    name: rick_db
    external: true
  fbl13:
    driver: bridge