# documentation: https://github.com/bluesky-social/pds
# slogan: Bluesky PDS (Personal Data Server)
# category: backend
# tags: bluesky, pds, platform
# logo: svgs/bluesky.svg
# port: 3000

services:
  pds:
    image: 'ghcr.io/bluesky-social/pds:0.4.182'
    volumes:
      - pds-data:/pds
    environment:
      - SERVICE_URL_PDS_3000
      - 'PDS_HOSTNAME=${SERVICE_FQDN_PDS}'
      - 'PDS_JWT_SECRET=${SERVICE_HEX_64_JWTSECRET}'
      - 'PDS_ADMIN_PASSWORD=${SERVICE_PASSWORD_ADMIN}'
      - 'PDS_ADMIN_EMAIL=${PDS_ADMIN_EMAIL}'
      - 'PDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX=${SERVICE_HEX_64_ROTATIONKEY}'
      - 'PDS_DATA_DIRECTORY=${PDS_DATA_DIRECTORY:-/pds}'
      - 'PDS_BLOBSTORE_DISK_LOCATION=${PDS_DATA_DIRECTORY:-/pds}/blocks'
      - 'PDS_BLOB_UPLOAD_LIMIT=${PDS_BLOB_UPLOAD_LIMIT:-104857600}'
      - 'PDS_DID_PLC_URL=${PDS_DID_PLC_URL:-https://plc.directory}'
      - 'PDS_EMAIL_FROM_ADDRESS=${PDS_EMAIL_FROM_ADDRESS}'
      - 'PDS_EMAIL_SMTP_URL=${PDS_EMAIL_SMTP_URL}'
      - 'PDS_BSKY_APP_VIEW_URL=${PDS_BSKY_APP_VIEW_URL:-https://api.bsky.app}'
      - 'PDS_BSKY_APP_VIEW_DID=${PDS_BSKY_APP_VIEW_DID:-did:web:api.bsky.app}'
      - 'PDS_REPORT_SERVICE_URL=${PDS_REPORT_SERVICE_URL:-https://mod.bsky.app/xrpc/com.atproto.moderation.createReport}'
      - 'PDS_REPORT_SERVICE_DID=${PDS_REPORT_SERVICE_DID:-did:plc:ar7c4by46qjdydhdevvrndac}'
      - 'PDS_CRAWLERS=${PDS_CRAWLERS:-https://bsky.network}'
      - 'LOG_ENABLED=${LOG_ENABLED:-true}'
    command: |
      sh -c '
        set -euo pipefail
        echo "Installing required packages and pdsadmin..."
        apk add --no-cache openssl curl bash jq coreutils gnupg util-linux-misc >/dev/null
        curl -o /usr/local/bin/pdsadmin.sh https://raw.githubusercontent.com/bluesky-social/pds/main/pdsadmin.sh
        chmod 700 /usr/local/bin/pdsadmin.sh
        ln -sf /usr/local/bin/pdsadmin.sh /usr/local/bin/pdsadmin
        echo "Creating an empty pds.env file so pdsadmin works..."
        touch ${PDS_DATA_DIRECTORY}/pds.env
        echo "Launching PDS, enjoy!..."
        exec node --enable-source-maps index.js
      '
    healthcheck:
      test:
        - CMD
        - wget
        - '--spider'
        - 'http://127.0.0.1:3000/xrpc/_health'
      interval: 5s
      timeout: 10s
      retries: 10
