networks:
  blockd-net:
    name: blockd-net
    driver: bridge
  syslog:
    name: syslog
    driver: bridge

volumes:
  blockd-data: {}
  prometheus_data: {}

services:
  blockd:
    container_name: blockd
    build:
      context: .
      dockerfile: ./Dockerfile
    ports:
      - 8081:8080
    networks:
      - blockd-net
      - syslog
    depends_on:
      blockd-db:
        condition: service_healthy
      chain-api:
        condition: service_started
    profiles: [blockd]

  chain-api:
    container_name: chain-api
    build:
      context: ../chain-api
      dockerfile: ../chain-api/Dockerfile
    ports:
      - 3000:3000
    networks:
      - blockd-net
      - syslog

  blockd-db:
    container_name: blockd-db
    image: postgres:16
    restart: always
    environment:
      - POSTGRES_USER=blockd
      - POSTGRES_PASSWORD=blockd
      - POSTGRES_DB=blockd
    volumes:
      - blockd-data:/var/lib/postgresql/data
      - ./migrations/blockd.sql:/docker-entrypoint-initdb.d/init.sql
    ports:
      - 8432:5432
    networks:
      - blockd-net
    healthcheck:
      test: pg_isready -U blockd -d blockd
      interval: 1s
      timeout: 5s
      retries: 10
      start_period: 5s
    profiles: [blockd, database, noback]

  blockd-cache:
    container_name: blockd-cache 
    image: redis:7.2.4
    restart: always
    networks:
      - blockd-net
    ports:
      - 6379:6379
    profiles: [blockd, database, noback]

  prometheus:
    image: prom/prometheus
    container_name: prometheus
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
    ports:
      - 9091:9090
    restart: unless-stopped
    networks:
      - blockd-net
    volumes:
      - ./prometheus:/etc/prometheus
      - prometheus_data:/prometheus
    profiles: [metrics]

  grafana:
    image: grafana/grafana
    container_name: grafana
    ports:
      - 3112:3000
    restart: unless-stopped
    networks:
      - blockd-net
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=grafana
    volumes:
      - ./grafana:/etc/grafana/provisioning/datasources
    profiles: [metrics]

  syslog:
    image: linuxserver/syslog-ng:3.36.1 
    container_name: syslog-ng
    environment:
      - PUID=0
      - PGID=0
      - TZ=UTC
    volumes:
      - /srv/syslog/config:/config
      - /srv/syslog/logs:/var/log
    ports:
      - 514:5514/udp
      - 601:6601/tcp
      - 6514:6514/tcp
    restart: unless-stopped
    networks:
      - syslog
    logging:
      driver: "json-file"
    profiles: [metrics]

