services:
  server:
    build:
      context: .
      dockerfile: ./Dockerfile
      target: server
    restart: unless-stopped
    depends_on:
      mongo:
        condition: service_healthy
    environment:
      - NODE_DB_URI=mongodb://mongo/habitica?replicaSet=rs # adjust if you run an external Mongo database
      - BASE_URL=http://127.0.0.1:3000 # change this to the URL under which your instance will be reachable
      - INVITE_ONLY=false # change to `true` after registration of initial users, to restrict further registrations
      - PUSH_CONFIGS_UNIFIEDPUSH_URL=${UP_BASE_URL:-} # optional: base URL for UnifiedPush distributor
      - PUSH_CONFIGS_UNIFIEDPUSH_AUTHORIZATION=${UP_AUTH_HEADER:-} # optional: Authorization header for UnifiedPush
    networks:
      - habitica
    ports:
      - "3000:3000"
  mongo:
    image: docker.io/mongo:latest
    restart: unless-stopped
    hostname: mongo
    command: ["--replSet", "rs", "--bind_ip_all", "--port", "27017"]
    healthcheck:
      test: ["CMD-SHELL", "echo \"try { rs.status() } catch (err) { rs.initiate({_id: 'rs', members: [{ _id: 0, host: 'mongo:27017' }]}) }\" | mongosh --quiet --port 27017"]
      interval: 10s
      timeout: 30s
      start_period: 0s
      start_interval: 1s
      retries: 30
    volumes:
      - ./mongodb-data/db:/data/db:rw,Z
      - ./mongodb-data/dbconf:/data/configdb:Z
    networks:
      habitica:
        aliases:
          - mongo
networks:
  habitica:
    driver: bridge
