services:

  database:
    image: postgres:16-alpine
    restart: always
    env_file:
      - ./envs/postgres
    volumes:
      - ./configs/postgres/init/:/docker-entrypoint-initdb.d/
      - ./data/postgres/:/var/lib/postgresql/data/
    healthcheck:
      test: "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"
      interval: 5s
      retries: 20

  redis:
    image: redis:alpine
    restart: always
    volumes:
      - ./data/redis/:/data/
    healthcheck:
      test: ["CMD", "redis-cli", "ping", "|", "grep", "PONG"]
      interval: 1s
      timeout: 5s
      retries: 5

  plc:
    ports:
      - 2582:3000
    build:
      context: ./repos/did-method-plc/
      dockerfile: packages/server/Dockerfile
    restart: always
    env_file:
      - ./envs/plc
    depends_on:
      database:
        condition: service_healthy

  pds:
    ports:
      - 2583:3000
    build:
      context: ./repos/atproto/
      dockerfile: services/pds/Dockerfile
    restart: always
    env_file:
      - ./envs/pds
    volumes:
      - ./data/pds/:/data/
    command: node --enable-source-maps index.js
    depends_on:
      database:
        condition: service_healthy

  bsky:
    ports:
      - 2584:2584
    build:
      context: ./repos/atproto/
      dockerfile: services/bsky/Dockerfile
    restart: always
    env_file:
      - ./envs/bsky
    user: root
    volumes:
      - ./data/bsky/:/data/
    command: node --enable-source-maps api.js
    depends_on:
      database:
        condition: service_healthy
      redis:
        condition: service_healthy

  bgs:
    ports:
      - 2470:2470
    build:
      context: ./repos/indigo/
      dockerfile: cmd/relay/Dockerfile
    restart: always
    env_file:
      - ./envs/bgs
    volumes:
      - ./data/bgs/:/data/
    depends_on:
      database:
        condition: service_healthy
    #command: ["/bigsky", "--crawl-insecure-ws"]

  social-app:
    ports:
      - 8100:8100
    build:
      context: ./repos/social-app/
      dockerfile: Dockerfile
    restart: always
    env_file:
      - ./envs/social-app
    command: "/usr/bin/bskyweb serve"

  ozone:
    ports:
      - 2585:3000
    build:
      context: ./repos/atproto/
      dockerfile: services/ozone/Dockerfile
    restart: always
    command: node --enable-source-maps api.js
    volumes:
      - ./data/ozone/:/data/
    env_file:
      - ./envs/ozone
    healthcheck:
      test: "wget -q --spider http://localhost:3000/xrpc/_health"
      interval: 5s
      retries: 20
    depends_on:
      database:
        condition: service_healthy

  ozone-web:
    ports:
      - 2586:3000
    build:
      context: ./repos/ozone/
    restart: always
    volumes:
      - ./data/ozone/:/data/
    env_file:
      - ./envs/ozone
    depends_on:
      database:
        condition: service_healthy

  jetstream:
    build:
      context: ./repos/jetstream/
      dockerfile: Dockerfile
    ports:
      - 6008:6008
    volumes:
      - ./data/jetstream:/data
    restart: always
    env_file:
      - ./envs/jetstream

  feed:
    ports:
      - 2587:3000
    build:
      context: ./repos/feed-generator/
    restart: always
    env_file:
      - ./envs/feed
    volumes:
      - ./data/feed:/data/
    depends_on:
      - jetstream

  chat:
    ports:
      - 3100:3100
    build:
      context: ./repos/chat/
    restart: always
    env_file:
      - ./envs/chat
    volumes:
      - ./data/chat:/data
