x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  pocketbase:
    <<: *defaults
    image: ${GHCR_IO_REGISTRY:-ghcr.io}/muchobien/pocketbase:${PB_VERSION:-0.30.0}
    environment:
      TZ: ${TZ:-UTC}
      # Optional ENCRYPTION (Ensure this is a 32-character long encryption key)
      # $ openssl rand -hex 16
      # https://pocketbase.io/docs/going-to-production/#enable-settings-encryption
      ENCRYPTION: ${PB_ENCRYPTION}
      PB_ADMIN_EMAIL: ${PB_ADMIN_EMAIL:-admin@example.com}
      PB_ADMIN_PASSWORD: ${PB_ADMIN_PASSWORD:-supersecret123}
    ports:
      - '${PB_PORT:-8090}:8090'
    volumes:
      - pb_data:/pb_data

      # optional public and hooks folders
      - ./pb_public:/pb_public
      - ./pb_hooks:/pb_hooks
    healthcheck: # optional, recommended since v0.10.0
      test: wget --no-verbose --tries=1 --spider http://localhost:8090/api/health || exit 1
      interval: 5s
      timeout: 5s
      retries: 5
      start_period: 10s
    deploy:
      resources:
        limits:
          cpus: ${POCKETBASE_CPU_LIMIT:-0.25}
          memory: ${POCKETBASE_MEMORY_LIMIT:-256M}
        reservations:
          cpus: ${POCKETBASE_CPU_RESERVATION:-0.1}
          memory: ${POCKETBASE_MEMORY_RESERVATION:-128M}

volumes:
  pb_data:
