services:
  server:
    build:
      context: .
      dockerfile_inline: |
        FROM oven/bun:1.3.11
        WORKDIR /app
        RUN bun init -y && bun add @sqaoss/flowy@1.3.0
        WORKDIR /app/node_modules/@sqaoss/flowy/server
        RUN bun install --production
        EXPOSE 4000
        VOLUME /data
        CMD ["bun", "src/index.ts"]
    # Publish on loopback only — the server is unauthenticated, so it must not
    # be reachable from the LAN. Prefer the native `flowy serve` for local dev.
    ports:
      - "127.0.0.1:4000:4000"
    volumes:
      - flowy-data:/data
    environment:
      - FLOWY_DB_PATH=/data/flowy.sqlite
      - PORT=4000
      # Bind all interfaces *inside* the container so Docker's loopback-only
      # host publish above can reach it; the host port stays 127.0.0.1.
      - HOST=0.0.0.0
    healthcheck:
      test: ["CMD", "bun", "-e", "fetch('http://localhost:4000/health').then(r => r.ok ? process.exit(0) : process.exit(1))"]
      interval: 5s
      timeout: 3s
      retries: 5

volumes:
  flowy-data:
