services:
  db:
    image: postgres:16
    container_name: memos-db
    hostname: memos-db
    environment:
      POSTGRES_DB: memos
      POSTGRES_USER: memosuser
      POSTGRES_PASSWORD: memospass
    volumes:
      - ./postgres_data:/var/lib/postgresql/data:rw
    healthcheck:
      test: ["CMD", "pg_isready", "-d", "memos", "-U", "memosuser"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: on-failure:3

  memos:
    image: ghcr.io/usememos/memos:latest
    container_name: memos
    hostname: memos
    ports:
      - "5230:5230"
    environment:
      MEMOS_DRIVER: postgres
      MEMOS_DSN: "postgresql://memosuser:memospass@memos-db:5432/memos?sslmode=disable"
    volumes:
      - ./data:/var/opt/memos:rw
    depends_on:
      db:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:5230/ || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
    restart: on-failure:3