version: '3'
volumes:
  dbvol:
    driver: local
services:
  db:
    image: postgres:14.3-alpine
    restart: always
    environment:
      - POSTGRES_USER=bsky
      - POSTGRES_PASSWORD=yksb
    # intentionally *not* exposing default postgresql port to host (conflicts with other local dev DBs)
    command: -p 6543
    ports:
      - '6543:6543'
    expose:
      - '6543'
    volumes: 
      - dbvol:/var/lib/postgresql/docker
      - ./docker-create-dev-dbs.sql:/docker-entrypoint-initdb.d/create-dev-dbs.sql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -p 6543 -U bsky"]
      interval: 3s
      timeout: 2s
      retries: 3

  plc:
    image: ghcr.io/bluesky-social/did-method-plc:plc-c54aea0373e65df0b87f5bc81710007092f539b1 # DID doc iteration branch
    ports:
      - "2582:2582"
    expose:
      - "2582"
    environment:
      - ENV=dev
      - DATABASE_URL=postgres://bsky:yksb@db:6543/plc_dev
      - PORT=2582
      - DEBUG_MODE=1
      - LOG_ENABLED=true
      - LOG_LEVEL=info
      - LOG_DESTINATION=1
    working_dir: /app/packages/server
    command: yarn run start
    links:
      - db
    depends_on:
      db:
        condition: service_healthy

  pds-one:
    image: ghcr.io/bluesky-social/atproto:pds-19d2bdc4576bfabe6609afe160cc2c220c351579
    ports:
      - "2583:2583"
    expose:
      - "2583"
    environment:
      - ENV=dev
      - DB_POSTGRES_URL=postgres://bsky:yksb@db:6543/pds_dev
      - AVAILABLE_USER_DOMAINS=.test,.dev.bsky.dev
      - DID_PLC_URL=http://plc:2582
      - PORT=2583
      - DEBUG_MODE=1
      - LOG_LEVEL=info
      - LOG_ENABLED=true
      - LOG_DESTINATION=1
    working_dir: /app/packages/pds
    command: yarn run start
    links:
      - db
      - plc
    depends_on:
      db:
        condition: service_healthy
      plc:
        condition: service_started

  bgs:
    # to build/run locally, uncomment this instead
    #build: ../bigsky/
    image: ghcr.io/bluesky-social/indigo:bigsky-ed809269938c453ebed3a05487acc6417d77bb4e
    ports:
      - "2470:2470"
    environment:
      - ATP_PLC_HOST=http://plc:2582
      - ATP_PDS_HOST=http://pds-one:2583
      - GOLOG_LOG_LEVEL=info
    links:
      - db
      - plc
      - pds-one
    depends_on:
      db:
        condition: service_healthy
      plc:
        condition: service_started
      pds-one:
        condition: service_started

  appview:
    image: ghcr.io/bluesky-social/atproto:bsky-19d2bdc4576bfabe6609afe160cc2c220c351579
    ports:
      - "2584:2584"
    expose:
      - "2584"
    environment:
      - ENV=dev
      - DB_POSTGRES_URL=postgres://bsky:yksb@db:6543/bsky_dev
      - DID_PLC_URL=http://plc:2582
      - PORT=2584
      - DEBUG_MODE=1
      - LOG_LEVEL=info
      - LOG_ENABLED=true
      - LOG_DESTINATION=1
    working_dir: /app/packages/bsky
    command: yarn run start
    links:
      - db
      - plc
      - bgs
    depends_on:
      db:
        condition: service_healthy
      plc:
        condition: service_started
      bgs:
        condition: service_started
